Spelling out the license - some geometry handlers

David Bovill david at openpartnership.net
Mon Nov 21 14:58:39 EST 2005


Sorry some bug fixes - sure they can be improved sped up?


License
This work is licensed under the Creative Commons Attribution- 
NonCommercial-ShareAlike 2.5 License. To view a copy of this license,  
visit http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a  
letter to Creative Commons, 543 Howard Street, 5th Floor, San  
Francisco, California, 94105, USA.


--> Groups and formatted sizes
-
function rect_GetVisibleRect groupRect, someGroup
     put the margins of someGroup into someMargin
     if the showBorder of someGroup is true then
         put the borderWidth of someGroup into someBorder
         if the showName of someGroup is true then
             put the effective textHeight of someGroup - someBorder -  
1 into someBit
             add someBit to item 2 of someMargin
         end if
         put subtractMargin(someBorder, groupRect) into groupRect
     end if
     put subtractMargin(someMargin, groupRect) into myInner_Rect
     return myInner_Rect
end rect_GetVisibleRect

on rect_SetVisibleRect myGroupRect, containerGroup, showInvisible
     put rect_GetVisibleRect(myGroupRect, containerGroup) into  
myInner_Rect
     testRect myInner_Rect, "Inner Rect"

     put the toplevel_GroupIDs of containerGroup into topGroupIDs
     put myInner_Rect into innerGroup_Rect
     repeat for each line someID in topGroupIDs
         if the visible of control id someID is false then
             if showInvisible is true then
                 set the visible of control id someID to true
             else
                 next repeat
             end if
         end if

         put the height of control id someID into groupHeight
         put item 2 of innerGroup_Rect + groupHeight into group_Bottom
         put group_Bottom into item 4 of innerGroup_Rect

         set the group_Rect of control id someID to innerGroup_Rect
         put group_Bottom into item 2 of innerGroup_Rect
     end repeat
end rect_SetVisibleRect

function width_MaxIndexGroupContainerWidth containingGroup
     put empty into widthList
     put the number of groups of containingGroup into maxNum
     repeat with groupNum = 1 to maxNum
         -- maybe can use formatted width of group?
         put the long id of group groupNum of containingGroup into  
indexGroup
         put the long id of fld 1 of indexGroup into someField
         put width_RealFormatted(someField) & "," after widthList
     end repeat
     return max(widthList)
end width_MaxIndexGroupContainerWidth

function formattedWidth_GetField someText, someField, someTextStyle
     lock screen
     put the htmlText of someField into oHtmlText
     set the text of someField to someText
     if someTextStyle is not empty then
         set the textStyle of char 1 to -1 of someField to someTextStyle
     end if
     put the formattedWidth of someField into someWidth
     set the htmlText of someField to oHtmlText
     unlock screen
     return someWidth
end formattedWidth_GetField

function width_RealFormatted someObject
     put the formattedWidth of someObject into someWidth
     if the showBorder of someObject is true then
         add (2 * the borderWidth of someObject) to someWidth
     end if
     return someWidth
end width_RealFormatted

function height_RealFormatted someObject
     put the formattedHeight of someObject into someHeight
     if the showBorder of someObject is true then
         add (2 * the borderHeight of someObject) to someHeight
     end if
     return someHeight
end height_RealFormatted


--> Margins
-
function addMargin someMargins, someRect
     margin_Normalise someMargin, left_Margin, top_Margin,  
right_Margin, bottom_Margin
     subtract left_Margin from item 1 of someRect
     subtract top_Margin from item 2 of someRect
     add right_Margin to item 3 of someRect
     add bottom_Margin to item 4 of someRect
     return someRect
end addMargin

function subtractMargin someMargin, someRect
     margin_Normalise someMargin, left_Margin, top_Margin,  
right_Margin, bottom_Margin
     add left_Margin to item 1 of someRect
     add top_Margin to item 2 of someRect
     subtract right_Margin from item 3 of someRect
     subtract bottom_Margin from item 4 of someRect
     return someRect
end subtractMargin

on margin_Normalise @someMargin, @left_Margin, @top_Margin,  
@right_Margin, @bottom_Margin
     if the number of items of someMargin < 4 then
         put item 1 of someMargin into defaultMargin
         put defaultMargin into left_Margin

         put item 2 of someMargin into actualMargin
         if actualMargin is empty then
             put defaultMargin into top_Margin
         else
             put actualMargin into top_Margin
         end if

         put item 3 of someMargin into actualMargin
         if actualMargin is empty then
             put defaultMargin into right_Margin
         else
             put actualMargin into right_Margin
         end if

         put item 4 of someMargin into actualMargin
         if actualMargin is empty then
             put defaultMargin into bottom_Margin
         else
             put actualMargin into bottom_Margin
         end if
     else
         put item 1 of someMargin into left_Margin
         put item 2 of someMargin into top_Margin
         put item 3 of someMargin into right_Margin
         put item 4 of someMargin into bottom_Margin
     end if
     put left_Margin,top_Margin,right_Margin,bottom_Margin into  
someMargin
end margin_Normalise


--> Tab Menus
-
function menu_TabInnerGroupRect tabButton, someMargin
     if someMargin is empty then put 16 into someMargin
     put the rect of tabButton into someRect
     put subtractMargin(someMargin, someRect) into innerRect
     put the textHeight of tabButton into someHeight
     add someHeight to item 2 of innerRect

     return innerRect
end menu_TabInnerGroupRect




More information about the use-livecode mailing list