/* -*- c++ -*- FILE: EventHandler.h RCS REVISION: $Revision: 1.25 $ COPYRIGHT: (c) 1999 -- 2003 Melinda Green, Don Hatch, and Jay Berkenbilt - Superliminal Software LICENSE: Free to use and modify for non-commercial purposes as long as the following conditions are adhered to: 1) Obvious credit for the source of this code and the designs it embodies are clearly made, and 2) Ports and derived versions of 4D Magic Cube programs are not distributed without the express written permission of the authors. DESCRIPTION: Generic EventHandler class. This class is designed to be machine-dependent. New ports of MagicCube4d can derive new Machine and Widgets classes to use this. There are a few issues with this collection of interfaces, however: */ //// 1. Only the UNIX code uses it right now. //// //// 2. Some of the macro support lives in the X Machine and Widget //// classes and would not exist in a port based soley on the current //// interfaces. (For example, the fast automoves button is created in //// MachineX directly.) #ifndef EVENTHANDLER_H #define EVENTHANDLER_H #include #include "MagicCube.h" #include "Preferences.h" class Machine; class Widgets; class PolygonManager4D; class PuzzleState; class History; class MacroManager; class EventHandler { public: typedef void (EventHandler::*callback_fn)(void*); enum event_type_e { EXPOSE, RESIZE, BUTTONDOWN, BUTTONUP, KEYPRESS, KEYRELEASE, DRAG }; enum button_e { LEFTBUTTON, MIDDLEBUTTON, RIGHTBUTTON }; // Event should really be its own class in its own file, but it's // not objectified enough to warrant this. Better to hide it in // here. class Event { public: event_type_e type; int x; int y; int w; int h; // dx, dy are deltas for drag event int dx; int dy; button_e button; int key; bool shift_is_down; bool control_is_down; }; class Callback { public: Callback(EventHandler* e, callback_fn cb, void *arg) : event_handler(e), callback(cb), arg(arg) { }; void apply() { (event_handler->*callback)(arg); } private: EventHandler* event_handler; callback_fn callback; void *arg; }; EventHandler(int argc, char** argv, char const* machine_type); ~EventHandler(); Callback* createCallback(callback_fn, void*); void run(); void undo_cb(void*); void redo_cb(void*); void add_cb(void*); void delete_cb(void*); void toggleFast_cb(void*); void scramble_cb(void *); void cheat_cb(void *); void reset_cb(void *); void save_cb(void *); void quit_cb(void *); void print_cb(void *); void newPuzzle_cb(void *); void applyMacro_cb(void *); void invertMacro_cb(void *); void expose_handler(Event*, void *); void buttonDown_handler(Event *event, void *); void keyPress_handler(Event *event, void *); void keyRelease_handler(Event *event, void *); void drag_handler(Event *event, void *); private: // Prohibit copying and assignment EventHandler(EventHandler const&); EventHandler& operator=(EventHandler const&); void readLogfile(char *filename); void dump(FILE *fp); // Return true on success bool writeLogfile(char *filename); void showAnimation(struct stickerspec *grip, int dir, int slicesmask); void getAReferenceSticker(Event* event, void *); // Button callback functions... void cancelAdd_cb(void *arg = 0); void applyMacroCBAfterGotRefStickers(void *arg = 0); void cancelApplyMacro_cb(void *); int macro_which; int macro_invert; static int const nrefs = 3; int refs[3][4]; // FIX THIS-- this is getting really hacky void applyMacroCommon(void *w, bool invert); void doneAdd_cb(void *); void addCBAfterGotRefStickers(void *arg = 0); void cancelDelete_cb(void *); Preferences preferences; Machine* machine; Widgets* widgets; PolygonManager4D* polymgr; PuzzleState* puzzle_state; History* history; MacroManager* macromgr; // If deleting_a_macro is true, then hitting the apply button // causes that macro to be deleted. If creating_a_macro is true, // then undos and redos are not allowed bool creating_a_macro; bool deleting_a_macro; // Support being able to set slicesmask on next twist. unsigned int next_slicesmask; // Whether applying macros should display each move bool fast_automoves; // In certain cases the user is asked to click on three reference // stickers. In this case the following variables are used... int number_of_reference_stickers_needed; int (*reference_stickers_needed)[4]; void (EventHandler::*what_to_do_after_got_reference_stickers) (void *arg); void* cur_ui_data; bool quick_mode; struct frame untwisted_frame; bool dragging; int nscramblechen; static float const DEF_TWIST_INCREMENT; }; #endif // Local Variables: // c-basic-offset: 4 // c-comment-only-line-offset: 0 // c-file-offsets: ((defun-block-intro . +) (block-open . 0) (substatement-open . 0) (statement-cont . +) (statement-case-open . +4) (arglist-intro . +) (arglist-close . +) (inline-open . 0)) // indent-tabs-mode: nil // End: