key_item.hh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #ifndef I4_KEY_ITEM_HH
  9. #define I4_KEY_ITEM_HH
  10. #include "menu/menu.hh"
  11. #include "font/font.hh"
  12. #include "window/style.hh"
  13. #include "device/keys.hh"
  14. class i4_key_item_class : public i4_menu_item_class
  15. {
  16. protected :
  17. i4_color_hint_class *color;
  18. i4_font_hint_class *font;
  19. i4_str *text;
  20. w16 pad_lr, pad_ud;
  21. w16 use_key, key_modifiers;
  22. i4_bool key_focused, valid;
  23. public :
  24. i4_bool has_keyboard_focus() { return key_focused; }
  25. i4_key_item_class(
  26. const i4_const_str &_text,
  27. i4_color_hint_class *color_hint,
  28. i4_font_hint_class *font_hint,
  29. i4_graphical_style_class *style,
  30. w16 key=I4_NO_KEY,
  31. w16 key_modifiers=0,
  32. w16 pad_left_right=0,
  33. w16 pad_up_down=0
  34. );
  35. ~i4_key_item_class();
  36. char *name() { return "key_item"; }
  37. virtual void parent_draw(i4_draw_context_class &context);
  38. virtual void receive_event(i4_event *ev);
  39. // called when selected or key is pressed
  40. virtual void action() = 0;
  41. // if usage is disallowed then the item will be grayed out on the menu
  42. void allow_use() { valid=i4_T; }
  43. void disallow_use() { valid=i4_F; }
  44. virtual void do_press()
  45. {
  46. if (!valid) return;
  47. else i4_menu_item_class::do_press();
  48. }
  49. i4_menu_item_class *copy()
  50. {
  51. return 0; // don't use this key_item anymore..
  52. }
  53. } ;
  54. class i4_key_accel_watcher_class : public i4_event_handler_class
  55. {
  56. struct key_item_pointer_type
  57. {
  58. i4_key_item_class *modkey[8];
  59. i4_key_item_class **get_from_modifiers(w16 modifiers);
  60. }
  61. user[I4_NUM_KEYS];
  62. w32 total;
  63. i4_bool initialized;
  64. public:
  65. i4_key_accel_watcher_class();
  66. void watch_key(i4_key_item_class *who, w16 key, w16 modifiers);
  67. void unwatch_key(i4_key_item_class *who, w16 key, w16 modifiers);
  68. void receive_event(i4_event *ev);
  69. char *name() { return "key accel watcher"; }
  70. };
  71. #endif