summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-29 13:58:56 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-29 13:58:56 (GMT)
commitf8a6d2ea1f8f6789645279f69471c13c7caa352b (patch)
treeb72c796018bca6244e39ecf4ca1db8d4770a51b0
parent716ac44c29a06e9a0e6267b50e263a65f7aba8ec (diff)
downloadpowder-f8a6d2ea1f8f6789645279f69471c13c7caa352b.zip
powder-f8a6d2ea1f8f6789645279f69471c13c7caa352b.tar.gz
Textboxes for decoration, addresses "No text boxes in deco editor to directly edit the values" in issue #23
-rw-r--r--src/Misc.cpp1
-rw-r--r--src/Misc.h15
-rw-r--r--src/game/GameView.cpp98
-rw-r--r--src/game/GameView.h9
-rw-r--r--src/interface/Slider.cpp6
5 files changed, 110 insertions, 19 deletions
diff --git a/src/Misc.cpp b/src/Misc.cpp
index c2963be..4451c4a 100644
--- a/src/Misc.cpp
+++ b/src/Misc.cpp
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <regex.h>
diff --git a/src/Misc.h b/src/Misc.h
index 12b88bd..98f0e31 100644
--- a/src/Misc.h
+++ b/src/Misc.h
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string>
+#include <sstream>
#include <vector>
#if defined(WIN32) && !defined(__GNUC__)
@@ -82,6 +83,20 @@ void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v);
void OpenURI(std::string uri);
+template <typename T> std::string NumberToString(T number)
+{
+ std::stringstream ss;
+ ss << number;
+ return ss.str();
+}
+
+template <typename T> T StringToNumber(const std::string & text)
+{
+ std::stringstream ss(text);
+ T number;
+ return (ss >> number)?number:0;
+}
+
void membwand(void * dest, void * src, size_t destsize, size_t srcsize);
// a b
// c d
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 6544674..290a72b 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -233,25 +233,40 @@ GameView::GameView():
pauseButton->SetActionCallback(new PauseAction(this));
AddComponent(pauseButton);
- class ColourChange : public ui::SliderAction
+ class ColourChange : public ui::SliderAction, public ui::TextboxAction
{
GameView * v;
public:
ColourChange(GameView * _v) { v = _v; }
void ValueChangedCallback(ui::Slider * sender)
{
- v->changeColour();
+ v->changeColourSlider();
+ }
+
+ void TextChangedCallback(ui::Textbox * sender)
+ {
+ v->changeColourText();
}
};
- ColourChange * colC = new ColourChange(this);
- colourRSlider = new ui::Slider(ui::Point(5, Size.Y-39), ui::Point(80, 14), 255);
- colourRSlider->SetActionCallback(colC);
- colourGSlider = new ui::Slider(ui::Point(95, Size.Y-39), ui::Point(80, 14), 255);
- colourGSlider->SetActionCallback(colC);
- colourBSlider = new ui::Slider(ui::Point(185, Size.Y-39), ui::Point(80, 14), 255);
- colourBSlider->SetActionCallback(colC);
+ colourRSlider = new ui::Slider(ui::Point(5, Size.Y-39), ui::Point(50, 14), 255);
+ colourRSlider->SetActionCallback(new ColourChange(this));
+ colourRValue = new ui::Textbox(ui::Point(60, Size.Y-41), ui::Point(25, 17), "255");
+ colourRValue->SetActionCallback(new ColourChange(this));
+
+ colourGSlider = new ui::Slider(ui::Point(95, Size.Y-39), ui::Point(50, 14), 255);
+ colourGSlider->SetActionCallback(new ColourChange(this));
+ colourGValue = new ui::Textbox(ui::Point(150, Size.Y-41), ui::Point(25, 17), "255");
+ colourGValue->SetActionCallback(new ColourChange(this));
+
+ colourBSlider = new ui::Slider(ui::Point(185, Size.Y-39), ui::Point(50, 14), 255);
+ colourBSlider->SetActionCallback(new ColourChange(this));
+ colourBValue = new ui::Textbox(ui::Point(240, Size.Y-41), ui::Point(25, 17), "255");
+ colourBValue->SetActionCallback(new ColourChange(this));
+
colourASlider = new ui::Slider(ui::Point(275, Size.Y-39), ui::Point(50, 14), 255);
- colourASlider->SetActionCallback(colC);
+ colourASlider->SetActionCallback(new ColourChange(this));
+ colourAValue = new ui::Textbox(ui::Point(330, Size.Y-41), ui::Point(25, 17), "255");
+ colourAValue->SetActionCallback(new ColourChange(this));
class ElementSearchAction : public ui::ButtonAction
{
@@ -487,32 +502,69 @@ void GameView::NotifyColourSelectorVisibilityChanged(GameModel * sender)
{
RemoveComponent(colourRSlider);
colourRSlider->SetParentWindow(NULL);
+ RemoveComponent(colourRValue);
+ colourRValue->SetParentWindow(NULL);
+
RemoveComponent(colourGSlider);
colourGSlider->SetParentWindow(NULL);
+ RemoveComponent(colourGValue);
+ colourGValue->SetParentWindow(NULL);
+
RemoveComponent(colourBSlider);
colourBSlider->SetParentWindow(NULL);
+ RemoveComponent(colourBValue);
+ colourBValue->SetParentWindow(NULL);
+
RemoveComponent(colourASlider);
colourASlider->SetParentWindow(NULL);
+ RemoveComponent(colourAValue);
+ colourAValue->SetParentWindow(NULL);
+
if(sender->GetColourSelectorVisibility())
{
AddComponent(colourRSlider);
+ AddComponent(colourRValue);
+
AddComponent(colourGSlider);
+ AddComponent(colourGValue);
+
AddComponent(colourBSlider);
+ AddComponent(colourBValue);
+
AddComponent(colourASlider);
+ AddComponent(colourAValue);
}
}
void GameView::NotifyColourSelectorColourChanged(GameModel * sender)
{
+ std::string intR, intG, intB, intA;
+
+ intR = NumberToString<int>(sender->GetColourSelectorColour().Red);
+ intG = NumberToString<int>(sender->GetColourSelectorColour().Green);
+ intB = NumberToString<int>(sender->GetColourSelectorColour().Blue);
+ intA = NumberToString<int>(sender->GetColourSelectorColour().Alpha);
+
colourRSlider->SetValue(sender->GetColourSelectorColour().Red);
- colourRSlider->SetColour(ui::Colour(0, sender->GetColourSelectorColour().Green, sender->GetColourSelectorColour().Blue), ui::Colour(255, sender->GetColourSelectorColour().Green, sender->GetColourSelectorColour().Blue));
+ colourRSlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(255, 0, 0));
+ if(!colourRValue->IsFocused())
+ colourRValue->SetText(intR);
+
colourGSlider->SetValue(sender->GetColourSelectorColour().Green);
- colourGSlider->SetColour(ui::Colour(sender->GetColourSelectorColour().Red, 0, sender->GetColourSelectorColour().Blue), ui::Colour(sender->GetColourSelectorColour().Red, 255, sender->GetColourSelectorColour().Blue));
+ colourGSlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(0, 255, 0));
+ if(!colourGValue->IsFocused())
+ colourGValue->SetText(intG);
+
colourBSlider->SetValue(sender->GetColourSelectorColour().Blue);
- colourBSlider->SetColour(ui::Colour(sender->GetColourSelectorColour().Red, sender->GetColourSelectorColour().Green, 0), ui::Colour(sender->GetColourSelectorColour().Red, sender->GetColourSelectorColour().Green, 255));
+ colourBSlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(0, 0, 255));
+ if(!colourBValue->IsFocused())
+ colourBValue->SetText(intB);
+
colourASlider->SetValue(sender->GetColourSelectorColour().Alpha);
- colourASlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(255, 255, 255));
+ colourASlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(sender->GetColourSelectorColour().Red, sender->GetColourSelectorColour().Green, sender->GetColourSelectorColour().Blue));
+ if(!colourAValue->IsFocused())
+ colourAValue->SetText(intA);
}
void GameView::NotifyRendererChanged(GameModel * sender)
@@ -803,6 +855,9 @@ void GameView::OnMouseWheel(int x, int y, int d)
void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
+ if(colourRValue->IsFocused() || colourGValue->IsFocused() || colourBValue->IsFocused() || colourAValue->IsFocused())
+ return;
+
if(selectMode!=SelectNone)
{
if(selectMode==PlaceSave)
@@ -937,6 +992,9 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
+ if(colourRValue->IsFocused() || colourGValue->IsFocused() || colourBValue->IsFocused() || colourAValue->IsFocused())
+ return;
+
if(selectMode!=SelectNone)
{
return;
@@ -1163,11 +1221,21 @@ void GameView::NotifyPlaceSaveChanged(GameModel * sender)
}
}
-void GameView::changeColour()
+void GameView::changeColourSlider()
{
c->SetColour(ui::Colour(colourRSlider->GetValue(), colourGSlider->GetValue(), colourBSlider->GetValue(), colourASlider->GetValue()));
}
+void GameView::changeColourText()
+{
+ c->SetColour(ui::Colour(
+ std::min(255U, StringToNumber<unsigned int>(colourRValue->GetText())),
+ std::min(255U, StringToNumber<unsigned int>(colourGValue->GetText())),
+ std::min(255U, StringToNumber<unsigned int>(colourBValue->GetText())),
+ std::min(255U, StringToNumber<unsigned int>(colourAValue->GetText())))
+ );
+}
+
void GameView::enableShiftBehaviour()
{
if(!shiftBehaviour)
diff --git a/src/game/GameView.h b/src/game/GameView.h
index 9010e4a..648faec 100644
--- a/src/game/GameView.h
+++ b/src/game/GameView.h
@@ -11,6 +11,7 @@
#include "interface/Point.h"
#include "interface/Button.h"
#include "interface/Slider.h"
+#include "interface/Textbox.h"
#include "ToolButton.h"
#include "RenderPreset.h"
#include "Brush.h"
@@ -75,6 +76,11 @@ private:
ui::Slider * colourBSlider;
ui::Slider * colourASlider;
+ ui::Textbox * colourRValue;
+ ui::Textbox * colourGValue;
+ ui::Textbox * colourBValue;
+ ui::Textbox * colourAValue;
+
bool drawModeReset;
ui::Point drawPoint1;
ui::Point drawPoint2;
@@ -93,7 +99,8 @@ private:
int lastOffset;
void setToolButtonOffset(int offset);
- void changeColour();
+ void changeColourSlider();
+ void changeColourText();
virtual ui::Point lineSnapCoords(ui::Point point1, ui::Point point2);
virtual ui::Point rectSnapCoords(ui::Point point1, ui::Point point2);
diff --git a/src/interface/Slider.cpp b/src/interface/Slider.cpp
index b4ae063..474343e 100644
--- a/src/interface/Slider.cpp
+++ b/src/interface/Slider.cpp
@@ -85,7 +85,7 @@ void Slider::SetColour(Colour col1, Colour col2)
this->col2 = col2;
bgGradient = (unsigned char*)Graphics::GenerateGradient(
(pixel[2]){PIXRGB(col1.Red, col1.Green, col1.Blue), PIXRGB(col2.Red, col2.Green, col2.Blue)},
- (float[2]){0.0f, 1.0f}, 2, Size.X-6);
+ (float[2]){0.0f, 1.0f}, 2, Size.X-7);
}
void Slider::SetValue(int value)
@@ -105,8 +105,8 @@ void Slider::Draw(const Point& screenPos)
if(bgGradient)
{
#ifndef OGLI
- for (int j = 3; j < Size.Y-6; j++)
- for (int i = 3; i < Size.X-6; i++)
+ for (int j = 3; j < Size.Y-7; j++)
+ for (int i = 3; i < Size.X-7; i++)
g->blendpixel(screenPos.X+i+2, screenPos.Y+j+2, bgGradient[(i-3)*3], bgGradient[(i-3)*3+1], bgGradient[(i-3)*3+2], 255);
#else
g->gradientrect(screenPos.X+5, screenPos.Y+5, Size.X-10, Size.Y-10, col1.Red, col1.Green, col1.Blue, col1.Alpha, col2.Red, col2.Green, col2.Blue, col2.Alpha);