Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; We include Gdip to be able to draw on screen
- #Include Gdip.ahk
- #Include Hunt.ahk
- #Include Props.ahk
- ; ########## START: Basic Setup ##########
- ; START: Basic Variables
- myP := Props()
- myP.Width := 1000 ; height of the drawing screen
- myP.height := 1000 ; widht of the drawing screen
- myP.L := 0 ; radius and width of the larger pie slice
- myP.S := 0 ; radius and width of the smaller pie slice
- myP.T := 1000 / 4096 ; 4.096 tiles per pixel, means that the pixel size per tile is 0.24414
- myP.R := -120 ; The start rotation will always face north, so -120 degrees is when the pie slice faces north
- ; END: Basic Variables
- ; START: GUI Setup for initial props
- requestGui := Gui("+AlwaysOnTop", "InputRequest") ; Setup a new GUI for the variables selection procedure
- requestGui.Add("Text", "w300 h50", "Select distance and direction")
- requestGui ; Setting the dropdown for the size of the pie
- .Add("DropDownList",
- "Choose1 w200 h200 vDistanceBox",
- ["Very far", "Far", "Pretty far", "Rather a long distance", "Quite some distance", "Some distance"])
- requestGui ; Setting the dropdown for the rotation of the pie
- .Add("DropDownList",
- "Choose1 w200 h200 vDirectionBox",
- ["North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West"])
- requestGui.Add("Button", "w200 h50 Center vSubmit", "OK")
- requestGui["Submit"].OnEvent("Click", Submit)
- requestGui.Show()
- ; END: Gui Setup for initial props
- ; ########## END: Basic Setup ##########
- ; TODO: Comment
- ^F1:: {
- huntDisplay := Hunt(myP)
- huntDisplay.Draw()
- }
- ; ########## START: Methods ##########
- ; Event handler for submit button click
- Submit(b, bparam) {
- SetSize(requestGui["DistanceBox"].Value)
- SetDirection(requestGui["DirectionBox"].Value)
- requestGui.Destroy()
- }
- ; Sets the size based on the dropdown value, which in the Props class sets the right sizes
- SetSize(value) {
- switch value {
- case 1:
- myP.SetSize(4096, 2000)
- case 2:
- myP.SetSize(1999, 1000)
- case 3:
- myP.SetSize(999, 500)
- case 4:
- myP.SetSize(499, 200)
- case 5:
- myP.SetSize(199, 50)
- case 6:
- myP.SetSize(49, 20)
- default:
- myP.SetSize(0, 0)
- }
- }
- SetDirection(value) {
- switch value {
- case 1:
- myP.SetDirection(-120)
- return
- case 2:
- myP.SetDirection(-120)
- return
- case 3:
- myP.SetDirection(-30)
- return
- case 4:
- myP.SetDirection(30)
- return
- case 5:
- myP.SetDirection(90)
- return
- case 6:
- myP.SetDirection(120)
- return
- case 7:
- myP.SetDirection(180)
- return
- case 8:
- myP.SetDirection(240)
- return
- default:
- myP.SetDirection(-120)
- return
- }
- }
- ; ########## END: Methods ##########
- ; Props.ahk file
- class Props {
- L := 0
- S := 0
- T := 0
- R := 0
- X := 0
- Y := 0
- Width := 0
- Height := 0
- __New() {
- }
- SetSize(l, s) {
- this.L := this.T * l
- this.S := this.T * s
- }
- SetDirection(r) {
- this.R := r
- }
- }
- ; Hunt.ahk file
- #Include Props.ahk
- class Hunt {
- ; ########## START: Variables ##########
- props := Props ; this is its own class, included at the top
- hWnd := 0
- hbm := Object
- hdc := Object
- obm := Object
- G := Object
- brush := Object
- GuiItem := Gui
- gdip := Object
- ; ########## END: Variables ##########
- __New(props) {
- this.props := props
- this.FindWindow() ; Find the window over which to create the GUI (eg. the Sklotopolis map)
- }
- FindWindow() {
- this.hWnd := WinExist("Sklotopolis")
- if this.hWnd {
- WinActivate "Sklotopolis"
- WinMove -1920, 0
- CoordMode "Pixel", "Window"
- PixelSearch &Ox, &Oy, 0, 31, 1000, 1031, 0xff1493
- this.props.X := Ox
- this.props.Y := Oy
- }
- else {
- retried := MsgBox("The external map does not exist, please open it and try again", "Warning", "RetryCancel")
- if (retried = "Retry")
- this.FindWindow()
- else
- return
- }
- return
- }
- Draw() {
- ; Call the setup method to actually setup the entire Gdip parts
- this.Setup()
- ; Start drawing on the canvas
- Gdip_DrawEllipse(this.G, this.brush, this.props.X, this.props.Y, this.props.L, this.props.L)
- MsgBox "Drawn elipse on the following coordinates: 'x: " this.props.X " y: " this.props.Y "'", "reference"
- Gdip_DrawPie(
- this.G, ; the graphics to draw on
- this.brush, ; the brush to use to draw the pie slice
- this.props.X, ; the x coordinates to start on? So this should be this.props.X? I think?
- this.props.Y, ; the y coordinates to start on? So this should be this.props.Y? I think?
- this.props.L, ; the width of the pie slice (since it's at 60 degrees, it's the same as the height)
- this.props.L, ; the height of the pie slice (since it's at 60 degrees, it's the same as the height)
- this.props.R, ; The angle at which to draw, -120 should be straight up from the point of the slice
- 60 ; the actual angle between the point's prongs. Which is 60 degrees of a circle (or Hexagon angle)
- )
- MsgBox "Drawn pie slice on the following coordinates: 'x: " this.props.X " y: " this.props.Y "'", "reference"
- ; Cleanup the graphics
- this.Cleanup()
- }
- Setup() {
- ; Start gdi+
- if !this.gdip := Gdip_Startup()
- {
- MsgBox "Gdpi plus failed to start. pleas ensure you have GDI+ on your system"
- ExitApp
- }
- ; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
- this.GuiItem := Gui("-Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs")
- this.GuiItem.Show("X" this.props.X " Y" this.props.Y " NA") ; Add this or not? \"X" this.props.X " Y" this.props.Y\
- ; Get a handle to this window we have created in order to update it later
- hWndGraphics := WinExist()
- ; Create a gdi bitmap (I don't know what that is) with width and height of what we are going to draw into it. This is the entire drawing area for everything
- ; aka should be 1000x1000px
- this.hbm := CreateDIBSection(this.props.Width, this.props.Height)
- ; Get a device context compatible with the screen
- this.hdc := CreateCompatibleDC()
- ; Select the bitmap into the device context
- this.obm := SelectObject(this.hdc, this.hbm)
- ; Get a pointer to the graphics of the bitmap, for use with drawing functions
- this.G := Gdip_GraphicsFromHDC(this.hdc)
- ; Set the smoothig mode to antialias = 4 to make shapes appear smoother (only used for vector drawing and filling)
- Gdip_SetSmoothingMode(this.G, 4)
- ; Create a fully opaque red pen (ARGB = transparency, red, green, blue) of width 2 (the thickness the pen will draw at) to draw a pie slice
- this.brush := Gdip_BrushCreateSolid(0xffff0000)
- ; Finish the method
- return
- }
- Cleanup() {
- ; Delete the brush as it is no loger needed and wastes memory
- Gdip_DeletePen(this.brush)
- ; Update the layered window
- UpdateLayeredWindow(
- this.hWnd, ; the window over which to draw
- this.hdc, ; the HDC?? I don't know what that is
- -1912, ; TODO: Make this relative to the x and y coordinates of this.hWnd' client
- 31, ; TODO: Make this relative to the x and y coordinates of this.hWnd' client
- this.props.Width, ; The width of the layered window (should be 1000 px)
- this.props.Height ; The height of the layered window (should be 1000 px)
- )
- ; Select the object back into he hdc
- SelectObject(this.hdc, this.obm)
- ; Now the bitmap may be deleted
- DeleteObject(this.hbm)
- ; Also the device context related to the bitmap may be deleted
- DeleteDC(this.hdc)
- ; The graphics may now be deleted
- Gdip_DeleteGraphics(this.G)
- return
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement