3
3
component = {}
4
4
component .__index = component
5
5
component .colors = {
6
- blue = {2 , 117 , 216 , 255 },
7
- green = {92 , 184 , 92 , 255 },
8
- cyan = {91 , 192 , 222 , 255 },
9
- orange = {240 , 173 , 78 , 255 },
10
- red = {217 , 83 , 79 , 255 },
11
- black = {0 , 0 , 0 , 255 },
12
- white = {255 , 255 , 255 , 255 },
13
- clearGray = {247 , 247 , 247 , 255 },
14
- darkGray = {41 , 43 , 44 , 255 },
15
- darkGrayAlpha = {41 , 43 , 44 , 150 },
6
+ blue = {0.01 , 0.46 , 0.85 , 1.0 },
7
+ green = {0.36 , 0.72 , 0.36 , 1.0 },
8
+ cyan = {0.36 , 0.75 , 0.87 , 1.0 },
9
+ orange = {0.94 , 0.68 , 0.31 , 1.0 },
10
+ red = {0.85 , 0.33 , 0.31 , 1.0 },
11
+ black = {0.0 , 0.0 , 0.0 , 1.0 },
12
+ white = {1.0 , 1.0 , 1.0 , 1.0 },
13
+ clearGray = {0.97 , 0.97 , 0.97 , 1.0 },
14
+ darkGray = {0.16 , 0.17 , 0.17 , 1.0 },
15
+ darkGrayAlpha = {0.16 , 0.17 , 0.17 , 0.59 },
16
16
}
17
17
component .style = {
18
18
bgColor = component .colors .blue ,
@@ -91,7 +91,7 @@ function component.new(t, x, y, w, h, group)
91
91
color = gooi .toRGBA (color )
92
92
end
93
93
self .style .bgColor = color
94
- self .style .borderColor = {color [1 ], color [2 ], color [3 ], 255 }
94
+ self .style .borderColor = {color [1 ], color [2 ], color [3 ], 1 }
95
95
self :make3d ()
96
96
return self
97
97
end
@@ -119,10 +119,10 @@ function component.new(t, x, y, w, h, group)
119
119
if not w then return self .style .borderWidth , self .style .borderColor ; end
120
120
121
121
self .style .borderWidth = w
122
- self .style .borderColor = color or {12 , 183 , 242 , 255 }
122
+ self .style .borderColor = color or {0.05 , 0.72 , 0.95 , 1 }
123
123
if type (color ) == " string" then
124
124
self .style .borderColor = gooi .toRGBA (color )
125
- self .style .borderColor [4 ] = 255
125
+ self .style .borderColor [4 ] = 1
126
126
end
127
127
self .style .borderStyle = style or " smooth"
128
128
self .style .showBorder = true
@@ -136,19 +136,19 @@ function component.new(t, x, y, w, h, group)
136
136
self .mode3d = false
137
137
return self
138
138
end
139
-
139
+
140
140
c .style = gooi .deepcopy (component .style )
141
141
142
142
function c :make3d ()
143
143
-- For a 3D look:
144
144
self .colorTop = self .style .bgColor
145
145
self .colorBot = self .style .bgColor
146
146
147
- self .colorTop = changeBrig (self .style .bgColor , 15 )
148
- self .colorBot = changeBrig (self .style .bgColor , - 15 )
147
+ self .colorTop = changeBrig (self .style .bgColor , 0.06 )
148
+ self .colorBot = changeBrig (self .style .bgColor , - 0.06 )
149
149
150
- self .colorTopHL = changeBrig (self .style .bgColor , 25 )
151
- self .colorBotHL = changeBrig (self .style .bgColor , - 5 )
150
+ self .colorTopHL = changeBrig (self .style .bgColor , 0.1 )
151
+ self .colorBotHL = changeBrig (self .style .bgColor , - 0.02 )
152
152
153
153
self .imgData3D = love .image .newImageData (1 , 2 )
154
154
self .imgData3D :setPixel (0 , 0 , self .colorTop [1 ], self .colorTop [2 ], self .colorTop [3 ], self .colorTop [4 ])
@@ -165,19 +165,19 @@ function component.new(t, x, y, w, h, group)
165
165
self .img3DHL :setFilter (" linear" , " linear" )
166
166
167
167
self .imgDataGlass = love .image .newImageData (1 , 2 )
168
- self .imgDataGlass :setPixel (0 , 0 , 255 , 255 , 255 , 80 )
169
- self .imgDataGlass :setPixel (0 , 1 , 255 , 255 , 255 , 40 )
168
+ self .imgDataGlass :setPixel (0 , 0 , 1 , 1 , 1 , 0.31 )
169
+ self .imgDataGlass :setPixel (0 , 1 , 1 , 1 , 1 , 0.16 )
170
170
self .imgGlass = love .graphics .newImage (self .imgDataGlass )
171
171
self .imgGlass :setFilter (" linear" , " linear" )
172
172
end
173
173
174
174
function c :makeShadow ()
175
175
self .heightShadow = 6
176
176
self .imgDataShadow = love .image .newImageData (1 , self .heightShadow )
177
- self .imgDataShadow :setPixel (0 , 0 , 0 , 0 , 0 , 80 )
178
- self .imgDataShadow :setPixel (0 , 1 , 0 , 0 , 0 , 30 )
179
- self .imgDataShadow :setPixel (0 , 2 , 0 , 0 , 0 , 5 )
180
-
177
+ self .imgDataShadow :setPixel (0 , 0 , 0 , 0 , 0 , 0.31 )
178
+ self .imgDataShadow :setPixel (0 , 1 , 0 , 0 , 0 , 0.12 )
179
+ self .imgDataShadow :setPixel (0 , 2 , 0 , 0 , 0 , 0.02 )
180
+
181
181
self .imgShadow = love .graphics .newImage (self .imgDataShadow )
182
182
self .imgShadow :setFilter (" linear" , " linear" )
183
183
end
@@ -188,7 +188,7 @@ function component.new(t, x, y, w, h, group)
188
188
function c :info () self :bg (component .colors .cyan ); return self end
189
189
function c :warning () self :bg (component .colors .orange ); return self end
190
190
function c :danger () self :bg (component .colors .red ); return self end
191
- function c :opacity (o ) self .style .bgColor [4 ] = o * 255 ; return self end
191
+ function c :opacity (o ) self .style .bgColor [4 ] = o ; return self end
192
192
193
193
function c :secondary ()
194
194
self :bg (component .colors .clearGray )
@@ -203,7 +203,7 @@ function component.new(t, x, y, w, h, group)
203
203
204
204
205
205
c :make3d ()
206
-
206
+
207
207
return setmetatable (c , component )
208
208
end
209
209
214
214
function component :draw ()-- Every component has the same base:
215
215
local style = self .style
216
216
if self .opaque and self .visible then
217
- local focusColorChange = 15
217
+ local focusColorChange = 0.06
218
218
local fs = - 1
219
219
if not self .enabled then focusColorChange = 0 end
220
220
local newColor = style .bgColor
@@ -236,7 +236,7 @@ function component:draw()-- Every component has the same base:
236
236
love .graphics .setColor (newColor )
237
237
238
238
if not self .enabled then
239
- love .graphics .setColor (63 , 63 , 63 , style .bgColor [4 ] or 255 )
239
+ love .graphics .setColor (1 / 4 , 1 / 4 , 1 / 4 , style .bgColor [4 ] or 1 )
240
240
end
241
241
242
242
local radiusCorner = style .radius
@@ -270,9 +270,9 @@ function component:draw()-- Every component has the same base:
270
270
end
271
271
272
272
if self .mode3d then
273
- love .graphics .setColor (255 , 255 , 255 , style .bgColor [4 ] or 255 )
273
+ love .graphics .setColor (1 , 1 , 1 , style .bgColor [4 ] or 1 )
274
274
if not self .enabled then
275
- love .graphics .setColor (0 , 0 , 0 , style .bgColor [4 ] or 255 )
275
+ love .graphics .setColor (0 , 0 , 0 , style .bgColor [4 ] or 1 )
276
276
end
277
277
love .graphics .draw (img ,
278
278
math.floor (self .x + self .w / 2 ),
@@ -296,7 +296,7 @@ function component:draw()-- Every component has the same base:
296
296
end
297
297
298
298
if self .glass then
299
- love .graphics .setColor (255 , 255 , 255 )
299
+ love .graphics .setColor (1 , 1 , 1 )
300
300
love .graphics .draw (self .imgGlass ,
301
301
self .x ,
302
302
self .y ,
@@ -306,7 +306,7 @@ function component:draw()-- Every component has the same base:
306
306
end
307
307
308
308
if self .bgImage then
309
- love .graphics .setColor (255 , 255 , 255 )
309
+ love .graphics .setColor (1 , 1 , 1 )
310
310
love .graphics .draw (self .bgImage ,
311
311
math.floor (self .x ),
312
312
math.floor (self .y ),
@@ -320,7 +320,7 @@ function component:draw()-- Every component has the same base:
320
320
if style .showBorder then
321
321
love .graphics .setColor (newColor )
322
322
if not self .enabled then
323
- love .graphics .setColor (63 , 63 , 63 )
323
+ love .graphics .setColor (1 / 4 , 1 / 4 , 1 / 4 )
324
324
end
325
325
love .graphics .rectangle (" line" ,
326
326
math.floor (self .x ),
@@ -348,7 +348,7 @@ function component:drawShadowPressed()
348
348
end , " replace" , 1 )
349
349
love .graphics .setStencilTest (" greater" , 0 )
350
350
351
- love .graphics .setColor (255 , 255 , 255 )
351
+ love .graphics .setColor (1 , 1 , 1 )
352
352
love .graphics .draw (self .imgShadow ,
353
353
self .x + self .w / 2 ,
354
354
self .y + self .h / 2 ,
@@ -397,7 +397,7 @@ function component:wasReleased()
397
397
local b = self :overIt () and self .enabled and self .visible
398
398
if self .type == " text" then
399
399
if b then
400
- love .keyboard .setTextInput (true )
400
+ love .keyboard .setTextInput (true )
401
401
end
402
402
end
403
403
@@ -517,24 +517,24 @@ function changeBrig(color, amount)
517
517
color = gooi .toRGBA (color )
518
518
end
519
519
520
- local r , g , b , a = color [1 ], color [2 ], color [3 ], color [4 ] or 255
520
+ local r , g , b , a = color [1 ], color [2 ], color [3 ], color [4 ] or 1
521
521
522
522
r = r + amount
523
523
g = g + amount
524
524
b = b + amount
525
525
-- a = a + amount
526
526
527
527
if r < 0 then r = 0 end
528
- if r > 255 then r = 255 end
528
+ if r > 1 then r = 1 end
529
529
530
530
if g < 0 then g = 0 end
531
- if g > 255 then g = 255 end
531
+ if g > 1 then g = 1 end
532
532
533
533
if b < 0 then b = 0 end
534
- if b > 255 then b = 255 end
534
+ if b > 1 then b = 1 end
535
535
536
536
-- if a < 0 then a = 0 end
537
- -- if a > 255 then a = 255 end
537
+ -- if a > 1 then a = 1 end
538
538
539
539
return {r , g , b , a }
540
540
end
0 commit comments