-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell_operation.cpp
83 lines (65 loc) · 2.22 KB
/
cell_operation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "libtcod.hpp"
#include "gui/gui.hpp"
#include "app.h"
#include "brush.h"
#include "cell_operation.h"
CellOperation::CellOperation() {
}
CellOperation::~CellOperation() {
}
void CellOperation::start() {
oldMouseX = app->canvasMouseX;
oldMouseY = app->canvasMouseY;
justCleared = false;
app->gui->useSymbolToggleButton->setVisible(true);
app->gui->useForegroundToggleButton->setVisible(true);
app->gui->useBackgroundToggleButton->setVisible(true);
app->gui->useSolidToggleButton->setVisible(true);
}
void CellOperation::update() {
TCOD_mouse_t mouse = app->mouse;
int mouseX = app->canvasMouseX;
int mouseY = app->canvasMouseY;
// If the user just let go of the mouse buttons
if(mouse.lbutton == false && mouse.rbutton == false && active == true) {
// First make a backup for undo
app->addUndo();
// Then blit the overlay onto the canvas
app->applyOverlayToCanvas();
}
// if the user press the left and right mouse button at the same time then
// erase the current stroke
if(mouse.lbutton == true && mouse.rbutton == true && active == true) {
app->clearOverlay();
justCleared = true; // justCleared is needed so that we don't get a dot at
// the end. Just try and comment out that line to see what happens. :)
}
if(mouse.lbutton == false && mouse.rbutton == false) {
justCleared = false;
}
if((mouse.lbutton || mouse.rbutton) && justCleared == false) {
active = true;
Brush *brush;
// If pressing the left mouse button use brush1 otherwise brush2
mouse.lbutton == true ? brush = &app->brush1 : brush = &app->brush2;
// In order to achieve continuous strokes we need to draw a line between the
// previous mouse position and the new one.
int x = oldMouseX;
int y = oldMouseY;
// Start a line from old mouse cell to new mouse cell
TCODLine::init(x, y, mouseX, mouseY);
do {
app->applyBrushToOverlayCell(x, y, brush);
} while(!TCODLine::step(&x, &y));
} else {
// if no button was pressed or we just cleared
active = false;
// Clear the overlay and draw a preview of brush1 on it
app->clearOverlay();
app->applyBrushToOverlayCell(mouseX, mouseY, &app->brush1);
}
oldMouseX = app->canvasMouseX;
oldMouseY = app->canvasMouseY;
}
void CellOperation::end() {
}