openscreen.pas 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. PROGRAM OpenScreen;
  2. {***********************************************************************
  3. * This is an example that shows how to open a p96 Screen and a Window
  4. * to get input events and how to paint on that screen.
  5. * Program terminates when space bar or any mouse button is pressed!
  6. *
  7. * alex (Sun Dec 29 01:42:59 1996)
  8. ***********************************************************************}
  9. {
  10. Translated to fpc pascal.
  11. 14 Mars 2001.
  12. Updated for fpc 1.0.7
  13. 08 Jan 2003.
  14. [email protected]
  15. }
  16. uses exec, amigados, agraphics, intuition, picasso96api, utility,systemvartags;
  17. Const
  18. Pens : Array [0..0] Of integer = (NOT(0));
  19. template : pchar = 'Width=W/N,Height=H/N,Depth=D/N';
  20. ScreenTitle : pchar = 'Picasso96 API Test';
  21. vecarray : Array[0..2] of longint = (0,0,0);
  22. ltrue : longint = 1;
  23. Var
  24. sc : pScreen;
  25. wdf,
  26. wdp : pWindow;
  27. rpf,
  28. rpp : pRastPort;
  29. terminate : Boolean;
  30. signals : longint;
  31. format : RGBFTYPE;
  32. x1, y1,
  33. x2, y2,
  34. x3, y3 : word;
  35. imsg : pIntuiMessage;
  36. msg : pMessage;
  37. Dimensions : Array [0..3] Of word;
  38. Width,
  39. Height,
  40. Depth : longint;
  41. rda : pRDArgs;
  42. procedure CleanUp(str : string);
  43. begin
  44. if assigned(wdp) then CloseWindow(wdp);
  45. if assigned(wdf) then CloseWindow(wdf);
  46. if assigned(sc) then p96CloseScreen(sc);
  47. if str <> '' then writeln(str);
  48. halt;
  49. end;
  50. BEGIN
  51. Width:=640;
  52. Height:=480;
  53. Depth:=8;
  54. rda := ReadArgs(template,@vecarray,Nil);
  55. If rda<>Nil Then Begin
  56. If vecarray[0] <> 0 then Width := long(@vecarray[0]);
  57. If vecarray[1] <> 0 then Height := long(@vecarray[1]);
  58. If vecarray[2] <> 0 then Depth := long(@vecarray[2]);
  59. FreeArgs(rda);
  60. End;
  61. sc:=p96OpenScreenTags([P96SA_Width, Width,
  62. P96SA_Height, Height,
  63. P96SA_Depth, Depth,
  64. P96SA_AutoScroll, lTRUE,
  65. P96SA_Pens, @Pens,
  66. P96SA_Title, ScreenTitle,
  67. TAG_DONE]);
  68. If sc=Nil Then CleanUp('Unable to open screen.');
  69. Dimensions[0]:=0;
  70. Dimensions[1]:=sc^.BarHeight+1;
  71. Dimensions[2]:=sc^.Width;
  72. Dimensions[3]:=sc^.Height-sc^.BarHeight-1;
  73. wdp:=OpenWindowTags(NIL,[WA_CustomScreen, sc,
  74. WA_Title,'Writepixel',
  75. WA_Left, (sc^.Width DIV 2-200) DIV 2+sc^.Width DIV 2,
  76. WA_Top, (sc^.Height-sc^.BarHeight-300) DIV 2,
  77. WA_Zoom, @Dimensions,
  78. WA_Width, 200,
  79. WA_Height, 300,
  80. WA_MinWidth, 100,
  81. WA_MinHeight, 100,
  82. WA_MaxWidth, -1,
  83. WA_MaxHeight, -1,
  84. WA_SimpleRefresh, lTRUE,
  85. WA_RMBTrap, lTRUE,
  86. WA_Activate, lTRUE,
  87. WA_CloseGadget, lTRUE,
  88. WA_DepthGadget, lTRUE,
  89. WA_DragBar, lTRUE,
  90. WA_SizeGadget, lTRUE,
  91. WA_SizeBBottom, lTRUE,
  92. WA_GimmeZeroZero, lTRUE,
  93. WA_ScreenTitle,ScreenTitle,
  94. WA_IDCMP, IDCMP_RAWKEY + IDCMP_CLOSEWINDOW,
  95. TAG_DONE]);
  96. If wdp = Nil Then CleanUp('Unable to open window 1.');
  97. wdf:=OpenWindowTags(NIL,[WA_CustomScreen,sc,
  98. WA_Title, 'FillRect',
  99. WA_Left,(sc^.Width div 2-200) div 2,
  100. WA_Top,(sc^.Height-sc^.BarHeight-300)div 2,
  101. WA_Zoom, @Dimensions,
  102. WA_Width, 200,
  103. WA_Height, 300,
  104. WA_MinWidth, 100,
  105. WA_MinHeight, 100,
  106. WA_MaxWidth, -1,
  107. WA_MaxHeight, -1,
  108. WA_SimpleRefresh, lTRUE,
  109. WA_RMBTrap, lTRUE,
  110. WA_Activate, lTRUE,
  111. WA_CloseGadget, lTRUE,
  112. WA_DepthGadget, lTRUE,
  113. WA_DragBar, lTRUE,
  114. WA_SizeGadget, lTRUE,
  115. WA_SizeBBottom, lTRUE,
  116. WA_GimmeZeroZero, lTRUE,
  117. WA_ScreenTitle, ScreenTitle,
  118. WA_IDCMP, IDCMP_RAWKEY or IDCMP_CLOSEWINDOW,
  119. TAG_DONE]);
  120. If wdf = Nil Then CleanUp('Unable to open window 2.');
  121. rpf:=wdf^.RPort;
  122. rpp:=wdp^.RPort;
  123. terminate:=False;
  124. signals:= longint((1 shl wdf^.UserPort^.mp_SigBit) or (1 shl wdp^.UserPort^.mp_SigBit));
  125. format:= RGBFTYPE(p96GetBitMapAttr (sc^.RastPort.BitMap, P96BMA_RGBFORMAT));
  126. Randomize;
  127. Repeat
  128. x1:=Random (wdf^.Width);
  129. y1:=Random (wdf^.Height);
  130. x2:=Random (wdf^.Width);
  131. y2:=Random (wdf^.Height);
  132. If x2<x1 Then Begin
  133. x3:=x2;
  134. x2:=x1;
  135. x1:=x3;
  136. End;
  137. If y2<y1 Then Begin
  138. y3:=y2;
  139. y2:=y1;
  140. y1:=y3;
  141. End;
  142. x3:=Random (wdp^.Width);
  143. y3:=Random (wdp^.Height);
  144. If format=RGBFB_CLUT Then Begin
  145. SetAPen (rpf, Random (255));
  146. RectFill (rpf,x1,y1,x2,y2);
  147. SetAPen (rpp, Random (255));
  148. WritePixel (rpp,x3,y3);
  149. End Else Begin
  150. p96RectFill (rpf, x1, y1, x2, y2,(Random(255) shl 16)+(Random(255) shl 8)+(Random (255)));
  151. p96WritePixel (rpp, x3, y3, ((Random(255)) shl 16) or ((Random(255)) shl 8) or (Random(255)));
  152. End;
  153. Repeat
  154. imsg:=pIntuiMessage(GetMsg (wdf^.UserPort));
  155. If imsg<>Nil Then Begin
  156. If ((imsg^.IClass=IDCMP_CLOSEWINDOW) Or ((imsg^.IClass=IDCMP_RAWKEY) And ((imsg^.Code=$40) or (imsg^.Code=$45)))) Then
  157. terminate:=True;
  158. ReplyMsg (pMessage(imsg));
  159. End;
  160. Until imsg=Nil;
  161. Repeat
  162. imsg:=pIntuiMessage(GetMsg (wdp^.UserPort));
  163. If imsg<>Nil Then Begin
  164. If ((imsg^.IClass=IDCMP_CLOSEWINDOW) Or ((imsg^.IClass=IDCMP_RAWKEY) And ((imsg^.Code=$40) or (imsg^.Code=$45)))) Then
  165. terminate:=True;
  166. ReplyMsg (pMessage(imsg));
  167. End;
  168. Until imsg=Nil;
  169. Until terminate;
  170. Forbid;
  171. Repeat
  172. msg:=GetMsg (wdf^.UserPort);
  173. If msg<>Nil Then
  174. ReplyMsg (msg);
  175. Until msg=Nil;
  176. Repeat
  177. msg:=GetMsg (wdp^.UserPort);
  178. If msg<>Nil Then
  179. ReplyMsg (msg);
  180. Until msg=Nil;
  181. Permit;
  182. CleanUp('');
  183. END.