#ifndef INPUTMENU_H #define INPUTMENU_H #include #include #include "ValuedGuiElement.h" #include "constant.h" extern void unload(); class InputMenu : public ValuedGuiElement { int length; int *x; int *y; const char **command; const int *acceleratorKey; int value; bool ownCoordinates; int oldMouseB; public: InputMenu(BITMAP *desiredCanvas, int desiredLength, int *desiredX, int *desiredY, const char **desiredCommand, const int *desiredAcceleratorKey, bool desiredBlocking, int desiredSelection = 0, bool desiredActive = false) : ValuedGuiElement(desiredCanvas, desiredBlocking, desiredActive), length(desiredLength), x(desiredX), y(desiredY), command(desiredCommand), acceleratorKey(desiredAcceleratorKey), value(desiredSelection), ownCoordinates(false), oldMouseB(0x0) {} InputMenu(BITMAP *desiredCanvas, int desiredX, int desiredY, int desiredLength, const char **desiredCommand, const int *desiredAcceleratorKey, bool vertical, bool desiredBlocking, int desiredSelection = 0, bool desiredActive = false) : ValuedGuiElement(desiredCanvas, desiredBlocking, desiredActive), length(desiredLength), command(desiredCommand), acceleratorKey(desiredAcceleratorKey), value(desiredSelection), ownCoordinates(true), oldMouseB(0x0) { x = (int*)malloc(desiredLength * sizeof(int)); if (!x) { unload(); allegro_message("Out of memory."); exit(0); } y = (int*)malloc(desiredLength * sizeof(int)); if (!y) { unload(); allegro_message("Out of memory."); exit(0); } if (vertical) { for (int i = 0; i < desiredLength; i++) x[i] = desiredX; for (int i = 0; i < desiredLength; i++) y[i] = desiredY + i * charHeight; } else { int nextUp = desiredX; for (int i = 0; i < desiredLength; i++) { x[i] = nextUp; nextUp += (strlen(desiredCommand[i]) + 1) * charWidth; } for (int i = 0; i < desiredLength; i++) y[i] = desiredY; } } InputMenu(const InputMenu &source) : ValuedGuiElement(source), length(source.length), command(source.command), acceleratorKey(source.acceleratorKey), value(source.value), ownCoordinates(source.ownCoordinates), oldMouseB(source.oldMouseB) { if (source.ownCoordinates) { x = (int*)malloc(source.length * sizeof(int)); if (!x) { unload(); allegro_message("Out of memory."); exit(0); } y = (int*)malloc(source.length * sizeof(int)); if (!y) { unload(); allegro_message("Out of memory."); exit(0); } memcpy(x, source.x, source.length * sizeof(int)); memcpy(y, source.y, source.length * sizeof(int)); } else { x = source.x; y = source.y; } } ~InputMenu() { if (ownCoordinates) { free(x); free(y); } } InputMenu& operator=(const InputMenu &source) { if (this == &source) return *this; else { if (ownCoordinates) { free(x); free(y); } if (source.ownCoordinates) { x = (int*)malloc(source.length * sizeof(int)); if (!x) { unload(); allegro_message("Out of memory."); exit(0); } y = (int*)malloc(source.length * sizeof(int)); if (!y) { unload(); allegro_message("Out of memory."); exit(0); } memcpy(x, source.x, source.length * sizeof(int)); memcpy(y, source.y, source.length * sizeof(int)); } else { x = source.x; y = source.y; } canvas = source.canvas; length = source.length; command = source.command; acceleratorKey = source.acceleratorKey; value = source.value; ownCoordinates = source.ownCoordinates; blocking = source.blocking; uncommit(); if (source.getCommitted()) commit(source.getCommitment()); active = source.active; oldMouseB = source.oldMouseB; return *this; } } int* getX(); int* getY(); void previous(); void next(); int accelerate(int ascii); void drawCommands(); void drawSelect(); void drawUnselect(); int getValue(); void setValue(int desiredValue); bool acknowledgeKeyStroke(int keyStroke); bool acknowledgeMouse(); void shift(int xOffset, int yOffset); bool within(int xTarget, int yTarget); void draw(); void erase(); }; #endif