ICON.C 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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/icon.c $
  15. * $Revision: 1.2 $
  16. * $Author: john $
  17. * $Date: 1994/11/18 23:07:33 $
  18. *
  19. * An icon class.
  20. *
  21. * $Log: icon.c $
  22. * Revision 1.2 1994/11/18 23:07:33 john
  23. * Changed a bunch of shorts to ints.
  24. *
  25. * Revision 1.1 1993/12/07 12:30:23 john
  26. * Initial revision
  27. *
  28. *
  29. */
  30. #pragma off (unreferenced)
  31. static char rcsid[] = "$Id: icon.c 1.2 1994/11/18 23:07:33 john Exp $";
  32. #pragma on (unreferenced)
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include "mem.h"
  36. #include "fix.h"
  37. #include "types.h"
  38. #include "gr.h"
  39. #include "ui.h"
  40. #include "key.h"
  41. #define Middle(x) ((2*(x)+1)/4)
  42. extern void ui_draw_shad( short x1, short y1, short x2, short y2, short c1, short c2 );
  43. void ui_draw_box_in1( short x1, short y1, short x2, short y2 )
  44. {
  45. gr_setcolor( CWHITE );
  46. gr_urect( x1+1, y1+1, x2-1, y2-1 );
  47. ui_draw_shad( x1+0, y1+0, x2-0, y2-0, CGREY, CBRIGHT );
  48. }
  49. void ui_draw_icon( UI_GADGET_ICON * icon )
  50. {
  51. int height, width, avg;
  52. int x, y;
  53. if ((icon->status==1) || (icon->position != icon->oldposition))
  54. {
  55. icon->status = 0;
  56. ui_mouse_hide();
  57. gr_set_current_canvas( icon->canvas );
  58. gr_get_string_size(icon->text, &width, &height, &avg );
  59. x = ((icon->width-1)/2)-((width-1)/2);
  60. y = ((icon->height-1)/2)-((height-1)/2);
  61. if (icon->position==1 )
  62. {
  63. // Draw pressed
  64. ui_draw_box_in( 0, 0, icon->width, icon->height );
  65. x += 2; y += 2;
  66. }
  67. else if (icon->flag)
  68. {
  69. // Draw part out
  70. ui_draw_box_in1( 0, 0, icon->width, icon->height );
  71. x += 1; y += 1;
  72. }
  73. else
  74. {
  75. // Draw released!
  76. ui_draw_box_out( 0, 0, icon->width, icon->height );
  77. }
  78. gr_set_fontcolor( CBLACK, -1 );
  79. gr_ustring( x, y, icon->text );
  80. ui_mouse_show();
  81. }
  82. }
  83. UI_GADGET_ICON * ui_add_gadget_icon( UI_WINDOW * wnd, char * text, short x, short y, short w, short h, int k,int (*f)(void) )
  84. {
  85. UI_GADGET_ICON * icon;
  86. icon = (UI_GADGET_ICON *)ui_gadget_add( wnd, 9, x, y, x+w-1, y+h-1 );
  87. icon->width = w;
  88. icon->height = h;
  89. //MALLOC( icon->text, char, strlen( text )+2);//Hack by KRB
  90. icon->text=(char *)malloc((strlen( text )+2)*sizeof(char));
  91. strcpy( icon->text, text );
  92. icon->trap_key = k;
  93. icon->user_function = f;
  94. icon->oldposition = 0;
  95. icon->position = 0;
  96. icon->pressed = 0;
  97. icon->canvas->cv_font = ui_small_font;
  98. // Call twice to get original;
  99. if (f)
  100. {
  101. icon->flag = (byte)f();
  102. icon->flag = (byte)f();
  103. } else {
  104. icon->flag = 0;
  105. }
  106. return icon;
  107. }
  108. void ui_icon_do( UI_GADGET_ICON * icon, int keypress )
  109. {
  110. int OnMe;
  111. OnMe = ui_mouse_on_gadget( (UI_GADGET *)icon );
  112. icon->oldposition = icon->position;
  113. if ( B1_PRESSED && OnMe )
  114. {
  115. icon->position = 1;
  116. } else {
  117. icon->position = 0;
  118. }
  119. icon->pressed = 0;
  120. if ((icon->position==0) && (icon->oldposition==1) && OnMe )
  121. icon->pressed = 1;
  122. if (icon->pressed == 1 || keypress==icon->trap_key )
  123. {
  124. icon->status = 1;
  125. icon->flag = (byte)icon->user_function();
  126. if (keypress==icon->trap_key) last_keypress = 0;
  127. }
  128. ui_draw_icon( icon );
  129. }
  130.