CHECKBOX.C 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/ui/rcs/checkbox.c $
  15. * $Revision: 1.4 $
  16. * $Author: john $
  17. * $Date: 1993/12/07 12:30:47 $
  18. *
  19. * Routines for doing checkbox gadgets.
  20. *
  21. * $Log: checkbox.c $
  22. * Revision 1.4 1993/12/07 12:30:47 john
  23. * new version.
  24. *
  25. * Revision 1.3 1993/10/26 13:46:20 john
  26. * *** empty log message ***
  27. *
  28. * Revision 1.2 1993/10/05 17:30:42 john
  29. * *** empty log message ***
  30. *
  31. * Revision 1.1 1993/09/20 10:35:07 john
  32. * Initial revision
  33. *
  34. *
  35. */
  36. #pragma off (unreferenced)
  37. static char rcsid[] = "$Id: checkbox.c 1.4 1993/12/07 12:30:47 john Exp $";
  38. #pragma on (unreferenced)
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include "mem.h"
  42. #include "fix.h"
  43. #include "types.h"
  44. #include "gr.h"
  45. #include "ui.h"
  46. #include "key.h"
  47. #define Middle(x) ((2*(x)+1)/4)
  48. void ui_draw_checkbox( UI_GADGET_CHECKBOX * checkbox )
  49. {
  50. if ((checkbox->status==1) || (checkbox->position != checkbox->oldposition))
  51. {
  52. checkbox->status = 0;
  53. ui_mouse_hide();
  54. gr_set_current_canvas( checkbox->canvas );
  55. if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)checkbox)
  56. gr_set_fontcolor( CRED, -1 );
  57. else
  58. gr_set_fontcolor( CBLACK, -1 );
  59. if (checkbox->position == 0 )
  60. {
  61. ui_draw_box_out( 0, 0, checkbox->width-1, checkbox->height-1 );
  62. if (checkbox->flag)
  63. ui_string_centered( Middle(checkbox->width), Middle(checkbox->height), "X" );
  64. else
  65. ui_string_centered( Middle(checkbox->width), Middle(checkbox->height), " " );
  66. } else {
  67. ui_draw_box_in( 0, 0, checkbox->width-1, checkbox->height-1 );
  68. if (checkbox->flag)
  69. ui_string_centered( Middle(checkbox->width)+1, Middle(checkbox->height)+1, "X" );
  70. else
  71. ui_string_centered( Middle(checkbox->width)+1, Middle(checkbox->height)+1, " " );
  72. }
  73. gr_ustring( checkbox->width+4, 2, checkbox->text );
  74. ui_mouse_show();
  75. }
  76. }
  77. UI_GADGET_CHECKBOX * ui_add_gadget_checkbox( UI_WINDOW * wnd, short x, short y, short w, short h, short group, char * text )
  78. {
  79. UI_GADGET_CHECKBOX * checkbox;
  80. checkbox = (UI_GADGET_CHECKBOX *)ui_gadget_add( wnd, 5, x, y, x+w-1, y+h-1 );
  81. checkbox->text = malloc(strlen(text)+5);
  82. strcpy(checkbox->text,text);
  83. checkbox->width = w;
  84. checkbox->height = h;
  85. checkbox->position = 0;
  86. checkbox->oldposition = 0;
  87. checkbox->pressed = 0;
  88. checkbox->flag = 0;
  89. checkbox->group = group;
  90. return checkbox;
  91. }
  92. void ui_checkbox_do( UI_GADGET_CHECKBOX * checkbox, int keypress )
  93. {
  94. int OnMe, ButtonLastSelected;
  95. keypress = keypress;
  96. OnMe = ui_mouse_on_gadget( (UI_GADGET *)checkbox );
  97. checkbox->oldposition = checkbox->position;
  98. if ((selected_gadget != NULL) && (selected_gadget->kind !=5))
  99. ButtonLastSelected = 0;
  100. else
  101. ButtonLastSelected = 1;
  102. if ( B1_PRESSED && OnMe && ButtonLastSelected )
  103. {
  104. checkbox->position = 1;
  105. } else {
  106. checkbox->position = 0;
  107. }
  108. if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)checkbox) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) )
  109. checkbox->position = 2;
  110. if ((checkbox->position==0) && (checkbox->oldposition==1) && OnMe )
  111. checkbox->pressed = 1;
  112. else if ((checkbox->position==0) && (checkbox->oldposition==2) && (CurWindow->keyboard_focus_gadget==(UI_GADGET *)checkbox) )
  113. checkbox->pressed = 1;
  114. else
  115. checkbox->pressed = 0;
  116. if (checkbox->pressed == 1)
  117. checkbox->flag ^= 1;
  118. ui_draw_checkbox( checkbox );
  119. }
  120.