'$INCLUDE:'SaveImage.BI'
'Grid-a-Pic
'GLOBAL VARIABLES
'INITIAL PARAMETERS
wWidth = dWidth - 401 ' Window size
wHeight = dHeight
mWidth
= _WIDTH(mp
) ' Map/pic sizegsiz = 35: hOff = 0: vOff = 0
abyt = 127: rbyt = 127: gbyt = 127: bbyt = 127
Make_Arrow
_TITLE "GridPic (esc to quit, arrows to pan, +/- to resize grid, 'h' for hex grid, 'b' for box grid)"
IF camera.x
< 0 THEN camera.x
= 0 IF camera.y
< 0 THEN camera.y
= 0
Hex_Grid gsiz, hOff, vOff
Box_Grid gsiz, hOff, vOff
'place finished image in screen window
_PUTIMAGE (400, 0), mp
, main&
, (camera.x
, camera.y
)-(camera.x
+ wWidth
, camera.y
+ wHeight
) 'map _PUTIMAGE (400, 0), grid&
, main&
, (camera.x
, camera.y
)-(camera.x
+ wWidth
, camera.y
+ wHeight
) 'grid overlay 'draw red box on mini map with limits of window display
((camera.x
+ wWidth
) * mF
, _HEIGHT(main&
) - 1 - (mF
* _HEIGHT(mp
)) + camera.y
* mF
+ wHeight
* mF
), &HFFFF0000, B
((camera.x
+ wWidth
) * mF
- 1, _HEIGHT(main&
) - 2 - (mF
* _HEIGHT(mp
)) + camera.y
* mF
+ wHeight
* mF
), &HFFFF0000, B
Para_Disp
' END: MAIN MODULE / BEGIN SUBROUTINES
s = siz
ho = 0
ho = ho + 1
vo = 0
LINE (0, vo
* s
+ v
)-(_WIDTH(grid&
) - 1, vo
* s
+ v
) vo = vo + 1
'Create control block
sx = xsiz / 2 - x * 4: sy = ysiz / 2 - 8
FOR p
= 1 TO x
' iterate through label characters IF p
= high
THEN ' print hotkey highlight color (red) else (black)
'superimpose a screen centered input box for various input routines
COLOR tcol
, &HFF000000 ' set text color with black background FOR x
= 0 TO 5 ' draw bounding box 6 pixels thick l
= _WIDTH(T&
) / 2 - (LEN(heading
) * 8) / 2 ' set heading position
DIM s
, sb
, ho
, vo
, ro
, col
, of
s
= siz
/ (2 * SIN(_PI / 3)) ' side length sb = s / 2
ho
= s
+ (s
* COS(_PI / 3)) ' horizontal offset vo
= 2 * (s
* SIN(_PI / 3)) ' vertical offset ro = -1
col = -1
LINE (ro
* ho
- sb
+ h
, col
* vo
+ of
+ v
)-(ro
* ho
+ s
- sb
+ h
, col
* vo
+ of
+ v
) 'hex horizontal LINE (ro
* ho
+ s
- sb
+ h
, col
* vo
+ of
+ v
)-(ro
* ho
+ s
+ ho
- s
- sb
+ h
, col
* vo
+ of
- (vo
/ 2) + v
) 'hex up leg LINE (ro
* ho
+ s
- sb
+ h
, col
* vo
+ of
+ v
)-(ro
* ho
+ s
+ ho
- s
- sb
+ h
, col
* vo
+ of
+ (vo
/ 2) + v
) 'hex down leg col = col + 1
ro = ro + 1
DialogBox "Load Image", 600, 400, 50, &HFF00FF00, &HFFFFFFFF
FUNCTION map!
(value!
, minRange!
, maxRange!
, newMinRange!
, newMaxRange!
)
map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
CASE IS < 400 ' left screen cases Load_Image
Save_Gridpic
CASE 200 TO 239 ' hex button click gtog
= _SETBIT(gtog
, 0) ' change to hex gtog
= _RESETBIT(gtog
, 1) ' make grid inactive ELSE ' otherwise if grid inactive gtog
= _SETBIT(gtog
, 1) ' activate it CASE 250 TO 289 ' box button click gtog
= _RESETBIT(gtog
, 1) ' make grid inactive gtog
= _SETBIT(gtog
, 1) ' activate it CASE IS > 24 ' color, size & offset abyt = map!(xpos, 5, 200, 1, 255)
rbyt = map!(xpos, 5, 200, 1, 255)
gbyt = map!(xpos, 5, 200, 1, 255)
bbyt = map!(xpos, 5, 200, 1, 255)
CASE IS > 200 ' size & offset cross gsiz = gsiz - 1
gsiz = gsiz + 1
IF vOff
> -gsiz
/ 2 THEN vOff
= vOff
- 1 IF hOff
> -gsiz
/ 2 THEN hOff
= hOff
- 1 CASE 286 TO 314 ' offset to (0, 0) hOff = 0: vOff = 0
CASE 315 TO 345 ' offset right IF hOff
< gsiz
/ 2 THEN hOff
= hOff
+ 1 IF vOff
< gsiz
/ 2 THEN vOff
= vOff
+ 1
camera.x = camera.x - (xpos - 400 - wWidth / 2)
camera.y = camera.y - (ypos - wHeight / 2)
'Background blank to mark and mask button use and/or changes
CN&
= _NEWIMAGE(xsiz
, ysiz
, 32) ' active button overlay COLOR , col
' set overlay background color _PUTIMAGE (xpos
, ypos
), CN&
, main&
' cover button
'Display available parameters and controls
Con_Blok 0, 0, 40, 24, "Open", 1, &HFF00FF00
Con_Blok 50, 0, 40, 24, "Save", 1, &HFF0000FF
Con_Blok 100, 0, 40, 24, "Quit", 1, &HFFFF0000
Con_Blok 200, 0, 40, 24, "Hex", 1, &HFFF0F0F0
Con_Blok 250, 0, 40, 24, "Box", 1, &HFFF0F0F0
Panel_Blank 250, 0, 40, 24, &H9F000000
Panel_Blank 200, 0, 40, 24, &H9F000000
Panel_Blank 200, 0, 40, 24, &H9F000000
Panel_Blank 250, 0, 40, 24, &H9F000000
LINE (5, 50)-(200, 60), &HFF7F7F7F, B
LINE (5, 50)-(map!
(abyt
, 1, 255, 5, 200), 60), &HFF7F7F7F, BF
LINE (5, 90)-(200, 100), &HFF7F0000, B
LINE (5, 90)-(map!
(rbyt
, 1, 255, 5, 200), 100), &HFF7F0000, BF
LINE (5, 130)-(200, 140), &HFF007F00, B
LINE (5, 130)-(map!
(gbyt
, 1, 255, 5, 200), 140), &HFF007F00, BF
LINE (5, 170)-(200, 180), &HFF0000FF, B
LINE (5, 170)-(map!
(bbyt
, 1, 255, 5, 200), 180), &HFF0000FF, BF
Con_Blok 225, 46, 32, 24, "-", 1, &HFF00007F
Con_Blok 343, 46, 32, 24, "+", 1, &HFF00007F
LINE (285, 90)-(315, 180), &HFFFFFFFF, B
' offset cross LINE (255, 120)-(345, 150), &HFFFFFFFF, B
CIRCLE (300, 135), 8, &HFFFF0000 LINE (290, 135)-(310, 135), &HFFFF0000 LINE (300, 125)-(300, 145), &HFFFF0000 RotoZoom3
285 + _WIDTH(arw&
) / 2, 90 + _HEIGHT(arw&
) / 2, arw&
, 1, 1, 0 RotoZoom3
255 + _WIDTH(arw&
) / 2, 120 + _HEIGHT(arw&
) / 2, arw&
, 1, 1, _PI * 3 / 2
' Thanks be to Galleon and Bplus for this SUB, wish I was this good...
' This assumes you have set your drawing location with _DEST or default to screen.
' X, Y - is where you want to put the middle of the image
' Image - is the handle assigned to the image to be rotated
' xScale, yScale - are shrinkage < 1 or magnification > 1 on the given axis, 1 just uses image size.
' These are multipliers so .5 will create image .5 size on given axis and 2 for twice image size.
' radianRotation is the Angle in Radian units to rotate the image
' note: Radian units for rotation because it matches angle units of other Basic Trig functions
' and saves a little time converting from degree.
' Use the _D2R() function if you prefer to work in degree units for angles.
DIM W&
, H&
, sinr!
, cosr!
, i&
, x2&
, y2&
' variables for image manipulation px(0) = -W& / 2: py(0) = -H& / 2 ' left top corner
px(1) = -W& / 2: py(1) = H& / 2 ' left bottom corner
px(2) = W& / 2: py(2) = H& / 2 ' right bottom
px(3) = W& / 2: py(3) = -H& / 2 ' right top
sinr!
= SIN(-radianRotation
): cosr!
= COS(-radianRotation
) 'rotation helpers FOR i&
= 0 TO 3 ' calc new point locations with rotation and zoom x2& = xScale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = yScale * (py(i&) * cosr! - px(i&) * sinr!) + Y
px(i&) = x2&: py(i&) = y2&
DialogBox "Save Image", 600, 400, 50, &HFF0000FF, &HFFFFFFFF
r
= SaveImage
(fn1$
, si&
, 0, 0, _WIDTH(si&
) - 1, _HEIGHT(si&
) - 1)
'$INCLUDE:'SaveImage.BM'