ChrisOS Research ProjectOperating systems · language systems · graphics · machine emulation
DOCUMENTATION ARCHIVEMAIN BRANCH
ChrisOS/Source reference: LIB/WIN.CC

Source reference: LIB/WIN.CC

Deterministic source record. The complete textual file is reproduced below; this page does not replace architectural interpretation in the authored chapters.

File identity

Field Value
Path LIB/WIN.CC
Lines 576
Bytes 12383
SHA-256 49efa9f1ed2e1a98f8cb64222dc9501c98fb1ff7de9b6e5c6f5f4ce9095d78c7
ChrisOS revision da3df29cb397932c43d32373871fb9380e688ade

Detected syntactic dependencies

Line Include
— No preprocessor include detected.

Detected symbols

Line Symbol
33 win_origin
41 win_mouse_in
61 win_begin
339 win_begin_keep
344 win_end
347 win_click
370 win_ox
374 win_oy
378 win_w
382 win_h
386 win_edge
390 win_vscroll
483 win_hscroll

Complete source

The following block is the complete textual file at the recorded revision. No lines are elided, abbreviated or paraphrased.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
#pragma abi(1, 0)

int g_win_x;
int g_win_y;
int g_win_w;
int g_win_h;
int g_win_drag;
int g_win_ox;
int g_win_oy;
int g_win_prev;
int g_win_edge;
int g_win_ready;
int g_win_placed;
int g_bar_h;
int g_win_max;
int g_win_restore_x;
int g_win_restore_y;
int g_win_restore_w;
int g_win_restore_h;
int g_win_resize;
int g_win_resize_x;
int g_win_resize_y;
int g_win_resize_mx;
int g_win_resize_my;
int g_win_resize_sx;
int g_win_resize_sy;
int g_win_resize_sw;
int g_win_resize_sh;
int g_win_skip_body;
int g_vdrag;
int g_hdrag;

void win_origin(int x, int y) {
  if (g_win_ready == 0) {
    g_win_x = x;
    g_win_y = y;
    g_win_placed = 1;
  }
}

int win_mouse_in() {
  int mx;
  int my;
  mx = mouse_x();
  my = mouse_y();
  if (mx < g_win_x) {
    return 0;
  }
  if (my < g_win_y) {
    return 0;
  }
  if (mx >= g_win_x + g_win_w) {
    return 0;
  }
  if (my >= g_win_y + g_win_h) {
    return 0;
  }
  return 1;
}

int win_begin(int w, int h, int title) {
  int mx;
  int my;
  int mb;
  int dw;
  int dh;
  int was;
  int lx;
  int ly;
  int nx;
  int ny;
  int nw;
  int nh;
  int changed;
  dw = disp_w();
  dh = disp_h();
  g_bar_h = 40;
  if (g_win_ready == 0) {
    g_win_w = w;
    g_win_h = h;
    if (g_win_placed == 0) {
      g_win_x = 56;
      g_win_y = 48;
    }
    if (g_win_x + g_win_w > dw) {
      g_win_x = 8;
    }
    if (g_win_y + g_win_h > dh - g_bar_h) {
      g_win_y = 8;
    }
    viewport(g_win_w, g_win_h);
    surf_place(g_win_x, g_win_y, g_win_w, g_win_h);
    g_win_ready = 1;
  }
  mx = mouse_x();
  my = mouse_y();
  mb = mouse_btn();
  was = g_win_prev;
  g_win_edge = 0;
  if (mb) {
    if (was == 0) {
      g_win_edge = 1;
    }
  }
  if (g_win_drag) {
    if (mb == 0) {
      g_win_drag = 0;
    } else {
      g_win_x = mx - g_win_ox;
      g_win_y = my - g_win_oy;
      if (g_win_y < 0) {
        g_win_y = 0;
      }
      if (g_win_y + g_win_h > dh - g_bar_h) {
        g_win_y = dh - g_bar_h - g_win_h;
        if (g_win_y < 0) {
          g_win_y = 0;
        }
      }
      if (g_win_x < 0) {
        g_win_x = 0;
      }
      if (g_win_x + g_win_w > dw) {
        g_win_x = dw - g_win_w;
        if (g_win_x < 0) {
          g_win_x = 0;
        }
      }
      surf_move(g_win_x, g_win_y);
    }
  } else {
    if (g_win_resize) {
      if (mb == 0) {
        g_win_resize = 0;
      } else {
        nx = g_win_resize_sx;
        ny = g_win_resize_sy;
        nw = g_win_resize_sw;
        nh = g_win_resize_sh;
        if (g_win_resize_x < 0) {
          nx = g_win_resize_sx + (mx - g_win_resize_mx);
          nw = g_win_resize_sw - (mx - g_win_resize_mx);
        }
        if (g_win_resize_x > 0) {
          nw = g_win_resize_sw + (mx - g_win_resize_mx);
        }
        if (g_win_resize_y < 0) {
          ny = g_win_resize_sy + (my - g_win_resize_my);
          nh = g_win_resize_sh - (my - g_win_resize_my);
        }
        if (g_win_resize_y > 0) {
          nh = g_win_resize_sh + (my - g_win_resize_my);
        }
        if (nw < 240) {
          if (g_win_resize_x < 0) {
            nx = nx - (240 - nw);
          }
          nw = 240;
        }
        if (nh < 160) {
          if (g_win_resize_y < 0) {
            ny = ny - (160 - nh);
          }
          nh = 160;
        }
        if (nx < 0) {
          if (g_win_resize_x < 0) {
            nw = nw + nx;
          }
          nx = 0;
        }
        if (ny < 0) {
          if (g_win_resize_y < 0) {
            nh = nh + ny;
          }
          ny = 0;
        }
        if (nx + nw > dw) {
          nw = dw - nx;
        }
        if (ny + nh > dh - g_bar_h) {
          nh = dh - g_bar_h - ny;
        }
        changed = 0;
        if (nx != g_win_x) {
          changed = 1;
        }
        if (ny != g_win_y) {
          changed = 1;
        }
        if (nw != g_win_w) {
          changed = 1;
        }
        if (nh != g_win_h) {
          changed = 1;
        }
        if (changed) {
          g_win_x = nx;
          g_win_y = ny;
          g_win_w = nw;
          g_win_h = nh;
          viewport(g_win_w, g_win_h);
          surf_place(g_win_x, g_win_y, g_win_w, g_win_h);
        }
      }
    } else {
      if (g_win_edge) {
      lx = mx - g_win_x;
      ly = my - g_win_y;
      if (mx >= g_win_x + g_win_w - 22) {
        if (mx < g_win_x + g_win_w) {
          if (my >= g_win_y) {
            if (my < g_win_y + 20) {
              g_win_prev = mb;
              surf_close();
              return 0;
            }
          }
        }
      }
      if (mx >= g_win_x + g_win_w - 44) {
        if (mx < g_win_x + g_win_w - 22) {
          if (my >= g_win_y) {
            if (my < g_win_y + 20) {
              if (g_win_max) {
                g_win_x = g_win_restore_x;
                g_win_y = g_win_restore_y;
                g_win_w = g_win_restore_w;
                g_win_h = g_win_restore_h;
                g_win_max = 0;
                viewport(g_win_w, g_win_h);
                surf_restore(g_win_x, g_win_y, g_win_w, g_win_h);
              } else {
                g_win_restore_x = g_win_x;
                g_win_restore_y = g_win_y;
                g_win_restore_w = g_win_w;
                g_win_restore_h = g_win_h;
                g_win_x = 0;
                g_win_y = 0;
                g_win_w = dw;
                g_win_h = dh - g_bar_h;
                g_win_max = 1;
                viewport(g_win_w, g_win_h);
                surf_maximize(g_win_x, g_win_y, g_win_w, g_win_h);
              }
              g_win_prev = mb;
              return 1;
            }
          }
        }
      }
      if (mx >= g_win_x + g_win_w - 66) {
        if (mx < g_win_x + g_win_w - 44) {
          if (my >= g_win_y) {
            if (my < g_win_y + 20) {
              g_win_prev = mb;
              surf_minimize();
              return 1;
            }
          }
        }
      }
      if (g_win_max == 0) {
        g_win_resize_x = 0;
        g_win_resize_y = 0;
        if (lx >= 0) {
          if (lx < 5) {
            g_win_resize_x = -1;
          }
        }
        if (lx >= g_win_w - 5) {
          if (lx < g_win_w) {
            g_win_resize_x = 1;
          }
        }
        if (ly >= 0) {
          if (ly < 5) {
            g_win_resize_y = -1;
          }
        }
        if (ly >= g_win_h - 5) {
          if (ly < g_win_h) {
            g_win_resize_y = 1;
          }
        }
        if (g_win_resize_x != 0) {
          g_win_resize = 1;
        }
        if (g_win_resize_y != 0) {
          g_win_resize = 1;
        }
        if (g_win_resize) {
          g_win_resize_mx = mx;
          g_win_resize_my = my;
          g_win_resize_sx = g_win_x;
          g_win_resize_sy = g_win_y;
          g_win_resize_sw = g_win_w;
          g_win_resize_sh = g_win_h;
          surf_raise();
          g_win_prev = mb;
          return 1;
        }
      }
      if (mx >= g_win_x) {
        if (mx < g_win_x + g_win_w - 66) {
          if (my >= g_win_y) {
            if (my < g_win_y + 20) {
              g_win_drag = 1;
              g_win_ox = mx - g_win_x;
              g_win_oy = my - g_win_y;
              surf_raise();
            }
          }
        }
      }
      }
    }
  }
  g_win_prev = mb;
  fillrgb(0, 0, g_win_w, 20, 0x00221C18);
  if (g_win_skip_body == 0) {
    fillrgb(0, 20, g_win_w, g_win_h - 20, 0x00F3EEE4);
  }
  g_win_skip_body = 0;
  fillrgb(g_win_w - 66, 0, 22, 20, 0x00685850);
  fillrgb(g_win_w - 44, 0, 22, 20, 0x00685850);
  fillrgb(g_win_w - 22, 0, 22, 20, 0x00804030);
  text(6, 3, title, 0x00F3EEE4);
  text(g_win_w - 59, 3, "_", 0x00FFFFFF);
  if (g_win_max) {
    text(g_win_w - 38, 3, "R", 0x00FFFFFF);
  } else {
    text(g_win_w - 38, 3, "M", 0x00FFFFFF);
  }
  text(g_win_w - 15, 3, "X", 0x00FFFFFF);
  return 1;
}

int win_begin_keep(int w, int h, int title) {
  g_win_skip_body = 1;
  return win_begin(w, h, title);
}

void win_end() {
}

int win_click(int x, int y, int w, int h) {
  int mx;
  int my;
  if (g_win_edge == 0) {
    return 0;
  }
  if (win_mouse_in() == 0) {
    return 0;
  }
  mx = mouse_x() - g_win_x;
  my = mouse_y() - g_win_y;
  if (mx >= x) {
    if (mx < x + w) {
      if (my >= y) {
        if (my < y + h) {
          return 1;
        }
      }
    }
  }
  return 0;
}

int win_ox() {
  return g_win_x;
}

int win_oy() {
  return g_win_y;
}

int win_w() {
  return g_win_w;
}

int win_h() {
  return g_win_h;
}

int win_edge() {
  return g_win_edge;
}

int win_vscroll(int x, int y, int h, int max_off, int view, int scroll) {
  int track;
  int ty;
  int th;
  int mx;
  int my;
  int ns;
  int mb;
  if (h < 40) {
    return scroll;
  }
  if (max_off < 0) {
    max_off = 0;
  }
  if (scroll < 0) {
    scroll = 0;
  }
  if (scroll > max_off) {
    scroll = max_off;
  }
  track = h - 32;
  fillrgb(x, y, 14, h, 0x00202830);
  fillrgb(x + 1, y + 1, 12, 14, 0x00406080);
  text(x + 3, y + 1, "^", 0x00FFFFFF);
  fillrgb(x + 1, y + h - 15, 12, 14, 0x00406080);
  text(x + 3, y + h - 14, "v", 0x00FFFFFF);
  if (max_off <= 0) {
    fillrgb(x + 2, y + 16, 10, track, 0x00304050);
  } else {
    th = (track * view) / (view + max_off);
    if (th < 12) {
      th = 12;
    }
    if (th > track) {
      th = track;
    }
    ty = y + 16 + ((track - th) * scroll) / max_off;
    fillrgb(x + 2, y + 16, 10, track, 0x00304050);
    fillrgb(x + 2, ty, 10, th, 0x007090B0);
  }
  mb = mouse_btn();
  if (mb == 0) {
    g_vdrag = 0;
  }
  if (win_mouse_in()) {
    mx = mouse_x() - g_win_x;
    my = mouse_y() - g_win_y;
    if (mb) {
      if (mx >= x) {
        if (mx < x + 14) {
          if (my >= y) {
            if (my < y + 16) {
              ns = scroll - 1;
              if (ns < 0) {
                ns = 0;
              }
              return ns;
            }
          }
          if (my >= y + h - 16) {
            if (my < y + h) {
              ns = scroll + 1;
              if (ns > max_off) {
                ns = max_off;
              }
              return ns;
            }
          }
          if (my >= y + 16) {
            if (my < y + h - 16) {
              g_vdrag = 1;
            }
          }
        }
      }
    }
  }
  if (g_vdrag) {
    if (max_off > 0) {
      my = mouse_y() - g_win_y;
      ns = ((my - (y + 16)) * max_off) / track;
      if (ns < 0) {
        ns = 0;
      }
      if (ns > max_off) {
        ns = max_off;
      }
      return ns;
    }
  }
  return scroll;
}

int win_hscroll(int x, int y, int w, int max_off, int view, int scroll) {
  int track;
  int tx;
  int tw;
  int mx;
  int my;
  int ns;
  int mb;
  if (w < 40) {
    return scroll;
  }
  if (max_off < 0) {
    max_off = 0;
  }
  if (scroll < 0) {
    scroll = 0;
  }
  if (scroll > max_off) {
    scroll = max_off;
  }
  track = w - 32;
  fillrgb(x, y, w, 14, 0x00202830);
  fillrgb(x + 1, y + 1, 14, 12, 0x00406080);
  text(x + 3, y + 1, "<", 0x00FFFFFF);
  fillrgb(x + w - 15, y + 1, 14, 12, 0x00406080);
  text(x + w - 12, y + 1, ">", 0x00FFFFFF);
  if (max_off <= 0) {
    fillrgb(x + 16, y + 2, track, 10, 0x00304050);
  } else {
    tw = (track * view) / (view + max_off);
    if (tw < 12) {
      tw = 12;
    }
    if (tw > track) {
      tw = track;
    }
    tx = x + 16 + ((track - tw) * scroll) / max_off;
    fillrgb(x + 16, y + 2, track, 10, 0x00304050);
    fillrgb(tx, y + 2, tw, 10, 0x007090B0);
  }
  mb = mouse_btn();
  if (mb == 0) {
    g_hdrag = 0;
  }
  if (win_mouse_in()) {
    mx = mouse_x() - g_win_x;
    my = mouse_y() - g_win_y;
    if (mb) {
      if (my >= y) {
        if (my < y + 14) {
          if (mx >= x) {
            if (mx < x + 16) {
              ns = scroll - 4;
              if (ns < 0) {
                ns = 0;
              }
              return ns;
            }
          }
          if (mx >= x + w - 16) {
            if (mx < x + w) {
              ns = scroll + 4;
              if (ns > max_off) {
                ns = max_off;
              }
              return ns;
            }
          }
          if (mx >= x + 16) {
            if (mx < x + w - 16) {
              g_hdrag = 1;
            }
          }
        }
      }
    }
  }
  if (g_hdrag) {
    if (max_off > 0) {
      mx = mouse_x() - g_win_x;
      ns = ((mx - (x + 16)) * max_off) / track;
      if (ns < 0) {
        ns = 0;
      }
      if (ns > max_off) {
        ns = max_off;
      }
      return ns;
    }
  }
  return scroll;
}

Role of this record

The atlas guarantees file-by-file traceability. Responsibility, invariants, ownership, concurrency, security, performance and subsystem interactions belong in authored chapters and must cite this file when applicable.

Document record ID: source-49efa9f1ed2e1a98 Reviewed source: da3df29cb397 Class: generated-source-reference