Platforms to show: All Mac Windows Linux Cross-Platform
/Overlay/Overlay Test with Text HiDPI
Required plugins for this example: MBS Overlay Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Overlay/Overlay Test with Text HiDPI
This example is the version from Sat, 3rd Jun 2022.
Project "Overlay Test with Text HiDPI.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
updatebar
End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
create false
End EventHandler
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub Action()
if o<>Nil then
o.IgnoreMouseClicks=me.Value
end if
End EventHandler
End Control
Control iText Inherits TextArea
ControlInstance iText Inherits TextArea
EventHandler Sub TextChange()
UpdateText
End EventHandler
End Control
EventHandler Function KeyDown(Key As String) As Boolean
Select case asc(key)
case 28 'left
move -10,0
Return true
case 29 'right
move 10,0
Return true
case 30 'top
move 0,-10
Return true
case 31 'down
move 0,10
Return true
end Select
End EventHandler
Sub Create(b as Boolean)
dim ScaleFactor as Double
#if RBVersion < 2015.04 then
// older Xojo and Real Studio without HiDPI
ScaleFactor = 1
p = new Picture(400, 150, 32)
m = new Picture(400, 150, 32)
#else
// for newer Xojo we ask here for pictures with high resolution
p = self.BitmapForCaching(400, 150)
m = self.BitmapForCaching(400, 150)
#if TargetMacOS then
// window size is *1 for Mac
ScaleFactor = 1
#else
// window size is *1, *2 or *3 for Windows
ScaleFactor = p.Width / 400
#endif
m.Graphics.ForeColor = &cFFFFFF
m.Graphics.FillRect 0, 0, m.Width, m.Height
#endif
p.Graphics.DrawPicture IconPict,0,0
m.Graphics.DrawPicture IconMask,0,0
o=new MyOverlay(500 * ScaleFactor,100 * ScaleFactor,400 * ScaleFactor,150 * ScaleFactor,b)
o.Pict=p
o.Mask=m
updatebar
o.Show
timer1.Mode=2
UpdateText
End Sub
Sub UpdateText()
Dim pg As Graphics = o.Pict.Graphics
dim mg as Graphics = o.Mask.Graphics
pg.ForeColor=&ccccccc
pg.FillRoundRect 190,10,200,120,50,50
pg.ForeColor=&c000000
#If TargetWindows Then
// no StyledTextPrinter on Windows?
pg.DrawString iText.Text, 200, 40,180
#Else
Dim stp As StyledTextPrinter
stp=iText.StyledTextPrinter(pg,180)
stp.DrawBlock 200,20,100
#EndIf
mg.ForeColor=&c333333
mg.FillRoundRect 190,10,200,120,50,50
End Sub
Private Sub move(x as integer, y as integer)
o.Move o.Left+x,o.top+y
End Sub
Private Sub updatebar()
dim pos,w,r,i as integer
w=128
m.Graphics.ForeColor=&c000000
m.Graphics.FillOval 0,130,w,20
p.Graphics.ForeColor=&c000000
counter=counter+4
pos=counter mod 512
for i=0 to w-1
pos=pos+4
pos=pos mod 512
if pos>255 then
r=511-pos
else
r=pos
end if
p.Graphics.ForeColor=rgb(r,0,0)
p.Graphics.DrawLine i,130,i,150
next
o.Update
End Sub
Property Private counter As Integer
Property Private m As picture
Property Private o As MyOverlay
Property Private p As picture
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
ExternalFile IconMask
End ExternalFile
ExternalFile IconPict
End ExternalFile
Class MyOverlay Inherits OverlayMBS
EventHandler Function MouseDown(x as integer, y as integer, modifiers as integer) As boolean
log "mousedown "+str(x)+" "+str(y)
End EventHandler
EventHandler Function MouseMoved(x as integer, y as integer, modifiers as integer) As boolean
log "mousemoved "+str(x)+" "+str(y)
End EventHandler
EventHandler Function MouseUp(x as integer, y as integer, modifiers as integer) As boolean
log "mouseup "+str(x)+" "+str(y)
End EventHandler
EventHandler Sub WindowBoundsChanged()
log "windowboundschanged"
End EventHandler
EventHandler Sub WindowClosed()
log "windowclosed"
End EventHandler
EventHandler Sub WindowHidden()
log "windowhidden"
End EventHandler
EventHandler Sub WindowShown()
log "windowShown"
End EventHandler
Private Function Window1open() As Boolean
dim i,c as integer
c=WindowCount-1
for i=0 to c
if window(i) isa MainWindow then
Return true
end if
next
End Function
Private Sub log(s as string)
System.DebugLog s
if Window1open then
MainWindow.Listbox1.InsertRow 0,s
end if
End Sub
End Class
End Project
See also:
The items on this page are in the following plugins: MBS Overlay Plugin.