Community snippets

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

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

Re: Community snippets

Post by [-hh] » Sun Mar 01, 2020 6:48 pm

[#55] LCB snippet: How to use the scrollWheel

As this is very uncompletely documented here some detailed info.
Works in LC 8/9:

Code: Select all

--> deltaX is the horizontal scroll
--> deltaY is the vertical scroll
--> deltaX and deltaY are -1 or 1 (or 0)

public handler OnMouseScroll(deltaX, deltaY)
  log [deltaX, deltaY]
end handler

--> on a mouse with vertical scroll only the
--> horizontal scroll is triggered with Shift
[p.s. LCB snippet #54 is NSWindow Ref (by shaosean, see last post)]
shiftLock happens

PaulDaMacMan
Posts: 518
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Community snippets

Post by PaulDaMacMan » Thu Sep 03, 2020 3:50 am

Here are two LCB functions for splitting a rect into a multi-rect List spaced evenly to fill the same space as the original rect...

Horizontal Split:

Code: Select all

public handler getRectListSplitHorz(in pRect, in pDiv as Integer) returns List
   variable tWidth as Integer
   variable tHeight as Integer
   variable tLeft as Integer
   variable tTop as Integer
   variable tRect
   variable tRectList as List
   variable tSplitWidth as Integer
   variable tCounter as Integer
   if pDiv < 2 then
      put 2 into pDiv
   end if
   put the top of pRect into tTop
   put the left of pRect into tLeft
   put the bottom of pRect into tHeight
   put the right of pRect into tWidth
   put tWidth/pDiv into tSplitWidth
   put rectangle [tLeft,tTop,tSplitWidth,tHeight] into tRect
   push tRect onto tRectList
   repeat with tCounter from 1 up to pDiv -1
      put rectangle [tLeft+(tSplitWidth*tCounter),tTop,(tSplitWidth*tCounter)+tSplitWidth,tHeight] into tRect
      push tRect onto tRectList
   end repeat
   return tRectList
end handler
Vertical Split:

Code: Select all

public handler getRectListSplitVert(in pRect, in pDiv as Integer) returns List
   variable tWidth as Integer
   variable tHeight as Integer
   variable tLeft as Integer
   variable tTop as Integer
   variable tRect
   variable tRectList as List
   variable tSplitHeight as Integer
   variable tCounter as Integer
   if pDiv < 2 then
      put 2 into pDiv
   end if
   put the top of pRect into tTop
   put the left of pRect into tLeft
   put the bottom of pRect into tHeight
   put the right of pRect into tWidth
   put tHeight/pDiv into tSplitHeight
   put rectangle [tLeft,tTop,tWidth,tSplitHeight] into tRect
   push tRect onto tRectList
   repeat with tCounter from 1 up to pDiv -1
      put rectangle [tLeft,tTop+(tSplitHeight*tCounter),tWidth,(tSplitHeight*tCounter)+tSplitHeight] into tRect
      push tRect onto tRectList
   end repeat
   return tRectList
end handler
use them like so:

Code: Select all

   put rectangle [tLeft,tTop,tRight,tBottom] into tRect
   put 8 into tSplits
   put getRectListSplitHorz(tRect,tSplits) into tRectList 
   --- tRectList now contains 8 rect elements

tRectList with stroked paths looks like this:
Screen Shot 2020-09-02 at 10.44.48 PM.png
Edited (code fixed)
My LCB Repos: https://github.com/PaulMcClernan/
My LiveCode YouTube Videos: PlayList

PaulDaMacMan
Posts: 518
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Community snippets

Post by PaulDaMacMan » Sun Dec 13, 2020 7:44 pm

This post in honor to the memory of Hermann Hoch, R.I.P. Thank You HH!

Not really documented anywhere AFAIK, but when you need to receive a string from a pointer to a C Char string ( *char) from a function in a foreign library, there is a function in libFoundation to convert a Pointer to a zero terminated C-string into a LiveCode String type:

Code: Select all

foreign handler MCStringCreateWithCString(in pCharStringPtr as Pointer, out rString as String) returns CBool binds to "<builtin>"
Use it like this:

Code: Select all

   variable tStrPtr as Pointer
   variable tString as String
      put c_Foreign_Func_That_Returns_Char_Pointer() into tStrPtr
      if MCStringCreateWithCString(tStrPtr, tString) then
         log tString
      end if
     
For passing to a *char type, you can instead use ZStringNative (or the other variations like Unicode). But for receiving, the LCB VM will let you use ZStringNative to receive a *char too, but it only works once (while the pointer is still valid I guess) and then the next time you try to use your function the engine will crash! Instead define your foreign function to return the actual *char Pointer to the *char back 'as Pointer' and then use the function above to turn it into a LiveCode String.
My LCB Repos: https://github.com/PaulMcClernan/
My LiveCode YouTube Videos: PlayList

SparkOut
Posts: 2555
Joined: Sun Sep 23, 2007 4:58 pm

Re: Community snippets

Post by SparkOut » Sun Dec 13, 2020 10:23 pm

PaulDaMacMan wrote:
Sun Dec 13, 2020 7:44 pm
This post in honor to the memory of Hermann Hoch, R.I.P. Thank You HH!
What??!! Really? When/how and oh no! I already miss Hermann on the forum. It's devastating to receive this news, and I am shocked and saddened to hear he is no longer with us. Condolences to his family. :cry:

PaulDaMacMan
Posts: 518
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Community snippets

Post by PaulDaMacMan » Mon Dec 14, 2020 1:26 am

SparkOut wrote:
Sun Dec 13, 2020 10:23 pm
PaulDaMacMan wrote:
Sun Dec 13, 2020 7:44 pm
This post in honor of the memory of Hermann Hoch, R.I.P. Thank You HH!
What??!! Really? When/how and oh no! I already miss Hermann on the forum. It's devastating to receive this news, and I am shocked and saddened to hear he is no longer with us. Condolences to his family. :cry:
Yeah, saddened by this news as well, I just saw it on the LC email List today. I had thought he'd been silent on here because he had just gotten frustrated with LiveCode but apparently he died from having a stroke back in March. :cry:
My LCB Repos: https://github.com/PaulMcClernan/
My LiveCode YouTube Videos: PlayList

bogs
Posts: 5432
Joined: Sat Feb 25, 2017 10:45 pm

Re: Community snippets

Post by bogs » Mon Dec 14, 2020 1:04 pm

PaulDaMacMan wrote:
Mon Dec 14, 2020 1:26 am
I had thought he'd been silent on here because he had just gotten frustrated...
I thought the same as well, and was very surprised to read this post, as well as the thread in the use - list (after Paul pointed it out to me).

I never met him in person, but I will always think about his helpful nature, and grieve along with his family over his loss.
Image

AndyP
Posts: 549
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Community snippets

Post by AndyP » Tue Dec 15, 2020 6:17 pm

Oh, that is very sad news indeed.
I was and still am amazed at what Hermann could achieve with LiveCode.
A real master of his trade.
Andy Piddock

http://livecode1001.blogspot.com

http://2108.co.uk/tinyide/ - Mini LC IDE alternative

http://2108.co.uk/script-editor-themer/ - Script Editor colour theming

http://livecodeshare.runrev.com/stack/897/LiveCode-Multi-Search

Post Reply

Return to “LiveCode Builder”