Skip to content

Commit e3545c7

Browse files
authored
Merge pull request #278 from parasol-framework/test/scripts
Script improvements
2 parents 1ba4755 + b53b5ac commit e3545c7

24 files changed

+393
-330
lines changed

docs/html/modules/classes/compressedstream.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/html/modules/classes/storagedevice.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/html/modules/classes/vectortext.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696

9797
<span class="glyphicon glyphicon-minus text-muted" data-toggle="tooltip" title="Not writeable"></span></td><th class="col-md-1">LineSpacing</th><td class="col-md-1"><span class="text-nowrap">INT</span></td><td>The number of pixels from one line to the next.</td></tr><tr class="no-hover"><td colspan="4" class="hiddenRow"><div id="fl-LineSpacing" class="accordion-body collapse"><div class="doc-content" style="margin:20px">
9898
<p>This field can be queried for the amount of space between each line, measured in display pixels.</p>
99+
</div></div></td></tr><tr id="_" data-toggle="collapse" data-target="#fl-OnChange" class="clickable"><td class="col-md-1"><a id="tf-OnChange"></a><span class="glyphicon glyphicon-ok text-danger" data-toggle="tooltip" title="Functional read access"></span>
100+
 
101+
<span class="glyphicon glyphicon-ok text-danger" data-toggle="tooltip" title="Functional write access"></span></td><th class="col-md-1">OnChange</th><td class="col-md-1"><span class="text-nowrap">FUNCTION</span></td><td>Receive notifications for changes to the text string.</td></tr><tr class="no-hover"><td colspan="4" class="hiddenRow"><div id="fl-OnChange" class="accordion-body collapse"><div class="doc-content" style="margin:20px">
102+
<p>Set this field with a function reference to receive notifications whenever the text string changes.</p>
103+
<p>The callback function prototype is <code>void Function(*VectorText)</code>.</p>
99104
</div></div></td></tr><tr id="_" data-toggle="collapse" data-target="#fl-Point" class="clickable"><td class="col-md-1"><a id="tf-Point"></a><span class="glyphicon glyphicon-ok text-danger" data-toggle="tooltip" title="Functional read access"></span>
100105

101106
<span class="glyphicon glyphicon-minus text-muted" data-toggle="tooltip" title="Not writeable"></span></td><th class="col-md-1">Point</th><td class="col-md-1"><span class="text-nowrap">INT</span></td><td>Returns the point-size of the font.</td></tr><tr class="no-hover"><td colspan="4" class="hiddenRow"><div id="fl-Point" class="accordion-body collapse"><div class="doc-content" style="margin:20px">

docs/html/modules/core.html

Lines changed: 8 additions & 8 deletions
Large diffs are not rendered by default.

examples/vue.fluid

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Optional parameters are:
1818
require 'gui/listview'
1919
require 'gui/scrollbar'
2020

21-
local glIntroduction = [[
22-
<body fill="rgb(20,20,40)" font-fill="rgb(255,255,255)" font-size="12pt" margins="2em"/>
21+
local glBody = [[<body fill="rgb(20,20,40)" font-fill="rgb(255,255,255)" font-size="12pt" margins="2em"/>]]
2322

23+
local glIntroduction = [[
2424
<template name="th">
2525
<cell stroke="rgb(255,255,255)" stroke-width="1" border="bottom"><p><b><inject/></b></p></cell>
2626
</template>
@@ -46,14 +46,6 @@ Optional parameters are:
4646
<row><cell><p>file</p></cell><cell>A source file to load and display in the application.</cell></row>
4747
</table></p>
4848

49-
</page>
50-
]]
51-
52-
local glUnsupported = [[
53-
<body fill="rgb(255,255,255)" font-fill="rgb(0,0,0)" font-size="12pt"/>
54-
55-
<page name="Index">
56-
<p>Unrecognised file "<print value="[@filename]"/>" selected.</p>
5749
</page>
5850
]]
5951

@@ -63,6 +55,29 @@ Optional parameters are:
6355

6456
----------------------------------------------------------------------------------------------------------------------
6557

58+
function displayInlineDoc(Content, Parameters)
59+
local doc = glViewArea.new('document', { })
60+
if type(Parameters) == 'table' then
61+
for k, v in pairs(Parameters) do
62+
doc.acSetKey(k, v)
63+
end
64+
end
65+
doc.acDataFeed(0, DATA_XML, Content)
66+
configureScrollbar(doc.view, doc.page)
67+
glTerminateView = function()
68+
doc.free()
69+
end
70+
end
71+
72+
----------------------------------------------------------------------------------------------------------------------
73+
74+
function displayError(Message)
75+
local page = glBody .. [[<page name="Index">]] .. Message .. [[</page>]]
76+
displayInlineDoc(page, { })
77+
end
78+
79+
----------------------------------------------------------------------------------------------------------------------
80+
6681
function configureScrollbar(View, Page)
6782
if glScrollbar then
6883
glScrollbar.changeViewport(View, Page)
@@ -101,25 +116,30 @@ function displayDoc(Path)
101116
end
102117

103118
function displayImage(Path)
104-
local pic = glWindow.scene.new('picture', { src=Path, flags=PCF_FORCE_ALPHA_32 })
105-
local img = glWindow.scene.new('VectorImage', { picture = pic })
106-
glWindow.scene.mtAddDef('Image', img)
107-
108-
local window = glViewArea.new('VectorViewport', { x = 0, y = 0, width='100%', height='100%', overflow='hidden' })
109-
local page = window.new('VectorViewport', { x=0, y=0, width=pic.bitmap.width, height=pic.bitmap.height })
110-
local rect = page.new('VectorRectangle', {
111-
x=0, y=0, width=pic.bitmap.width, height=pic.bitmap.height, fill='url(#Image)'
112-
})
119+
catch(function()
120+
local pic = glWindow.scene.new('picture', { src=Path, flags='ForceAlpha32' })
121+
local img = glWindow.scene.new('VectorImage', { picture = pic })
122+
glWindow.scene.mtAddDef('Image', img)
123+
124+
local window = glViewArea.new('VectorViewport', { x = 0, y = 0, width='100%', height='100%', overflow='hidden' })
125+
local page = window.new('VectorViewport', { x=0, y=0, width=pic.bitmap.width, height=pic.bitmap.height })
126+
local rect = page.new('VectorRectangle', {
127+
x=0, y=0, width=pic.bitmap.width, height=pic.bitmap.height, fill='url(#Image)'
128+
})
113129

114-
glTerminateView = function()
115-
window.free()
116-
pic.free()
117-
img.free()
118-
end
130+
glTerminateView = function()
131+
window.free()
132+
pic.free()
133+
img.free()
134+
end
119135

120-
configureScrollbar(window, page)
136+
configureScrollbar(window, page)
121137

122-
glStats = { width = pic.bitmap.width, height = pic.bitmap.height }
138+
glStats = { width = pic.bitmap.width, height = pic.bitmap.height }
139+
end,
140+
function(Exception)
141+
displayError("<p>Failed to process selected file.</p>")
142+
end)
123143
end
124144

125145
function displayText(Path)
@@ -148,13 +168,7 @@ function displayFile(Path)
148168
elseif (lpath:find('^.+%.ripl$')) or (lpath:find('^.+%.rpl$')) then
149169
displayDoc(Path)
150170
else -- File is unsupported
151-
local doc = glViewArea.new('document', { })
152-
doc.acSetKey('filename', Path)
153-
doc.acDataFeed(0, DATA_XML, glUnsupported)
154-
configureScrollbar(doc.view, doc.page)
155-
glTerminateView = function()
156-
doc.free()
157-
end
171+
displayError([[<p>Unrecognised file "]] .. Path .. [["</p>]])
158172
end
159173

160174
glViewArea.scene.surface.mtScheduleRedraw()
@@ -228,7 +242,7 @@ end
228242
displayFile(arg('file'))
229243
else
230244
local doc = glViewArea.new('document', { })
231-
doc.acDataFeed(0, DATA_XML, glIntroduction)
245+
doc.acDataFeed(0, DATA_XML, glBody .. glIntroduction)
232246
configureScrollbar(doc.view, doc.page)
233247
glTerminateView = function()
234248
doc.free()

include/parasol/modules/vector.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,12 @@ struct VectorPainter {
532532
objVectorImage * Image; // A VectorImage object, suitable for image fills.
533533
objVectorGradient * Gradient; // A VectorGradient object, suitable for gradient fills.
534534
struct FRGB Colour; // A single RGB colour definition, suitable for block colour fills.
535+
void reset() {
536+
Colour.Alpha = 0;
537+
Gradient = NULL;
538+
Image = NULL;
539+
Pattern = NULL;
540+
}
535541
};
536542

537543
struct PathCommand {

scripts/gui.fluid

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,70 @@
11
-- Graphical User Interface functions
22

33
if (gui == nil) then
4-
-- The following values are the default. They can be overridden by the "style:values.xml" file.
4+
-- The following values are the default 'light' theme. They can be overridden by the "style:values.xml" file.
55
gui = {
6+
theme = 'light',
67
dpi = 160,
78
fonts = {
89
-- Use percentages for scalable sizes, where 100% is equivalent to the value of gui.interface.fontSize
9-
default = { face='Noto Sans,Source Sans 3', size='100%' },
10-
window = { face='Noto Sans,Source Sans 3', size='100%' }, -- For text that is not inside a widget
11-
button = { face='Noto Sans,Source Sans 3', size='100%' }, -- Text inside buttons
12-
icon = { face='Noto Sans,Source Sans 3', size='100%' }, -- Text at the bottom of icons
13-
menu = { face='Noto Sans,Source Sans 3', size='100%' }, -- Menu item text
10+
default = { face='Noto Sans,Source Sans Pro', size='100%' },
11+
window = { face='Noto Sans,Source Sans Pro', size='100%' }, -- For text that is not inside a widget
12+
button = { face='Noto Sans,Source Sans Pro', size='100%' }, -- Text inside buttons
13+
icon = { face='Noto Sans,Source Sans Pro', size='100%' }, -- Text at the bottom of icons
14+
menu = { face='Noto Sans,Source Sans Pro', size='100%' }, -- Menu item text
1415
titlebar = { face='Noto Sans', size='100%' }, -- Window titlebar text
1516
small = { face='Tiny', size='60%' }, -- Recommended text for small sizes
16-
large = { face='Noto Sans,Source Sans 3', size='130%' }, -- Recommended text for headers
17-
widget = { face='Noto Sans,Source Sans 3', size='100%' }, -- Text inside widgets (e.g. combobox)
18-
label = { face='Noto Sans,Source Sans 3::bold', size='100%' } -- Text for labels and outside widgets
17+
large = { face='Noto Sans,Source Sans Pro', size='130%' }, -- Recommended text for headers
18+
widget = { face='Noto Sans,Source Sans Pro', size='100%' }, -- Text inside widgets (e.g. combobox)
19+
label = { face='Noto Sans,Source Sans Pro::bold', size='100%' } -- Text for labels and outside widgets
1920
},
20-
colours = {
21+
style = {
2122
-- These are all fills, so any SVG compliant fill value can potentially be used to define a 'colour'.
22-
widgetText = 'rgb(255,255,255)',
23-
widgetBkgd = 'rgb(0,0,0,100)',
24-
widgetStroke = 'rgb(255,255,255,60)',
25-
widgetStrokeFocus = 'rgb(255,255,255,160)',
26-
widgetStrokeDisabled = 'rgb(255,255,255,60)',
27-
shadow = 'rgb(0,0,0,100)', -- Base colour/alpha value for stroked shadows
28-
highlight = 'rgb(255,255,255,150)', -- Base colour/alpha value for stroked highlights
29-
button = 'rgb(230,230,230)', -- Button background (raised)
30-
buttonClick = 'rgb(200,200,200)', -- Button background when clicked (depressed)
31-
menubar = 'rgb(190,190,190)', -- Menubar background fill
32-
menu = 'rgb(240,240,240)', -- Menu background fill
33-
border = 'rgb(144,144,144)', -- Standard border for any area filled with 'background'
34-
borderFocus = 'rgb(160,160,160)', -- Colour to use when 'border' has the user's focus
35-
menuborder = 'rgb(200,200,200)', -- Menu border
36-
desktop = 'rgb(160,160,160)', -- Background colour for the desktop
37-
recess = 'rgb(160,160,160)', -- Background colour for recessed areas with no content.
38-
background = 'rgb(255,255,255)', -- Standard background for hosting text & paper-based layouts
39-
textHighlight = 'rgb(224,224,240)', -- Background fill for text that is highlighted
40-
window = 'rgb(220,220,220)', -- Background fill for windows
41-
windowText = 'rgb(0,0,0)' -- Colour for text that is drawn directly to the window
23+
widget = {
24+
text = 'rgb(255,255,255)',
25+
bkgd = 'rgb(0,0,0,100)',
26+
stroke = 'rgb(255,255,255,60)',
27+
strokeFocus = 'rgb(255,255,255,160)',
28+
strokeDisabled = 'rgb(255,255,255,60)',
29+
strokeWidth = 2,
30+
width = 160, -- Default width for common widgets (px)
31+
gap = 6, -- Recommended gap between widgets (px)
32+
margin = 6 -- Recommended internal margin for widgets (px)
33+
},
34+
button = {
35+
bkgd = 'rgb(230,230,230)', -- Background when raised / default
36+
bkgdActive = 'rgb(200,200,200)' -- Background when temporarily clicked (depressed)
37+
},
38+
page = {
39+
bkgd = 'rgb(255,255,255)', -- Background for hosting text & paper-based layouts
40+
border = 'rgb(144,144,144)', -- Border stroke for any area surrounding 'bkgd'
41+
borderFocus = 'rgb(160,160,160)', -- Stroke to use when 'border' has the user's focus
42+
text = 'rgb(0,0,0)', -- Default colour for text drawn over 'bkgd'
43+
textHighlight = 'rgb(0,0,0)', -- Colour for 'text' when temporarily highlighted
44+
textHighlightBkgd = 'rgb(224,224,240)' -- Background fill for 'text' that is highlighted
45+
},
46+
window = {
47+
bkgd = 'rgb(220,220,220)',
48+
text = 'rgb(0,0,0)' -- Colour for text that is drawn directly to the window
49+
},
50+
menubar = {
51+
bkgd = 'rgb(190,190,190)'
52+
},
53+
menu = {
54+
bkgd = 'rgb(240,240,240)',
55+
border = 'rgb(200,200,200)' -- Stroke for menu border
56+
},
57+
desktop = {
58+
bkgd = 'rgb(160,160,160)'
59+
},
60+
recess = 'rgb(160,160,160)', -- Fill for recessed areas with no content.
61+
strokeShadow = 'rgb(0,0,0,100)', -- Base colour/alpha value for stroked shadows
62+
strokeHighlight = 'rgb(255,255,255,150)' -- Base colour/alpha value for stroked highlights
4263
},
4364
interface = {
44-
inputBorder = 1, -- Stroke size for borders that receive keyboard input
45-
outputBorder = 1, -- Stroke size for borders containing immutable content
46-
widgetMargin = 5, -- Recommended internal margin for widgets (px)
47-
widgetGap = 6, -- Recommended gap between widgets (px)
48-
fontSize = 11, -- Default font-size for everything (pt)
49-
sliderSize = 16, -- Max size for slider widgets (px)
50-
scrollSize = 18, -- Max size for scroll widgets (px)
51-
scrollOpacity = 100, -- Opacity for scrollbar background fills
52-
iconTheme = 'Default',
53-
iconSize = 20 -- Recommended default size for icons (px) and should be linked to fontSize
65+
fontSize = 11, -- Default font-size for everything (pt)
66+
iconTheme = 'Default',
67+
iconSize = 20 -- Recommended default size for icons (px) and should be linked to fontSize
5468
},
5569
iconThemes = {
5670
default = { first={ r=90,g=90,b=90 }, last={ r=70,g=70,b=110 } },
@@ -67,7 +81,10 @@ if (gui == nil) then
6781
grey = { first={ r=100,g=100,b=100 }, last={ r=70,g=70,b=70 } },
6882
pearl = { first={ r=250,g=249,b=248 }, last={ r=210,g=211,b=212 } }
6983
},
70-
_counter = 0
84+
_counter = 0,
85+
configureScene = function(Window, Scene)
86+
-- A custom configure function can be defined that adds definitions to the window scene, e.g. images and patterns for fills.
87+
end
7188
}
7289

7390
function convertFontSizes() -- Convert font percentage sizes to their px size
@@ -92,14 +109,15 @@ if (gui == nil) then
92109
local xml = obj.new('xml', { path=path })
93110

94111
if (xml != nil) then
112+
--[[
95113
local err, index = xml.mtFindTag('/colours')
96114
if (err == ERR_Okay) then
97-
for k,v in pairs(gui.colours) do
115+
for k,v in pairs(gui.style) do
98116
err, colour = xml.mtGetAttrib(index, k)
99-
if (err == ERR_Okay) then gui.colours[k] = colour end
117+
if (err == ERR_Okay) then gui.style[k] = colour end
100118
end
101119
end
102-
120+
--]]
103121
local err, index = xml.mtFindTag('/interface')
104122
if (err == ERR_Okay) then
105123
for k,v in pairs(gui.interface) do
@@ -170,11 +188,11 @@ gui.pixel = function(val)
170188
return num
171189
elseif (alpha == 'in') then
172190
return gui.dpi * num
173-
elseif (alpha == 'mm') then // 25.4 units per inch
191+
elseif (alpha == 'mm') then -- 25.4 units per inch
174192
return gui.dpi * (num / 25.4)
175-
elseif (alpha == 'pt') then // 72 units per inch
193+
elseif (alpha == 'pt') then -- 72 units per inch
176194
return gui.dpi * (num / 72)
177-
elseif (alpha == 'dp') then // 160dpi relative value
195+
elseif (alpha == 'dp') then -- 160dpi relative value
178196
return num * (gui.dpi * 0.00625)
179197
end
180198
end
@@ -188,6 +206,10 @@ end
188206
-- Convert an RGB string to an RGB table.
189207

190208
gui.strToRGB = function(Value)
209+
if not Value then
210+
error('Empty value passed to strToRGB()\n' .. debug.traceback())
211+
end
212+
191213
if (string.byte(Value) == 35) then
192214
local colour = tonumber(Value)
193215
if (Value:len() == 7) then
@@ -262,6 +284,10 @@ end
262284
-- Convert HSV table to RGB
263285

264286
gui.hsvToRGB = function(Value)
287+
if not Value then
288+
error('Empty value passed to hsvToRGB()\n' .. debug.traceback())
289+
end
290+
265291
local h = Value.h / 60
266292
local s = Value.s
267293
local v = Value.v
@@ -302,6 +328,10 @@ end
302328
-- Convert RGB table to HSV
303329

304330
gui.rgbToHSV = function(Value)
331+
if not Value then
332+
error('Empty value passed to rgbToHSV()\n' .. debug.traceback())
333+
end
334+
305335
local max = gui.rgbValue(Value)
306336
local hsv = { v = max }
307337
if max > 0 then
@@ -361,7 +391,9 @@ end
361391
-- Generate a simple gradient fill for vectors.
362392

363393
gui.simpleGradient = function(Scene, Name, Colours, X1, Y1, X2, Y2, Units, IgnoreClashes)
364-
if not Name then error('A name for the gradient is required.') end
394+
if not Name then
395+
error('A name for the gradient is required.\n' .. debug.traceback())
396+
end
365397

366398
local stops = { }
367399
local i = 0

0 commit comments

Comments
 (0)