Code: Select all
; Coords within the window for the bottom left of the board (0,0).
global SG_ORIGIN_X=290
global SG_ORIGIN_Y=769
; Offset to measure within the square.
global SG_OFFSET_X=43 ; from the left
global SG_OFFSET_Y=72 ; from the top
; Scans Grid into array for evaluation later
scanGrid(newBoard, gemColorsHex, gemColorsRGB)
{
startTime := A_TickCount
updateStatusBox("Scanning grid...")
; Loop X then Y: get a full column from the bottom then move to the next
Loop, 8
{
x := A_Index
px := xCoordToPixel(A_Index)
Loop, 8
{
y := A_Index
py := yCoordToPixel(A_Index)
PixelGetColor, sg_color, %px%, %py%, RGB ; gets pixel color as an RGB Hex number
gemColorsHex[x, y] := sg_color
}
}
updateStatusBox("Grid scan took " (A_TickCount - startTime))
}
yCoordToPixel(y)
{
return Round( SG_ORIGIN_Y - (y-1) * SG_SIZE_Y - SG_OFFSET_Y )
}
; Convert a board square x coord to a screen x coord.
xCoordToPixel(x)
{
return Round ((x-1) * SG_SIZE_X + SG_ORIGIN_X + SG_OFFSET_X )
}
updateStatusBox(newStatus)
{
Gui, GoW_Helper: Default
GuiControlGet, contents,, StatusText
GuiControl,, StatusText, % newStatus "`n" contents
}