Repository navigation
Expand file tree
/
Copy pathForegroundRGBToolbar.lua
More file actions
244 lines (202 loc) · 5.64 KB
/
Copy pathForegroundRGBToolbar.lua
File metadata and controls
244 lines (202 loc) · 5.64 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
-- SCRIPT: Foreground RGB Toolbar.lua
-- DATE: August 31, 2020
-- AUTHOR: iivii | @odd_codes
-- WEBSITE: https://odd.codes
-- GITHUB: https://github.com/iiviigames/Asepritely
-- DESC: Shows the RGB values of the current foreground color in a
-- popup window.
-- USAGE: Simply press the "GO" button to view the RGB values of your
-- foreground color.
-- ==========================================================================
-- GLOBALS
-- ==========================================================================
-- Initialize the Toolbar Popup
local tool = Dialog("Palette Toolbar")
-- Get the size of the Toolbar
local size = tool.bounds
-- Set the size of the Toolbar
-- w,h = 298, 155
w,h = 310, 200
tool.bounds = Rectangle(size.x+600,size.y,w,h)
-- Get the current Sprite being edited in Aseprite
local spr = app.activeSprite
-- Alert if no active sprite has been found
if not spr then
return app.alert("Error! No sprite is being edited!")
end
-- Get the current Palette being used in Aseprite
local pal = spr.palettes[1]
-- HELPER FUNCTIONS
-- ==========================================================================
-- Prints the contents of a table to the console
-- Stands for "print table"
function pt(t)
for k,v in pairs(t) do
print(tostring(k)..": "..tostring(v))
end
end
-- Use this if your table contains many tables of its own.
-- Stands for "print table recursively".
function ptr(t)
for k,v in pairs(t) do
if type(k) == 'table' then
print(tostring(k))
pt(v)
else
print(tostring(k)..": "..tostring(v))
end
end
end
-- APP FUNCTIONS
-- ==========================================================================
-- Retrieves the active foreground color
function getForeColor()
return app.fgColor
end
-- Retrieves the RGB values that make up the foreground color.
function getForeRGB()
-- Store RGB values
local color = getForeColor()
local r = color.red
local g = color.green
local b = color.blue
-- Return the individual components
return r,g,b
end
-- Modifies existing toolbar RGB values with new ones
function setBoxRGB()
local r,g,b = getForeRGB()
tool:modify{id="red", text=r}
tool:modify{id="green", text=g}
tool:modify{id="blue", text=b}
end
-- DEBUG FUNCTIONS
-- ==========================================================================
-- (Simply add functions to the the dbg table if you want to extend its use.)
-- (Called only if dbg.run is true)
local dbg = {
run = true
}
-- Executes any of the dbg functions that you pass to it, with any bad keys
-- being ignored.
-- NOTE: THIS IS CALLED AT THE BOTTOM IN THE MAIN AREA
-- dbg.run MUST BE TRUE or this won't execute.
-- EX: dbg:show('bounds', 'balette')
-- (in the above example, 'balette' would fail to run, as it's mispelled!)
function dbg:show(...)
-- Make sure the dbg.run is true, or this won't do anything
if self.run == false then return end
-- string arguments
local a = {...}
-- Performs the debug function after verification
local function call(tab,fnc)
fnc(tab)
return
end
-- Loop through all arguments and perform functions
for i=1, #a do
local arg = a[i]
local func = self[arg]
local chk = type(func)
-- Check if the resulting index is a function, and execute.
if chk == "function" then
-- func() on its own also works, but it might not depending on
-- the way you write functions, so use this instead.
call(self,func)
end
end
end
-- Print the toolbar boundaries
function dbg:bounds()
print("X: "..tostring(size.x))
print("Y: "..tostring(size.y))
print("W: "..tostring(size.width))
print("H: "..tostring(size.height))
end
-- Print the palette colors
function dbg:palette()
for i=1, #pal-1 do
local col = pal:getColor(i)
print(col)
end
end
-- INITIALIZE TOOLBAR
-- ==========================================================================
-- LABELS/LAYOUT
-- --------------------------------------------------------------------
-- Create the Color Label
tool:label{
id="color_label",
-- label="Foreground Color",
label="Currently Selected Color"
}
-- Create a Separator
tool:separator()
-- Create a New Row
tool:newrow()
-- Create the color display box
tool:color{
id="current_color",
label="Foreground Color",
color=getForeColor()
}
-- Create a Separator
tool:separator()
-- CREATE RGB DISPLAY
-- -----------------------------------------------------------------------
-- Store RGB values
local r,g,b = getForeRGB()
-- Red
tool:label{
id="red",
label="R:",
text=r
}
-- Green
tool:label{
id="green",
label="G:",
text=g
}
-- Blue
tool:label{
id="blue",
label="B:",
text=b
}
-- Create a Separator
tool:separator()
-- BUTTONS
-- -------------------------------------------------------------------------
-- Create the button for getting current active color
tool:button{
id="get_current_color",
label="Get Foreground Color",
text="GO",
onclick=function()
-- Store and set color of foreground
local c = getForeColor()
tool:modify{
id="current_color",
color=c
}
-- Update the current RGB values with the new data
local r,g,b=getForeRGB()
tool:modify{id="red", text=r}
tool:modify{id="green", text=g}
tool:modify{id="blue", text=b}
end
}
-- Create the quit button
tool:button{
text="Close",
onclick=function()
tool:close()
end
}
-- MAIN
-- ==========================================================================
-- Shows the Window Toolbar
tool:show{wait=false}
-- Performs any dbg calls
dbg:show('bounds','bad')