1 /*
2 	GWEN
3 	Copyright (c) 2010 Facepunch Studios
4 	See license in Gwen.h
5 */
6 
7 #pragma once
8 #ifndef GWEN_CONTROLS_COLORPICKER_H
9 #define GWEN_CONTROLS_COLORPICKER_H
10 
11 #include "Gwen/Controls/Base.h"
12 #include "Gwen/Gwen.h"
13 #include "Gwen/Skin.h"
14 
15 namespace Gwen
16 {
17 namespace ControlsInternal
18 {
19 class GWEN_EXPORT ColorDisplay : public Controls::Base
20 {
21 public:
GWEN_CONTROL_INLINE(ColorDisplay,Controls::Base)22 	GWEN_CONTROL_INLINE(ColorDisplay, Controls::Base)
23 	{
24 		SetSize(32, 32);
25 		m_Color = Color(255, 0, 0, 255);
26 		m_DrawCheckers = true;
27 	}
28 
Render(Gwen::Skin::Base * skin)29 	virtual void Render(Gwen::Skin::Base* skin)
30 	{
31 		skin->DrawColorDisplay(this, m_Color);
32 	}
33 
SetColor(Gwen::Color color)34 	virtual void SetColor(Gwen::Color color) { m_Color = color; }
GetColor()35 	virtual Gwen::Color GetColor() { return m_Color; }
36 
SetRed(int red)37 	virtual void SetRed(int red) { m_Color.r = red; }
SetGreen(int green)38 	virtual void SetGreen(int green) { m_Color.g = green; }
SetBlue(int blue)39 	virtual void SetBlue(int blue) { m_Color.b = blue; }
SetAlpha(int alpha)40 	virtual void SetAlpha(int alpha) { m_Color.a = alpha; }
41 
SetDrawCheckers(bool should)42 	virtual void SetDrawCheckers(bool should) { m_DrawCheckers = should; }
43 
44 protected:
45 	Gwen::Color m_Color;
46 	bool m_DrawCheckers;
47 };
48 }  // namespace ControlsInternal
49 namespace Controls
50 {
51 class GWEN_EXPORT ColorPicker : public Base
52 {
53 public:
54 	GWEN_CONTROL(ColorPicker, Base);
55 
56 	virtual void Render(Skin::Base* skin);
57 	virtual void Layout(Skin::Base* skin);
58 	virtual void CreateControls();
59 	virtual void SlidersMoved(Gwen::Controls::Base* control);
60 	virtual void NumericTyped(Gwen::Controls::Base* control);
61 	virtual void UpdateControls();
62 	virtual void UpdateColorControls(Gwen::String name, Gwen::Color col, int sliderVal);
63 	virtual void CreateColorControl(Gwen::String name, int y);
64 
65 	virtual void SetColor(Gwen::Color color);
GetColor()66 	virtual Gwen::Color GetColor() { return m_Color; }
67 
68 	int GetColorByName(Gwen::String colorName);
69 	void SetColorByName(Gwen::String colorName, int colorValue);
70 	Gwen::String GetColorFromName(Gwen::String name);
71 	virtual void SetAlphaVisible(bool visible);
72 
SetRed(int red)73 	virtual void SetRed(int red) { m_Color.r = red; }
SetGreen(int green)74 	virtual void SetGreen(int green) { m_Color.g = green; }
SetBlue(int blue)75 	virtual void SetBlue(int blue) { m_Color.b = blue; }
SetAlpha(int alpha)76 	virtual void SetAlpha(int alpha) { m_Color.a = alpha; }
77 
78 	Event::Caller onColorChanged;
79 
80 protected:
81 	Gwen::Color m_Color;
82 };
83 }  // namespace Controls
84 }  // namespace Gwen
85 #endif
86