Maybe like this with oGDIp ...
Code: Select all
#SingleInstance force
#include OGdip.ahk
OGdip.Startup() ; This function initializes GDI+ and must be called first.
; Create GUI container for our drawings. 'Text' will work too, but semantically 'Picture' is better.
gui, add, Picture, w550 h550 x10 y10 hwndMainBox Border
bmp := new OGdip.Bitmap(550,550) ; Create new empty Bitmap with given width and height
; .G refers to Graphics surface of this Bitmap, it's used to draw things
bmp.G.Clear(0xFFA0A0A0) ; Clear fills bitmap with single color.
bmp.G.SetOptions({smooth:2}) ; Sets high-quality antialiasing
Gui, +LastFound
; OGdip doesn't provide any method similar to .Attach, to avoid unnecessary redraws.
; We'll put drawn image manually later.
; create pens for drawing
RedPenThin := new OGdip.Pen(0xFFFF0000,5) ; Pen(ARGB Color, thickness)
RedPenBold := new OGdip.Pen(0xFFFF0000,1) ; Pen(ARGB Color, thickness)
GreenPen := new OGdip.Pen(0xFF00FF00,1)
PurplePen := new OGdip.Pen(0xFF800080,1)
YellowPen := new OGdip.Pen(0x80FFFF00,3) ; this one has a transparency set to 80
AquaPen := new OGdip.Pen(0xFF00FFFF,1)
; create some brushes (to use only with filled forms)
GreenBrush:= new OGdip.Brush(0xAA00FF00) ; this brush has a transparency set to AA
BrownBrush:= new OGdip.Brush(0xFFA52A2A) ; this bursh is not transparent
YellowBrush:= new OGdip.Brush(0xaaFFFF00)
; In OGdip, we need to set Pen or Brush first, then draw some figures.
; Every .G.Draw method tries to both stroke the figure with Pen, and fill it with Brush, there is no separate .Draw/.Fill methods
; Most methods of .G can be chained together in one line:
bmp.G.SetPen(RedPenBold).DrawRectangle(10,10,277,50)
bmp.G.SetPen(RedPenThin).DrawRectangle(10,80,100,75)
; Green rectangle in original example do not have pen strokes.
; We can remove previously set Pen with empty string:
bmp.G.SetPen("").SetBrush(GreenBrush)
bmp.G.DrawRectangle(20,145,50,50) ;FillRectangle
; Switching tools may seem excessive in this example, I admit, but there is a logic behind it.
; For instance, if you need to draw many lines with single pen, you have to specify it only once.
bmp.G.SetPen(PurplePen).SetBrush("")
bmp.G.DrawEllipse(10,210,100,50) ; .DrawEllipse(posx,posy,Width,Height)
bmp.G.SetPen("").SetBrush(BrownBrush).DrawEllipse(10,280,50,50) ; Also try .DrawEllipseC( centerX, centerY, radiusX [, radiusY] )
bmp.G.SetPen(AquaPen).DrawLine(10,350,300,290) ; Draw a line (lines don't use brush, because they aren't closed.)
; You can use array of arrays for polygon, but you don't have to:
; plain numbers or arrays of coords, or mix of both will work too.
bmp.G.SetPen(PurplePen).SetBrush("")
bmp.G.DrawPolygon([[30,400],[30,500],[100,500]]) ; Draw a polygon (triangle)
; Now image can be drawn into Picture control.
; You can also use control name, like "Static1"
bmp.SetToControl(MainBox)
sf_background := new OGdip.Bitmap(550,550) ; clone the current bitmap
sf_background.G.DrawImage(bmp) ; draw the bmp on it
gui, add, button , gup, move up
gui, add, button , x+10 yp gdown, move down
gui, add, button , x+10 yp gleft, move left
gui, add, button , x+10 yp gright, move right
Gui, +E0x02000000 +E0x00080000 ; WS_EX_COMPOSITED & WS_EX_LAYERED => Double Buffer
gui, +Resize
gui, color, green
gui, Show, w700 h700
x:=y:=0 ; translation position of the moving spot
return
guiclose:
esc::
bmp := ""
OGdip.Shutdown() ; It's probably not necessary, but it's a good manners to delete all objects and shutdown GDI+ properly.
exitapp
return
right:: x += 10, bmp.G.Clear(0xFFFFFF00).DrawImage(sf_background), state:=bmp.G.SaveState(), bmp.G.TransformMove(x, y).SetPen("").SetBrush(YellowBrush).DrawEllipse(200,280,50,50).RestoreState(state), bmp.SetToControl(MainBox)
left:: x -= 10, bmp.G.Clear(0xFFFFFF00).DrawImage(sf_background), state:=bmp.G.SaveState(), bmp.G.TransformMove(x, y).SetPen("").SetBrush(YellowBrush).DrawEllipse(200,280,50,50).RestoreState(state), bmp.SetToControl(MainBox)
up:: y -= 10, bmp.G.Clear(0xFFFFFF00).DrawImage(sf_background), state:=bmp.G.SaveState(), bmp.G.TransformMove(x, y).SetPen("").SetBrush(YellowBrush).DrawEllipse(200,280,50,50).RestoreState(state), bmp.SetToControl(MainBox)
down:: y += 10, bmp.G.Clear(0xFFFFFF00).DrawImage(sf_background), state:=bmp.G.SaveState(), bmp.G.TransformMove(x, y).SetPen("").SetBrush(YellowBrush).DrawEllipse(200,280,50,50).RestoreState(state), bmp.SetToControl(MainBox)