gemwin.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. {
  2. Copyright (c) 2017 Karoly Balogh
  3. Simple, resizable and movable GEM Window
  4. Example program for Free Pascal's Atari TOS bindings
  5. This example program is in the Public Domain under the terms of
  6. Unlicense: http://unlicense.org/
  7. **********************************************************************}
  8. {$APPTYPE GUI}
  9. program gemwin;
  10. uses
  11. aes, vdi, xbios;
  12. var
  13. win_h: smallint;
  14. win_name: pchar;
  15. win_info: pchar;
  16. vdi_h: smallint;
  17. const
  18. WIN_KIND = NAME or INFO or CLOSER or MOVER or SIZER or FULLER;
  19. function open_vwk: smallint;
  20. var
  21. work_in: array[0..16] of smallint;
  22. work_out: array[0..64] of smallint;
  23. dummy, i: smallint;
  24. handle: smallint;
  25. begin
  26. handle:=graf_handle(@dummy,@dummy,@dummy,@dummy);
  27. work_in[0]:=2+xbios_getrez();
  28. for i:=1 to 9 do work_in[i]:=1;
  29. work_in[10]:=2;
  30. v_opnvwk(@work_in, @handle, @work_out);
  31. open_vwk:=handle;
  32. end;
  33. function open_win: smallint;
  34. var
  35. handle: smallint;
  36. dim: TGRECT;
  37. begin
  38. handle:=wind_create(WIN_KIND, 0, 0, 0, 0);
  39. win_name:='FPC GEM Window';
  40. wind_set(handle, WF_NAME, hi(ptruint(win_name)), lo(ptruint(win_name)), 0, 0);
  41. win_info:='Move me and resize me...';
  42. wind_set(handle, WF_INFO, hi(ptruint(win_info)), lo(ptruint(win_info)), 0, 0);
  43. wind_get(0, WF_WORKXYWH, @dim.x, @dim.y, @dim.w, @dim.h);
  44. dim.x:=dim.x + (dim.w div 20);
  45. dim.y:=dim.y + (dim.h div 20);
  46. dim.w:=dim.w - (dim.w div 20) * 2;
  47. dim.h:=dim.h - (dim.h div 20) * 2;
  48. wind_open(handle, dim.x, dim.y, dim.w, dim.h);
  49. open_win:=handle;
  50. end;
  51. procedure wind_set_grect(wh: smallint; rect: PGRECT);
  52. var
  53. fsrect: TGRECT;
  54. begin
  55. if rect = nil then
  56. begin
  57. wind_get(0, WF_WORKXYWH, @fsrect.x, @fsrect.y, @fsrect.w, @fsrect.h);
  58. rect:=@fsrect;
  59. end;
  60. wind_set(wh,WF_CURRXYWH,rect^.x,rect^.y,rect^.w,rect^.h);
  61. end;
  62. function min(a, b: smallint): smallint;
  63. begin
  64. if a < b then
  65. min:=a
  66. else
  67. min:=b;
  68. end;
  69. function max(a, b: smallint): smallint;
  70. begin
  71. if a > b then
  72. max:=a
  73. else
  74. max:=b;
  75. end;
  76. function rc_intersect(p1: PGRECT; p2: PGRECT): boolean;
  77. var
  78. tx, ty, tw, th: smallint;
  79. begin
  80. tw:=min(p2^.x+p2^.w, p1^.x+p1^.w);
  81. th:=min(p2^.y+p2^.h, p1^.y+p1^.h);
  82. tx:=max(p2^.x, p1^.x);
  83. ty:=max(p2^.y, p1^.y);
  84. p2^.x:=tx;
  85. p2^.y:=ty;
  86. p2^.w:=tw-tx;
  87. p2^.h:=th-ty;
  88. rc_intersect:=(tw > tx) and (th > ty);
  89. end;
  90. procedure wind_redraw(wh: smallint; rect: PGRECT);
  91. var
  92. xyarray: array[0..3] of smallint;
  93. wrect: TGRECT;
  94. begin
  95. wind_update(BEG_UPDATE);
  96. v_hide_c(vdi_h);
  97. wind_get(wh,WF_WORKXYWH,@wrect.x,@wrect.y,@wrect.w,@wrect.h);
  98. if rc_intersect(rect,@wrect) then
  99. begin
  100. xyarray[0]:=wrect.x;
  101. xyarray[1]:=wrect.y;
  102. xyarray[2]:=wrect.x+wrect.w-1;
  103. xyarray[3]:=wrect.y+wrect.h-1;
  104. vsf_color(vdi_h,WHITE);
  105. v_bar(vdi_h,@xyarray);
  106. end;
  107. v_show_c(vdi_h,1);
  108. wind_update(END_UPDATE);
  109. end;
  110. procedure event_loop;
  111. var
  112. msg_buf: array[0..7] of smallint;
  113. begin
  114. repeat
  115. evnt_mesag(@msg_buf);
  116. case msg_buf[0] of
  117. WM_CLOSED:
  118. break;
  119. WM_REDRAW:
  120. wind_redraw(win_h,PGRECT(@msg_buf[4]));
  121. WM_MOVED,
  122. WM_SIZED:
  123. wind_set_grect(win_h,PGRECT(@msg_buf[4]));
  124. WM_FULLED:
  125. wind_set_grect(win_h,nil);
  126. end;
  127. until false;
  128. end;
  129. begin
  130. appl_init;
  131. vdi_h:=open_vwk;
  132. win_h:=open_win;
  133. event_loop;
  134. wind_close(win_h);
  135. wind_delete(win_h);
  136. v_clsvwk(vdi_h);
  137. appl_exit;
  138. end.