1 #pragma once 2 #ifndef GWEN_CONTROLS_PROPERTY_COLORSELECTOR_H 3 #define GWEN_CONTROLS_PROPERTY_COLORSELECTOR_H 4 5 #include "Gwen/Controls/Properties.h" 6 #include "Gwen/Controls/WindowControl.h" 7 #include "Gwen/Controls/HSVColorPicker.h" 8 9 namespace Gwen 10 { 11 namespace Controls 12 { 13 namespace Property 14 { 15 class ColorSelector : public Property::Text 16 { 17 public: GWEN_CONTROL_INLINE(ColorSelector,Property::Text)18 GWEN_CONTROL_INLINE(ColorSelector, Property::Text) 19 { 20 m_Button = new Button(this); 21 m_Button->Dock(Pos::Right); 22 m_Button->SetWidth(20); 23 m_Button->onPress.Add(this, &ThisClass::OnButtonPress); 24 } 25 OnButtonPress(Controls::Base * control)26 void OnButtonPress(Controls::Base* control) 27 { 28 Gwen::Controls::WindowControl* wind = new Gwen::Controls::WindowControl(GetCanvas()); 29 wind->SetTitle(L"Color Selection"); 30 wind->SetSize(256, 180); 31 wind->SetPos(GetCanvas()->Width() * 0.5 - 128, GetCanvas()->Height() * 0.5 - 128); 32 wind->SetDeleteOnClose(true); 33 wind->DisableResizing(); 34 wind->MakeModal(true); 35 36 Gwen::Controls::HSVColorPicker* picker = new Gwen::Controls::HSVColorPicker(wind); 37 picker->SetName("picker"); 38 39 float defaultColor[3]; 40 Gwen::Utility::Strings::To::Floats(Gwen::Utility::UnicodeToString(m_TextBox->GetText()), defaultColor, 3); 41 42 picker->SetColor(Gwen::Color(defaultColor[0], defaultColor[1], defaultColor[2], 255), false, true); 43 picker->onColorChanged.Add(this, &ThisClass::ColorChanged); 44 } 45 ColorChanged(Controls::Base * control)46 void ColorChanged(Controls::Base* control) 47 { 48 Gwen::Controls::HSVColorPicker* picker = control->DynamicCastHSVColorPicker(); 49 50 Gwen::String colorStr; 51 colorStr += Gwen::Utility::ToString((int)picker->GetColor().r) + " "; 52 colorStr += Gwen::Utility::ToString((int)picker->GetColor().g) + " "; 53 colorStr += Gwen::Utility::ToString((int)picker->GetColor().b); 54 55 m_TextBox->SetText(colorStr); 56 DoChanged(); 57 } 58 GetPropertyValue()59 virtual UnicodeString GetPropertyValue() 60 { 61 return m_TextBox->GetText(); 62 } 63 SetPropertyValue(const UnicodeString & v,bool bFireChangeEvents)64 virtual void SetPropertyValue(const UnicodeString& v, bool bFireChangeEvents) 65 { 66 m_TextBox->SetText(v, bFireChangeEvents); 67 } 68 IsEditing()69 virtual bool IsEditing() 70 { 71 return m_TextBox == Gwen::KeyboardFocus; 72 } 73 74 Button* m_Button; 75 }; 76 } // namespace Property 77 } // namespace Controls 78 } // namespace Gwen 79 #endif 80