tritongadgets.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. PROGRAM GadgetDemo;
  2. uses triton, tritonmacros, utility;
  3. {
  4. If you have seen gadtoolsgadgets.c in the RKRM's then you
  5. have seen this program. One diffs is that this example
  6. is made in Triton. Much better.:)
  7. Jun 06 1998
  8. Updated for fpc 1.0.7
  9. 11 Jan 2003.
  10. [email protected]
  11. }
  12. CONST
  13. MYGAD_SLIDER = 1;
  14. MYGAD_SLIDERTEXT = 10;
  15. MYGAD_STRING1 = 2;
  16. MYGAD_STRING2 = 3;
  17. MYGAD_STRING3 = 4;
  18. MYGAD_BUTTON = 5;
  19. (* Range for the slider: *)
  20. SLIDER_MIN = 1;
  21. SLIDER_MAX = 20;
  22. SLIDER_DEF = 10;
  23. VAR
  24. Project : pTR_Project;
  25. trmsg : pTR_Message;
  26. quit : Boolean;
  27. dummy : longint;
  28. Triton_App : pTR_App;
  29. Function longToStr (I : Longint) : String;
  30. Var S : String;
  31. begin
  32. Str (I,S);
  33. longToStr:=S;
  34. end;
  35. PROCEDURE CleanExit(errstring : STRING; rc : Integer);
  36. BEGIN
  37. IF Project <> NIL THEN TR_CloseProject(Project);
  38. if Triton_App <> nil then TR_DeleteApp(Triton_App);
  39. IF errstring <> '' THEN WriteLn(errstring);
  40. Halt(rc)
  41. END;
  42. begin
  43. if not Assigned(TritonBase) then
  44. begin
  45. writeln('cannot open ' + TRITONNAME);
  46. Halt(5);
  47. end;
  48. Triton_App := TR_CreateAppTags([
  49. TRCA_Name, AsTag('TritonGadtools'),
  50. TRCA_LongName, AsTag('GadToolsDemo in Triton'),
  51. TRCA_Version, AsTag('0.01'),
  52. TRCA_Info, AsTag('Just a test of Triton'),
  53. TRCA_Release, AsTag('1.0'),
  54. TRCA_Date, AsTag('26-05-1998'),
  55. TAG_DONE]);
  56. if Triton_App = nil then CleanExit('Can''t create Application',20);
  57. ProjectStart;
  58. WindowID(1);
  59. WindowTitle('Instead of GadTools :)');
  60. WindowPosition(TRWP_CENTERTOP);
  61. HorizGroupA;
  62. Space;
  63. VertGroupA;
  64. Space;
  65. LineArray;
  66. BeginLine;
  67. Space;
  68. TextID('_Volume:',MYGAD_SLIDER); SetTRTag(TRAT_Flags,TROF_RIGHTALIGN);
  69. Space;
  70. SliderGadget(SLIDER_MIN,SLIDER_MAX,5,MYGAD_SLIDER);
  71. Space;
  72. TextID(string('5'),MYGAD_SLIDERTEXT); SetTRTag(TRAT_MinWidth, 2);
  73. Space;
  74. EndLine;
  75. SpaceS;
  76. BeginLine;
  77. Space;
  78. TextID('_First:',MYGAD_STRING1); SetTRTag(TRAT_Flags, TROF_RIGHTALIGN);
  79. Space;
  80. StringGadget('Try pressing',MYGAD_STRING1); SetTRTag(TRAT_Value,50);
  81. Space;
  82. EndLine;
  83. SpaceS;
  84. BeginLine;
  85. Space;
  86. TextID('_Second:',MYGAD_STRING2); SetTRTag(TRAT_Flags, TROF_RIGHTALIGN);
  87. Space;
  88. StringGadget('TAB or Shift-TAB',MYGAD_STRING2); SetTRTag(TRAT_Value,50);
  89. Space;
  90. EndLine;
  91. SpaceS;
  92. BeginLine;
  93. Space;
  94. TextID('_Third:',MYGAD_STRING3); SetTRTag(TRAT_Flags, TROF_RIGHTALIGN);
  95. Space;
  96. StringGadget('To see what happens!',MYGAD_STRING3); SetTRTag(TRAT_Value,50);
  97. Space;
  98. EndLine;
  99. EndArray;
  100. Space;
  101. CenteredButton('_Click Here',MYGAD_BUTTON);
  102. Space;
  103. EndGroup;
  104. Space;
  105. EndGroup;
  106. EndProject;
  107. Project := TR_OpenProject(Triton_App,@tritontags);
  108. IF Project = NIL THEN CleanExit('No project',20);
  109. quit := False;
  110. WHILE NOT quit DO BEGIN
  111. dummy := TR_Wait(Triton_App,0);
  112. REPEAT
  113. trmsg := TR_GetMsg(Triton_App);
  114. IF trmsg <> NIL THEN BEGIN
  115. IF (trmsg^.trm_Project = Project) THEN BEGIN
  116. CASE trmsg^.trm_Class OF
  117. TRMS_CLOSEWINDOW : quit := True;
  118. TRMS_NEWVALUE :
  119. BEGIN
  120. case trmsg^.trm_ID of
  121. MYGAD_SLIDER : begin
  122. TR_SetText(Project,MYGAD_SLIDERTEXT,LongToStr(trmsg^.trm_Data));
  123. writeln('Slider at level ',trmsg^.trm_Data);
  124. end;
  125. MYGAD_STRING1 : writeln('String Gadget 1: "',TR_GetString(Project,MYGAD_STRING1),'".');
  126. MYGAD_STRING2 : writeln('String Gadget 2: "',TR_GetString(Project,MYGAD_STRING2),'".');
  127. MYGAD_STRING3 : writeln('String Gadget 3: "',TR_GetString(Project,MYGAD_STRING3),'".');
  128. END;
  129. END;
  130. TRMS_ACTION :
  131. BEGIN
  132. if trmsg^.trm_ID = MYGAD_BUTTON then begin
  133. TR_SetValue(Project,MYGAD_SLIDER,SLIDER_DEF);
  134. TR_SetText(Project,MYGAD_SLIDERTEXT,LongToStr(SLIDER_DEF));
  135. writeln('Button was pressed, slider reset to 10.');
  136. end;
  137. END;
  138. TRMS_ERROR: WriteLN(TR_GetErrorString(trmsg^.trm_Data));
  139. END;
  140. END;
  141. TR_ReplyMsg(trmsg);
  142. END;
  143. UNTIL quit OR (trmsg = NIL);
  144. END;
  145. CleanExit('',0);
  146. END.