USERBOX.C 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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/userbox.c $
  15. * $Revision: 1.4 $
  16. * $Author: john $
  17. * $Date: 1993/12/07 12:30:05 $
  18. *
  19. * Routines for user-boxes.
  20. *
  21. * $Log: userbox.c $
  22. * Revision 1.4 1993/12/07 12:30:05 john
  23. * new version.
  24. *
  25. * Revision 1.3 1993/10/26 13:46:13 john
  26. * *** empty log message ***
  27. *
  28. * Revision 1.2 1993/10/05 17:32:01 john
  29. * *** empty log message ***
  30. *
  31. * Revision 1.1 1993/09/20 10:35:53 john
  32. * Initial revision
  33. *
  34. *
  35. */
  36. #pragma off (unreferenced)
  37. static char rcsid[] = "$Id: userbox.c 1.4 1993/12/07 12:30:05 john Exp $";
  38. #pragma on (unreferenced)
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include "fix.h"
  42. #include "types.h"
  43. #include "gr.h"
  44. #include "ui.h"
  45. #include "key.h"
  46. void ui_draw_userbox( UI_GADGET_USERBOX * userbox )
  47. {
  48. if ( userbox->status==1 )
  49. {
  50. userbox->status = 0;
  51. ui_mouse_hide();
  52. gr_set_current_canvas( userbox->canvas );
  53. if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)userbox)
  54. gr_setcolor( CRED );
  55. else
  56. gr_setcolor( CBRIGHT );
  57. gr_box( -1, -1, userbox->width, userbox->height );
  58. ui_mouse_show();
  59. }
  60. }
  61. UI_GADGET_USERBOX * ui_add_gadget_userbox( UI_WINDOW * wnd, short x, short y, short w, short h )
  62. {
  63. UI_GADGET_USERBOX * userbox;
  64. userbox = (UI_GADGET_USERBOX *)ui_gadget_add( wnd, 7, x, y, x+w-1, y+h-1 );
  65. userbox->width = w;
  66. userbox->height = h;
  67. userbox->b1_held_down=0;
  68. userbox->b1_clicked=0;
  69. userbox->b1_double_clicked=0;
  70. userbox->b1_dragging=0;
  71. userbox->b1_drag_x1=0;
  72. userbox->b1_drag_y1=0;
  73. userbox->b1_drag_x2=0;
  74. userbox->b1_drag_y2=0;
  75. userbox->b1_done_dragging = 0;
  76. userbox->keypress = 0;
  77. userbox->mouse_onme = 0;
  78. userbox->mouse_x = 0;
  79. userbox->mouse_y = 0;
  80. userbox->bitmap = &(userbox->canvas->cv_bitmap);
  81. return userbox;
  82. }
  83. void ui_userbox_do( UI_GADGET_USERBOX * userbox, int keypress )
  84. {
  85. int OnMe, olddrag;
  86. OnMe = ui_mouse_on_gadget( (UI_GADGET *)userbox );
  87. olddrag = userbox->b1_dragging;
  88. userbox->mouse_onme = OnMe;
  89. userbox->mouse_x = Mouse.x - userbox->x1;
  90. userbox->mouse_y = Mouse.y - userbox->y1;
  91. userbox->b1_clicked = 0;
  92. if (OnMe)
  93. {
  94. if ( B1_JUST_PRESSED )
  95. {
  96. userbox->b1_dragging = 1;
  97. userbox->b1_drag_x1 = Mouse.x - userbox->x1;
  98. userbox->b1_drag_y1 = Mouse.y - userbox->y1;
  99. userbox->b1_clicked = 1;
  100. }
  101. if ( B1_PRESSED )
  102. {
  103. userbox->b1_held_down = 1;
  104. userbox->b1_drag_x2 = Mouse.x - userbox->x1;
  105. userbox->b1_drag_y2 = Mouse.y - userbox->y1;
  106. }
  107. else {
  108. userbox->b1_held_down = 0;
  109. userbox->b1_dragging = 0;
  110. }
  111. if ( B1_DOUBLE_CLICKED )
  112. userbox->b1_double_clicked = 1;
  113. else
  114. userbox->b1_double_clicked = 0;
  115. }
  116. if (!B1_PRESSED)
  117. userbox->b1_dragging = 0;
  118. userbox->b1_done_dragging = 0;
  119. if (olddrag==1 && userbox->b1_dragging==0 )
  120. {
  121. if ((userbox->b1_drag_x1 != userbox->b1_drag_x2) || (userbox->b1_drag_y1 != userbox->b1_drag_y2) )
  122. userbox->b1_done_dragging = 1;
  123. }
  124. if (CurWindow->keyboard_focus_gadget==(UI_GADGET *)userbox)
  125. userbox->keypress = keypress;
  126. ui_draw_userbox( userbox );
  127. }
  128.