summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-05-13 16:43:41 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-05-13 16:43:41 (GMT)
commit4032a0469b1f40f7197468f34986e365bd6e7314 (patch)
treef324519139168068628f8d6e0fc8046001c9c0a1 /src
parenta2e91c247fab4a2cee8936d83979f4a72390f7e7 (diff)
downloadpowder-4032a0469b1f40f7197468f34986e365bd6e7314.zip
powder-4032a0469b1f40f7197468f34986e365bd6e7314.tar.gz
Click function for tools that aren't continuous. Debug helper for UI components (Ctrl+Shift D when DEBUG is defined), fix add sign window logic
Diffstat (limited to 'src')
-rw-r--r--src/Graphics.cpp2
-rw-r--r--src/Graphics.h2
-rw-r--r--src/PowderToy.cpp4
-rw-r--r--src/cat/CommandInterface.h2
-rw-r--r--src/game/GameController.cpp10
-rw-r--r--src/game/GameController.h1
-rw-r--r--src/game/GameView.cpp1
-rw-r--r--src/game/SignTool.cpp15
-rw-r--r--src/game/Tool.h10
-rw-r--r--src/interface/Engine.h2
-rw-r--r--src/interface/Window.cpp114
-rw-r--r--src/interface/Window.h3
-rw-r--r--src/simulation/Gravity.cpp8
-rw-r--r--src/simulation/Simulation.cpp4
14 files changed, 150 insertions, 28 deletions
diff --git a/src/Graphics.cpp b/src/Graphics.cpp
index 13c0457..2711237 100644
--- a/src/Graphics.cpp
+++ b/src/Graphics.cpp
@@ -1,5 +1,5 @@
#include <cmath>
-#include <SDL/SDL.h>
+#include "SDL.h"
#include <bzlib.h>
#include <string>
#include "Config.h"
diff --git a/src/Graphics.h b/src/Graphics.h
index 6312185..9b91701 100644
--- a/src/Graphics.h
+++ b/src/Graphics.h
@@ -1,7 +1,7 @@
#ifndef GRAPHICS_H
#define GRAPHICS_H
-#include <SDL/SDL.h>
+#include "SDL.h"
#include <string>
#if defined(OGLR)
#ifdef MACOSX
diff --git a/src/PowderToy.cpp b/src/PowderToy.cpp
index 0e43231..7e3b534 100644
--- a/src/PowderToy.cpp
+++ b/src/PowderToy.cpp
@@ -1,8 +1,8 @@
#include <time.h>
-#include <SDL/SDL.h>
+#include "SDL.h"
#ifdef WIN32
-#include <SDL/SDL_syswm.h>
+#include "SDL_syswm.h"
#endif
#include <iostream>
#include <sstream>
diff --git a/src/cat/CommandInterface.h b/src/cat/CommandInterface.h
index ca480dd..2da30c2 100644
--- a/src/cat/CommandInterface.h
+++ b/src/cat/CommandInterface.h
@@ -9,7 +9,7 @@
#define KITTY_H_
#include <string>
-#include <SDL/SDL.h>
+#include "SDL.h"
//#include "game/GameModel.h"
class GameModel;
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 529137a..7f852a6 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -304,6 +304,16 @@ void GameController::DrawPoints(int toolSelection, queue<ui::Point*> & pointQueu
}
}
+void GameController::ToolClick(int toolSelection, ui::Point point)
+{
+ Simulation * sim = gameModel->GetSimulation();
+ Tool * activeTool = gameModel->GetActiveTool(toolSelection);
+ Brush * cBrush = gameModel->GetBrush();
+ if(!activeTool || !cBrush)
+ return;
+ activeTool->Click(sim, cBrush, PointTranslate(point));
+}
+
void GameController::StampRegion(ui::Point point1, ui::Point point2)
{
int saveSize;
diff --git a/src/game/GameController.h b/src/game/GameController.h
index 8f49668..bb6e61a 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -63,6 +63,7 @@ public:
void SetZoomPosition(ui::Point position);
void AdjustBrushSize(int direction, bool logarithmic = false);
void AdjustZoomSize(int direction, bool logarithmic = false);
+ void ToolClick(int toolSelection, ui::Point point);
void DrawPoints(int toolSelection, queue<ui::Point*> & pointQueue);
void DrawRect(int toolSelection, ui::Point point1, ui::Point point2);
void DrawLine(int toolSelection, ui::Point point1, ui::Point point2);
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index cfc6a19..c05ca12 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -599,6 +599,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
}
if(drawMode == DrawPoints)
{
+ c->ToolClick(toolIndex, ui::Point(x, y));
pointQueue.push(new ui::Point(x, y));
}
if(drawModeReset)
diff --git a/src/game/SignTool.cpp b/src/game/SignTool.cpp
index 50ddb8a..fa004a8 100644
--- a/src/game/SignTool.cpp
+++ b/src/game/SignTool.cpp
@@ -26,17 +26,16 @@ public:
OkayAction(SignWindow * prompt_) { prompt = prompt_; }
void ActionCallback(ui::Button * sender)
{
- ui::Engine::Ref().CloseWindow();
- prompt->SelfDestruct();
-
+ ui::Engine::Ref().CloseWindow();
if(prompt->signID==-1 && prompt->textField->GetText().length())
{
prompt->sim->signs.push_back(sign(prompt->textField->GetText(), prompt->signPosition.X, prompt->signPosition.Y, sign::Left));
}
- else
+ else if(prompt->textField->GetText().length())
{
prompt->sim->signs[prompt->signID] = sign(sign(prompt->textField->GetText(), prompt->signPosition.X, prompt->signPosition.Y, sign::Left));
}
+ prompt->SelfDestruct();
}
};
@@ -71,11 +70,7 @@ void SignWindow::OnDraw()
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 200, 200, 200, 255);
}
-void SignTool::Draw(Simulation * sim, Brush * brush, ui::Point position)
+void SignTool::Click(Simulation * sim, Brush * brush, ui::Point position)
{
- if(!opened) //Ensure the dialogue can only be shown one at a time.
- {
- opened = true;
- new SignWindow(this, sim, -1, position);
- }
+ new SignWindow(this, sim, -1, position);
} \ No newline at end of file
diff --git a/src/game/Tool.h b/src/game/Tool.h
index 935e598..3a66ae4 100644
--- a/src/game/Tool.h
+++ b/src/game/Tool.h
@@ -28,6 +28,7 @@ public:
}
string GetName() { return toolName; }
virtual ~Tool() {}
+ virtual void Click(Simulation * sim, Brush * brush, ui::Point position) { }
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) {
sim->ToolBrush(position.X, position.Y, toolID, brush);
}
@@ -45,18 +46,15 @@ class SignTool: public Tool
{
public:
SignTool():
- Tool(0, "SIGN", 0, 0, 0),
- opened(false)
+ Tool(0, "SIGN", 0, 0, 0)
{
}
virtual ~SignTool() {}
- virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
+ virtual void Click(Simulation * sim, Brush * brush, ui::Point position);
+ virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) { }
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { }
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { }
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { }
- void SetClosed() { opened = false; }
-protected:
- bool opened;
};
class PropertyTool: public Tool
diff --git a/src/interface/Engine.h b/src/interface/Engine.h
index b8f6b73..f40f45f 100644
--- a/src/interface/Engine.h
+++ b/src/interface/Engine.h
@@ -1,7 +1,7 @@
#pragma once
#include <stack>
-#include <SDL/SDL.h>
+#include "SDL.h"
#include "Singleton.h"
#include "Platform.h"
#include "Graphics.h"
diff --git a/src/interface/Window.cpp b/src/interface/Window.cpp
index 4d4f9b7..2de6463 100644
--- a/src/interface/Window.cpp
+++ b/src/interface/Window.cpp
@@ -11,6 +11,9 @@ Window::Window(Point _position, Point _size):
AllowExclusiveDrawing(true),
halt(false),
destruct(false)
+#ifdef DEBUG
+ ,debugMode(false)
+#endif
{
}
@@ -125,12 +128,55 @@ void Window::DoDraw()
Components[i]->Draw( Point(scrpos) );
}
}
+#ifdef DEBUG
+ if(debugMode)
+ {
+ if(focusedComponent_==Components[i])
+ {
+ ui::Engine::Ref().g->fillrect(Components[i]->Position.X+Position.X, Components[i]->Position.Y+Position.Y, Components[i]->Size.X, Components[i]->Size.Y, 0, 255, 0, 90);
+ }
+ else
+ {
+ ui::Engine::Ref().g->fillrect(Components[i]->Position.X+Position.X, Components[i]->Position.Y+Position.Y, Components[i]->Size.X, Components[i]->Size.Y, 255, 0, 0, 90);
+ }
+ }
+#endif
}
+#ifdef DEBUG
+ if(debugMode)
+ {
+ if(focusedComponent_)
+ {
+ int xPos = focusedComponent_->Position.X+focusedComponent_->Size.X+5+Position.X;
+ Graphics * g = ui::Engine::Ref().g;
+ char tempString[512];
+ char tempString2[512];
+
+ sprintf(tempString, "Position: L %d, R %d, T: %d, B: %d", focusedComponent_->Position.X, Size.X-(focusedComponent_->Position.X+focusedComponent_->Size.X), focusedComponent_->Position.Y, Size.Y-(focusedComponent_->Position.Y+focusedComponent_->Size.Y));
+ sprintf(tempString2, "Size: %d, %d", focusedComponent_->Size.X, focusedComponent_->Size.Y);
+
+ if(Graphics::textwidth(tempString)+xPos > XRES+BARSIZE)
+ xPos = XRES+BARSIZE-(Graphics::textwidth(tempString)+5);
+ if(Graphics::textwidth(tempString2)+xPos > XRES+BARSIZE)
+ xPos = XRES+BARSIZE-(Graphics::textwidth(tempString2)+5);
+
+ g->drawtext(xPos, focusedComponent_->Position.Y+Position.Y+1, tempString, 0, 0, 0, 200);
+ g->drawtext(xPos, focusedComponent_->Position.Y+Position.Y, tempString, 255, 255, 255, 255);
+ g->drawtext(xPos, focusedComponent_->Position.Y+Position.Y+13, tempString2, 0, 0, 0, 200);
+ g->drawtext(xPos, focusedComponent_->Position.Y+Position.Y+12, tempString2, 255, 255, 255, 255);
+ }
+ return;
+ }
+#endif
}
void Window::DoTick(float dt)
{
+#ifdef DEBUG
+ if(debugMode)
+ return;
+#endif
//on mouse hover
for(int i = Components.size() - 1; i >= 0 && !halt; --i)
{
@@ -161,6 +207,50 @@ void Window::DoTick(float dt)
void Window::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
+#ifdef DEBUG
+ if(character = 'd' && ctrl && shift)
+ debugMode = !debugMode;
+ if(debugMode)
+ {
+ if(focusedComponent_!=NULL)
+ {
+ if(shift)
+ {
+ if(key == KEY_UP)
+ focusedComponent_->Size.Y--;
+ if(key == KEY_DOWN)
+ focusedComponent_->Size.Y++;
+ if(key == KEY_LEFT)
+ focusedComponent_->Size.X--;
+ if(key == KEY_RIGHT)
+ focusedComponent_->Size.X++;
+ }
+ if(ctrl)
+ {
+ if(key == KEY_UP)
+ focusedComponent_->Size.Y++;
+ if(key == KEY_DOWN)
+ focusedComponent_->Size.Y--;
+ if(key == KEY_LEFT)
+ focusedComponent_->Size.X++;
+ if(key == KEY_RIGHT)
+ focusedComponent_->Size.X--;
+ }
+ if(!shift)
+ {
+ if(key == KEY_UP)
+ focusedComponent_->Position.Y--;
+ if(key == KEY_DOWN)
+ focusedComponent_->Position.Y++;
+ if(key == KEY_LEFT)
+ focusedComponent_->Position.X--;
+ if(key == KEY_RIGHT)
+ focusedComponent_->Position.X++;
+ }
+ }
+ return;
+ }
+#endif
//on key press
if(focusedComponent_ != NULL)
{
@@ -175,6 +265,10 @@ void Window::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool a
void Window::DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
+#ifdef DEBUG
+ if(debugMode)
+ return;
+#endif
//on key unpress
if(focusedComponent_ != NULL)
{
@@ -200,6 +294,9 @@ void Window::DoMouseDown(int x_, int y_, unsigned button)
if(x >= Components[i]->Position.X && y >= Components[i]->Position.Y && x < Components[i]->Position.X + Components[i]->Size.X && y < Components[i]->Position.Y + Components[i]->Size.Y)
{
FocusComponent(Components[i]);
+#ifdef DEBUG
+ if(!debugMode)
+#endif
Components[i]->OnMouseClick(x - Components[i]->Position.X, y - Components[i]->Position.Y, button);
clickState = true;
break;
@@ -209,6 +306,11 @@ void Window::DoMouseDown(int x_, int y_, unsigned button)
if(!clickState)
FocusComponent(NULL);
+
+#ifdef DEBUG
+ if(debugMode)
+ return;
+#endif
//on mouse down
for(int i = Components.size() - 1; i > -1 && !halt; --i)
@@ -227,6 +329,10 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy)
//on mouse move (if true, and inside)
int x = x_ - Position.X;
int y = y_ - Position.Y;
+#ifdef DEBUG
+ if(debugMode)
+ return;
+#endif
for(int i = Components.size() - 1; i > -1 && !halt; --i)
{
if(!Components[i]->Locked && Components[i]->Visible)
@@ -277,6 +383,10 @@ void Window::DoMouseUp(int x_, int y_, unsigned button)
{
int x = x_ - Position.X;
int y = y_ - Position.Y;
+#ifdef DEBUG
+ if(debugMode)
+ return;
+#endif
//on mouse unclick
for(int i = Components.size() - 1; i >= 0 && !halt; --i)
{
@@ -306,6 +416,10 @@ void Window::DoMouseWheel(int x_, int y_, int d)
{
int x = x_ - Position.X;
int y = y_ - Position.Y;
+#ifdef DEBUG
+ if(debugMode)
+ return;
+#endif
//on mouse wheel focused
for(int i = Components.size() - 1; i >= 0 && !halt; --i)
{
diff --git a/src/interface/Window.h b/src/interface/Window.h
index 4e705f0..c077abb 100644
--- a/src/interface/Window.h
+++ b/src/interface/Window.h
@@ -86,6 +86,9 @@ enum ChromeStyle
void finalise();
bool halt;
bool destruct;
+#ifdef DEBUG
+ bool debugMode;
+#endif
};
diff --git a/src/simulation/Gravity.cpp b/src/simulation/Gravity.cpp
index b0372a3..356872a 100644
--- a/src/simulation/Gravity.cpp
+++ b/src/simulation/Gravity.cpp
@@ -388,15 +388,15 @@ void Gravity::update_grav(void)
for (x = 0; x < XRES / CELL; x++) {
if (x == j && y == i)//Ensure it doesn't calculate with itself
continue;
- distance = sqrt(pow(j - x, 2) + pow(i - y, 2));
+ distance = sqrt(pow(j - x, 2.0f) + pow(i - y, 2.0f));
#ifdef GRAV_DIFF
val = th_gravmap[i*(XRES/CELL)+j] - th_ogravmap[i*(XRES/CELL)+j];
#else
val = th_gravmap[i*(XRES/CELL)+j];
#endif
- th_gravx[y*(XRES/CELL)+x] += M_GRAV * val * (j - x) / pow(distance, 3);
- th_gravy[y*(XRES/CELL)+x] += M_GRAV * val * (i - y) / pow(distance, 3);
- th_gravp[y*(XRES/CELL)+x] += M_GRAV * val / pow(distance, 2);
+ th_gravx[y*(XRES/CELL)+x] += M_GRAV * val * (j - x) / pow(distance, 3.0f);
+ th_gravy[y*(XRES/CELL)+x] += M_GRAV * val * (i - y) / pow(distance, 3.0f);
+ th_gravp[y*(XRES/CELL)+x] += M_GRAV * val / pow(distance, 2.0f);
}
}
}
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index 41565a2..a992ef8 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -1138,7 +1138,7 @@ void *Simulation::transform_save(void *odata, int *size, matrix2d transform, vec
return ndata;
}
-void Simulation::orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[])
+inline void Simulation::orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[])
{
resblock1[0] = (block1&0x000000FF);
resblock1[1] = (block1&0x0000FF00)>>8;
@@ -1151,7 +1151,7 @@ void Simulation::orbitalparts_get(int block1, int block2, int resblock1[], int r
resblock2[3] = (block2&0xFF000000)>>24;
}
-void Simulation::orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[])
+inline void Simulation::orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[])
{
int block1tmp = 0;
int block2tmp = 0;