Simple GUI

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Simple GUI

Post by Imortis »

Coolman wrote: Mar 04, 2022 19:50 ...
I found a very good documentation about freebasic here :

https://documentation.help/FreeBASIC/

...
That page is very out of date. The official documentation, which that was pulled from, can be found here:
https://www.freebasic.net/wiki/DocToc
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: Simple GUI

Post by Coolman »

thank you. it's true that it's better.

I found this code, does anyone know how to enlarge the display font?

Code: Select all

'' Define character range
Const FIRSTCHAR = 32, LASTCHAR = 127

Const NUMCHARS = (LASTCHAR - FIRSTCHAR) + 1
Dim As UByte Ptr p, myFont
Dim As Integer i

'' Open a 256 color graphics screen (320*200)
ScreenRes 320, 200, 8

'' Create custom font into PUT buffer

myFont = ImageCreate(NUMCHARS * 8, 9)

 '' Put font header at start of pixel data

#ifndef ImageInfo '' older versions of FB don't have the ImageInfo feature
p = myFont + IIf(myFont[0] = 7, 32, 4)
#else
ImageInfo( myFont, , , , , p )
#endif

p[0] = 0
p[1] = FIRSTCHAR
p[2] = LASTCHAR

 '' PUT each character into the font and update width information
For i = FIRSTCHAR To LASTCHAR
   
    '' Here we could define a custom width for each letter, but for simplicity we use
    '' a fixed width of 8 since we are reusing the default font glyphs
    p[3 + i - FIRSTCHAR] = 8
   
    '' Create character onto custom font buffer by drawing using default font
    Draw String myFont, ((i - FIRSTCHAR) * 8, 1), Chr(i), 32 + (i Mod 24) + 24
   
Next i

'' Now the font buffer is ready; we could save it using BSAVE for later use
Rem BSave "myfont.bmp", myFont

'' Here we draw a string using the custom font
Draw String (10, 10), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", , myFont
Draw String (10, 26), "abcdefghijklmnopqrstuvwxyz", , myFont
Draw String (66, 58), "Hello world!", , myFont

'' Free the font from memory, now we are done with it
ImageDestroy myFont

Sleep

Lothar Schirm
Posts: 436
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Simple GUI

Post by Lothar Schirm »

VANYA wrote: Mar 04, 2022 19:37 Hi Lothar Schirm!

And there is no desire to implement the xFont library in your library? This would help with the font size and make it possible to use not only 127 ASCII characters, but also Unicode. In any case, I like what you do.
I do not want to invest further work in this GUI. I just need some simple controls for graphics applications as a hobby programmer. There would be also other desirable features like file open/save dialog, pulldown menu, multiline textbox ... For such things I use the Windows API instead of writing further thousand lines of code. More advanced GUIs in pure FreeBASIC are Muttonhead's sGUI or FB_GUI by BasicScience https://freebasic.net/forum/viewtopic.php?t=12592. I did not yet test them, but I believe FB_GUI uses xFont.
Post Reply