Okay SCREEN 0 fans, here we go again. Remember back in the Q-Rasic Period when we needed three rows and three columns per element to make things like spreadsheets? Well now thanks to hardware overlays those dinosaur days are over!
PRESS ANY KEY TO EXPAND GRID.
So I kept this demo as simple as possible jut for illustration purposes. Imagine how cool this stuff could be when you expand it to be used with functions like resizable screens, etc.
Now there is a downside. As in our example here, hardware images are layered over your software screen images. This is important if you want to create a popup effect using another software image. We would want the popup to be 'on top' but the hardware image would still overlay the popup! Now I get around this challenge by coding two _putimage routines. Take our grid example, above. When a popup isn't supposed to be 'over' the hardware lines, it uses the routine in the example above, but when the popup should cover part or all of the grid, the second routine (not shown above) would cut the grid lines up so they would approximate the borders of the popup. This would make it appear the software popup window is over the grid, when the reality is we just poked a hole... or in this case a square, out of the hardware grid so the popup window could fit in it.
Pete
PRESS ANY KEY TO EXPAND GRID.
Code: (Select All)
_Title"Adaptable grid. Any key widens."
t1 = _NewImage(1200, 1, 32) ' We make a horizontal and vertical line and copy them to the hardware memory.
_Dest t1
Line (0, 0)-(1200, 0), _RGB32(0, 255, 0), B
Hline& = _CopyImage(t1, 33) ' Horizontal line. Mote: 33 is always the hardware memory number.
_Dest 0
_FreeImage t1
t1 = _NewImage(1, 800, 32)
_Dest t1
Line (0, 0)-(0, 800), _RGB32(0, 255, 0), B
Vline& = _CopyImage(t1, 33) ' Vertical line.
_Dest 0
_FreeImage t1
_KeyClear ' We're using a simple inkey loop, so we clear the keyboard buffer before it begins.
NumberOfCol = 1 ' This will let us start with 2-columns in the loop, instead of just one.
indent = 5 ' This will make us a nice 5 character-length left and right border, and also centers the grid.
Do
NumberOfCol = NumberOfCol + 1
fw = _FontWidth: fh = _FontHeight
i = 0: k = 0: noe = 0: Restore
Do
Read a$
If a$ = "eof" Then Exit Do
If Len(a$) + 3 > k Then k = Len(a$) + 3
noe = noe + 1
Loop
ElementsPerColumn = noe \ NumberOfCol
If noe Mod NumberOfCol Then ElementsPerColumn = ElementsPerColumn + 1
top = 2
WidthNeeded = k * NumberOfCol + 1: h = top + ElementsPerColumn + 1
Width WidthNeeded + indent * 2, h: _Font 16
Restore
For col = 1 To NumberOfCol
Locate 1: x = (col - 1) * k + 3
For j = 0 To ElementsPerColumn - 1
Locate top + j, x + indent
Read a$: If a$ = "eof" Then Exit For
Print a$;
Next
Next
Do
_Limit 30
sx1 = 0: sy1 = 0: sy2 = 0 ' sx and sy tell us which part of the line to use. These coordinates tell the routine to use the part of our horizontal line from its top-left start (sx1) and keep its height 0 (1-pixel) with the line top height (sy1) - line bottom height (sy2).
dx1 = fw / 2 + indent * fw ' dx and dy tell the routine where to place the line segment on our screen. Note that fw (font width) and fh (font height) are needed to convert graphics pixels to text columns and rows. fw / 2 is needed to center our line in the text column and indent will center the grid to the screen.
dy1 = (top - 1) * fh ' Start the grid at the (top) row. Again, the -1 is needed because columns and rows start at one, but pixels start at zero.
sx2 = (WidthNeeded - 1) * fw '
For i = 0 To ElementsPerColumn
_PutImage (dx1, dy1 + i * fh), Hline&, , (sx1, sy1)-(sx2, sy2)
Next
sx1 = 0: sx2 = 0: sy1 = 0
sy2 = ElementsPerColumn * fh ' Our vertical line segment length. We don't subtract one (-1) here because we want the line to stretch to the bottom of the grid.
For i = 0 To NumberOfCol ' Again, we don't subtract one (-1) so we can make the final vertical line at the right side of our grid.
_PutImage (dx1 + (i * k + 0) * fw, dy1), Vline&, , (sx1, sy1)-(sx2, sy2)
Next
_Display
Loop Until Len(InKey$)
noe = 0
Loop
Data Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida
Data Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine
Data Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska
Data Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota
Data Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee
Data Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming,eof
So I kept this demo as simple as possible jut for illustration purposes. Imagine how cool this stuff could be when you expand it to be used with functions like resizable screens, etc.
Now there is a downside. As in our example here, hardware images are layered over your software screen images. This is important if you want to create a popup effect using another software image. We would want the popup to be 'on top' but the hardware image would still overlay the popup! Now I get around this challenge by coding two _putimage routines. Take our grid example, above. When a popup isn't supposed to be 'over' the hardware lines, it uses the routine in the example above, but when the popup should cover part or all of the grid, the second routine (not shown above) would cut the grid lines up so they would approximate the borders of the popup. This would make it appear the software popup window is over the grid, when the reality is we just poked a hole... or in this case a square, out of the hardware grid so the popup window could fit in it.
Pete

