' /////////////////////////////////////////////////////////////////////////////
' Draw entire array on screen in the specified fonts/colors for each character.
' Like PlotTextToScreen but faster because it uses precalculated coordinates
' to find the tile on the tile sheet, and the destination on the screen.
' Receives:
' imgScreen& = handle to screen to draw tile on
' arrImage() = array of image handles pointing to 16x16 tile sheets of 16x16 pixel tiles colored black (256 tiles)
' arrTileSheetMap() = array of TileSheetMapType which holds precalculated positions of tiles on tilesheet
' arrTileMap() = array of TileMapType which holds precalculated positions where tiles go on screen
' tileWidthPx% = width of tiles in pixels
' tileHeightPx% = height of tiles in pixels
' TextInfo = TextInfoType which stores info about the text to plot (# columns, # rows. among other things not used here)
' arrText(80, 80) = 2D array of PlotTextType which stores character code, forecolor, backcolor, bitmap font's tileset image handle; indexed by arrText(column #, index in arrLineOrder)
' arrLineOrder(80) AS INTEGER = array storing the row position of lines of text in arrText (done this way to speed up scrolling text)
Sub PlotTextToScreenFast
(imgScreen&
, arrImage
() AS Long, arrTileSheetMap
() AS TileSheetMapType
, arrTileMap
() AS TileMapType
, tileWidthPx%
, tileHeightPx%
, TextInfo
AS TextInfoType
, arrText
() AS PlotTextType
, arrLineOrder
() AS INTEGER)
TextInfo.numCols
= UBound(arrText
, 1) TextInfo.numRows
= UBound(arrText
, 2)
For dy%
= 1 To TextInfo.numRows
iRowPos% = arrLineOrder(dy%)
For dx%
= 1 To TextInfo.numCols
TileNum% = arrText(dx%, dy%).charCode
TileColor& = arrText(dx%, dy%).foreColor
BackColor& = arrText(dx%, dy%).backColor
IF arrText
(dx%
, dy%
).fontNumber
> 0 AND arrText
(dx%
, dy%
).fontNumber
< 11 THEN 'THIS IS WHERE THE PROGRAM CRASHES:
DrawColorTileFast imgScreen&, arrImage(arrText(dx%, dy%).fontNumber), arrTileSheetMap(), arrTileMap(), tileWidthPx%, tileHeightPx%, TileNum%, TileColor&, BackColor&, dx%, iRowPos%
'THIS IS WHERE THE PROGRAM CRASHES:
DrawColorTileFast imgScreen&, arrImage(1), arrTileSheetMap(), arrTileMap(), tileWidthPx%, tileHeightPx%, TileNum%, TileColor&, BackColor&, dx%, iRowPos%
End Sub ' PlotTextToScreenFast
' /////////////////////////////////////////////////////////////////////////////
' Like DrawColorTile but faster because it uses precalculated coordinates
' to find the tile on the tile sheet, and the destination on the screen.
' Receives:
' imgScreen& = handle to screen to draw tile on
' imgTiles& = handle to 16x16 tile sheet of 16x16 pixel tiles colored black (256 tiles)
' arrTileSheetMap() = array of TileSheetMapType which holds precalculated positions of tiles on tilesheet
' arrTileMap() = array of TileMapType which holds precalculated positions where tiles go on screen
' tileWidthPx% = width of tiles in pixels
' tileHeightPx% = height of tiles in pixels
' TileNum% = ordinal number of tile on tile sheet to draw (0-255)
' TileColor& = color to use for tile
' BackColor& = color to use for background
' dx% = column # to draw tile at (where each column is 16 pixels wide)
' dy% = row # to draw tile at (where each row is 16 pixels high)
' *** QUESTION
' *** IF THE SUB RECEIVES IMAGE HANDLE PARAMETERS imgScreen&, imgTiles&
' *** ARE THESE BY REFERENCE?
' *** IF NOT, DO THESE LOCAL COPIES HAVE TO BE RELEASED WITH _FREEIMAGE ?
Sub DrawColorTileFast
(imgScreen&
, imgTiles&
, arrTileSheetMap
() AS TileSheetMapType
, arrTileMap
() AS TileMapType
, tileWidthPx%
, tileHeightPx%
, TileNum%
, TileColor&
, BackColor&
, dx%
, dy%
)
' IS THERE A BACKGROUND COLOR?
ColorSprite&
= _NewImage(tileWidthPx%
, tileHeightPx%
, 32)
' COPY THE TEMPORARY TILE TO THE SCREEN imgScreen&
_PutImage (arrTileMap
(dx%
, dy%
).xPos
, arrTileMap
(dx%
, dy%
).yPos
), ColorSprite&
, imgScreen&
, (0, 0)-(tileWidthPx%
- 1, tileHeightPx%
- 1) ' portion of source to the top-left corner of the destination page
' CREATE A TEMPORARY TILE TO COLOR
UniversalSprite&
= _NewImage(tileWidthPx%
, tileHeightPx%
, 32)
' COPY THE TILE TO THE TEMPORARY ONE
_PutImage (0, 0), imgTiles&
, UniversalSprite&
, (arrTileSheetMap
(TileNum%
).xStart
, arrTileSheetMap
(TileNum%
).yStart
)-(arrTileSheetMap
(TileNum%
).xEnd
, arrTileSheetMap
(TileNum%
).yEnd
)
' COLOR IN THE TEMPORARY TILE
' REPLACING BLACK (THE SOURCE COLOR) WITH THE TILE COLOR
'THIS IS WHERE THE PROGRAM CRASHES:
ColorSprite& = swapcolor&(UniversalSprite&, cBlack&, TileColor&)
' COPY THE TEMPORARY TILE TO THE SCREEN imgScreen&
_PutImage (arrTileMap
(dx%
, dy%
).xPos
, arrTileMap
(dx%
, dy%
).yPos
), ColorSprite&
, imgScreen&
, (0, 0)-(tileWidthPx%
- 1, tileHeightPx%
- 1) ' portion of source to the top-left corner of the destination page
' ADDED PER FellipeHeitor
' /////////////////////////////////////////////////////////////////////////////
' Image color swap?
' https://www.qb64.org/forum/index.php?topic=2312.0
' Receives:
' handle& = image handle to swap colors in
' oldcolor~& = old color to be replaced
' newcolor~& = new color
' Return value = image handle to copy of image with the new colors
Function swapcolor&
(handle&
, oldcolor~&
, newcolor~&
) 'Dim c As _Unsigned Long
'THIS IS WHERE THE PROGRAM CRASHES:
a& = a& + 4
_MemPut m
, m.OFFSET
+ a&
, newcolor~&