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