openscreen.pas 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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;
  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. if not Assigned(P96Base) then
  52. begin
  53. writeln('Cannot open ', PICASSO96APINAME);
  54. Halt(5);
  55. end;
  56. Width:=640;
  57. Height:=480;
  58. Depth:=8;
  59. rda := ReadArgs(template,@vecarray,Nil);
  60. If rda<>Nil Then Begin
  61. If vecarray[0] <> 0 then Width := long(@vecarray[0]);
  62. If vecarray[1] <> 0 then Height := long(@vecarray[1]);
  63. If vecarray[2] <> 0 then Depth := long(@vecarray[2]);
  64. FreeArgs(rda);
  65. End;
  66. sc:=p96OpenScreenTags([P96SA_Width, Width,
  67. P96SA_Height, Height,
  68. P96SA_Depth, Depth,
  69. P96SA_AutoScroll, lTRUE,
  70. P96SA_Pens, AsTag(@Pens),
  71. P96SA_Title, AsTag(ScreenTitle),
  72. TAG_DONE]);
  73. If sc=Nil Then CleanUp('Unable to open screen.');
  74. Dimensions[0]:=0;
  75. Dimensions[1]:=sc^.BarHeight+1;
  76. Dimensions[2]:=sc^.Width;
  77. Dimensions[3]:=sc^.Height-sc^.BarHeight-1;
  78. wdp:=OpenWindowTags(NIL,[WA_CustomScreen, AsTag(sc),
  79. WA_Title, AsTag('Writepixel'),
  80. WA_Left, (sc^.Width DIV 2-200) DIV 2+sc^.Width DIV 2,
  81. WA_Top, (sc^.Height-sc^.BarHeight-300) DIV 2,
  82. WA_Zoom, AsTag(@Dimensions),
  83. WA_Width, 200,
  84. WA_Height, 300,
  85. WA_MinWidth, 100,
  86. WA_MinHeight, 100,
  87. WA_MaxWidth, -1,
  88. WA_MaxHeight, -1,
  89. WA_SimpleRefresh, lTRUE,
  90. WA_RMBTrap, lTRUE,
  91. WA_Activate, lTRUE,
  92. WA_CloseGadget, lTRUE,
  93. WA_DepthGadget, lTRUE,
  94. WA_DragBar, lTRUE,
  95. WA_SizeGadget, lTRUE,
  96. WA_SizeBBottom, lTRUE,
  97. WA_GimmeZeroZero, lTRUE,
  98. WA_ScreenTitle, AsTag(ScreenTitle),
  99. WA_IDCMP, IDCMP_RAWKEY + IDCMP_CLOSEWINDOW,
  100. TAG_DONE]);
  101. If wdp = Nil Then CleanUp('Unable to open window 1.');
  102. wdf:=OpenWindowTags(NIL,[WA_CustomScreen, PtrUInt(sc),
  103. WA_Title, PtrUInt(PChar('FillRect')),
  104. WA_Left,(sc^.Width div 2-200) div 2,
  105. WA_Top,(sc^.Height-sc^.BarHeight-300)div 2,
  106. WA_Zoom, PtrUInt(@Dimensions),
  107. WA_Width, 200,
  108. WA_Height, 300,
  109. WA_MinWidth, 100,
  110. WA_MinHeight, 100,
  111. WA_MaxWidth, -1,
  112. WA_MaxHeight, -1,
  113. WA_SimpleRefresh, lTRUE,
  114. WA_RMBTrap, lTRUE,
  115. WA_Activate, lTRUE,
  116. WA_CloseGadget, lTRUE,
  117. WA_DepthGadget, lTRUE,
  118. WA_DragBar, lTRUE,
  119. WA_SizeGadget, lTRUE,
  120. WA_SizeBBottom, lTRUE,
  121. WA_GimmeZeroZero, lTRUE,
  122. WA_ScreenTitle, PtrUInt(PChar(ScreenTitle)),
  123. WA_IDCMP, IDCMP_RAWKEY or IDCMP_CLOSEWINDOW,
  124. TAG_DONE]);
  125. If wdf = Nil Then CleanUp('Unable to open window 2.');
  126. rpf:=wdf^.RPort;
  127. rpp:=wdp^.RPort;
  128. terminate:=False;
  129. signals:= longint((1 shl wdf^.UserPort^.mp_SigBit) or (1 shl wdp^.UserPort^.mp_SigBit));
  130. format:= RGBFTYPE(p96GetBitMapAttr (sc^.RastPort.BitMap, P96BMA_RGBFORMAT));
  131. Randomize;
  132. Repeat
  133. x1:=Random (wdf^.Width);
  134. y1:=Random (wdf^.Height);
  135. x2:=Random (wdf^.Width);
  136. y2:=Random (wdf^.Height);
  137. If x2<x1 Then Begin
  138. x3:=x2;
  139. x2:=x1;
  140. x1:=x3;
  141. End;
  142. If y2<y1 Then Begin
  143. y3:=y2;
  144. y2:=y1;
  145. y1:=y3;
  146. End;
  147. x3:=Random (wdp^.Width);
  148. y3:=Random (wdp^.Height);
  149. If format=RGBFB_CLUT Then Begin
  150. SetAPen (rpf, Random (255));
  151. RectFill (rpf,x1,y1,x2,y2);
  152. SetAPen (rpp, Random (255));
  153. WritePixel (rpp,x3,y3);
  154. End Else Begin
  155. p96RectFill (rpf, x1, y1, x2, y2,(Random(255) shl 16)+(Random(255) shl 8)+(Random (255)));
  156. p96WritePixel (rpp, x3, y3, ((Random(255)) shl 16) or ((Random(255)) shl 8) or (Random(255)));
  157. End;
  158. Repeat
  159. imsg:=pIntuiMessage(GetMsg (wdf^.UserPort));
  160. If imsg<>Nil Then Begin
  161. If ((imsg^.IClass=IDCMP_CLOSEWINDOW) Or ((imsg^.IClass=IDCMP_RAWKEY) And ((imsg^.Code=$40) or (imsg^.Code=$45)))) Then
  162. terminate:=True;
  163. ReplyMsg (pMessage(imsg));
  164. End;
  165. Until imsg=Nil;
  166. Repeat
  167. imsg:=pIntuiMessage(GetMsg (wdp^.UserPort));
  168. If imsg<>Nil Then Begin
  169. If ((imsg^.IClass=IDCMP_CLOSEWINDOW) Or ((imsg^.IClass=IDCMP_RAWKEY) And ((imsg^.Code=$40) or (imsg^.Code=$45)))) Then
  170. terminate:=True;
  171. ReplyMsg (pMessage(imsg));
  172. End;
  173. Until imsg=Nil;
  174. Until terminate;
  175. Forbid;
  176. Repeat
  177. msg:=GetMsg (wdf^.UserPort);
  178. If msg<>Nil Then
  179. ReplyMsg (msg);
  180. Until msg=Nil;
  181. Repeat
  182. msg:=GetMsg (wdp^.UserPort);
  183. If msg<>Nil Then
  184. ReplyMsg (msg);
  185. Until msg=Nil;
  186. Permit;
  187. CleanUp('');
  188. END.