display hex value in deco editor (replaces Cancel button)
This commit is contained in:
parent
a4f12d367b
commit
a9ccbf409b
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iomanip>
|
||||||
#include "ColourPickerActivity.h"
|
#include "ColourPickerActivity.h"
|
||||||
#include "interface/Textbox.h"
|
#include "interface/Textbox.h"
|
||||||
#include "interface/Label.h"
|
#include "interface/Label.h"
|
||||||
@ -49,6 +50,7 @@ ColourPickerActivity::ColourPickerActivity(ui::Colour initialColour, ColourPicke
|
|||||||
if (alpha > 255)
|
if (alpha > 255)
|
||||||
a->aValue->SetText("255");
|
a->aValue->SetText("255");
|
||||||
a->currentAlpha = format::StringToNumber<int>(a->aValue->GetText());
|
a->currentAlpha = format::StringToNumber<int>(a->aValue->GetText());
|
||||||
|
a->UpdateHexLabel(r, g, b, alpha);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -76,16 +78,8 @@ ColourPickerActivity::ColourPickerActivity(ui::Colour initialColour, ColourPicke
|
|||||||
aValue->SetInputType(ui::Textbox::Number);
|
aValue->SetInputType(ui::Textbox::Number);
|
||||||
AddComponent(aValue);
|
AddComponent(aValue);
|
||||||
|
|
||||||
class CancelAction: public ui::ButtonAction
|
hexValue = new::ui::Label(ui::Point(150, Size.Y-23), ui::Point(53, 17), "0xFFFFFFFF");
|
||||||
{
|
AddComponent(hexValue);
|
||||||
ColourPickerActivity * a;
|
|
||||||
public:
|
|
||||||
CancelAction(ColourPickerActivity * a) : a(a) { }
|
|
||||||
void ActionCallback(ui::Button * sender)
|
|
||||||
{
|
|
||||||
a->Exit();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class OkayAction: public ui::ButtonAction
|
class OkayAction: public ui::ButtonAction
|
||||||
{
|
{
|
||||||
@ -108,17 +102,24 @@ ColourPickerActivity::ColourPickerActivity(ui::Colour initialColour, ColourPicke
|
|||||||
AddComponent(doneButton);
|
AddComponent(doneButton);
|
||||||
SetOkayButton(doneButton);
|
SetOkayButton(doneButton);
|
||||||
|
|
||||||
ui::Button * cancelButton = new ui::Button(ui::Point(Size.X-90, Size.Y-23), ui::Point(40, 17), "Cancel");
|
|
||||||
cancelButton->SetActionCallback(new CancelAction(this));
|
|
||||||
AddComponent(cancelButton);
|
|
||||||
SetCancelButton(cancelButton);
|
|
||||||
|
|
||||||
rValue->SetText(format::NumberToString<int>(initialColour.Red));
|
rValue->SetText(format::NumberToString<int>(initialColour.Red));
|
||||||
gValue->SetText(format::NumberToString<int>(initialColour.Green));
|
gValue->SetText(format::NumberToString<int>(initialColour.Green));
|
||||||
bValue->SetText(format::NumberToString<int>(initialColour.Blue));
|
bValue->SetText(format::NumberToString<int>(initialColour.Blue));
|
||||||
aValue->SetText(format::NumberToString<int>(initialColour.Alpha));
|
aValue->SetText(format::NumberToString<int>(initialColour.Alpha));
|
||||||
RGB_to_HSV(initialColour.Red, initialColour.Green, initialColour.Blue, ¤tHue, ¤tSaturation, ¤tValue);
|
RGB_to_HSV(initialColour.Red, initialColour.Green, initialColour.Blue, ¤tHue, ¤tSaturation, ¤tValue);
|
||||||
currentAlpha = initialColour.Alpha;
|
currentAlpha = initialColour.Alpha;
|
||||||
|
UpdateHexLabel(initialColour.Red, initialColour.Green, initialColour.Blue, initialColour.Alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColourPickerActivity::UpdateHexLabel(int r, int g, int b, int a)
|
||||||
|
{
|
||||||
|
std::stringstream hex;
|
||||||
|
hex << std::hex << "0x" << std::setfill('0') << std::setw(2) << std::uppercase << a << std::setw(2) << r << std::setw(2) << g << std::setw(2) << b;
|
||||||
|
hexValue->SetText(hex.str());
|
||||||
|
}
|
||||||
|
void ColourPickerActivity::OnTryExit(ExitMethod method)
|
||||||
|
{
|
||||||
|
Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColourPickerActivity::OnMouseMove(int x, int y, int dx, int dy)
|
void ColourPickerActivity::OnMouseMove(int x, int y, int dx, int dy)
|
||||||
@ -161,6 +162,7 @@ void ColourPickerActivity::OnMouseMove(int x, int y, int dx, int dy)
|
|||||||
rValue->SetText(format::NumberToString<int>(cr));
|
rValue->SetText(format::NumberToString<int>(cr));
|
||||||
gValue->SetText(format::NumberToString<int>(cg));
|
gValue->SetText(format::NumberToString<int>(cg));
|
||||||
bValue->SetText(format::NumberToString<int>(cb));
|
bValue->SetText(format::NumberToString<int>(cb));
|
||||||
|
UpdateHexLabel(cr, cg, cb, currentAlpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,6 +204,7 @@ void ColourPickerActivity::OnMouseDown(int x, int y, unsigned button)
|
|||||||
rValue->SetText(format::NumberToString<int>(cr));
|
rValue->SetText(format::NumberToString<int>(cr));
|
||||||
gValue->SetText(format::NumberToString<int>(cg));
|
gValue->SetText(format::NumberToString<int>(cg));
|
||||||
bValue->SetText(format::NumberToString<int>(cb));
|
bValue->SetText(format::NumberToString<int>(cb));
|
||||||
|
UpdateHexLabel(cr, cg, cb, currentAlpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,6 +217,7 @@ void ColourPickerActivity::OnMouseUp(int x, int y, unsigned button)
|
|||||||
rValue->SetText(format::NumberToString<int>(cr));
|
rValue->SetText(format::NumberToString<int>(cr));
|
||||||
gValue->SetText(format::NumberToString<int>(cg));
|
gValue->SetText(format::NumberToString<int>(cg));
|
||||||
bValue->SetText(format::NumberToString<int>(cb));
|
bValue->SetText(format::NumberToString<int>(cb));
|
||||||
|
UpdateHexLabel(cr, cg, cb, currentAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mouseDown)
|
if(mouseDown)
|
||||||
|
@ -27,12 +27,16 @@ class ColourPickerActivity: public WindowActivity {
|
|||||||
ui::Textbox * gValue;
|
ui::Textbox * gValue;
|
||||||
ui::Textbox * bValue;
|
ui::Textbox * bValue;
|
||||||
ui::Textbox * aValue;
|
ui::Textbox * aValue;
|
||||||
|
ui::Label * hexValue;
|
||||||
|
|
||||||
ColourPickedCallback * callback;
|
ColourPickedCallback * callback;
|
||||||
|
|
||||||
|
void UpdateHexLabel(int r, int g, int b, int a);
|
||||||
public:
|
public:
|
||||||
virtual void OnMouseMove(int x, int y, int dx, int dy);
|
virtual void OnMouseMove(int x, int y, int dx, int dy);
|
||||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||||
virtual void OnMouseUp(int x, int y, unsigned button);
|
virtual void OnMouseUp(int x, int y, unsigned button);
|
||||||
|
virtual void OnTryExit(ExitMethod method);
|
||||||
ColourPickerActivity(ui::Colour initialColour, ColourPickedCallback * callback = NULL);
|
ColourPickerActivity(ui::Colour initialColour, ColourPickedCallback * callback = NULL);
|
||||||
virtual ~ColourPickerActivity();
|
virtual ~ColourPickerActivity();
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
|
Loading…
Reference in New Issue
Block a user