Skip to content

Commit

Permalink
WAGE: Moved console text selection to callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Apr 21, 2016
1 parent 4007a69 commit e74a8ba
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 80 deletions.
117 changes: 68 additions & 49 deletions engines/wage/gui.cpp
Expand Up @@ -143,8 +143,8 @@ static void cursorTimerHandler(void *refCon) {
gui->_cursorDirty = true;
}

static void sceneWindowCallback(WindowClick click, Common::Event &event, void *gui);
static void consoleWindowCallback(WindowClick click, Common::Event &event, void *gui);
static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *gui);
static bool consoleWindowCallback(WindowClick click, Common::Event &event, void *gui);

Gui::Gui(WageEngine *engine) {
_engine = engine;
Expand Down Expand Up @@ -315,18 +315,29 @@ void Gui::drawScene() {
_consoleTextArea.setHeight(_scene->_textBounds->height() - 2 * kBorderWidth);
}

static void sceneWindowCallback(WindowClick click, Common::Event &event, void *g) {
static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *g) {
Gui *gui = (Gui *)g;

return gui->processSceneEvents(click, event);
}

bool Gui::processSceneEvents(WindowClick click, Common::Event &event) {
if (_cursorIsArrow == false) {
CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3);
_cursorIsArrow = true;
}

if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) {
Designed *obj = gui->_scene->lookUpEntity(event.mouse.x - gui->_sceneWindow->getDimensions().left,
event.mouse.y - gui->_sceneWindow->getDimensions().top);
Designed *obj = _scene->lookUpEntity(event.mouse.x - _sceneWindow->getDimensions().left,
event.mouse.y - _sceneWindow->getDimensions().top);

if (obj != nullptr)
gui->_engine->processTurn(NULL, obj);
_engine->processTurn(NULL, obj);

return;
return true;
}

return false;
}

// Render console
Expand All @@ -339,13 +350,18 @@ void Gui::drawConsole() {
_consoleWindow->setDirty(true);
}

static void consoleWindowCallback(WindowClick click, Common::Event &event, void *g) {
static bool consoleWindowCallback(WindowClick click, Common::Event &event, void *g) {
Gui *gui = (Gui *)g;

gui->processConsoleEvents(click, event);
return gui->processConsoleEvents(click, event);
}

void Gui::processConsoleEvents(WindowClick click, Common::Event &event) {
bool Gui::processConsoleEvents(WindowClick click, Common::Event &event) {
if (click != kBorderInner && _cursorIsArrow == false) {
CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3);
_cursorIsArrow = true;
}

if (click == kBorderScrollUp || click == kBorderScrollDown) {
if (event.type == Common::EVENT_LBUTTONDOWN) {
int textFullSize = _lines.size() * _consoleLineHeight + _consoleTextArea.height();
Expand Down Expand Up @@ -376,8 +392,49 @@ void Gui::processConsoleEvents(WindowClick click, Common::Event &event) {
}
}

return;
return true;
}

if (click == kBorderInner) {
if (event.type == Common::EVENT_LBUTTONDOWN) {
startMarking(event.mouse.x, event.mouse.y);
} else if (event.type == Common::EVENT_LBUTTONUP) {
if (_inTextSelection) {
_inTextSelection = false;

if (_selectionEndY == -1 ||
(_selectionEndX == _selectionStartX && _selectionEndY == _selectionStartY)) {
_selectionStartY = _selectionEndY = -1;
_consoleFullRedraw = true;
_menu->enableCommand(kMenuEdit, kMenuActionCopy, false);
} else {
_menu->enableCommand(kMenuEdit, kMenuActionCopy, true);

bool cutAllowed = false;

if (_selectionStartY == _selectionEndY && _selectionStartY == (int)_lines.size() - 1)
cutAllowed = true;

_menu->enableCommand(kMenuEdit, kMenuActionCut, cutAllowed);
_menu->enableCommand(kMenuEdit, kMenuActionClear, cutAllowed);
}
}
} else if (event.type == Common::EVENT_MOUSEMOVE) {
if (_inTextSelection) {
updateTextSelection(event.mouse.x, event.mouse.y);
return true;
}

if (_cursorIsArrow) {
CursorMan.replaceCursor(macCursorBeam, 11, 16, 3, 8, 3);
_cursorIsArrow = false;
}
}

return true;
}

return false;
}

void Gui::loadFonts() {
Expand Down Expand Up @@ -443,21 +500,6 @@ void Gui::mouseMove(int x, int y) {

return;
}

if (_inTextSelection) {
updateTextSelection(x, y);
return;
}

if (_consoleTextArea.contains(x, y)) {
if (_cursorIsArrow) {
CursorMan.replaceCursor(macCursorBeam, 11, 16, 3, 8, 3);
_cursorIsArrow = false;
}
} else if (_cursorIsArrow == false) {
CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3);
_cursorIsArrow = true;
}
}

void Gui::pushArrowCursor() {
Expand Down Expand Up @@ -502,35 +544,12 @@ void Gui::mouseUp(int x, int y) {
return;
}

if (_inTextSelection) {
_inTextSelection = false;

if (_selectionEndY == -1 ||
(_selectionEndX == _selectionStartX && _selectionEndY == _selectionStartY)) {
_selectionStartY = _selectionEndY = -1;
_consoleFullRedraw = true;
_menu->enableCommand(kMenuEdit, kMenuActionCopy, false);
} else {
_menu->enableCommand(kMenuEdit, kMenuActionCopy, true);

bool cutAllowed = false;

if (_selectionStartY == _selectionEndY && _selectionStartY == (int)_lines.size() - 1)
cutAllowed = true;

_menu->enableCommand(kMenuEdit, kMenuActionCut, cutAllowed);
_menu->enableCommand(kMenuEdit, kMenuActionClear, cutAllowed);
}
}

return;
}

void Gui::mouseDown(int x, int y) {
if (_menu->mouseClick(x, y)) {
_menuDirty = true;
} else if (_consoleTextArea.contains(x, y)) {
startMarking(x, y);
}
}

Expand Down
3 changes: 2 additions & 1 deletion engines/wage/gui.h
Expand Up @@ -114,7 +114,8 @@ class Gui {

bool builtInFonts() { return _builtInFonts; }

void processConsoleEvents(WindowClick click, Common::Event &event);
bool processSceneEvents(WindowClick click, Common::Event &event);
bool processConsoleEvents(WindowClick click, Common::Event &event);

private:
void drawScene();
Expand Down
32 changes: 6 additions & 26 deletions engines/wage/macwindow.cpp
Expand Up @@ -291,42 +291,22 @@ static WindowClick isInBorder(Common::Rect &rect, int x, int y) {
}

bool MacWindow::processEvent(Common::Event &event) {
WindowClick click = isInBorder(_innerDims, event.mouse.x, event.mouse.y);

switch (event.type) {
case Common::EVENT_MOUSEMOVE:
//mouseMove(event.mouse.x, event.mouse.y);
break;
case Common::EVENT_LBUTTONDOWN:
mouseDown(event);
setHighlight(click);
break;
case Common::EVENT_LBUTTONUP: {
setHighlight(kBorderNone);

WindowClick click = isInBorder(_innerDims, event.mouse.x, event.mouse.y);
(*_callback)(click, event, _dataPtr);
}
case Common::EVENT_LBUTTONUP:
setHighlight(kBorderNone);
break;

default:
return false;
}

return true;
}

void MacWindow::mouseDown(Common::Event &event) {
WindowClick click = isInBorder(_innerDims, event.mouse.x, event.mouse.y);

if (click == kBorderNone)
return;

setHighlight(click);

if (click == kBorderScrollUp || click == kBorderScrollDown || click == kBorderInner) {
if (!_callback)
return;

(*_callback)(click, event, _dataPtr);
}
return (*_callback)(click, event, _dataPtr);
}

} // End of namespace Wage
6 changes: 2 additions & 4 deletions engines/wage/macwindow.h
Expand Up @@ -86,7 +86,7 @@ class MacWindow {
void setDirty(bool dirty) { _contentIsDirty = dirty; }
int getId() { return _id; }
bool processEvent(Common::Event &event);
void setCallback(void (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; }
void setCallback(bool (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; }

private:
void drawBorder();
Expand All @@ -95,8 +95,6 @@ class MacWindow {
const Graphics::Font *getTitleFont();
bool builtInFonts();

void mouseDown(Common::Event &event);

private:
Graphics::ManagedSurface _surface;
Graphics::ManagedSurface _borderSurface;
Expand All @@ -115,7 +113,7 @@ class MacWindow {

Common::String _title;

void (*_callback)(WindowClick, Common::Event &, void *);
bool (*_callback)(WindowClick, Common::Event &, void *);
void *_dataPtr;
};

Expand Down

0 comments on commit e74a8ba

Please sign in to comment.