-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathui_iconwidget.lua
More file actions
executable file
·79 lines (66 loc) · 1.76 KB
/
ui_iconwidget.lua
File metadata and controls
executable file
·79 lines (66 loc) · 1.76 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
-- iconwidget
local log = require 'log'
local Widget = require 'ui_widget'
local Util = require 'util'
local IconWidget = {
-- icon name
-- baizeCmd and optional param
}
IconWidget.__index = IconWidget
setmetatable(IconWidget, {__index = Widget})
function IconWidget.new(o)
o.enabled = true
local fname = 'assets/icons/' .. o.icon .. '.png'
local imageData = love.image.newImageData(fname)
if not imageData then
log.error('could not load', fname)
else
o.img = love.graphics.newImage(imageData)
assert(o.img)
o.imgWidth = imageData:getWidth() * _G.UI_SCALE
o.imgHeight = imageData:getHeight() * _G.UI_SCALE
-- log.trace('loaded', fname, o.imgWidth, o.imgHeight)
end
return setmetatable(o, IconWidget)
end
function IconWidget:draw()
-- very important!: reset color before drawing to canvas to have colors properly displayed
local _, cy, _, ch = self.parent:screenRect()
local wx, wy, ww, wh = self:screenRect()
if wy < cy then
return
end
if wy + wh > cy + ch then
return
end
-- nb no backColor or textColor
if self.enabled then
local mx, my = love.mouse.getPosition()
if self.baizeCmd and Util.inRect(mx, my, self:screenRect()) then
Util.setColorFromName('UiForeground')
if love.mouse.isDown(1) then
wx = wx + 2
wy = wy + 2
end
else
Util.setColorFromName('UiForeground')
end
else
Util.setColorFromName('UiGrayedOut')
end
if self.img then
love.graphics.draw(self.img, wx, wy, 0, _G.UI_SCALE, _G.UI_SCALE)
end
--[[
if self.text then
love.graphics.setFont(self.parent.font)
love.graphics.print(self.text, wx + iconWidth + 8, wy + 3)
end
]]
if _G.SETTINGS.debug then
Util.setColorFromName('UiGrayedOut')
love.graphics.setLineWidth(1)
love.graphics.rectangle('line', wx, wy, ww, wh)
end
end
return IconWidget