TextArea

Archives Forums/BlitzPlus Bug Reports/TextArea

_PJ_(Posted 2015) [#1]
Whilst trying to narrow down the cause of an issue I have with corruption appearing in FontNames and Fonts used, I believe it may be related to the issues of accessing fonts in Buffers.
The following highlights such issue:


Global TYPEFACE%
Global TYPEFACE_NAME$

Global Window=CreateWindow("Window",0,0,256,128)
Global TextBox=CreateTextArea(0,0,128,32,Window)
Global IMAGE=CreateImage(128,32)

TYPEFACE=LoadFont("Blitz",10)
SetBuffer(ImageBuffer(IMAGE))
SetFont TYPEFACE
LockTextArea TextBox
SetTextAreaFont TextBox,TYPEFACE
TYPEFACE_NAME=FontName(TYPEFACE)
SetTextAreaColor TextBox, 255,0,0
UnlockTextArea TextBox



Floyd(Posted 2015) [#2]
What is that supposed to demonstrate? It doesn't even have a Graphics command yet it attempts to use graphics.

One possible glitch is that SetFont applies to a buffer. So different buffers can have different fonts.

Graphics 600, 400, 0, 2

img1 = CreateImage( 300, 50 )
img2 = CreateImage( 300, 50 )
buff1 = ImageBuffer( img1 )
buff2 = ImageBuffer( img2 )

fontSmall = LoadFont( "Arial", 14 )
fontLarge = LoadFont( "Arial", 40 )

SetBuffer buff1
SetFont fontSmall

SetBuffer buff2
SetFont fontLarge

SetBuffer buff1
Text 10,10, "small"

SetBuffer buff2
Text 10,10, "large"

SetBuffer BackBuffer()
DrawImage img1, 50, 50
DrawImage img2, 50, 200

Flip
WaitKey



_PJ_(Posted 2015) [#3]
Right, accessing fonts across buffers may cause issues and I think this is ultimately what is causing me problems.

Your mention of not having a graphics command, Does the requirement for a graphics command therefore entail that any images loaded, even for use within gadgets or for Canvas etc. should need to have a graphics buffer set and therefore will have a separate window?

Certainly there is no error occurring in the following, but this entails a redundant graphics window to be present...

Graphics 1024,768,32
;SetBuffer(BackBuffer())

Global TYPEFACE%
Global TYPEFACE_NAME$

Global Window=CreateWindow("Window",0,0,256,128)
Global TextBox=CreateTextArea(0,0,128,32,Window)
Global IMAGE=CreateImage(128,32)

TYPEFACE=LoadFont("Blitz",10)
SetBuffer(ImageBuffer(IMAGE))
SetFont TYPEFACE
;SetBuffer(BackBuffer())
LockTextArea TextBox
SetTextAreaFont TextBox,TYPEFACE
TYPEFACE_NAME=FontName(TYPEFACE)
SetTextAreaColor TextBox, 255,0,0
UnlockTextArea TextBox


It wasn't clear to me since none of the GUI documentation ever implies that Graphics commands need be set and there's no example code for many of the functions - so I had assumed that Loading or modiying an image resource might be done without the need for a display window.


Floyd(Posted 2015) [#4]
I never really thought about this, but the G in GUI does seem like Graphics would be required.


Kryzon(Posted 2015) [#5]
BlitzPlus is now open source, so you have the luxury of checking how the functions work internally:
https://github.com/blitz-research/blitzplus/blob/master/blitz2d/b2dimage.cpp#L145

LoadImage asks the graphics driver to create a graphics object, and the driver needs a graphics context to do this (that is, yes, a Graphics call is needed before loading or using images).


_PJ_(Posted 2015) [#6]
Yeah obviously for the 'standard' use of the image functionality, but it just seemed a little unnecessary if working on a GUI Canvas buffer within a window.

Oh well :)