Page 1 of 1
The Pink Circle Example
Posted: Thu Apr 09, 2015 6:32 am
by Peter Wood
As well as the choice of colour, I found one "real" issues and a couple of other annoynances with the pink circle example.
The issue is the example uses "real" instead of "Real" which causes a compilation error.
The first annoyance is the radius of the circle is set to the width of the widget so it can display a "window" on a circle at times. I made the following change to the paint handler:
Code: Select all
public handler onPaint()
variable tCirclePath as Path
variable tShortest as Real
if my width < my height then
put my width into tShortest
else
put my height into tShortest
end if
put circle path centered at point [my width / 2, my height / 2] with radius ((tShortest - mMargin)/2) into tCirclePath
set the paint of this canvas to solid paint with color [0, 1, 0]
fill tCirclePath on this canvas
end handler
A another minor annoyance, some of the handlers start with "On" and some with "on".
It would be good if the docs could be updated in the next release.
Re: The Pink Circle Example
Posted: Thu Apr 09, 2015 6:42 am
by FourthWorld
I think I missed something: I remember when "private" was introduced - now we have to declare "public" for all non-private handlers?
Re: The Pink Circle Example
Posted: Thu Apr 09, 2015 6:47 am
by Peter Wood
I can only answer by experimenting. It seems the public keyword is necessary. When I removed it from the onPaint handler, the code compiles but the widget doesn't display anything.
By the way, I am using the 8.0 DP 1 release.
Re: The Pink Circle Example
Posted: Thu Apr 09, 2015 10:06 pm
by peter-b
To confirm, the default visibility of handlers, variables, etc. is private. Only explicitly "public" definitions are exported from a module.
Re: The Pink Circle Example
Posted: Fri Apr 15, 2016 12:09 pm
by dave.kilroy
Thank you @PeterWood for the hint about "real" and "Real". I seem to have found another issue in the example as it appears in the "Extending LiveCode" bit of the Guide:
Code: Select all
public handler setMargin(in pMargin as real) as undefined
put pMargin into mMargin
redraw all
end handler
It's that final "as undefined" that is the problem - as far as I can tell this is a typo and it certainly won't compile for me when it's in place. In fact the only thing I can get to compile which has anything after the final bracket is "return as <type>". Is this correct or is there some other way of defining handlers I don't know about?
By the way, please note the "real" as opposed to "Real" in the above example from the Guide, I plan to attempt to send in pull requests on the Guide to tidy up these and other little niggles...
EDIT: forgot to say, "undefined" seems to be deprecated as a type anyway
Re: The Pink Circle Example
Posted: Fri Apr 15, 2016 1:47 pm
by pink
is this example available publicly?
and what is wrong with pink?

Re: The Pink Circle Example
Posted: Fri Apr 15, 2016 1:59 pm
by dave.kilroy
Hi @pink!
Yes, in LC8 open the dictionary, choose the 'Guide' tab, then from the drop-down choose "Expanding LiveCode" - it's a really nice intro to LCB (at least it appeared so to me as a LCB newbie) - but it has several little typos and the example doesn't compile!
Re: The Pink Circle Example
Posted: Fri Apr 15, 2016 6:09 pm
by [-hh]
Hi all.
This example compiled here in one of the early dp-versions of LC8.
Meanwhile LCBuilder has changed some things, also lowercase and uppercase rules.
So the point is not a "wrong" example but a missing update to LCBuilder as of LC 8.0.0-rc-1.
Since you have it already running, please post the running code here, so others (including me) can use it.
Thanks, Hermann
Re: The Pink Circle Example
Posted: Fri Apr 15, 2016 7:30 pm
by dave.kilroy
Hi all - this is a version of what is in Guide that compiles and runs for me (i.e. with capitalised "Real", without "as undefined" - and also without Peter's tweak for it's width and height)
Code: Select all
widget community.livecode.beaumont.pinkCircle
metadata title is "My Pink Circle"
metadata author is "Benjamin Beaumont"
metadata version is "1.0.0"
use com.livecode.canvas
use com.livecode.widget
use com.livecode.engine
// Properties
property circleMargin get mMargin set setMargin
// Local variables
private variable mMargin as Real
public handler onCreate()
put 0 into mMargin
end handler
public handler OnPaint()
// Create a path with a radius of half the width of the canvas
// Set the paint to a solid pink color
// Fill the path
variable tCirclePath as Path
put circle path centered at point [my width / 2, my height / 2] with radius ((my width - mMargin)/2) into tCirclePath
set the paint of this canvas to solid paint with color [1, 0, 1]
fill tCirclePath on this canvas
end handler
public handler setMargin(in pMargin as Real)
put pMargin into mMargin
redraw all
end handler
end widget