Textboxes for decoration, addresses "No text boxes in deco editor to directly edit the values" in issue #23
This commit is contained in:
parent
716ac44c29
commit
f8a6d2ea1f
@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sstream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
15
src/Misc.h
15
src/Misc.h
@ -3,6 +3,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if defined(WIN32) && !defined(__GNUC__)
|
#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);
|
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);
|
void membwand(void * dest, void * src, size_t destsize, size_t srcsize);
|
||||||
// a b
|
// a b
|
||||||
// c d
|
// c d
|
||||||
|
@ -233,25 +233,40 @@ GameView::GameView():
|
|||||||
pauseButton->SetActionCallback(new PauseAction(this));
|
pauseButton->SetActionCallback(new PauseAction(this));
|
||||||
AddComponent(pauseButton);
|
AddComponent(pauseButton);
|
||||||
|
|
||||||
class ColourChange : public ui::SliderAction
|
class ColourChange : public ui::SliderAction, public ui::TextboxAction
|
||||||
{
|
{
|
||||||
GameView * v;
|
GameView * v;
|
||||||
public:
|
public:
|
||||||
ColourChange(GameView * _v) { v = _v; }
|
ColourChange(GameView * _v) { v = _v; }
|
||||||
void ValueChangedCallback(ui::Slider * sender)
|
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(50, 14), 255);
|
||||||
colourRSlider = new ui::Slider(ui::Point(5, Size.Y-39), ui::Point(80, 14), 255);
|
colourRSlider->SetActionCallback(new ColourChange(this));
|
||||||
colourRSlider->SetActionCallback(colC);
|
colourRValue = new ui::Textbox(ui::Point(60, Size.Y-41), ui::Point(25, 17), "255");
|
||||||
colourGSlider = new ui::Slider(ui::Point(95, Size.Y-39), ui::Point(80, 14), 255);
|
colourRValue->SetActionCallback(new ColourChange(this));
|
||||||
colourGSlider->SetActionCallback(colC);
|
|
||||||
colourBSlider = new ui::Slider(ui::Point(185, Size.Y-39), ui::Point(80, 14), 255);
|
colourGSlider = new ui::Slider(ui::Point(95, Size.Y-39), ui::Point(50, 14), 255);
|
||||||
colourBSlider->SetActionCallback(colC);
|
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 = 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
|
class ElementSearchAction : public ui::ButtonAction
|
||||||
{
|
{
|
||||||
@ -487,32 +502,69 @@ void GameView::NotifyColourSelectorVisibilityChanged(GameModel * sender)
|
|||||||
{
|
{
|
||||||
RemoveComponent(colourRSlider);
|
RemoveComponent(colourRSlider);
|
||||||
colourRSlider->SetParentWindow(NULL);
|
colourRSlider->SetParentWindow(NULL);
|
||||||
|
RemoveComponent(colourRValue);
|
||||||
|
colourRValue->SetParentWindow(NULL);
|
||||||
|
|
||||||
RemoveComponent(colourGSlider);
|
RemoveComponent(colourGSlider);
|
||||||
colourGSlider->SetParentWindow(NULL);
|
colourGSlider->SetParentWindow(NULL);
|
||||||
|
RemoveComponent(colourGValue);
|
||||||
|
colourGValue->SetParentWindow(NULL);
|
||||||
|
|
||||||
RemoveComponent(colourBSlider);
|
RemoveComponent(colourBSlider);
|
||||||
colourBSlider->SetParentWindow(NULL);
|
colourBSlider->SetParentWindow(NULL);
|
||||||
|
RemoveComponent(colourBValue);
|
||||||
|
colourBValue->SetParentWindow(NULL);
|
||||||
|
|
||||||
RemoveComponent(colourASlider);
|
RemoveComponent(colourASlider);
|
||||||
colourASlider->SetParentWindow(NULL);
|
colourASlider->SetParentWindow(NULL);
|
||||||
|
RemoveComponent(colourAValue);
|
||||||
|
colourAValue->SetParentWindow(NULL);
|
||||||
|
|
||||||
if(sender->GetColourSelectorVisibility())
|
if(sender->GetColourSelectorVisibility())
|
||||||
{
|
{
|
||||||
AddComponent(colourRSlider);
|
AddComponent(colourRSlider);
|
||||||
|
AddComponent(colourRValue);
|
||||||
|
|
||||||
AddComponent(colourGSlider);
|
AddComponent(colourGSlider);
|
||||||
|
AddComponent(colourGValue);
|
||||||
|
|
||||||
AddComponent(colourBSlider);
|
AddComponent(colourBSlider);
|
||||||
|
AddComponent(colourBValue);
|
||||||
|
|
||||||
AddComponent(colourASlider);
|
AddComponent(colourASlider);
|
||||||
|
AddComponent(colourAValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::NotifyColourSelectorColourChanged(GameModel * sender)
|
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->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->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->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->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)
|
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)
|
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!=SelectNone)
|
||||||
{
|
{
|
||||||
if(selectMode==PlaceSave)
|
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)
|
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)
|
if(selectMode!=SelectNone)
|
||||||
{
|
{
|
||||||
return;
|
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()));
|
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()
|
void GameView::enableShiftBehaviour()
|
||||||
{
|
{
|
||||||
if(!shiftBehaviour)
|
if(!shiftBehaviour)
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "interface/Point.h"
|
#include "interface/Point.h"
|
||||||
#include "interface/Button.h"
|
#include "interface/Button.h"
|
||||||
#include "interface/Slider.h"
|
#include "interface/Slider.h"
|
||||||
|
#include "interface/Textbox.h"
|
||||||
#include "ToolButton.h"
|
#include "ToolButton.h"
|
||||||
#include "RenderPreset.h"
|
#include "RenderPreset.h"
|
||||||
#include "Brush.h"
|
#include "Brush.h"
|
||||||
@ -75,6 +76,11 @@ private:
|
|||||||
ui::Slider * colourBSlider;
|
ui::Slider * colourBSlider;
|
||||||
ui::Slider * colourASlider;
|
ui::Slider * colourASlider;
|
||||||
|
|
||||||
|
ui::Textbox * colourRValue;
|
||||||
|
ui::Textbox * colourGValue;
|
||||||
|
ui::Textbox * colourBValue;
|
||||||
|
ui::Textbox * colourAValue;
|
||||||
|
|
||||||
bool drawModeReset;
|
bool drawModeReset;
|
||||||
ui::Point drawPoint1;
|
ui::Point drawPoint1;
|
||||||
ui::Point drawPoint2;
|
ui::Point drawPoint2;
|
||||||
@ -93,7 +99,8 @@ private:
|
|||||||
|
|
||||||
int lastOffset;
|
int lastOffset;
|
||||||
void setToolButtonOffset(int offset);
|
void setToolButtonOffset(int offset);
|
||||||
void changeColour();
|
void changeColourSlider();
|
||||||
|
void changeColourText();
|
||||||
virtual ui::Point lineSnapCoords(ui::Point point1, ui::Point point2);
|
virtual ui::Point lineSnapCoords(ui::Point point1, ui::Point point2);
|
||||||
virtual ui::Point rectSnapCoords(ui::Point point1, ui::Point point2);
|
virtual ui::Point rectSnapCoords(ui::Point point1, ui::Point point2);
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ void Slider::SetColour(Colour col1, Colour col2)
|
|||||||
this->col2 = col2;
|
this->col2 = col2;
|
||||||
bgGradient = (unsigned char*)Graphics::GenerateGradient(
|
bgGradient = (unsigned char*)Graphics::GenerateGradient(
|
||||||
(pixel[2]){PIXRGB(col1.Red, col1.Green, col1.Blue), PIXRGB(col2.Red, col2.Green, col2.Blue)},
|
(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)
|
void Slider::SetValue(int value)
|
||||||
@ -105,8 +105,8 @@ void Slider::Draw(const Point& screenPos)
|
|||||||
if(bgGradient)
|
if(bgGradient)
|
||||||
{
|
{
|
||||||
#ifndef OGLI
|
#ifndef OGLI
|
||||||
for (int j = 3; j < Size.Y-6; j++)
|
for (int j = 3; j < Size.Y-7; j++)
|
||||||
for (int i = 3; i < Size.X-6; i++)
|
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);
|
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
|
#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);
|
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user