Platforms to show: All Mac Windows Linux Cross-Platform
/MacCG/CoreGraphics Overlay Window/EasyOverlay/My First EasyOverlay
Function:
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/CoreGraphics Overlay Window/EasyOverlay/My First EasyOverlay
This example is the version from Sun, 10th Dec 2016.
Function:
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/CoreGraphics Overlay Window/EasyOverlay/My First EasyOverlay
This example is the version from Sun, 10th Dec 2016.
Project "My First EasyOverlay.rbp"
FileTypes
Filetype text
End FileTypes
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
EventHandler Sub Open()
myTestOverlay =new TestOverlay
myTestOverlay.init 200,200,400,200
myTestOverlay.IgnoreClicks=false //Otherwise the Mouse Events will not fire
myTestOverlay.Moveable=true
myTestOverlay.Refresh
End EventHandler
Property myTestOverlay As TestOverlay
End Class
Class TestOverlay Inherits EasyOverlayWindow
EventHandler Sub Paint(o As EasyOverlayWindow)
o.ForeColorTransparency=127
o.FillRoundRect 0,0,400,200,10,10
o.ForeColorTransparency=255
o.ForeColor=rgb(0,0,255)
o.DrawString "My first EasyOverlayWindow",100,50
End EventHandler
End Class
Class EasyOverlayWindow Inherits OverlayWindowMBS
Event MouseDown(x As Integer, y As Integer, ModifierKeys As Integer,MouseButton as integer, ClickCount As Integer) As Boolean
End Event
Event MouseDrag(x As Integer, y As Integer, ModifierKeys As Integer,MouseButton as integer)
End Event
Event MouseMove(X As Integer, Y As Integer,ModifierKeys As Integer)
End Event
Event MouseUp(x As Integer, y As Integer, ModifierKeys As Integer,MouseButton as integer, ClickCount As Integer)
End Event
Event Paint(o As EasyOverlayWindow)
End Event
Event WindowDragAction(X As Integer, Y As Integer)
End Event
EventHandler Function MouseDown(x as double, y as double, ModifierKeys as integer, MouseButton as integer, ClickCount as integer) As boolean
systemmousex=System.MouseX
systemmousey=System.MouseY
MouseClicked=MouseDown(x-left,y-top,ModifierKeys, MouseButton, ClickCount)
if Moveable then
return true
end if
End EventHandler
EventHandler Function MouseDragged(x as double, y as double, ModifierKeys as integer, MouseDeltaX as double, MouseDeltaY as double, MouseButton as integer) As boolean
if Moveable then
left=left+System.MouseX-systemmousex
top=top+System.MouseY-systemmousey
systemmousey=System.MouseY
systemmousex=System.MouseX
if MouseDeltaX<>0 or MouseDeltaY<>0 then WindowDragAction left,top
end if
if MouseClicked then
MouseDrag x-left,y-top,ModifierKeys, MouseButton
end if
End EventHandler
EventHandler Function MouseMoved(x as double, y as double, ModifierKeys as integer, MouseDeltaX as double, MouseDeltaY as double) As boolean
MouseMove x-left,y-top,ModifierKeys
End EventHandler
EventHandler Function MouseUp(x as double, y as double, ModifierKeys as integer, MouseButton as integer, ClickCount as integer) As boolean
if MouseClicked then
MouseUp x-left,y-top,ModifierKeys, MouseButton, ClickCount
end if
End EventHandler
Private Sub AddOval(c as CGContextMBS, center as CGPOintMBS, a as single, b as single)
dim pi as single
pi=ACos(0)*2.0
c.SaveGState
c.TranslateCTM center.x, center.y
c.ScaleCTM a,b
c.MoveToPoint 1,0
c.AddArc 0, 0, 1, 0.0, 2*pi, false
c.ClosePath
c.RestoreGState
End Sub
Sub Clear()
myContext.ClearRect myRect
End Sub
Sub DrawBevelFrame(x As Integer, y As Integer, w As Integer, h As integer, TopLeftColor As color, ButtomRightColor As color)
dim d,i,LineWidthMerk As integer
dim ColorMerk As color
ColorMerk=foreColor // Remember ForeColor
LineWidthMerk=LineWidth// Remember LineWidth
d=ceil(LineWidth/2)
LineWidth=1
for i= 1 to LineWidthMerk
ForeColor=ButtomRightColor //Draw ButtomRight
DrawLine x+w-i, y+i, x+w-i, y+h //right vert
DrawLine x+i, y+h-i, x+w-i, y+h-i //down hor
ForeColor=TopLeftColor // Draw TopLeft
DrawLine x, y+i, x+w-i, y+i //Up hor
DrawLine x+i, y, x+i, y+h-i // left vert
next
ForeColor=ColorMerk // Set ForeColor as it was before
LineWidth=LineWidthMerk // set LineWidth as it was before
End Sub
Sub DrawLine(x1 As integer, y1 As integer, x2 As integer, y2 As integer)
dim ct As CGContextMBS
dim yy1 As integer, yy2 ,xx1,xx2 As integer
dim c As color
'c=rgb(255,0,0)
'myForeColor
xx1=x1'+LineWidth/2
xx2=x2'+LineWidth/2
yy1=height-y1
yy2=height-y2
ct=myContext
ct.beginPath
ct.moveToPoint xx1,yy1
ct.AddLineToPoint xx2,yy2
ct.strokePath
End Sub
Sub DrawOval(x As Integer, y As Integer, w As Integer, h As Integer)
dim c as CGContextMBS
dim center as CGPointMBS
dim yy,l As integer
yy=height-y
l=lineWidth/2
center=CGMakePointMBS(x+l+w/2,yy-l-h/2)
c=myContext
c.BeginPath
AddOval c,center, w/2,h/2
c.strokePath
End Sub
Sub DrawPicture(p As Picture, x As Integer, y As integer)
dim r As CGRectMBS
dim ci As CGImageMBS
ci=CGCreateImageMBS(p,p.mask)
r=CGMakeRectMBS(x,height-p.height-y, p.width, p.height)
myContext.DrawPicture ci,r
End Sub
Sub DrawRect(x As integer, y As integer, w As integer, h As integer)
dim r As CGRectMBS
dim d As integer
d=ceil(LineWidth/2)
r=CGMakeRectMBS(x+d,height-h-y+d,w-LineWidth,h-LineWidth)
myContext.strokerect r
'dim d As integer
'
'
'
'd=ceil(LineWidth/2)
'
'DrawLine x+d, y+d, x+w, y+d //Up hor
'
'DrawLine x+d, y, x+d, y+h // left vert
'
'DrawLine x+w-d, y, x+w-d, y+h //right vert
'
'DrawLine x+d, y+h-d, x+w, y+h-d //down hor
End Sub
Sub DrawRoundRect(x As Integer, y As Integer,w As Integer, h As Integer,arcx As integer,arcy as integer)
doDrawRoundRect x+Linewidth/2, y+LineWidth/2, w-lineWidth, h-LineWidth, arcx, arcy,false
End Sub
Sub DrawString(Text As string, x As integer, y As Integer)
dim c As CGContextMBS
c=myContext
c.selectFont myTextFont, myTextSize, 1
c.ShowTextAtPoint text,x,height-y-myTextSize
End Sub
Sub DrawStringWithShadow(text As string, x As Integer, y As Integer, ShadowSize As integer, ShadowTransparency As Integer, ShadowColor as Color=&c000000)
dim colorMerk As Color
dim transMerk As Integer
ColorMerk=ForeColor
transMerk=ForeColorTransparency
// set Shadow values
ForeColor=ShadowColor
ForeColorTransparency=ShadowTransparency
// Draw Shadow
DrawString text,x+ShadowSize,y+shadowSize
// set String values
ForeColor=colorMerk
ForeColorTransparency=transMerk
// draw string
DrawString text,x,y
End Sub
Sub DrawWindow()
myContext.flush
End Sub
Sub FillOval(x As integer, y As integer, w As integer, h As integer)
dim c as CGContextMBS
dim center as CGPointMBS
dim yy,xx As integer
yy=height-y
xx=width-x
center=CGMakePointMBS(x+w/2,yy-h/2)
c=myContext
c.BeginPath
AddOval c,center, w/2,h/2
c.FillPath
End Sub
Sub FillRect(x As Integer, y As Integer, w As Integer, h As Integer)
dim r As CGRectMBS
r=CGMakeRectMBS(x,height-h-y,w,h)
myContext.Fillrect r
End Sub
Sub FillRoundRect(x As Integer, y As Integer,w As Integer, h As Integer,arcx As integer,arcy as integer)
doDrawRoundRect x,y,w,h,arcx,arcy,true
End Sub
Function ForeColor() As Color
return myForeColor
End Function
Sub ForeColor(Assigns c As Color)
myContext.setRGBFillColor c.red/255, c.green/255, c.blue/255, ForeColorTransparency/255
myContext.SetRGBStrokeColor c.red/255, c.green/255, c.blue/255, ForeColorTransparency/255
myForeColor=c
End Sub
Function ForeColorTransparency() As Integer
return myTransparency
End Function
Sub ForeColorTransparency(Assigns v As Integer)
dim c As color
c=ForeColor
myContext.setRGBFillColor c.red/255, c.green/255, c.blue/255, v/255
myContext.SetRGBStrokeColor c.red/255, c.green/255, c.blue/255, v/255
myTransparency=v
End Sub
Sub Init(wLeft As Integer, wTop As Integer, wWidth As integer, wHeight As integer,AttachedWindow As window=nil)
// Create Overlay Window
'
if me.Create(wLeft,wTop,wWidth,wHeight)<>0 then beep
me.InstallEventHandler
if AttachedWindow<>NIL then me.AttachToWindow(AttachedWindow,true)
me.show
// Create RECT and CONTEXT
myRect=CGMakeRectMBS(0,0,me.width,me.height)
myContext=me.context
myContext.ClearRect myRect
// set Defaults
foreColor=rgb(0,0,0)
ForeColorTransparency=255
LineWidth=1
TextFont="Helvetica"
TextSize=12
Width=wWidth
Height=wHeight
End Sub
Function LineWidth() As Integer
Return myLineWidth
End Function
Sub LineWidth(Assigns v As Integer)
myContext.setLineWidth(v)
myLineWidth=v
End Sub
Sub Refresh()
if myContext<>NIL and myRect<>Nil then
Paint me
myContext.flush
end if
End Sub
Function StringWidth(text As String) As Integer
dim p As picture
dim g As graphics
p = new Picture(32,32,32) // Dummy Picture
g=p.graphics
g.TextFont=TextFont
g.TextSize=TextSize
return g.stringWidth(text)
End Function
Function TextFont() As String
return myTextFont
End Function
Sub TextFont(Assigns v As string)
myTextFont=v
End Sub
Function TextSize() As Integer
return myTextSize
End Function
Sub TextSize(Assigns v As Integer)
myTextSize=v
End Sub
Sub Update()
myRect=CGMakeRectMBS(0,0,width,height)
myContext=me.context
myContext.ClearRect myRect
refresh
End Sub
Sub doDrawRoundRect(x As Integer, y As Integer,w As Integer, h As Integer,arcx As integer,arcy as integer,filled As boolean)
dim ct As CGContextMBS
dim yy, xp, yp As integer
yy=height-h-y
ct=myContext
ct.beginPath
xp=x+arcX
yp=yy
ct.MoveToPoint xp,yp //goto TopLeft
xp=xp+w - 2*arcx
ct.AddLineToPoint xp,yp // top line
xp=xp+arcx
ct.AddQuadCurveToPoint xp, yp, xp, yp+arcy // TopRight corner
yp=yp+h-arcy
ct.AddLineToPoint xp,yp // right line
yp=yp+arcy
ct.AddQuadCurveToPoint xp, yp, xp-arcx, yp // Bottom/Right Corner
xp=xp-w+arcx
ct.addLineToPoint xp, yp //bottom line
xp=x
yp=yp-arcy
ct.AddQuadCurveToPoint xp, yp+arcy, xp, yp //BottomLeft corner
yp=yy+arcy
ct.addLineToPoint xp,yp // left line
ct.AddQuadCurveToPoint x, yy, x+arcX, yy // TopLeft corner
if filled then
ct.fillPath
else
ct.StrokePath
end if
End Sub
Note "Info"
EasyOverlay is a easy to use OverlayWindowMBS
You can use it almost like a Graphics Class
This Methodes and Properties are equal with the Graphics Class:
DrawLine x1,y1,x2,y2
DrawOval x, y, width, height
FillOval x, y, width, height
DrawRect x, y, width, height
FillRect x, y, width, height
DrawRoundRect x As Integer, y As Integer, width As Integer, height As Integer, arcx As integer, arcy as integer
FillRoundRect x As Integer, y As Integer, width As Integer, height As Integer, arcx As integer, arcy as integer
DrawPicture p, x, y // No scaling yet!
DrawString text, x, y
TextSize
TextFont
StringWidth
ForeColor
New Methodes:
DrawStringWithShadow text As string, x As Integer, y As Integer, ShadowSize As integer, ShadowTransparency As Integer, ShadowColor as Color
DrawBevelFrame x As Integer, y As Integer, width As Integer, height As integer, TopLeftColor As color, ButtomRightColor As color
Refresh (Fire the Paint Event)
Clear (Clear the OverlayWindow)
Init left as integer, top as integer, width as integer, height as integer [,w as window]
(use init after you created EasyOverlay. If w<>Nil the overlay will be attached to w)
Update (use it after you resized the overlay)
New Properties:
ForeColorTransparency as Integer (0=transparent - 255=opaque)
LineWidth as Integer (Use this insteat of PenWidth/PenHeight)
Moveable as boolean (if true, the overlay can be draged)
Exemples:
This Example creates a moveable OverlayWindow
// Create a Class name: "TestOverlay" Super: "EasyOverlayWindow"
// Add a Propertie "myTestOverlay as TestOverlay" to your 'App Class'
// Put this code into the 'Open Event' of your 'App Class'
myTestOverlay =new TestOverlay
myTestOverlay.EatMouseEvents=true //Otherwise the Mouse Events will not fire
myTestOverlay.init 200,200,400,200
myTestOverlay.Moveable=true
myTestOverlay.Refresh
// Put this code into the 'Paint Event' of 'TestOverlay'
o.ForeColorTransparency=127
o.FillRoundRect 0,0,400,200,10,10
o.ForeColorTransparency=255
o.ForeColor=rgb(0,0,255)
o.DrawString "My first EasyOverlayWindow",100,50
Property Private Black As Color
Property Private MouseClicked As Boolean
Property Private MouseWasClicked As Boolean
Property Moveable As Boolean
Property Private myContext As CGContextMBS
Property Private myForeColor As Color
Property Private myLineWidth As Integer
Property Private myRect As CGRectMBS
Property Private myTextFont As String
Property Private myTextSize As Integer
Property Private myTransparency As Integer
Property systemmousex As Integer
Property systemmousey As Integer
End Class
End Project
See also:
- /MacCG/CoreGraphics Bitmap
- /MacCG/CoreGraphics DirectDisplay/Capture Screen with CGContextMBS
- /MacCG/CoreGraphics DirectDisplay/CG Displaylist
- /MacCG/CoreGraphics DirectDisplay/CG Modelist
- /MacCG/CoreGraphics DirectDisplay/CGDisplay Rotation
- /MacCG/CoreGraphics DirectDisplay/CGDisplayMBS CreateImageAsync
- /MacCG/CoreGraphics DirectDisplay/CGDisplayReconfigurationEventMBS test
- /MacCG/CoreGraphics DirectDisplay/CGDisplayStreamEvent test
- /MacCG/CoreGraphics DirectDisplay/CGScreenRefreshEvent Test
- /MacCG/CoreGraphics DirectDisplay/Gamma Test
- /MacCG/CoreGraphics Overlay Window/EasyOverlay/EasyOverlay
- /MacCG/CoreGraphics Overlay Window/EasyOverlay/Magnify
- /MacCG/CoreGraphics Overlay Window/Mac and Win Transparent Splash/SplashScreen
- /MacCG/CoreGraphics Overlay Window/Overlay Window/Addressbook like number display
- /MacCG/CoreGraphics Overlay Window/Overlay Window/Attached OverlayWindows
- /MacCG/CoreGraphics Overlay Window/Overlay Window/Dock like Poff
- /MacCG/CoreGraphics Overlay Window/Overlay Window/Magician
- /MacCG/CoreGraphics Overlay Window/Overlay Window/Overlay in background
- /MacCG/CoreGraphics Overlay Window/Overlay Window/Overlay Rectangle Mac
- /MacCG/CoreGraphics Overlay Window/Overlay Window/Overlay Window
- /MacCG/CoreGraphics Overlay Window/Overlay Window/Overlay Window Animated
- /MacCG/CoreGraphics Overlay Window/Overlay Window/Overlay Window with Events
- /MacCG/CoreGraphics Overlay Window/Photoshop Splash Screen/Photoshop Splash Screen
- /MacCG/CoreGraphics Overlay Window/Transparent Windows/Custom Window with RB window
- /MacCG/CoreGraphics PDF/Create PDF with Picture
- /MacCG/CoreGraphics PDF/Getpicture PDF
- /MacCG/CoreGraphics PDF/PDF Font list
- /MacCG/CoreGraphics PDF/PDF Fontfamily list
- /MacCG/CoreGraphics PDF/PDF properties
- /MacCG/CoreGraphics PDF/PDF Text
- /MacCG/CoreGraphics PDF/PDF Transparency
- /MacCG/CoreGraphics PDF/PDF using Save and Restore
- /MacCG/CoreGraphics PDF/PDF Viewer White on Black
- /MacCG/CoreGraphics PDF/PDF with paths
- /MacCG/CoreGraphics PDF/PDF with paths and gradient
- /MacCG/CoreGraphics PDF/Show PDF
- /MacCG/CoreGraphics PDF/Simple Make PDF
The items on this page are in the following plugins: MBS MacCG Plugin.
Links
MBS FileMaker Plugins