Platforms to show: All Mac Windows Linux Cross-Platform
/MacOSX/ResizeTest
Feedback.
Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /MacOSX/ResizeTest
This example is the version from Wed, 2nd Mar 2010.
Notes: Last modified: Wed, 2nd Mar 2010
Feedback.
Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /MacOSX/ResizeTest
This example is the version from Wed, 2nd Mar 2010.
Notes: Last modified: Wed, 2nd Mar 2010
Class Window1
Inherits Window
// Constants
Const CarbonLib = Carbon
// Controls
ControlInstance
Sub LiveAction(NewWidth As Integer, NewHeight As Integer, ReziseFactor As Double) Handles Event
StaticText1.text="Height: "+str(newHeight)
StaticText2.text="Width: "+str(NewWidth)
StaticText3.text= str(ReziseFactor)
End Sub
Sub Open() Handles Event
me.myWindow=self // This is a must
me.top=self.height-me.height
me.left=self.width-me.width
End Sub
End ControlInstance
ControlInstance
Sub Action() Handles Event
growfield1.hasBackColor= not me.value
growfield1.refresh
setWindowMetal self,me.value
End Sub
End ControlInstance
ControlInstance
End ControlInstance
ControlInstance
End ControlInstance
ControlInstance
End ControlInstance
ControlInstance
End ControlInstance
// Methods
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
Class App
Inherits Application
End Class
Class GrowField
Inherits Canvas
// Properties
Private Dim DarkColor As Color
Private Dim LightColor As Color
Private Dim myOverlay As OverlayWindowMBS
Dim myWindow As Window
Private Dim ClickX As Integer
Private Dim ClickY As Integer
Private Dim ResizeValue As Double
Private Dim doResize As Boolean
Private Dim RectColor As Color
Private Dim RectTransparency As Integer
Private Dim RectThickness As Integer
Private Dim ResizeHight As Integer
Dim BackColor As Color
Dim HasBackColor As Boolean
Dim BorderColor As Color
Dim HasBorder As Boolean
Private Dim ResizeWidth As Integer
Private Dim LastH As Integer
// New events
Event Action(ResizeFactor As Double, NewWidth as Integer, NewHeight As Integer)
Event Open()
Event LiveAction(NewWidth As Integer, NewHeight As Integer, ReziseFactor As Double)
// Event implementations
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 Sub
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 Sub
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 Sub
Function MouseDown(X As Integer, Y As Integer) As Boolean
ClickX=system.MouseX
ClickY=system.MouseY
CreateOverlay
Return true
End Function
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 Sub
// Methods
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
End Class
Links
MBS REAL studio Chart Plugins - Pfarrgemeinde St. Arnulf Nickenich