RADIO.C 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/radio.c $
  15. * $Revision: 1.5 $
  16. * $Author: john $
  17. * $Date: 1994/04/22 11:10:15 $
  18. *
  19. * Radio box gadget stuff.
  20. *
  21. * $Log: radio.c $
  22. * Revision 1.5 1994/04/22 11:10:15 john
  23. * *** empty log message ***
  24. *
  25. * Revision 1.4 1993/12/07 12:29:40 john
  26. * new version.
  27. *
  28. * Revision 1.3 1993/10/26 13:46:39 john
  29. * *** empty log message ***
  30. *
  31. * Revision 1.2 1993/10/05 17:31:42 john
  32. * *** empty log message ***
  33. *
  34. * Revision 1.1 1993/09/20 10:35:36 john
  35. * Initial revision
  36. *
  37. *
  38. */
  39. #pragma off (unreferenced)
  40. static char rcsid[] = "$Id: radio.c 1.5 1994/04/22 11:10:15 john Exp $";
  41. #pragma on (unreferenced)
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include "fix.h"
  45. #include "types.h"
  46. #include "gr.h"
  47. #include "ui.h"
  48. #include "key.h"
  49. #include "mono.h"
  50. #define Middle(x) ((2*(x)+1)/4)
  51. void ui_draw_radio( UI_GADGET_RADIO * radio )
  52. {
  53. if ((radio->status==1) || (radio->position != radio->oldposition))
  54. {
  55. radio->status = 0;
  56. ui_mouse_hide();
  57. gr_set_current_canvas( radio->canvas );
  58. if (radio->flag)
  59. gr_set_fontcolor( CRED, -1 );
  60. else
  61. gr_set_fontcolor( CBLACK, -1 );
  62. if (radio->position == 0 )
  63. {
  64. ui_draw_box_out( 0, 0, radio->width-1, radio->height-1 );
  65. ui_string_centered( Middle(radio->width), Middle(radio->height), "þ" );
  66. } else {
  67. ui_draw_box_in( 0, 0, radio->width-1, radio->height-1 );
  68. ui_string_centered( Middle(radio->width)+1, Middle(radio->height)+1, "þ" );
  69. }
  70. if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)radio)
  71. gr_set_fontcolor( CRED, CWHITE );
  72. else
  73. gr_set_fontcolor( CBLACK, CWHITE );
  74. gr_ustring( radio->width+4, 2, radio->text );
  75. ui_mouse_show();
  76. }
  77. }
  78. UI_GADGET_RADIO * ui_add_gadget_radio( UI_WINDOW * wnd, short x, short y, short w, short h, short group, char * text )
  79. {
  80. UI_GADGET_RADIO * radio;
  81. radio = (UI_GADGET_RADIO *)ui_gadget_add( wnd, 4, x, y, x+w-1, y+h-1 );
  82. radio->text = strdup(text);
  83. radio->width = w;
  84. radio->height = h;
  85. radio->position = 0;
  86. radio->oldposition = 0;
  87. radio->pressed = 0;
  88. radio->flag = 0;
  89. radio->group = group;
  90. return radio;
  91. }
  92. void ui_radio_do( UI_GADGET_RADIO * radio, int keypress )
  93. {
  94. UI_GADGET * tmp;
  95. UI_GADGET_RADIO * tmpr;
  96. int OnMe, ButtonLastSelected;
  97. keypress = keypress;
  98. OnMe = ui_mouse_on_gadget( (UI_GADGET *)radio );
  99. radio->oldposition = radio->position;
  100. if (selected_gadget != NULL)
  101. {
  102. if (selected_gadget->kind==4)
  103. ButtonLastSelected = 1;
  104. else
  105. ButtonLastSelected = 0;
  106. } else
  107. ButtonLastSelected = 1;
  108. if ( B1_PRESSED && OnMe && ButtonLastSelected )
  109. {
  110. radio->position = 1;
  111. } else {
  112. radio->position = 0;
  113. }
  114. if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)radio) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) )
  115. radio->position = 2;
  116. if ((radio->position==0) && (radio->oldposition==1) && OnMe )
  117. radio->pressed = 1;
  118. else if ((radio->position==0) && (radio->oldposition==2) && (CurWindow->keyboard_focus_gadget==(UI_GADGET *)radio) )
  119. radio->pressed = 1;
  120. else
  121. radio->pressed = 0;
  122. if ((radio->pressed == 1) && (radio->flag==0))
  123. {
  124. tmp = (UI_GADGET *)radio->next;
  125. while (tmp != (UI_GADGET *)radio )
  126. {
  127. if (tmp->kind==4)
  128. {
  129. tmpr = (UI_GADGET_RADIO *)tmp;
  130. if ((tmpr->group == radio->group ) && (tmpr->flag) )
  131. {
  132. tmpr->flag = 0;
  133. tmpr->status = 1;
  134. tmpr->pressed = 0;
  135. }
  136. }
  137. tmp = tmp->next;
  138. }
  139. radio->flag = 1;
  140. }
  141. ui_draw_radio( radio );
  142. }
  143.