]> git.saurik.com Git - wxWidgets.git/blob - src/ribbon/art_internal.cpp
Don't use margins for wxGrid in place text editor controls.
[wxWidgets.git] / src / ribbon / art_internal.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/ribbon/art_internal.cpp
3 // Purpose: Helper functions & classes used by ribbon art providers
4 // Author: Peter Cawley
5 // Modified by:
6 // Created: 2009-08-04
7 // RCS-ID: $Id$
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_RIBBON
19
20 #include "wx/ribbon/art.h"
21 #include "wx/ribbon/art_internal.h"
22 #include "wx/ribbon/bar.h"
23 #include "wx/ribbon/buttonbar.h"
24 #include "wx/ribbon/gallery.h"
25
26 #ifndef WX_PRECOMP
27 #include "wx/dc.h"
28 #endif
29
30 #ifdef __WXMSW__
31 #include "wx/msw/private.h"
32 #endif
33
34 wxRibbonArtProvider::wxRibbonArtProvider() {}
35 wxRibbonArtProvider::~wxRibbonArtProvider() {}
36
37 wxColour wxRibbonInterpolateColour(const wxColour& start_colour,
38 const wxColour& end_colour,
39 int position,
40 int start_position,
41 int end_position)
42 {
43 if(position <= start_position)
44 {
45 return start_colour;
46 }
47 if(position >= end_position)
48 {
49 return end_colour;
50 }
51 position -= start_position;
52 end_position -= start_position;
53 int r = end_colour.Red() - start_colour.Red();
54 int g = end_colour.Green() - start_colour.Green();
55 int b = end_colour.Blue() - start_colour.Blue();
56 r = start_colour.Red() + (((r * position * 100) / end_position) / 100);
57 g = start_colour.Green() + (((g * position * 100) / end_position) / 100);
58 b = start_colour.Blue() + (((b * position * 100) / end_position) / 100);
59 return wxColour(r, g, b);
60 }
61
62 bool wxRibbonCanLabelBreakAtPosition(const wxString& label, size_t pos)
63 {
64 return label[pos] == ' ';
65 }
66
67 void wxRibbonDrawParallelGradientLines(wxDC& dc,
68 int nlines,
69 const wxPoint* line_origins,
70 int stepx,
71 int stepy,
72 int numsteps,
73 int offset_x,
74 int offset_y,
75 const wxColour& start_colour,
76 const wxColour& end_colour)
77 {
78 int rd, gd, bd;
79 rd = end_colour.Red() - start_colour.Red();
80 gd = end_colour.Green() - start_colour.Green();
81 bd = end_colour.Blue() - start_colour.Blue();
82
83 for (int step = 0; step < numsteps; ++step)
84 {
85 int r,g,b;
86
87 r = start_colour.Red() + (((step*rd*100)/numsteps)/100);
88 g = start_colour.Green() + (((step*gd*100)/numsteps)/100);
89 b = start_colour.Blue() + (((step*bd*100)/numsteps)/100);
90
91 wxPen p(wxColour((unsigned char)r,
92 (unsigned char)g,
93 (unsigned char)b));
94 dc.SetPen(p);
95
96 for(int n = 0; n < nlines; ++n)
97 {
98 dc.DrawLine(offset_x + line_origins[n].x, offset_y + line_origins[n].y,
99 offset_x + line_origins[n].x + stepx, offset_y + line_origins[n].y + stepy);
100 }
101
102 offset_x += stepx;
103 offset_y += stepy;
104 }
105 }
106
107 wxRibbonHSLColour wxRibbonShiftLuminance(wxRibbonHSLColour colour,
108 float amount)
109 {
110 if(amount <= 1.0f)
111 return colour.Darker(colour.luminance * (1.0f - amount));
112 else
113 return colour.Lighter((1.0f - colour.luminance) * (amount - 1.0f));
114 }
115
116 wxBitmap wxRibbonLoadPixmap(const char* const* bits, wxColour fore)
117 {
118 wxImage xpm = wxBitmap(bits).ConvertToImage();
119 xpm.Replace(255, 0, 255, fore.Red(), fore.Green(), fore.Blue());
120 return wxBitmap(xpm);
121 }
122
123 wxRibbonHSLColour::wxRibbonHSLColour(const wxColour& col)
124 {
125 float red = float(col.Red()) / 255.0;
126 float green = float(col.Green()) / 255.0;
127 float blue = float(col.Blue()) / 255.0;
128 float Min = wxMin(red, wxMin(green, blue));
129 float Max = wxMax(red, wxMax(green, blue));
130 luminance = 0.5 * (Max + Min);
131 if (Min == Max)
132 {
133 // colour is a shade of grey
134 hue = 0.0;
135 saturation = 0.0;
136 }
137 else
138 {
139 if(luminance <= 0.5)
140 saturation = (Max - Min) / (Max + Min);
141 else
142 saturation = (Max - Min) / (2.0 - (Max + Min));
143
144 if(Max == red)
145 {
146 hue = 60.0 * (green - blue) / (Max - Min);
147 if(hue < 0.0)
148 hue += 360.0;
149 }
150 else if(Max == green)
151 {
152 hue = 60.0 * (blue - red) / (Max - Min);
153 hue += 120.0;
154 }
155 else // Max == blue
156 {
157 hue = 60.0 * (red - green) / (Max - Min);
158 hue += 240.0;
159 }
160 }
161 }
162
163 wxColour wxRibbonHSLColour::ToRGB() const
164 {
165 float _hue = (hue - floor(hue / 360.0f) * 360.0f);
166 float _saturation = saturation;
167 float _luminance = luminance;
168 if(_saturation > 1.0) _saturation = 1.0;
169 if(_saturation < 0.0) _saturation = 0.0;
170 if(_luminance > 1.0) _luminance = 1.0;
171 if(_luminance < 0.0) _luminance = 0.0;
172
173 float red, blue, green;
174 if(_saturation == 0.0)
175 {
176 // colour is a shade of grey
177 red = blue = green = _luminance;
178 }
179 else
180 {
181 double tmp2 = (_luminance < 0.5)
182 ? _luminance * (1.0 + _saturation)
183 : (_luminance + _saturation) - (_luminance * _saturation);
184 double tmp1 = 2.0 * _luminance - tmp2;
185
186 double tmp3R = _hue + 120.0;
187 if(tmp3R > 360.0)
188 tmp3R -= 360.0;
189 if(tmp3R < 60.0)
190 red = tmp1 + (tmp2 - tmp1) * tmp3R / 60.0;
191 else if(tmp3R < 180.0)
192 red = tmp2;
193 else if(tmp3R < 240.0)
194 red = tmp1 + (tmp2 - tmp1) * (240.0 - tmp3R) / 60.0;
195 else
196 red = tmp1;
197
198 double tmp3G = _hue;
199 if(tmp3G > 360.0)
200 tmp3G -= 360.0;
201 if(tmp3G < 60.0)
202 green = tmp1 + (tmp2 - tmp1) * tmp3G / 60.0;
203 else if(tmp3G < 180.0)
204 green = tmp2;
205 else if(tmp3G < 240.0)
206 green = tmp1 + (tmp2 - tmp1) * (240.0 - tmp3G) / 60.0;
207 else
208 green = tmp1;
209
210 double tmp3B = _hue + 240.0;
211 if(tmp3B > 360.0)
212 tmp3B -= 360.0;
213 if(tmp3B < 60.0)
214 blue = tmp1 + (tmp2 - tmp1) * tmp3B / 60.0;
215 else if(tmp3B < 180.0)
216 blue = tmp2;
217 else if(tmp3B < 240.0)
218 blue = tmp1 + (tmp2 - tmp1) * (240.0 - tmp3B) / 60.0;
219 else
220 blue = tmp1;
221 }
222 return wxColour(
223 (unsigned char)(red * 255.0),
224 (unsigned char)(green * 255.0),
225 (unsigned char)(blue * 255.0));
226 }
227
228 wxRibbonHSLColour wxRibbonHSLColour::Darker(float delta) const
229 {
230 return Lighter(-delta);
231 }
232
233 wxRibbonHSLColour& wxRibbonHSLColour::MakeDarker(float delta)
234 {
235 luminance -= delta;
236 return *this;
237 }
238
239 wxRibbonHSLColour wxRibbonHSLColour::Lighter(float delta) const
240 {
241 return wxRibbonHSLColour(hue, saturation, luminance + delta);
242 }
243
244 wxRibbonHSLColour wxRibbonHSLColour::Saturated(float delta) const
245 {
246 return wxRibbonHSLColour(hue, saturation + delta, luminance);
247 }
248
249 wxRibbonHSLColour wxRibbonHSLColour::Desaturated(float delta) const
250 {
251 return Saturated(-delta);
252 }
253
254 wxRibbonHSLColour wxRibbonHSLColour::ShiftHue(float delta) const
255 {
256 return wxRibbonHSLColour(hue + delta, saturation, luminance);
257 }
258
259 #endif // wxUSE_RIBBON