tritongadgets.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. Triton_App := TR_CreateAppTags([
  44. TRCA_Name,'TritonGadtools',
  45. TRCA_LongName,'GadToolsDemo in Triton',
  46. TRCA_Version,'0.01',
  47. TRCA_Info,'Just a test of Triton',
  48. TRCA_Release,'1.0',
  49. TRCA_Date,'26-05-1998',
  50. TAG_DONE]);
  51. if Triton_App = nil then CleanExit('Can''t create Application',20);
  52. ProjectStart;
  53. WindowID(1);
  54. WindowTitle('Instead of GadTools :)');
  55. WindowPosition(TRWP_CENTERTOP);
  56. HorizGroupA;
  57. Space;
  58. VertGroupA;
  59. Space;
  60. LineArray;
  61. BeginLine;
  62. Space;
  63. TextID('_Volume:',MYGAD_SLIDER); SetTRTag(TRAT_Flags,TROF_RIGHTALIGN);
  64. Space;
  65. SliderGadget(SLIDER_MIN,SLIDER_MAX,5,MYGAD_SLIDER);
  66. Space;
  67. TextID('5',MYGAD_SLIDERTEXT); SetTRTag(TRAT_MinWidth, 2);
  68. Space;
  69. EndLine;
  70. SpaceS;
  71. BeginLine;
  72. Space;
  73. TextID('_First:',MYGAD_STRING1); SetTRTag(TRAT_Flags, TROF_RIGHTALIGN);
  74. Space;
  75. StringGadget('Try pressing',MYGAD_STRING1); SetTRTag(TRAT_Value,50);
  76. Space;
  77. EndLine;
  78. SpaceS;
  79. BeginLine;
  80. Space;
  81. TextID('_Second:',MYGAD_STRING2); SetTRTag(TRAT_Flags, TROF_RIGHTALIGN);
  82. Space;
  83. StringGadget('TAB or Shift-TAB',MYGAD_STRING2); SetTRTag(TRAT_Value,50);
  84. Space;
  85. EndLine;
  86. SpaceS;
  87. BeginLine;
  88. Space;
  89. TextID('_Third:',MYGAD_STRING3); SetTRTag(TRAT_Flags, TROF_RIGHTALIGN);
  90. Space;
  91. StringGadget('To see what happens!',MYGAD_STRING3); SetTRTag(TRAT_Value,50);
  92. Space;
  93. EndLine;
  94. EndArray;
  95. Space;
  96. CenteredButton('_Click Here',MYGAD_BUTTON);
  97. Space;
  98. EndGroup;
  99. Space;
  100. EndGroup;
  101. EndProject;
  102. Project := TR_OpenProject(Triton_App,@tritontags);
  103. IF Project = NIL THEN CleanExit('No project',20);
  104. quit := False;
  105. WHILE NOT quit DO BEGIN
  106. dummy := TR_Wait(Triton_App,0);
  107. REPEAT
  108. trmsg := TR_GetMsg(Triton_App);
  109. IF trmsg <> NIL THEN BEGIN
  110. IF (trmsg^.trm_Project = Project) THEN BEGIN
  111. CASE trmsg^.trm_Class OF
  112. TRMS_CLOSEWINDOW : quit := True;
  113. TRMS_NEWVALUE :
  114. BEGIN
  115. case trmsg^.trm_ID of
  116. MYGAD_SLIDER : begin
  117. TR_SetText(Project,MYGAD_SLIDERTEXT,LongToStr(trmsg^.trm_Data));
  118. writeln('Slider at level ',trmsg^.trm_Data);
  119. end;
  120. MYGAD_STRING1 : writeln('String Gadget 1: "',TR_GetString(Project,MYGAD_STRING1),'".');
  121. MYGAD_STRING2 : writeln('String Gadget 2: "',TR_GetString(Project,MYGAD_STRING2),'".');
  122. MYGAD_STRING3 : writeln('String Gadget 3: "',TR_GetString(Project,MYGAD_STRING3),'".');
  123. END;
  124. END;
  125. TRMS_ACTION :
  126. BEGIN
  127. if trmsg^.trm_ID = MYGAD_BUTTON then begin
  128. TR_SetValue(Project,MYGAD_SLIDER,SLIDER_DEF);
  129. TR_SetText(Project,MYGAD_SLIDERTEXT,LongToStr(SLIDER_DEF));
  130. writeln('Button was pressed, slider reset to 10.');
  131. end;
  132. END;
  133. TRMS_ERROR: WriteLN(TR_GetErrorString(trmsg^.trm_Data));
  134. END;
  135. END;
  136. TR_ReplyMsg(trmsg);
  137. END;
  138. UNTIL quit OR (trmsg = NIL);
  139. END;
  140. CleanExit('',0);
  141. END.