Page 2 of 2

Re: Community snippets

Posted: Sun Mar 01, 2020 6:48 pm
by [-hh]
[#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)]

Re: Community snippets

Posted: Thu Sep 03, 2020 3:50 am
by PaulDaMacMan
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)

Re: Community snippets

Posted: Sun Dec 13, 2020 7:44 pm
by PaulDaMacMan
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.

Re: Community snippets

Posted: Sun Dec 13, 2020 10:23 pm
by SparkOut
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:

Re: Community snippets

Posted: Mon Dec 14, 2020 1:26 am
by PaulDaMacMan
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:

Re: Community snippets

Posted: Mon Dec 14, 2020 1:04 pm
by bogs
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.

Re: Community snippets

Posted: Tue Dec 15, 2020 6:17 pm
by AndyP
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.