aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CGUIColorSelectDialog.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CGUIColorSelectDialog.cpp
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CGUIColorSelectDialog.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CGUIColorSelectDialog.cpp966
1 files changed, 483 insertions, 483 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CGUIColorSelectDialog.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CGUIColorSelectDialog.cpp
index 0744ce9..d7dba9e 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CGUIColorSelectDialog.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CGUIColorSelectDialog.cpp
@@ -1,483 +1,483 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "CGUIColorSelectDialog.h" 5#include "CGUIColorSelectDialog.h"
6 6
7#ifdef _IRR_COMPILE_WITH_GUI_ 7#ifdef _IRR_COMPILE_WITH_GUI_
8 8
9#include "IGUISkin.h" 9#include "IGUISkin.h"
10#include "IGUIEnvironment.h" 10#include "IGUIEnvironment.h"
11#include "IVideoDriver.h" 11#include "IVideoDriver.h"
12#include "IGUIButton.h" 12#include "IGUIButton.h"
13#include "IGUIStaticText.h" 13#include "IGUIStaticText.h"
14#include "IGUIFont.h" 14#include "IGUIFont.h"
15#include "IGUISpriteBank.h" 15#include "IGUISpriteBank.h"
16#include "IFileList.h" 16#include "IFileList.h"
17#include "os.h" 17#include "os.h"
18#include "fast_atof.h" 18#include "fast_atof.h"
19 19
20namespace irr 20namespace irr
21{ 21{
22namespace gui 22namespace gui
23{ 23{
24 24
25const s32 CSD_WIDTH = 350; 25const s32 CSD_WIDTH = 350;
26const s32 CSD_HEIGHT = 300; 26const s32 CSD_HEIGHT = 300;
27 27
28namespace 28namespace
29{ 29{
30 30
31struct subElementPredefines 31struct subElementPredefines
32{ 32{
33 const wchar_t *pre; 33 const wchar_t *pre;
34 const wchar_t *init; 34 const wchar_t *init;
35 const wchar_t *post; 35 const wchar_t *post;
36 int x, y; 36 int x, y;
37 int range_down ,range_up; 37 int range_down ,range_up;
38}; 38};
39 39
40static const subElementPredefines Template [] = 40static const subElementPredefines Template [] =
41{ 41{
42 { L"A:", L"0", 0,50,165, 0, 255 }, 42 { L"A:", L"0", 0,50,165, 0, 255 },
43 { L"R:", L"0", 0,20,205, 0, 255 }, 43 { L"R:", L"0", 0,20,205, 0, 255 },
44 { L"G:", L"0", 0,20,230, 0, 255 }, 44 { L"G:", L"0", 0,20,230, 0, 255 },
45 { L"B:", L"0", 0,20,255, 0, 255 }, 45 { L"B:", L"0", 0,20,255, 0, 255 },
46 { L"H:", L"0", L"°",80,205, 0, 360 }, 46 { L"H:", L"0", L"°",80,205, 0, 360 },
47 { L"S:", L"0", L"%",80,230, 0, 100 }, 47 { L"S:", L"0", L"%",80,230, 0, 100 },
48 { L"L:", L"0", L"%",80,255, 0, 100 }, 48 { L"L:", L"0", L"%",80,255, 0, 100 },
49}; 49};
50 50
51} 51}
52 52
53//! constructor 53//! constructor
54CGUIColorSelectDialog::CGUIColorSelectDialog(const wchar_t* title, IGUIEnvironment* environment, IGUIElement* parent, s32 id) 54CGUIColorSelectDialog::CGUIColorSelectDialog(const wchar_t* title, IGUIEnvironment* environment, IGUIElement* parent, s32 id)
55 : IGUIColorSelectDialog(environment, parent, id, 55 : IGUIColorSelectDialog(environment, parent, id,
56 core::rect<s32>((parent->getAbsolutePosition().getWidth()-CSD_WIDTH)/2, 56 core::rect<s32>((parent->getAbsolutePosition().getWidth()-CSD_WIDTH)/2,
57 (parent->getAbsolutePosition().getHeight()-CSD_HEIGHT)/2, 57 (parent->getAbsolutePosition().getHeight()-CSD_HEIGHT)/2,
58 (parent->getAbsolutePosition().getWidth()-CSD_WIDTH)/2+CSD_WIDTH, 58 (parent->getAbsolutePosition().getWidth()-CSD_WIDTH)/2+CSD_WIDTH,
59 (parent->getAbsolutePosition().getHeight()-CSD_HEIGHT)/2+CSD_HEIGHT)), 59 (parent->getAbsolutePosition().getHeight()-CSD_HEIGHT)/2+CSD_HEIGHT)),
60 Dragging(false) 60 Dragging(false)
61{ 61{
62 #ifdef _DEBUG 62 #ifdef _DEBUG
63 IGUIElement::setDebugName("CGUIColorSelectDialog"); 63 IGUIElement::setDebugName("CGUIColorSelectDialog");
64 #endif 64 #endif
65 65
66 Text = title; 66 Text = title;
67 67
68 IGUISkin* skin = Environment->getSkin(); 68 IGUISkin* skin = Environment->getSkin();
69 69
70 const s32 buttonw = environment->getSkin()->getSize(EGDS_WINDOW_BUTTON_WIDTH); 70 const s32 buttonw = environment->getSkin()->getSize(EGDS_WINDOW_BUTTON_WIDTH);
71 const s32 posx = RelativeRect.getWidth() - buttonw - 4; 71 const s32 posx = RelativeRect.getWidth() - buttonw - 4;
72 72
73 CloseButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), 73 CloseButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw),
74 this, -1, L"", skin ? skin->getDefaultText(EGDT_WINDOW_CLOSE) : L"Close"); 74 this, -1, L"", skin ? skin->getDefaultText(EGDT_WINDOW_CLOSE) : L"Close");
75 if (skin && skin->getSpriteBank()) 75 if (skin && skin->getSpriteBank())
76 { 76 {
77 CloseButton->setSpriteBank(skin->getSpriteBank()); 77 CloseButton->setSpriteBank(skin->getSpriteBank());
78 CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), skin->getColor(EGDC_WINDOW_SYMBOL)); 78 CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), skin->getColor(EGDC_WINDOW_SYMBOL));
79 CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), skin->getColor(EGDC_WINDOW_SYMBOL)); 79 CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), skin->getColor(EGDC_WINDOW_SYMBOL));
80 } 80 }
81 CloseButton->setSubElement(true); 81 CloseButton->setSubElement(true);
82 CloseButton->setTabStop(false); 82 CloseButton->setTabStop(false);
83 CloseButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); 83 CloseButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
84 CloseButton->grab(); 84 CloseButton->grab();
85 85
86 OKButton = Environment->addButton( 86 OKButton = Environment->addButton(
87 core::rect<s32>(RelativeRect.getWidth()-80, 30, RelativeRect.getWidth()-10, 50), 87 core::rect<s32>(RelativeRect.getWidth()-80, 30, RelativeRect.getWidth()-10, 50),
88 this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_OK) : L"OK"); 88 this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_OK) : L"OK");
89 OKButton->setSubElement(true); 89 OKButton->setSubElement(true);
90 OKButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); 90 OKButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
91 OKButton->grab(); 91 OKButton->grab();
92 92
93 CancelButton = Environment->addButton( 93 CancelButton = Environment->addButton(
94 core::rect<s32>(RelativeRect.getWidth()-80, 55, RelativeRect.getWidth()-10, 75), 94 core::rect<s32>(RelativeRect.getWidth()-80, 55, RelativeRect.getWidth()-10, 75),
95 this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_CANCEL) : L"Cancel"); 95 this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_CANCEL) : L"Cancel");
96 CancelButton->setSubElement(true); 96 CancelButton->setSubElement(true);
97 CancelButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); 97 CancelButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
98 CancelButton->grab(); 98 CancelButton->grab();
99 99
100 video::IVideoDriver* driver = Environment->getVideoDriver(); 100 video::IVideoDriver* driver = Environment->getVideoDriver();
101 ColorRing.Texture = driver->getTexture ( "#colorring" ); 101 ColorRing.Texture = driver->getTexture ( "#colorring" );
102 if ( 0 == ColorRing.Texture ) 102 if ( 0 == ColorRing.Texture )
103 { 103 {
104 buildColorRing(core::dimension2d<u32>(128, 128), 1, 104 buildColorRing(core::dimension2d<u32>(128, 128), 1,
105 Environment->getSkin()->getColor(EGDC_3D_SHADOW)); 105 Environment->getSkin()->getColor(EGDC_3D_SHADOW));
106 } 106 }
107 107
108 core::rect<s32> r(20,20, 0,0); 108 core::rect<s32> r(20,20, 0,0);
109 109
110 ColorRing.Control = Environment->addImage(ColorRing.Texture, r.UpperLeftCorner, true, this); 110 ColorRing.Control = Environment->addImage(ColorRing.Texture, r.UpperLeftCorner, true, this);
111 ColorRing.Control->setSubElement(true); 111 ColorRing.Control->setSubElement(true);
112 ColorRing.Control->grab(); 112 ColorRing.Control->grab();
113 113
114 for ( u32 i = 0; i != sizeof (Template) / sizeof ( subElementPredefines ); ++i ) 114 for ( u32 i = 0; i != sizeof (Template) / sizeof ( subElementPredefines ); ++i )
115 { 115 {
116 if ( Template[i].pre ) 116 if ( Template[i].pre )
117 { 117 {
118 r.UpperLeftCorner.X = Template[i].x; 118 r.UpperLeftCorner.X = Template[i].x;
119 r.UpperLeftCorner.Y = Template[i].y; 119 r.UpperLeftCorner.Y = Template[i].y;
120 r.LowerRightCorner.X = r.UpperLeftCorner.X + 15; 120 r.LowerRightCorner.X = r.UpperLeftCorner.X + 15;
121 r.LowerRightCorner.Y = r.UpperLeftCorner.Y + 20; 121 r.LowerRightCorner.Y = r.UpperLeftCorner.Y + 20;
122 IGUIElement *t = Environment->addStaticText(Template[i].pre, r, false, false, this); 122 IGUIElement *t = Environment->addStaticText(Template[i].pre, r, false, false, this);
123 t->setSubElement(true); 123 t->setSubElement(true);
124 } 124 }
125 125
126 if ( Template[i].post ) 126 if ( Template[i].post )
127 { 127 {
128 r.UpperLeftCorner.X = Template[i].x + 56; 128 r.UpperLeftCorner.X = Template[i].x + 56;
129 r.UpperLeftCorner.Y = Template[i].y; 129 r.UpperLeftCorner.Y = Template[i].y;
130 r.LowerRightCorner.X = r.UpperLeftCorner.X + 15; 130 r.LowerRightCorner.X = r.UpperLeftCorner.X + 15;
131 r.LowerRightCorner.Y = r.UpperLeftCorner.Y + 20; 131 r.LowerRightCorner.Y = r.UpperLeftCorner.Y + 20;
132 IGUIElement *t = Environment->addStaticText( Template[i].post, r, false, false, this); 132 IGUIElement *t = Environment->addStaticText( Template[i].post, r, false, false, this);
133 t->setSubElement(true); 133 t->setSubElement(true);
134 } 134 }
135 135
136 r.UpperLeftCorner.X = Template[i].x + 15; 136 r.UpperLeftCorner.X = Template[i].x + 15;
137 r.UpperLeftCorner.Y = Template[i].y-2; 137 r.UpperLeftCorner.Y = Template[i].y-2;
138 r.LowerRightCorner.X = r.UpperLeftCorner.X + 40; 138 r.LowerRightCorner.X = r.UpperLeftCorner.X + 40;
139 r.LowerRightCorner.Y = r.UpperLeftCorner.Y + 20; 139 r.LowerRightCorner.Y = r.UpperLeftCorner.Y + 20;
140 140
141 gui::IGUISpinBox* spin = Environment->addSpinBox( Template[i].init, r, true, this); 141 gui::IGUISpinBox* spin = Environment->addSpinBox( Template[i].init, r, true, this);
142 spin->setSubElement(true); 142 spin->setSubElement(true);
143 spin->setDecimalPlaces(0); 143 spin->setDecimalPlaces(0);
144 spin->setRange((f32)Template[i].range_down, (f32)Template[i].range_up); 144 spin->setRange((f32)Template[i].range_down, (f32)Template[i].range_up);
145 spin->grab(); 145 spin->grab();
146 146
147 Battery.push_back(spin); 147 Battery.push_back(spin);
148 } 148 }
149 149
150 bringToFront(CancelButton); 150 bringToFront(CancelButton);
151 bringToFront(OKButton); 151 bringToFront(OKButton);
152} 152}
153 153
154 154
155//! destructor 155//! destructor
156CGUIColorSelectDialog::~CGUIColorSelectDialog() 156CGUIColorSelectDialog::~CGUIColorSelectDialog()
157{ 157{
158 if (CloseButton) 158 if (CloseButton)
159 CloseButton->drop(); 159 CloseButton->drop();
160 160
161 if (OKButton) 161 if (OKButton)
162 OKButton->drop(); 162 OKButton->drop();
163 163
164 if (CancelButton) 164 if (CancelButton)
165 CancelButton->drop(); 165 CancelButton->drop();
166 166
167 for (u32 i = 0; i != Battery.size(); ++i) 167 for (u32 i = 0; i != Battery.size(); ++i)
168 Battery[i]->drop(); 168 Battery[i]->drop();
169 169
170 if (ColorRing.Control) 170 if (ColorRing.Control)
171 ColorRing.Control->drop(); 171 ColorRing.Control->drop();
172} 172}
173 173
174 174
175//! renders a antialiased, colored ring 175//! renders a antialiased, colored ring
176void CGUIColorSelectDialog::buildColorRing( const core::dimension2d<u32> & dim, s32 supersample, const video::SColor& borderColor ) 176void CGUIColorSelectDialog::buildColorRing( const core::dimension2d<u32> & dim, s32 supersample, const video::SColor& borderColor )
177{ 177{
178 const core::dimension2d<u32> d(dim.Width * supersample, dim.Height * supersample); 178 const core::dimension2d<u32> d(dim.Width * supersample, dim.Height * supersample);
179 video::IVideoDriver* driver = Environment->getVideoDriver(); 179 video::IVideoDriver* driver = Environment->getVideoDriver();
180 180
181 video::IImage *RawTexture = driver->createImage(video::ECF_A8R8G8B8, d); 181 video::IImage *RawTexture = driver->createImage(video::ECF_A8R8G8B8, d);
182 182
183 RawTexture->fill ( 0x00808080 ); 183 RawTexture->fill ( 0x00808080 );
184 184
185 const s32 radiusOut = ( d.Width / 2 ) - 4; 185 const s32 radiusOut = ( d.Width / 2 ) - 4;
186 const s32 fullR2 = radiusOut * radiusOut; 186 const s32 fullR2 = radiusOut * radiusOut;
187 187
188 video::SColorf rgb(0,0,0); 188 video::SColorf rgb(0,0,0);
189 video::SColorHSL hsl; 189 video::SColorHSL hsl;
190 hsl.Luminance = 50; 190 hsl.Luminance = 50;
191 hsl.Saturation = 100; 191 hsl.Saturation = 100;
192 192
193 core::position2d<s32> p; 193 core::position2d<s32> p;
194 for ( p.Y = -radiusOut; p.Y <= radiusOut; p.Y += 1 ) 194 for ( p.Y = -radiusOut; p.Y <= radiusOut; p.Y += 1 )
195 { 195 {
196 s32 y2 = p.Y * p.Y; 196 s32 y2 = p.Y * p.Y;
197 197
198 for (p.X = -radiusOut; p.X <= radiusOut; p.X += 1) 198 for (p.X = -radiusOut; p.X <= radiusOut; p.X += 1)
199 { 199 {
200 s32 r2 = y2 + ( p.X * p.X ); 200 s32 r2 = y2 + ( p.X * p.X );
201 201
202 // test point in circle 202 // test point in circle
203 s32 testa = r2 - fullR2; 203 s32 testa = r2 - fullR2;
204 204
205 if ( testa < 0 ) 205 if ( testa < 0 )
206 { 206 {
207 // dotproduct u ( x,y ) * v ( 1, 0 ) = cosinus(a) 207 // dotproduct u ( x,y ) * v ( 1, 0 ) = cosinus(a)
208 208
209 const f32 r = sqrtf((f32) r2); 209 const f32 r = sqrtf((f32) r2);
210 210
211 // normalize, dotproduct = xnorm 211 // normalize, dotproduct = xnorm
212 const f32 xn = r == 0.f ? 0.f : -p.X * core::reciprocal(r); 212 const f32 xn = r == 0.f ? 0.f : -p.X * core::reciprocal(r);
213 213
214 hsl.Hue = acosf(xn)*core::RADTODEG; 214 hsl.Hue = acosf(xn)*core::RADTODEG;
215 if ( p.Y > 0 ) 215 if ( p.Y > 0 )
216 hsl.Hue = 360 - hsl.Hue; 216 hsl.Hue = 360 - hsl.Hue;
217 hsl.Hue -= 90; 217 hsl.Hue -= 90;
218 218
219 const f32 rTest = r / radiusOut; 219 const f32 rTest = r / radiusOut;
220#if 0 220#if 0
221 if (rTest < 0.33f) 221 if (rTest < 0.33f)
222 { 222 {
223 // luminance from 0 to 50 223 // luminance from 0 to 50
224 hsl.Luminance = 50*(rTest/0.33); 224 hsl.Luminance = 50*(rTest/0.33);
225 hsl.Saturation = 0.f; 225 hsl.Saturation = 0.f;
226 hsl.toRGB(rgb); 226 hsl.toRGB(rgb);
227 } 227 }
228 else 228 else
229 if ( rTest < 0.66f ) 229 if ( rTest < 0.66f )
230 { 230 {
231 // saturation from 0 to 100 231 // saturation from 0 to 100
232 hsl.Saturation = 100*(( rTest - 0.33f ) / 0.33f); 232 hsl.Saturation = 100*(( rTest - 0.33f ) / 0.33f);
233 hsl.Luminance = 50; 233 hsl.Luminance = 50;
234 hsl.toRGB(rgb); 234 hsl.toRGB(rgb);
235 } 235 }
236 else 236 else
237 { 237 {
238 // luminance from 50 to 100 238 // luminance from 50 to 100
239 hsl.Luminance = 100*(0.5f + ( ( rTest - 0.66f ) / .66f )); 239 hsl.Luminance = 100*(0.5f + ( ( rTest - 0.66f ) / .66f ));
240 hsl.Saturation = 100; 240 hsl.Saturation = 100;
241 hsl.toRGB(rgb); 241 hsl.toRGB(rgb);
242 } 242 }
243 // borders should be slightly transparent 243 // borders should be slightly transparent
244 if ( rTest >= 0.95f ) 244 if ( rTest >= 0.95f )
245 rgb.a = (1.f-rTest)*20; 245 rgb.a = (1.f-rTest)*20;
246 else 246 else
247 rgb.a=1.f; 247 rgb.a=1.f;
248#else 248#else
249 if ( rTest > 0.5f ) 249 if ( rTest > 0.5f )
250 { 250 {
251 hsl.Saturation = 100; 251 hsl.Saturation = 100;
252 hsl.Luminance = 50; 252 hsl.Luminance = 50;
253 hsl.toRGB(rgb); 253 hsl.toRGB(rgb);
254 } 254 }
255 // borders should be slightly transparent 255 // borders should be slightly transparent
256 if ( rTest < 0.5f ) 256 if ( rTest < 0.5f )
257 rgb.a = 0; 257 rgb.a = 0;
258 else if ( rTest >= 0.95f ) 258 else if ( rTest >= 0.95f )
259 rgb.a = (1.f-rTest)*20; 259 rgb.a = (1.f-rTest)*20;
260 else if ( rTest <= 0.55f ) 260 else if ( rTest <= 0.55f )
261 rgb.a = (rTest-0.5f)*20; 261 rgb.a = (rTest-0.5f)*20;
262 else 262 else
263 rgb.a=1.f; 263 rgb.a=1.f;
264#endif 264#endif
265 RawTexture->setPixel(4+p.X+radiusOut, 4+p.Y+radiusOut, rgb.toSColor()); 265 RawTexture->setPixel(4+p.X+radiusOut, 4+p.Y+radiusOut, rgb.toSColor());
266 } 266 }
267 } 267 }
268 } 268 }
269 269
270 RawTexture->unlock (); 270 RawTexture->unlock ();
271 271
272 if ( supersample > 1 ) 272 if ( supersample > 1 )
273 { 273 {
274 video::IImage * filter = driver->createImage(video::ECF_A8R8G8B8, dim ); 274 video::IImage * filter = driver->createImage(video::ECF_A8R8G8B8, dim );
275 RawTexture->copyToScalingBoxFilter(filter); 275 RawTexture->copyToScalingBoxFilter(filter);
276 RawTexture->drop(); 276 RawTexture->drop();
277 RawTexture = filter; 277 RawTexture = filter;
278 } 278 }
279 279
280 bool generateMipLevels = driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); 280 bool generateMipLevels = driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
281 driver->setTextureCreationFlag( video::ETCF_CREATE_MIP_MAPS, false); 281 driver->setTextureCreationFlag( video::ETCF_CREATE_MIP_MAPS, false);
282 282
283 ColorRing.Texture = driver->addTexture ( "#colorring", RawTexture); 283 ColorRing.Texture = driver->addTexture ( "#colorring", RawTexture);
284 RawTexture->drop(); 284 RawTexture->drop();
285 285
286 driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, generateMipLevels); 286 driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, generateMipLevels);
287} 287}
288 288
289 289
290//! called if an event happened. 290//! called if an event happened.
291bool CGUIColorSelectDialog::OnEvent(const SEvent& event) 291bool CGUIColorSelectDialog::OnEvent(const SEvent& event)
292{ 292{
293 if (isEnabled()) 293 if (isEnabled())
294 { 294 {
295 switch(event.EventType) 295 switch(event.EventType)
296 { 296 {
297 case EET_GUI_EVENT: 297 case EET_GUI_EVENT:
298 switch(event.GUIEvent.EventType) 298 switch(event.GUIEvent.EventType)
299 { 299 {
300 case EGET_SPINBOX_CHANGED: 300 case EGET_SPINBOX_CHANGED:
301 { 301 {
302 for ( u32 i = 0; i!= Battery.size (); ++i ) 302 for ( u32 i = 0; i!= Battery.size (); ++i )
303 { 303 {
304 if ( event.GUIEvent.Caller == Battery[i] ) 304 if ( event.GUIEvent.Caller == Battery[i] )
305 { 305 {
306 if (i<4) 306 if (i<4)
307 { 307 {
308 video::SColor rgb((u32)Battery[0]->getValue(), (u32)Battery[1]->getValue(), 308 video::SColor rgb((u32)Battery[0]->getValue(), (u32)Battery[1]->getValue(),
309 (u32)Battery[2]->getValue(), (u32)Battery[3]->getValue()); 309 (u32)Battery[2]->getValue(), (u32)Battery[3]->getValue());
310 video::SColorHSL hsl; 310 video::SColorHSL hsl;
311 video::SColorf rgb2(rgb); 311 video::SColorf rgb2(rgb);
312 hsl.fromRGB(rgb2); 312 hsl.fromRGB(rgb2);
313 Battery[4]->setValue(hsl.Hue); 313 Battery[4]->setValue(hsl.Hue);
314 Battery[5]->setValue(hsl.Saturation); 314 Battery[5]->setValue(hsl.Saturation);
315 Battery[6]->setValue(hsl.Luminance); 315 Battery[6]->setValue(hsl.Luminance);
316 } 316 }
317 else 317 else
318 { 318 {
319 video::SColorHSL hsl(Battery[4]->getValue(), Battery[5]->getValue(), 319 video::SColorHSL hsl(Battery[4]->getValue(), Battery[5]->getValue(),
320 Battery[6]->getValue()); 320 Battery[6]->getValue());
321 video::SColorf rgb2; 321 video::SColorf rgb2;
322 hsl.toRGB(rgb2); 322 hsl.toRGB(rgb2);
323 video::SColor rgb = rgb2.toSColor(); 323 video::SColor rgb = rgb2.toSColor();
324 Battery[1]->setValue((f32)rgb.getRed()); 324 Battery[1]->setValue((f32)rgb.getRed());
325 Battery[2]->setValue((f32)rgb.getGreen()); 325 Battery[2]->setValue((f32)rgb.getGreen());
326 Battery[3]->setValue((f32)rgb.getBlue()); 326 Battery[3]->setValue((f32)rgb.getBlue());
327 } 327 }
328 } 328 }
329 } 329 }
330 return true; 330 return true;
331 } 331 }
332 332
333 case EGET_ELEMENT_FOCUS_LOST: 333 case EGET_ELEMENT_FOCUS_LOST:
334 Dragging = false; 334 Dragging = false;
335 break; 335 break;
336 case EGET_BUTTON_CLICKED: 336 case EGET_BUTTON_CLICKED:
337 if (event.GUIEvent.Caller == CloseButton || 337 if (event.GUIEvent.Caller == CloseButton ||
338 event.GUIEvent.Caller == CancelButton) 338 event.GUIEvent.Caller == CancelButton)
339 { 339 {
340 sendCancelEvent(); 340 sendCancelEvent();
341 remove(); 341 remove();
342 return true; 342 return true;
343 } 343 }
344 else 344 else
345 if (event.GUIEvent.Caller == OKButton) 345 if (event.GUIEvent.Caller == OKButton)
346 { 346 {
347 sendSelectedEvent(); 347 sendSelectedEvent();
348 remove(); 348 remove();
349 return true; 349 return true;
350 } 350 }
351 break; 351 break;
352 352
353 case EGET_LISTBOX_CHANGED: 353 case EGET_LISTBOX_CHANGED:
354 case EGET_LISTBOX_SELECTED_AGAIN: 354 case EGET_LISTBOX_SELECTED_AGAIN:
355 default: 355 default:
356 break; 356 break;
357 } 357 }
358 break; 358 break;
359 case EET_MOUSE_INPUT_EVENT: 359 case EET_MOUSE_INPUT_EVENT:
360 switch(event.MouseInput.Event) 360 switch(event.MouseInput.Event)
361 { 361 {
362 case EMIE_LMOUSE_PRESSED_DOWN: 362 case EMIE_LMOUSE_PRESSED_DOWN:
363 DragStart.X = event.MouseInput.X; 363 DragStart.X = event.MouseInput.X;
364 DragStart.Y = event.MouseInput.Y; 364 DragStart.Y = event.MouseInput.Y;
365 Dragging = true; 365 Dragging = true;
366 Environment->setFocus(this); 366 Environment->setFocus(this);
367 return true; 367 return true;
368 case EMIE_LMOUSE_LEFT_UP: 368 case EMIE_LMOUSE_LEFT_UP:
369 Dragging = false; 369 Dragging = false;
370 Environment->removeFocus(this); 370 Environment->removeFocus(this);
371 return true; 371 return true;
372 case EMIE_MOUSE_MOVED: 372 case EMIE_MOUSE_MOVED:
373 if (Dragging) 373 if (Dragging)
374 { 374 {
375 // gui window should not be dragged outside its parent 375 // gui window should not be dragged outside its parent
376 if (Parent) 376 if (Parent)
377 if (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 || 377 if (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 ||
378 event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 || 378 event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 ||
379 event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 || 379 event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 ||
380 event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1) 380 event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1)
381 381
382 return true; 382 return true;
383 383
384 move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y)); 384 move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y));
385 DragStart.X = event.MouseInput.X; 385 DragStart.X = event.MouseInput.X;
386 DragStart.Y = event.MouseInput.Y; 386 DragStart.Y = event.MouseInput.Y;
387 return true; 387 return true;
388 } 388 }
389 default: 389 default:
390 break; 390 break;
391 } 391 }
392 default: 392 default:
393 break; 393 break;
394 } 394 }
395 } 395 }
396 396
397 return IGUIElement::OnEvent(event); 397 return IGUIElement::OnEvent(event);
398} 398}
399 399
400 400
401//! draws the element and its children 401//! draws the element and its children
402void CGUIColorSelectDialog::draw() 402void CGUIColorSelectDialog::draw()
403{ 403{
404 if (!IsVisible) 404 if (!IsVisible)
405 return; 405 return;
406 406
407 IGUISkin* skin = Environment->getSkin(); 407 IGUISkin* skin = Environment->getSkin();
408 core::rect<s32> rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER), 408 core::rect<s32> rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER),
409 AbsoluteRect, &AbsoluteClippingRect); 409 AbsoluteRect, &AbsoluteClippingRect);
410 410
411 if (Text.size()) 411 if (Text.size())
412 { 412 {
413 rect.UpperLeftCorner.X += 2; 413 rect.UpperLeftCorner.X += 2;
414 rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; 414 rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;
415 415
416 IGUIFont* font = skin->getFont(EGDF_WINDOW); 416 IGUIFont* font = skin->getFont(EGDF_WINDOW);
417 if (font) 417 if (font)
418 font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, 418 font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true,
419 &AbsoluteClippingRect); 419 &AbsoluteClippingRect);
420 } 420 }
421 421
422 IGUIElement::draw(); 422 IGUIElement::draw();
423 423
424 // draw color selector after the window elements 424 // draw color selector after the window elements
425 core::vector2di pos(ColorRing.Control->getAbsolutePosition().UpperLeftCorner); 425 core::vector2di pos(ColorRing.Control->getAbsolutePosition().UpperLeftCorner);
426 pos.X += ColorRing.Texture->getOriginalSize().Width/2; 426 pos.X += ColorRing.Texture->getOriginalSize().Width/2;
427 pos.Y += ColorRing.Texture->getOriginalSize().Height/2; 427 pos.Y += ColorRing.Texture->getOriginalSize().Height/2;
428#if 0 428#if 0
429 const f32 h = Battery[4]->getValue(); 429 const f32 h = Battery[4]->getValue();
430 const f32 s = Battery[5]->getValue(); 430 const f32 s = Battery[5]->getValue();
431 const f32 l = Battery[6]->getValue(); 431 const f32 l = Battery[6]->getValue();
432 const f32 factor = 58.f*(((s==0)&&(l<50))?(l*0.33f/50):( 432 const f32 factor = 58.f*(((s==0)&&(l<50))?(l*0.33f/50):(
433 (s<100)?((.33f+(s*0.33f/100))):((0.66f+(l-50)*0.33f/50)))); 433 (s<100)?((.33f+(s*0.33f/100))):((0.66f+(l-50)*0.33f/50))));
434 434
435#else 435#else
436 const f32 factor = 44; 436 const f32 factor = 44;
437#endif 437#endif
438 pos.X += core::round32(sinf(Battery[4]->getValue()*core::DEGTORAD)*factor); 438 pos.X += core::round32(sinf(Battery[4]->getValue()*core::DEGTORAD)*factor);
439 pos.Y -= core::round32(cosf(Battery[4]->getValue()*core::DEGTORAD)*factor); 439 pos.Y -= core::round32(cosf(Battery[4]->getValue()*core::DEGTORAD)*factor);
440 Environment->getVideoDriver()->draw2DPolygon(pos, 4, 0xffffffff, 4); 440 Environment->getVideoDriver()->draw2DPolygon(pos, 4, 0xffffffff, 4);
441} 441}
442 442
443 443
444video::SColor CGUIColorSelectDialog::getColor() 444video::SColor CGUIColorSelectDialog::getColor()
445{ 445{
446 return video::SColor((u32)Battery[0]->getValue(), (u32)Battery[1]->getValue(), 446 return video::SColor((u32)Battery[0]->getValue(), (u32)Battery[1]->getValue(),
447 (u32)Battery[2]->getValue(), (u32)Battery[3]->getValue()); 447 (u32)Battery[2]->getValue(), (u32)Battery[3]->getValue());
448} 448}
449 449
450video::SColorHSL CGUIColorSelectDialog::getColorHSL() 450video::SColorHSL CGUIColorSelectDialog::getColorHSL()
451{ 451{
452 return video::SColorHSL(Battery[4]->getValue(), Battery[5]->getValue(), 452 return video::SColorHSL(Battery[4]->getValue(), Battery[5]->getValue(),
453 Battery[6]->getValue()); 453 Battery[6]->getValue());
454} 454}
455 455
456//! sends the event that the file has been selected. 456//! sends the event that the file has been selected.
457void CGUIColorSelectDialog::sendSelectedEvent() 457void CGUIColorSelectDialog::sendSelectedEvent()
458{ 458{
459 SEvent event; 459 SEvent event;
460 event.EventType = EET_GUI_EVENT; 460 event.EventType = EET_GUI_EVENT;
461 event.GUIEvent.Caller = this; 461 event.GUIEvent.Caller = this;
462 event.GUIEvent.Element = 0; 462 event.GUIEvent.Element = 0;
463 event.GUIEvent.EventType = EGET_FILE_SELECTED; 463 event.GUIEvent.EventType = EGET_FILE_SELECTED;
464 Parent->OnEvent(event); 464 Parent->OnEvent(event);
465} 465}
466 466
467 467
468//! sends the event that the file choose process has been canceld 468//! sends the event that the file choose process has been canceld
469void CGUIColorSelectDialog::sendCancelEvent() 469void CGUIColorSelectDialog::sendCancelEvent()
470{ 470{
471 SEvent event; 471 SEvent event;
472 event.EventType = EET_GUI_EVENT; 472 event.EventType = EET_GUI_EVENT;
473 event.GUIEvent.Caller = this; 473 event.GUIEvent.Caller = this;
474 event.GUIEvent.Element = 0; 474 event.GUIEvent.Element = 0;
475 event.GUIEvent.EventType = EGET_FILE_CHOOSE_DIALOG_CANCELLED; 475 event.GUIEvent.EventType = EGET_FILE_CHOOSE_DIALOG_CANCELLED;
476 Parent->OnEvent(event); 476 Parent->OnEvent(event);
477} 477}
478 478
479 479
480} // end namespace gui 480} // end namespace gui
481} // end namespace irr 481} // end namespace irr
482 482
483#endif // _IRR_COMPILE_WITH_GUI_ 483#endif // _IRR_COMPILE_WITH_GUI_