Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

Required plugins for this example: MBS MacCG Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/ResizeTest
This example is the version from Sun, 17th Mar 2012.
Project "ResizeTest.rbp"
Filetype text
End FileTypes
Class Window1 Inherits Window
Const CarbonLib = "CarbonLib"
Control GrowField1 Inherits GrowField
ControlInstance GrowField1 Inherits GrowField
EventHandler Sub LiveAction(NewWidth As Integer, NewHeight As Integer, ReziseFactor As Double) StaticText1.text="Height: "+str(newHeight) StaticText2.text="Width: "+str(NewWidth) StaticText3.text= str(ReziseFactor) End EventHandler
EventHandler Sub Open() me.myWindow=self // This is a must me.top=self.height-me.height me.left=self.width-me.width End EventHandler
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub Action() growfield1.hasBackColor= not me.value growfield1.refresh setWindowMetal self,me.value End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Sub setWindowMetal(w As window, b As boolean) // Added 8/25/2002 by Kevin Ballard // Modified 9/15/2002 by Kevin Ballard // This function is only useful in RB v5. // If you want to use it, check the Composite property of the window. Then you can // use this function to change the Metal status at runtime, something RB v5 lets you do // only at design-time. // In RB versions less than v5, it will simply add a metal border to the window, which looks bad. const attrib = 256 dim err as integer if TargetCarbon then Declare Function ChangeWindowAttributes Lib CarbonLib(window as WindowPtr, setTheseAttributes as Integer, clearTheseAttributes as Integer) as Integer 'If IsJaguar() Then if b then err = ChangeWindowAttributes(w, attrib, 0) else err = ChangeWindowAttributes(w, 0, attrib) end 'End If end if // TargetCarbon End Sub
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class GrowField Inherits Canvas
Event Action(ResizeFactor As Double, NewWidth as Integer, NewHeight As Integer) End Event
Event LiveAction(NewWidth As Integer, NewHeight As Integer, ReziseFactor As Double) End Event
Event Open() End Event
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean ClickX=system.MouseX ClickY=system.MouseY CreateOverlay Return true End EventHandler
EventHandler Sub MouseDrag(X As Integer, Y As Integer) dim w,h As Integer h=myWindow.Height+(system.MouseY-clickY) h=max(h,myWindow.minHeight) if h>myWindow.maxHeight then h=myWindow.maxHeight end if ResizeHight=h ResizeValue=100/(100+((myWindow.height)-h)/h*100) w=myWindow.width * ResizeValue ResizeWidth=w if LastH<>h then // fires only if value has changed DrawOverlay w, h LiveAction w,h, ResizeValue end if LastH=h End EventHandler
EventHandler Sub MouseUp(X As Integer, Y As Integer) myOverlay.Close if doResize then myWindow.height=myWindow.height*ResizeValue myWindow.width=myWindow.width*ResizeValue end if Action ResizeValue, ResizeWidth, ResizeHight LastH=0 End EventHandler
EventHandler Sub Open() Open if myWindow=NIL then msgBox me.name+" needs: ""me.myWindow=self"" in the Open Event" quit end if RectTransparency=max(RectTransparency,1) if RectTransparency>255 then msgBox me.name+" RectTransparency range = 0-255!" quit end if If RectThickness <=0 then RectThickness=1 end if End EventHandler
EventHandler Sub Paint(g As Graphics) Dim i,s,w,h As Integer if HasBackColor then g.foreColor=BackColor g.FillRect 0,0,g.width,g.height end if if HasBorder then g.foreColor=BorderColor g.DrawRect 0,0,g.width,g.height end if s=g.width/3 w=g.width-1 h=w // aspect ratio is always 1:1 for i=0 to 2 g.foreColor=DarkColor g.DrawLine i*s,w,h,i*s g.foreColor=LightColor g.DrawLine i*s+1,w,h,i*s+1 next End EventHandler
Private Sub CreateOverlay() dim t,l,w,h As Integer l=myWindow.left t=myWindow.top w=screen(0).width-myWindow.left'-10 h=screen(0).height-myWindow.top'-10 myOverlay=new OverlayWindowMBS if myOverlay.Create(l,t,w,h)<>0 then MsgBox "Can't create overlay window!" else myOverlay.Show drawOverlay myWindow.width, myWindow.height'-30 end if End Sub
Private Sub DrawOverlay(OverlayRectWidth As Integer, OverlayRectHeight As Integer) dim ct as CGContextMBS dim r,r2,rAll as CGRectMBS dim l,t As Integer l=myWindow.left-myOverlay.left t=myOverlay.height-myWindow.height+(myWindow.height-OverlayRectHeight) rAll=CGMakeRectMBS(0,0,myOverlay.width,myOverlay.height) // Size of the whole Overlay r=CGMakeRectMBS(l,t,OverlayRectWidth,OverlayRectHeight) // Outside r2=CGMakeRectMBS(r.left+RectThickness, r.top+RectThickness, r.width-2*RectThickness, r.height-2*RectThickness) // Inside ct=myOverlay.Context ct.ClearRect rAll // clear the whole overlay ct.SetRGBFillColor RectColor.red/255, RectColor.green/255, RectColor.blue/255, 1/RectTransparency ct.FillRect r ct.ClearRect r2 // clear inside a Rectangle will stay ct.Flush End Sub
Property BackColor As Color
Property BorderColor As Color
Property Private ClickX As Integer
Property Private ClickY As Integer
Property Private DarkColor As Color
Property HasBackColor As Boolean
Property HasBorder As Boolean
Property Private LastH As Integer
Property Private LightColor As Color
Property Private RectColor As Color
Property Private RectThickness As Integer
Property Private RectTransparency As Integer
Property Private ResizeHight As Integer
Property Private ResizeValue As Double
Property Private ResizeWidth As Integer
Property Private doResize As Boolean
Property Private myOverlay As OverlayWindowMBS
Property myWindow As Window
End Class
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCG Plugin.

MBS FileMaker blog