From a9ccbf409b8970bde83a0f9d87b61d8192bfd525 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Wed, 19 Sep 2012 20:30:39 -0400 Subject: [PATCH] display hex value in deco editor (replaces Cancel button) --- src/colourpicker/ColourPickerActivity.cpp | 34 +++++++++++++---------- src/colourpicker/ColourPickerActivity.h | 4 +++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/colourpicker/ColourPickerActivity.cpp b/src/colourpicker/ColourPickerActivity.cpp index 16007e17b..18e42d61b 100644 --- a/src/colourpicker/ColourPickerActivity.cpp +++ b/src/colourpicker/ColourPickerActivity.cpp @@ -6,6 +6,7 @@ */ #include +#include #include "ColourPickerActivity.h" #include "interface/Textbox.h" #include "interface/Label.h" @@ -49,6 +50,7 @@ ColourPickerActivity::ColourPickerActivity(ui::Colour initialColour, ColourPicke if (alpha > 255) a->aValue->SetText("255"); a->currentAlpha = format::StringToNumber(a->aValue->GetText()); + a->UpdateHexLabel(r, g, b, alpha); } }; @@ -76,16 +78,8 @@ ColourPickerActivity::ColourPickerActivity(ui::Colour initialColour, ColourPicke aValue->SetInputType(ui::Textbox::Number); AddComponent(aValue); - class CancelAction: public ui::ButtonAction - { - ColourPickerActivity * a; - public: - CancelAction(ColourPickerActivity * a) : a(a) { } - void ActionCallback(ui::Button * sender) - { - a->Exit(); - } - }; + hexValue = new::ui::Label(ui::Point(150, Size.Y-23), ui::Point(53, 17), "0xFFFFFFFF"); + AddComponent(hexValue); class OkayAction: public ui::ButtonAction { @@ -108,17 +102,24 @@ ColourPickerActivity::ColourPickerActivity(ui::Colour initialColour, ColourPicke AddComponent(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(initialColour.Red)); gValue->SetText(format::NumberToString(initialColour.Green)); bValue->SetText(format::NumberToString(initialColour.Blue)); aValue->SetText(format::NumberToString(initialColour.Alpha)); RGB_to_HSV(initialColour.Red, initialColour.Green, initialColour.Blue, ¤tHue, ¤tSaturation, ¤tValue); 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) @@ -161,6 +162,7 @@ void ColourPickerActivity::OnMouseMove(int x, int y, int dx, int dy) rValue->SetText(format::NumberToString(cr)); gValue->SetText(format::NumberToString(cg)); bValue->SetText(format::NumberToString(cb)); + UpdateHexLabel(cr, cg, cb, currentAlpha); } } @@ -202,6 +204,7 @@ void ColourPickerActivity::OnMouseDown(int x, int y, unsigned button) rValue->SetText(format::NumberToString(cr)); gValue->SetText(format::NumberToString(cg)); bValue->SetText(format::NumberToString(cb)); + UpdateHexLabel(cr, cg, cb, currentAlpha); } } @@ -214,6 +217,7 @@ void ColourPickerActivity::OnMouseUp(int x, int y, unsigned button) rValue->SetText(format::NumberToString(cr)); gValue->SetText(format::NumberToString(cg)); bValue->SetText(format::NumberToString(cb)); + UpdateHexLabel(cr, cg, cb, currentAlpha); } if(mouseDown) diff --git a/src/colourpicker/ColourPickerActivity.h b/src/colourpicker/ColourPickerActivity.h index d3b9decdf..ec53b91a8 100644 --- a/src/colourpicker/ColourPickerActivity.h +++ b/src/colourpicker/ColourPickerActivity.h @@ -27,12 +27,16 @@ class ColourPickerActivity: public WindowActivity { ui::Textbox * gValue; ui::Textbox * bValue; ui::Textbox * aValue; + ui::Label * hexValue; ColourPickedCallback * callback; + + void UpdateHexLabel(int r, int g, int b, int a); public: virtual void OnMouseMove(int x, int y, int dx, int dy); virtual void OnMouseDown(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); virtual ~ColourPickerActivity(); virtual void OnDraw();