newbutton.pp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. {
  2. * Demo showing the use of user defined object class: CROSSBUTTON
  3. *
  4. * Form definition file generated with fdesign.
  5. * changed stub button to crossbutton
  6. }
  7. uses xforms;
  8. Const FL_CROSSBUTTON=2000;
  9. FL_CROSSBUTTON_BW = 2;
  10. { How to draw it }
  11. type TSPEC = TFL_BUTTON_STRUCT;
  12. PSPEC = ^TSPEC;
  13. Procedure draw_crossbutton(ob : PFL_OBJECT);cdecl;
  14. var temp : longint;
  15. xx, yy, ww, hh ,tt : TFL_Coord;
  16. begin
  17. temp:=0;
  18. { if redraw is demanded by FL_ENTER, ignore it }
  19. if PSPEC(ob^.spec)^.event = FL_ENTER then exit;
  20. { draw the bounding box first }
  21. fl_drw_box(ob^.boxtype, ob^.x, ob^.y, ob^.w, ob^.h, ob^.col1, ob^.bw);
  22. { draw the box that contains the cross }
  23. if ob^.w>ob^.h then tt:=ob^.h else tt:=ob^.w;
  24. ww := tt div 2 - 1;
  25. hh:=ww;
  26. xx := ob^.x + FL_BOUND_WIDTH;
  27. yy := ob^.y + (ob^.h - hh) div 2;
  28. { if pushed, draw a down box with the cross }
  29. if PSPEC(ob^.spec)^.val<>0 then
  30. begin
  31. fl_drw_box(FL_DOWN_BOX, xx, yy, ww, hh, ob^.col1, ob^.bw);
  32. fl_drw_text(FL_ALIGN_CENTER, xx-2, yy-2, ww+4, hh+4, ob^.col2, 0, 0, '@9plus');
  33. end
  34. else
  35. begin
  36. fl_drw_box(FL_UP_BOX, xx, yy, ww, hh, ob^.col1, ob^.bw);
  37. end;
  38. { label }
  39. if (ob^.align = FL_ALIGN_CENTER) then
  40. fl_drw_text(FL_ALIGN_LEFT, xx + ww + 3, ob^.y, 0, ob^.h,
  41. ob^.lcol, ob^.lstyle, ob^.lsize, ob^.thelabel)
  42. else
  43. fl_draw_object_label_outside(ob);
  44. if (ob^.thetype = FL_RETURN_BUTTON) then
  45. fl_drw_text(FL_ALIGN_CENTER,
  46. TFL_Coord (ob^.x + ob^.w - round(0.8 * ob^.h)),
  47. TFL_Coord (ob^.y + round(0.2 * ob^.h)),
  48. TFL_Coord (round(0.6 * ob^.h)),
  49. TFL_Coord (round(0.6 * ob^.h)), ob^.lcol, 0, 0, '@returnarrow');
  50. end;
  51. { creation }
  52. function fl_create_crossbutton(Thetype : Longint; x,y,w,h : TFL_Coord; thelabel : Pchar) : PFL_OBJECT;
  53. var ob : PFL_OBJECT;
  54. begin
  55. fl_add_button_class(FL_CROSSBUTTON, PFL_Drawbutton(@draw_crossbutton), nil);
  56. ob := fl_create_generic_button(FL_CROSSBUTTON, thetype, x, y,w, h, thelabel);
  57. ob^.boxtype := FL_NO_BOX;
  58. ob^.col2 := FL_BLACK; { cross color }
  59. { ob^.bw := FL_CROSSBUTTON_BW; }
  60. fl_create_crossbutton:=ob;
  61. end;
  62. function fl_add_crossbutton(Thetype : longint; x,y,w,h : TFL_COORD; thelabel : pchar): PFL_OBJECT;
  63. var ob : PFL_OBJECT;
  64. theform : PFL_FORM;
  65. begin
  66. ob := fl_create_crossbutton(thetype, x, y, w, h, thelabel);
  67. theform:=fl_current_form;
  68. fl_add_object(theform, ob);
  69. fl_add_crossbutton:=ob;
  70. end;
  71. {*** Forms and Objects ***}
  72. type TFD_NEwBut = record
  73. newbut : PFL_FORM;
  74. bexit : PFL_object;
  75. vdata : pointer;
  76. ldata : Longint;
  77. end;
  78. PFD_NewBut= ^TFD_NewBut;
  79. function create_form_newbut : PFD_Newbut;
  80. var
  81. obj : PFL_OBJECT;
  82. fdui : PFD_newbut;
  83. oldbw : longint;
  84. begin
  85. new (fdui);
  86. oldbw := fl_get_border_width;
  87. fl_set_border_width(-2);
  88. fdui^.newbut := fl_bgn_form(FL_NO_BOX, 310, 190);
  89. obj := fl_add_box(FL_UP_BOX,0,0,310,190,'');
  90. obj := fl_add_labelframe(FL_ENGRAVED_FRAME,40,45,100,120,'CrossB');
  91. fl_set_object_boxtype(obj,FL_FLAT_BOX);
  92. fl_set_object_lstyle(obj,FL_BOLD_STYLE);
  93. obj := fl_add_crossbutton(FL_RADIO_BUTTON,50,115,80,30,'cross1');
  94. fl_set_object_color(obj,FL_COL1,FL_RED);
  95. obj := fl_add_crossbutton(FL_RADIO_BUTTON,50,85,80,30,'Button');
  96. fl_set_object_color(obj,FL_COL1,FL_GREEN);
  97. obj := fl_add_crossbutton(FL_RADIO_BUTTON,50,55,80,30,'Button');
  98. fl_set_object_color(obj,FL_COL1,FL_BLUE);
  99. obj := fl_add_labelframe(FL_ENGRAVED_FRAME,180,45,100,120,'CrossB');
  100. fl_set_object_boxtype(obj,FL_FLAT_BOX);
  101. fl_set_object_lstyle(obj,FL_BOLD_STYLE);
  102. obj := fl_add_crossbutton(FL_PUSH_BUTTON,190,115,80,30,'Button');
  103. fl_set_object_color(obj,FL_COL1,FL_RED);
  104. obj := fl_add_crossbutton(FL_PUSH_BUTTON,190,85,90,30,'Button');
  105. fl_set_object_color(obj,FL_COL1,FL_GREEN);
  106. obj := fl_add_crossbutton(FL_PUSH_BUTTON,190,55,80,30,'Button');
  107. fl_set_object_color(obj,FL_COL1,FL_BLUE);
  108. obj := fl_add_button(FL_NORMAL_BUTTON,125,10,65,25,'Exit');
  109. fdui^.bexit :=obj;
  110. fl_end_form;
  111. fl_set_border_width(oldbw);
  112. create_form_newbut:=fdui;
  113. end;
  114. var cbform : PFD_newbut;
  115. begin
  116. fl_initialize(@argc, argv, 'FormDemo', nil, 0);
  117. cbform := create_form_newbut();
  118. fl_show_form(cbform^.newbut, FL_PLACE_CENTER, 0, nil);
  119. while(fl_do_forms <> cbform^.bexit) do ;
  120. end.