free1.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. { This demo is meant to demonstrate the use of a free
  2. object in a form.
  3. }
  4. program free1;
  5. uses xforms;
  6. Const
  7. onn : boolean = True;
  8. dcol : longint = 1;
  9. var
  10. cole : TFL_COLOR;
  11. form : PFL_FORM;
  12. obj : PFL_OBJECT;
  13. i, j, depth, col : Longint;
  14. dummy : cardinal;
  15. { The call back routine }
  16. function handle_it(obj : PFL_OBJECT; event : longint;
  17. mx,my : TFL_Coord;
  18. key : longint; ev : pointer) : longint;cdecl;
  19. begin
  20. exit;
  21. case event of
  22. FL_DRAW:
  23. fl_rect(obj^.x,obj^.y,obj^.w,obj^.h, obj^.u_ldata);
  24. FL_RELEASE:
  25. onn := not(onn);
  26. FL_STEP:
  27. if (onn) then
  28. begin
  29. if (obj^.u_ldata = cole) then
  30. dcol := -1;
  31. if (obj^.u_ldata = FL_FREE_COL1) then
  32. dcol := 1;
  33. obj^.u_ldata := dcol;
  34. fl_redraw_object(obj);
  35. end;
  36. end;
  37. handle_it:=0;
  38. end;
  39. procedure done(ob : PFL_OBJECT; data : longint); cdecl;
  40. begin
  41. halt(0)
  42. end;
  43. begin
  44. fl_initialize(@argc, argv, 'FormDemo', nil, 0);
  45. form := fl_bgn_form(FL_UP_BOX,400,400);
  46. obj := fl_add_button(FL_NORMAL_BUTTON,320,20,40,30,'Exit');
  47. fl_set_object_callback(obj, PFL_CALLBACKPTR(@done), 0);
  48. obj := fl_add_free(FL_CONTINUOUS_FREE,40,80,320,280
  49. ,'',PFL_HANDLEPTR(@handle_it));
  50. fl_end_form();
  51. depth := fl_get_visual_depth;
  52. { can't do it if less than 4 bit deep }
  53. if depth=8 then writeln ('depth of 8');
  54. if (depth < 4) then
  55. begin
  56. writeln ('This Demo requires a depth of at least 4 bits');
  57. halt(1);
  58. end;
  59. cole := ((1 shl depth)-1);
  60. if (cole > 64) then
  61. cole := 64;
  62. col := FL_FREE_COL1;
  63. { obj^.u_ldata := col;
  64. } cole := cole+col;
  65. i:=col;
  66. while i<=cole do
  67. begin
  68. j := round(255 * (i - col) /(cole - col));
  69. dummy:=fl_mapcolor(i, j, j, j);
  70. inc(i);
  71. end;
  72. fl_show_form(form,FL_PLACE_CENTER,FL_NOBORDER,'Free Object');
  73. fl_do_forms();
  74. end.