summaryrefslogtreecommitdiff
path: root/src/game/ToolButton.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-30 16:03:18 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-30 16:03:18 (GMT)
commit1d297cb57a338f2a9e34d0f16642afc6a83c1041 (patch)
tree7d5514be702ff98f9b1e53eecdbf0c67096d76f6 /src/game/ToolButton.cpp
parent259fc2bcf75d754af043a5d3fa39b6ee0c0b1dec (diff)
downloadpowder-1d297cb57a338f2a9e34d0f16642afc6a83c1041.zip
powder-1d297cb57a338f2a9e34d0f16642afc6a83c1041.tar.gz
Line and rect drawing
Diffstat (limited to 'src/game/ToolButton.cpp')
-rw-r--r--src/game/ToolButton.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/game/ToolButton.cpp b/src/game/ToolButton.cpp
new file mode 100644
index 0000000..374d424
--- /dev/null
+++ b/src/game/ToolButton.cpp
@@ -0,0 +1,88 @@
+/*
+ * ToolButton.cpp
+ *
+ * Created on: Jan 30, 2012
+ * Author: Simon
+ */
+
+#include "ToolButton.h"
+#include "interface/Keys.h"
+
+ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_):
+ ui::Button(position, size, text_)
+{
+ SetSelectionState(-1);
+}
+
+void ToolButton::OnMouseClick(int x, int y, unsigned int button)
+{
+ isButtonDown = true;
+}
+
+void ToolButton::OnMouseUp(int x, int y, unsigned int button)
+{
+ if(isButtonDown)
+ {
+ if(button == BUTTON_LEFT)
+ SetSelectionState(0);
+ if(button == BUTTON_RIGHT)
+ SetSelectionState(1);
+ if(button == BUTTON_MIDDLE)
+ SetSelectionState(2);
+ DoAction();
+ }
+ isButtonDown = false;
+}
+
+void ToolButton::Draw(const ui::Point& screenPos)
+{
+ Graphics * g = ui::Engine::Ref().g;
+ int totalColour = background.Red + 3*background.Green + 2*background.Blue;
+
+ g->fillrect(screenPos.X, screenPos.Y, Size.X, Size.Y, background.Red, background.Green, background.Blue, 255);
+
+ if (totalColour<544)
+ {
+ g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, ButtonText.c_str(), 255, 255, 255, 255);
+ }
+ else
+ {
+ g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, ButtonText.c_str(), 0, 0, 0, 255);
+ }
+ if(currentSelection!=-1)
+ {
+ //g->fillrect(screenPos.X+1, screenPos.Y+1, Size.X-2, Size.Y-2, 255, 255, 255, 170);
+ g->fillrect(screenPos.X+2, screenPos.Y+2, Size.Y-4, Size.Y-4, 0, 0, 0, 170);
+ g->drawtext(screenPos.X+5, screenPos.Y+4, selectionText, 255, 255, 255, 255);
+ }
+}
+
+void ToolButton::SetSelectionState(int state)
+{
+ currentSelection = state;
+ switch(state)
+ {
+ case 0:
+ selectionText = "L";
+ break;
+ case 1:
+ selectionText = "R";
+ break;
+ case 2:
+ selectionText = "M";
+ break;
+ default:
+ selectionText = "";
+ break;
+ }
+}
+
+int ToolButton::GetSelectionState()
+{
+ return currentSelection;
+}
+
+ToolButton::~ToolButton() {
+ // TODO Auto-generated destructor stub
+}
+