summaryrefslogtreecommitdiff
path: root/src/game/GameView.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-03-28 21:01:44 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-03-28 21:01:44 (GMT)
commite9770d8ee7a44d5680c23749c786a03c0d5b41ff (patch)
treeb63b4bb60ab0262724a01cb5bc21b116b035748f /src/game/GameView.cpp
parent63af6abd29a161f6d1aa257aeb76f6891f512f74 (diff)
downloadpowder-e9770d8ee7a44d5680c23749c786a03c0d5b41ff.zip
powder-e9770d8ee7a44d5680c23749c786a03c0d5b41ff.tar.gz
Clipboard and Stamp from selection (no way to paste/place yet)
Diffstat (limited to 'src/game/GameView.cpp')
-rw-r--r--src/game/GameView.cpp100
1 files changed, 96 insertions, 4 deletions
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 1fa039c..16f7551 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -21,7 +21,10 @@ GameView::GameView():
drawPoint1(0, 0),
drawPoint2(0, 0),
drawMode(DrawPoints),
- drawModeReset(false)
+ drawModeReset(false),
+ selectMode(SelectNone),
+ selectPoint1(0, 0),
+ selectPoint2(0, 0)
{
int currentX = 1;
//Set up UI
@@ -461,6 +464,12 @@ void GameView::NotifyBrushChanged(GameModel * sender)
void GameView::OnMouseMove(int x, int y, int dx, int dy)
{
+ if(selectMode!=SelectNone)
+ {
+ if(selectPoint1.X!=-1)
+ selectPoint2 = ui::Point(x, y);
+ return;
+ }
currentMouse = ui::Point(x, y);
if(isMouseDown && drawMode == DrawPoints)
{
@@ -471,6 +480,15 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy)
void GameView::OnMouseDown(int x, int y, unsigned button)
{
+ if(selectMode!=SelectNone)
+ {
+ if(button!=3)
+ {
+ selectPoint1 = ui::Point(x, y);
+ selectPoint2 = selectPoint1;
+ }
+ return;
+ }
if(currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES && !(zoomEnabled && !zoomCursorFixed))
{
if(button == BUTTON_LEFT)
@@ -493,6 +511,23 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
void GameView::OnMouseUp(int x, int y, unsigned button)
{
+ if(selectMode!=SelectNone)
+ {
+ int x2 = (selectPoint1.X>selectPoint2.X)?selectPoint1.X:selectPoint2.X;
+ int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y;
+ int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X;
+ int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y;
+ if(button !=3 && x2-x1>0 && y2-y1>0)
+ {
+ if(selectMode==SelectCopy)
+ c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2));
+ else if(selectMode==SelectStamp)
+ c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2));
+ }
+ selectMode = SelectNone;
+ return;
+ }
+
if(zoomEnabled && !zoomCursorFixed)
zoomCursorFixed = true;
else
@@ -529,6 +564,10 @@ void GameView::OnMouseWheel(int x, int y, int d)
{
if(!d)
return;
+ if(selectMode!=SelectNone)
+ {
+ return;
+ }
if(zoomEnabled && !zoomCursorFixed)
{
c->AdjustZoomSize(d);
@@ -545,6 +584,10 @@ void GameView::OnMouseWheel(int x, int y, int d)
void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
+ if(selectMode!=SelectNone)
+ {
+ return;
+ }
switch(key)
{
case KEY_CTRL:
@@ -588,11 +631,26 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
if(ctrl)
c->SetDecoration();
break;
+ case 's':
+ selectMode = SelectStamp;
+ selectPoint1 = ui::Point(-1, -1);
+ break;
+ case 'c':
+ if(ctrl)
+ {
+ selectMode = SelectCopy;
+ selectPoint1 = ui::Point(-1, -1);
+ }
+ break;
}
}
void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
+ if(selectMode!=SelectNone)
+ {
+ return;
+ }
if(!isMouseDown)
drawMode = DrawPoints;
else
@@ -633,6 +691,11 @@ void GameView::NotifyZoomChanged(GameModel * sender)
zoomEnabled = sender->GetZoomEnabled();
}
+void GameView::NotifyClipboardChanged(GameModel * sender)
+{
+ //Could use this to have a mini preview of the clipboard, meh
+}
+
void GameView::changeColour()
{
c->SetColour(ui::Colour(colourRSlider->GetValue(), colourGSlider->GetValue(), colourBSlider->GetValue(), colourASlider->GetValue()));
@@ -642,6 +705,7 @@ void GameView::OnDraw()
{
if(ren)
{
+ Graphics * g = ui::Engine::Ref().g;
ren->render_parts();
ren->render_fire();
ren->DrawWalls();
@@ -649,18 +713,46 @@ void GameView::OnDraw()
{
if(drawMode==DrawRect && isMouseDown)
{
- activeBrush->RenderRect(ui::Engine::Ref().g, c->PointTranslate(drawPoint1), c->PointTranslate(currentMouse));
+ activeBrush->RenderRect(g, c->PointTranslate(drawPoint1), c->PointTranslate(currentMouse));
}
else if(drawMode==DrawLine && isMouseDown)
{
- activeBrush->RenderLine(ui::Engine::Ref().g, c->PointTranslate(drawPoint1), c->PointTranslate(currentMouse));
+ activeBrush->RenderLine(g, c->PointTranslate(drawPoint1), c->PointTranslate(currentMouse));
}
else
{
- activeBrush->RenderPoint(ui::Engine::Ref().g, c->PointTranslate(currentMouse));
+ activeBrush->RenderPoint(g, c->PointTranslate(currentMouse));
}
}
ren->RenderZoom();
ren->DrawSigns();
+
+ if(selectMode!=SelectNone)
+ {
+ if(selectPoint1.X==-1)
+ {
+ g->fillrect(0, 0, XRES, YRES, 0, 0, 0, 100);
+ }
+ else
+ {
+ int x2 = (selectPoint1.X>selectPoint2.X)?selectPoint1.X:selectPoint2.X;
+ int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y;
+ int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X;
+ int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y;
+
+ if(x2>XRES-1)
+ x2 = XRES-1;
+ if(y2>YRES-1)
+ y2 = YRES-1;
+
+ g->fillrect(0, 0, XRES, y1, 0, 0, 0, 100);
+ g->fillrect(0, y2, XRES, YRES-y2, 0, 0, 0, 100);
+
+ g->fillrect(0, y1-1, x1, (y2-y1)+2, 0, 0, 0, 100);
+ g->fillrect(x2, y1-1, XRES-x2, (y2-y1)+2, 0, 0, 0, 100);
+
+ g->xor_rect(x1, y1, (x2-x1)+1, (y2-y1)+1);
+ }
+ }
}
}