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: 326
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/

Post Reply

Return to “LiveCode Builder”