'$INCLUDE:'SaveImage.BI'
'Grid-a-Pic version 0.2
'Thanks go to: Steve McNeill for SaveImage
' Galleon/Bplus for Rotozoom3
'GLOBAL VARIABLES
' bit 0 = Hex(1) Box(0)
' bit 1 = 1 on 0 off
'INITIAL PARAMETERS
wWidth = dWidth - 401 ' Window size
wHeight = dHeight
mWidth
= _WIDTH(mp
) ' Map/pic sizegsiz = 35: hOff = 0: vOff = 0 ' grid size 35 pixels, no offsets
abyt = 127: rbyt = 127: gbyt = 127: bbyt = 127
main&
= _NEWIMAGE(dWidth
, dHeight
, 32) ' Complete display screengrid&
= _NEWIMAGE(mWidth
, mHeight
, 32) ' grid handlearw&
= _NEWIMAGE(30, 30, 32) ' grid positioning arrowMake_Arrow
_TITLE "GridPic (esc to quit, arrows to pan, +/- to resize grid, 'h' for hex grid, 'b' for box grid)"
'Main program loop
in = -1 ' short around the input loop on startup
gtog
= _RESETBIT(gtog
, 0) ' then make it a box ELSE ' if it's already a box : in = -1
gtog
= _SETBIT(gtog
, 0) ' then make it a hex ELSE ' if it's already a hex ELSE ' if the grid is off gtog
= _SETBIT(gtog
, 0) ' set for hex and, : in = -1
IF _KEYDOWN(45) THEN gsiz
= gsiz
- 1 - (gsiz
= 6): in
= -1 'decrease grid size, limit to 6 or more IF _KEYDOWN(18432) THEN camera.y
= camera.y
- 10 - ((camera.y
= 0) * 10): in
= -1 IF _KEYDOWN(19200) THEN camera.x
= camera.x
- 10 - ((camera.x
= 0) * 10): in
= -1 IF _KEYDOWN(19712) THEN camera.x
= camera.x
+ 10 + ((camera.x
> (_WIDTH(mp
) - wWidth
)) * 10): in
= -1
in = -1
in = 0
'Create grid overlay
Hex_Grid gsiz, hOff, vOff
Box_Grid gsiz, hOff, vOff
'place finished images in screen window
_PUTIMAGE , grid&
, mpt&
' overlay grid onto temp map _PUTIMAGE (400, 0), mpt&
, main&
, (camera.x
, camera.y
)-(camera.x
+ wWidth
, camera.y
+ wHeight
) 'temp map to main display Image_Resize
0, 200, 399, _HEIGHT(main&
) - 1, mp
, main&
, "l", "u" 'Place nav map in navmap window navrat = navrat / b
LINE (camera.x
* navrat
, 200 + camera.y
* navrat
)-((camera.x
+ wWidth
) * navrat
, 200 + (camera.y
+ wHeight
) * navrat
), &HFFFF0000, B
LINE (camera.x
* navrat
+ 1, 201 + camera.y
* navrat
)-((camera.x
+ wWidth
) * navrat
- 1, 199 + (camera.y
+ wHeight
) * navrat
), &HFFFF0000, B
Para_Disp
'End main program loop
' 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
cr&
= _DEST ' save calling destination dbox&
= _NEWIMAGE(xsiz
, ysiz
, 32) ' define box COLOR tcol
, &HFF000000 ' set text color with black background FOR x%
= 0 TO 5 ' draw bounding box 6 pixels thick b~& = -Black * (x% < 2) - bcol * (x% >= 2) ' color=outer two black, balance bcol
LINE (0 + x%
, 0 + x%
)-(xsiz
- 1 - x%
, ysiz
- 1 - x%
), b~&
, B
'draw color border _DEST cr&
' reset to calling destination
'siz= size in pixels across hex flats
'h= horizontal bias
'v= vertical bias
DIM s
, sb
, ho
, vo
, vo2
, ro
, col
, of
, roho
, colvo
s
= siz
/ (2 * SIN(_PI / 3)) ' side length sb = s / 2 ' slope apex horzontal distance
ho = s + sb ' horizontal offset
vo = siz ' vertical offset
vo2 = vo / 2 ' 1/2 vertical offset
ro = -1 ' starting row position
col = -1 ' starting column position
roho = ro * ho + h ' row position x horizontal offset + horizontal bias
of
= -(vo2
) * (ro
MOD 2 = 0) ' even/odd bias, branchless for: IF ro MOD 2 = 0 THEN of = vo2 ELSE of = 0 colvo = col * vo + v + of ' column position x vertical offset + vertical bias + even/odd row bias
LINE (roho
- sb
, colvo
)-(roho
+ sb
, colvo
) ' hex horizontal LINE (roho
+ sb
, colvo
)-(roho
+ s
, colvo
- vo2
) ' hex up leg LINE (roho
+ sb
, colvo
)-(roho
+ s
, colvo
+ vo2
) ' hex down leg col = col + 1 ' advance column
ro = ro + 1 ' advance row
'²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²
xrt
= (xlim
- xpos
) / _WIDTH(i
) ' width of area divided by width of image yrt
= (ylim
- ypos
) / _HEIGHT(i
) ' height of area divided by height of image rt = -xrt * (xrt < yrt) - yrt * (yrt <= xrt) ' pick the smaller of the two ratios to fit area
navrat = rt ' for global use-can be removed in other programs that don't need it
xs
= _WIDTH(i
) * rt
' final image size ratio in x ys
= _HEIGHT(i
) * rt
' final image size ratio in y
xp
= -xpos
* (xj
= "l") - (_SHR(xlim
- xpos
, 1) + xpos
- _SHR(xs
, 1)) * (xj
= "c") - (xlim
- xs
) * (xj
= "r") xl = xp + xs
yp
= -ypos
* (yj
= "u") - (_SHR(ylim
- ypos
, 1) + ypos
- _SHR(ys
, 1)) * (yj
= "c") - (ylim
- ys
) * (yj
= "d") yl = yp + ys
DialogBox "Load Image", 600, 400, 50, &HFF00FF00, &HFFFFFFFF
camera.x = 0: camera.y = 0
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 24 TO 199 ' 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
'move the camera box in the navmap
'LINE (camera.x * navrat, 200 + camera.y * navrat)-((camera.x + wWidth) * navrat, 200 + (camera.y + wHeight) * navrat), &HFFFF0000, B
'LINE (camera.x * navrat + 1, 201 + camera.y * navrat)-((camera.x + wWidth) * navrat - 1, 199 + (camera.y + wHeight) * navrat), &HFFFF0000, B
''This works at the upper left corner
camera.x = xpos / navrat
camera.y = (ypos - 200) / navrat
''Trying to get it centered
'camera.x = (xpos - ((wWidth / 2) / navrat)) / navrat ' - wWidth * navrat
'camera.y = (ypos - 200) / navrat
'camera.x = map!(xpos, 0, 400, 0, _WIDTH(mp) - 1)
'camera.y = map!(ypos,200,_height(main&)-1,0, )
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'