Canvas

Moderators: LCMark, LCfraser

Post Reply
MaxV
Posts: 1539
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Canvas

Post by MaxV » Thu Aug 02, 2018 3:42 pm

Hello,
I'm struggled with Canvas. After 2 years no real documentation so I'm wandering in the dark.
I tried this widget, but I get an empty widget, what's wrong?

Code: Select all

widget com.livecode.widget.testmax
-- proviamo un semplice test
 --Libraries

 use com.livecode.canvas
 use com.livecode.widget
 use com.livecode.engine
 use com.livecode.logic

 --Metadata
 metadata title is "Test Text"
 metadata author is "Massimiliano Vessi"
 metadata version is "0.0.1"
 metadata svgicon is "M1123 1409L1123 1228Q1035 1284 949 1284 898 1284 861 1261 832 1244 822 1216 811 1186 811 1087L811 792 1085 792 1085 611 811 611 811 320 647 320Q636 410 607 467 578 524 529 566 481 606 413 629L413 792 540 792 540 1196Q540 1274 557 1317 574 1359 616 1395 659 1432 720 1452 782 1472 860 1472 927 1472 989 1458 1046 1445 1123 1409ZM1536 416L1536 1376Q1536 1495 1451.5 1579.5 1367 1664 1248 1664L288 1664Q169 1664 84.5 1579.5 0 1495 0 1376L0 416Q0 297 84.5 212.5 169 128 288 128L1248 128Q1367 128 1451.5 212.5 1536 297 1536 416Z"

 --Properties
 property theText get gText set setText
 metadata theText.editor is "com.livecode.pi.string"
 metadata theText.label is "The text to show"
 metadata theText.default is "Ciao!"

--Variables
 private variable gText as String
 private variable mTextPaint as Paint

--handlers

--handler onCreate()
--   put "The text to show" into mText
--end handler

handler OnPaint()
   put solid paint with color [1,1,1] into mTextPaint
   set the paint of this canvas to mTextPaint
   set the font of this canvas to font "FreeSans" at size 12
   fill text gText at point [0,12] on this canvas
end handler

private handler setText(in pText as String)
	put pText into gText
end handler

handler onSave(out rProperties as Array)
   put the empty array into rProperties
   put gText into rProperties["theText"]
end handler

handler OnLoad(in pProperties as Array)
   put pProperties["theText"] into gText
end handler

end widget

Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 888
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Canvas

Post by trevordevore » Thu Aug 02, 2018 4:45 pm

You need to define your OnPaint() handler as `public`.

Code: Select all

public handler OnPaint()
   put solid paint with color [1,1,1] into mTextPaint
   set the paint of this canvas to mTextPaint
   set the font of this canvas to font "FreeSans" at size 12
   fill text gText at point [0,12] on this canvas
end handler
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

MaxV
Posts: 1539
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Canvas

Post by MaxV » Mon Aug 06, 2018 1:35 pm

Thank Trevore, it works... but I knew that all handlers are public if not declared as private. Like variables.
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 888
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Canvas

Post by trevordevore » Mon Aug 06, 2018 2:04 pm

Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1761
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Canvas

Post by [-hh] » Tue Aug 07, 2018 11:03 am

Max, before you waste time with testing public/private:
For *user-variables* and *user-handlers* being public is not yet implemented in LCB ...
shiftLock happens

MaxV
Posts: 1539
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Canvas

Post by MaxV » Tue Aug 07, 2018 11:56 am

So what handlers must be declared as public?
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1761
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Canvas

Post by [-hh] » Tue Aug 07, 2018 12:22 pm

AFAIK there is no closed list of such handlers.
I use as a thumb rule: All handlers must be public that handle LCB messages starting with "On".
OnAttach, OnClick, ..., OnVisibilityChanged. See the examples in the Dictionary.
shiftLock happens

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 168
Joined: Thu Apr 18, 2013 2:48 pm

Re: Canvas

Post by livecodeali » Mon Aug 13, 2018 9:29 am

Hi Max,
I added an overview of the canvas API with examples in the Extending LiveCode document in the 9.0 GM release:

https://github.com/livecode/livecode-id ... canvas-api

Please give that a read and let me know what we can do to improve it. Thanks!

MaxV
Posts: 1539
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Canvas

Post by MaxV » Mon Aug 20, 2018 12:20 pm

livecodeali wrote:
Mon Aug 13, 2018 9:29 am
Hi Max,
I added an overview of the canvas API with examples in the Extending LiveCode document in the 9.0 GM release:

https://github.com/livecode/livecode-id ... canvas-api

Please give that a read and let me know what we can do to improve it. Thanks!
WOW, I really need it!
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “LiveCode Builder”