art_internal.py
6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
"""
This module contains methods used throughout the :class:`bar` library.
"""
import wx
import math
def RibbonInterpolateColour(start_colour, end_colour, position, start_position, end_position):
if position <= start_position:
return start_colour
if position >= end_position:
return end_colour
position -= start_position
end_position -= start_position
r = end_colour.Red() - start_colour.Red()
g = end_colour.Green() - start_colour.Green()
b = end_colour.Blue() - start_colour.Blue()
r = start_colour.Red() + (((r * position * 100) / end_position) / 100)
g = start_colour.Green() + (((g * position * 100) / end_position) / 100)
b = start_colour.Blue() + (((b * position * 100) / end_position) / 100)
return wx.Colour(r, g, b)
def RibbonShiftLuminance(colour, amount):
if amount <= 1.0:
return colour.Darker(colour.luminance * (1.0 - amount))
else:
return colour.Lighter((1.0 - colour.luminance) * (amount - 1.0))
def RibbonCanLabelBreakAtPosition(label, pos):
return label[pos] == ' '
def RibbonDrawParallelGradientLines(dc, nlines, line_origins, stepx, stepy, numsteps, offset_x,
offset_y, start_colour, end_colour):
rd = end_colour.Red() - start_colour.Red()
gd = end_colour.Green() - start_colour.Green()
bd = end_colour.Blue() - start_colour.Blue()
for step in xrange(numsteps):
r = start_colour.Red() + (((step*rd*100)/numsteps)/100)
g = start_colour.Green() + (((step*gd*100)/numsteps)/100)
b = start_colour.Blue() + (((step*bd*100)/numsteps)/100)
p = wx.Pen(wx.Colour(r, g, b))
dc.SetPen(p)
for n in xrange(nlines):
dc.DrawLine(offset_x + line_origins[n].x, offset_y + line_origins[n].y,
offset_x + line_origins[n].x + stepx, offset_y + line_origins[n].y + stepy)
offset_x += stepx
offset_y += stepy
def RibbonLoadPixmap(bits, fore):
xpm = wx.BitmapFromXPMData(bits).ConvertToImage()
xpm.Replace(255, 0, 255, fore.Red(), fore.Green(), fore.Blue())
return wx.BitmapFromImage(xpm)
class RibbonHSLColour(object):
def __init__(self, h=0.0, s=0.0, l=0.0):
if isinstance(h, wx.Colour):
red, green, blue = h.Red()/255.0, h.Green()/255.0, h.Blue()/255.0
Min = min(red, min(green, blue))
Max = max(red, max(green, blue))
luminance = 0.5 * (Max + Min)
if Min == Max:
# colour is a shade of grey
hue = 0.0
saturation = 0.0
else:
if luminance <= 0.5:
saturation = (Max - Min) / (Max + Min)
else:
saturation = (Max - Min) / (2.0 - (Max + Min))
if Max == red:
hue = 60.0 * (green - blue) / (Max - Min)
if hue < 0.0:
hue += 360.0
elif Max == green:
hue = 60.0 * (blue - red) / (Max - Min)
hue += 120.0
else: # Max == blue
hue = 60.0 * (red - green) / (Max - Min)
hue += 240.0
self.hue = hue
self.saturation = saturation
self.luminance = luminance
else:
self.hue = h
self.saturation = s
self.luminance = l
def ToRGB(self):
_hue = (self.hue - math.floor(self.hue / 360.0) * 360.0)
_saturation = self.saturation
_luminance = self.luminance
if _saturation > 1.0:
_saturation = 1.0
if _saturation < 0.0:
_saturation = 0.0
if _luminance > 1.0:
_luminance = 1.0
if _luminance < 0.0:
_luminance = 0.0
if _saturation == 0.0:
# colour is a shade of grey
red = blue = green = _luminance
else:
tmp2 = (_luminance < 0.5 and [_luminance*(1.0 + _saturation)] or [(_luminance+_saturation) - (_luminance*_saturation)])[0]
tmp1 = 2.0 * _luminance - tmp2
tmp3R = _hue + 120.0
if tmp3R > 360.0:
tmp3R -= 360.0
if tmp3R < 60.0:
red = tmp1 + (tmp2 - tmp1) * tmp3R / 60.0
elif tmp3R < 180.0:
red = tmp2
elif tmp3R < 240.0:
red = tmp1 + (tmp2 - tmp1) * (240.0 - tmp3R) / 60.0
else:
red = tmp1
tmp3G = _hue
if tmp3G > 360.0:
tmp3G -= 360.0
if tmp3G < 60.0:
green = tmp1 + (tmp2 - tmp1) * tmp3G / 60.0
elif tmp3G < 180.0:
green = tmp2
elif tmp3G < 240.0:
green = tmp1 + (tmp2 - tmp1) * (240.0 - tmp3G) / 60.0
else:
green = tmp1
tmp3B = _hue + 240.0
if tmp3B > 360.0:
tmp3B -= 360.0
if tmp3B < 60.0:
blue = tmp1 + (tmp2 - tmp1) * tmp3B / 60.0
elif tmp3B < 180.0:
blue = tmp2
elif tmp3B < 240.0:
blue = tmp1 + (tmp2 - tmp1) * (240.0 - tmp3B) / 60.0
else:
blue = tmp1
return wx.Colour(red * 255.0, green * 255.0, blue * 255.0)
def Darker(self, delta):
return self.Lighter(-delta)
def MakeDarker(self, delta):
self.luminance -= delta
return self
def Lighter(self, delta):
return RibbonHSLColour(self.hue, self.saturation, self.luminance + delta)
def Saturated(self, delta):
return RibbonHSLColour(self.hue, self.saturation + delta, self.luminance)
def Desaturated(self, delta):
return self.Saturated(-delta)
def ShiftHue(self, delta):
return RibbonHSLColour(self.hue + delta, self.saturation, self.luminance)
class RibbonPageTabInfo(object):
def __init__(self):
self.page = -1
self.active = False
self.hovererd = False
self.rect = wx.Rect()
self.ideal_width = 0
self.small_begin_need_separator_width = 0
self.small_must_have_separator_width = 0
self.minimum_width = 0