Changing the FONT in Drawtext

Started by Baggey, December 11, 2021, 21:38:15

Previous topic - Next topic

Midimaster

#15
The data are gobal! Only the name looks a little bit "complicate"

instead of a simple "glyph" you have to write...
Global MyFont:TImagefont=CreateMyDefault()
...
DrawImage MyFont._glyph[n]._image, 100,100
.....

...if you want to access the images.

But even that is not necessary. Because if you get established your own font you simple write only one time a SetImageFont()-command to use the font all the time afterwards with regular DrawText() commands.

Global MyFont:TImagefont=CreateMyDefault()
SetImageFont MyFont
....
'and in the main loop:
Repeat
  DrawText "Y", 100,100
....


thats all


Your code

It is not neccessary to call CreateMyDefault() again and again:
   While Not AppTerminate() And Not KeyHit(KEY_ESCAPE)
     
      Cls
     '*********** WRONG *************
     createdefault()
...
      Repeat Until KeyHit(key_space)
     
    Wend



move this outside the Main loop:
    createdefault()
   While Not AppTerminate() And Not KeyHit(KEY_ESCAPE)     
      Cls
       DrawPixmap pixmap,0,0
     
      ...
    Wend

...back from North Pole.

Baggey

#16
So, Ive started to put together a "Character Designer" for the Drawtext() Command. This will lead to altering the Original "Blitzfont.bin" Which i can then Customize the Font in BlitzmaxNG

*** UPDATE Ver_1.04 *** Ive added the Function CreateDefaultGlyph:TImageFont()  passing back to setimagefont but have access violation?

I think its todo with this Function CreateDefaultGlphys:TImageFont() and this line font._glyphs[n]._image=TImage(GlyphImage[n])

'
    Function CreateDefaultGlphys:TImageFont()
       '
       For Local n:Int=0 Until 96
          Local glyph:TImageGlyph=New TImageGlyph
          font._glyphs[n]=glyph
          glyph._advance=8
          glyph._w=8
          glyph._h=16
          font._glyphs[n]._image=TImage(GlyphImage[n])
       Next
       '
       Return font
       '
    End Function
    '


Version 1.03  Ive added or rather created an old fashioned style text KEY input FUNCTION with Blinking cursor. Need to save value when entered and alter Glyph!

Version 1.02   Added, Button Checking all though im sort off using a console Window. Mouse Coords to help with this. Large Character for visual change! Key Input still to do?
                   Ive added a Flashing Cursor Function. Its more of a pulsing color effect rather than just a flash. All these little features will come in usefull for My C64 Emulator. Text     
                   input is something to work on?

Im using this to learn BlitzmaxNG I will be using the Functions created here to add USER Input to the ZX Spectrum and C64 Emulator's.

This is Runnable code in BlitzmaxNG

Code (blitzmax) Select

'
    SuperStrict
    '
    ' Version_1.04
    '
    AppTitle = "Drawtext() Character Designer"
    '   
    Graphics 800,600
    '
    Global FontPixMap1:TPixmap=TPixmap.Create(96*8,16,PF_RGBA8888)
    Global FontPixmap2:TPixmap=TPixmap.Create(96*8,16,PF_RGBA8888)
    Global font:TImageFont=New TImageFont
    Global GlyphImage:TImage[96]
    Global Character:Byte=57
    Global Time:Int=MilliSecs() , Flash:Byte=0 , BlinkRate:Int=700
    '
    Global GetText:Getkey = New Getkey
    '
    Global xpos:Int=0, ypos:Int=0
    '
    Global LastEvent:Int=0 , Event:Int=0
    Global DebugMsg:String="Nothing to say!"
    Global Quot:String=Chr 34
    Global _String:String=""
    Global Char:Int=0
    '
    CreateGlyphPixmap()
    Create96GlyphImages()
    '
    While Not AppTerminate() And Not KeyHit(KEY_ESCAPE)
       ' 
       Cls
       '
       DrawPixmap FontPixMap1,0,14
       SetColor 0,0,255
       DrawPixmap FontPixMap2,0,28
       '
       FlashGlyph()
       '
       Checkeys()
       DrawMousePosition()
       '
       SetColor 220,0,0
       DrawText("CHARACTER "+Character+"   ASCII "+(Character+32),8,56)
       '
       SetColor 255,255,255
       DrawGlyph(Character)
       ' Character , x,y Coords , ScaleX , ScaleY
       DrawBigGlyph(Character,8,132,8,8)
       Check_String()
       '
       'Print ~0 ' What is this?
       '
       '
       ' CODE HERE READY TO TURN INTO FUNCTION
       '
       
       '
       '
       'Print Event
       If MouseHit(1) And Event=0 Then
            xpos:Int=MouseX() ; ypos:Int=MouseY()
            CheckButtons()
         Else If Event<>0 Then
            CheckButtons()
       End If   
       '       
       'SetColor 255,100,200 ' Pink
       DrawTextStdFONT()
       SetColor 255,100,200  ' Magenta
       DrawText ("Debug Messaging ... "+DebugMsg,8,580)
       Flip(0)
       '
    Wend
    '
    '
    Function DrawTextStdFONT()
       '
       SetColor 50,255,255 ' Cyan
       DrawText("!"+Quot+"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVYXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}"+Chr(32+94)+Chr(32+95),14,520)
       SetColor 255,255,255
       '
    End Function
    '
    '
    Function Check_String()
           '
           If _String<>"" Then
               '
               Local Value:Int= _String.ToInt
               If Value<0 Or Value>255 Then ' Check to see if we have valid Byte
                   DebugMsg = "Invalid INPUT!" ; Return
               End If
               DebugMsg = "LastEvent="+LastEvent+"   "+_String
               '
               AlterGlyphImage(Character,LastEvent,Value)
               Event=0 ; _String=""
               '
           End If
           '
       End Function
    '
    '
    Function AlterGlyphImage(Character:Int, Row:Int, Value:Int)
        '
        ' We must deccrease Row by one This is todo with Event
        Row:-1
        '
        If Row>15 Return 'img
            Local pix:TPixmap=LockImage(GlyphImage[Character])
            Local bit:Int=128
                    For Local i:Int=0 To 7
                            If value & bit
                                 pix.WritePixel i,Row,$FFFFFFFF
                            Else
                                 pix.WritePixel i,Row,0
                            EndIf
                            bit = bit Shr 1
                    Next
            UnlockImage GlyphImage[Character]
        '
        ' Set Altered FONT
        SetImageFont CreateDefaultGlphys()
        '
    End Function
    '
    '
    Function CheckButtons()
        '
        'Local xpos:Int=MouseX(), ypos:Int=MouseY()
                '
                If (xpos>=176) And (xpos<=199) Then
                  '
                  Select True
                     '
                     Case (ypos>=82) And (ypos<=89) ' And (xpos>=176) And (xpos<=199)
                             '
                             DebugMsg = "first row"
                             GetText.TextInputEnabled=True ; Event=1
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,80,"",0,3)         
                             '
                     Case (ypos>=95) And (ypos<=102)
                             '
                             DebugMsg = "Second row"
                             GetText.TextInputEnabled=True ; Event=2
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,94,"",0,3)
                             '
                     Case (ypos>=110) And (ypos<=118)
                             '
                             DebugMsg = "Third row"
                             GetText.TextInputEnabled=True ; Event=3
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,108,"",0,3)
                             '
                     Case (ypos>=124) And (ypos<=134)
                             '
                             DebugMsg = "Fourth row"
                             GetText.TextInputEnabled=True ; Event=4
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,122,"",0,3)
                             '
                     Case (ypos>=137) And (ypos<=145)
                            '
                             DebugMsg = "Fifth row"
                             GetText.TextInputEnabled=True ; Event=5
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,136,"",0,3)
                             '
                     Case (ypos>=151) And (ypos<=159)
                             '
                             DebugMsg = "Sixth row"
                             GetText.TextInputEnabled=True ; Event=6
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             GetText.Input_(204,150,"",0,3)
                             '
                     Case (ypos>=167) And (ypos<=175)
                             '
                             DebugMsg = "Seventh row"
                             GetText.TextInputEnabled=True ; Event=7
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,164,"",0,3)
                             '
                     Case (ypos>=180) And (ypos<=188)
                             '
                             DebugMsg = "Eighth row"
                             GetText.TextInputEnabled=True ; Event=8
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,178,"",0,3)
                             '
                     Case (ypos>=193) And (ypos<=201)
                            '
                            DebugMsg = "Nineth row"
                            GetText.TextInputEnabled=True ; Event=9
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,192,"",0,3)
                            '
                     Case (ypos>=208) And (ypos<=216)
                            '
                            DebugMsg = "Tenth row"
                            GetText.TextInputEnabled=True ; Event=10
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,206,"",0,3)
                            '
                     Case (ypos>=222) And (ypos<=230)
                            '
                            DebugMsg = "Eleventh row"
                            GetText.TextInputEnabled=True ; Event=11
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,220,"",0,3)
                            '
                     Case (ypos>=235) And (ypos<=243)
                            '
                            DebugMsg = "Twelveth row"
                            GetText.TextInputEnabled=True ; Event=12
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            GetText.Input_(204,234,"",0,3)
                            '
                     Case (ypos>=250) And (ypos<=258)
                            '
                            DebugMsg = "Thirteenth row"
                            GetText.TextInputEnabled=True ; Event=13
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,248,"",0,3)
                            '
                     Case (ypos>=263) And (ypos<=271)
                            '
                            DebugMsg = "Fourteenth row"
                            GetText.TextInputEnabled=True ; Event=14
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,262,"",0,3)
                            '
                     Case (ypos>=277) And (ypos<=285)
                            '
                            DebugMsg = "Fifteenth row"
                            GetText.TextInputEnabled=True ; Event=15
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,276,"",0,3)
                            '
                     Case (ypos>=292) And (ypos<=300)
                            '
                            DebugMsg = "Sixteenth row"
                            GetText.TextInputEnabled=True ; Event=16
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,290,"",0,3)
                            '
                     '
                     Default  DebugMsg="Nothing To say!"
                     '
                  End Select
                  '
                  Else
                       DebugMsg="Nothing To say!"
               End If 
               '
    End Function
    '
    '
    Function DrawMousePosition()
       '
       DrawText("USE X,Y Feedback to SETMOUSE Position  X="+MouseX()+"  Y="+MouseY(),8,318)
       '
    End Function
    '
    '
    Function DrawBigGlyph(character:Int,PosX:Int,PosY:Int,scaleX:Int,scaleY:Int)
    '
        SetColor 200,50,255
        SetScale(scaleX,scaleY) ; DrawText(Chr(Character+32),PosX,PosY) ;  SetScale(1,1)
    '
    End Function
    '
    '
    Function FlashGlyph()
    '
       ' Time is a difficult thing!
       '
       If MilliSecs()>(Time+BlinkRate) Then
            Flash = 1
            Time = MilliSecs()
         Else If (MilliSecs()>(Time+(BlinkRate/4))) And (MilliSecs()<(Time+(BlinkRate/2))) Then
            Flash = 2
         Else If (MilliSecs()>(Time+(BlinkRate/2))) And (MilliSecs()<(Time + BlinkRate)) Then
            Flash = 3
       End If
       '
       Select Flash
              Case 1 ; SetColor 150,0,0
              Case 2 ; SetColor 190,0,0
              Case 3 ; SetColor 255,0,0
       End Select
       '
       DrawImage GlyphImage[Character],(8*Character),42
       '
    End Function
    '
    '
    Function Checkeys()
       '
       If Not Getkey.TextInputEnabled Then
           '
           Local keyed:Int=GetChar()
           'Print keyed
           If Keyed=(46) And (Character<=95) Then Character:+1 ' Hmm? period is a fullstop!?
           If (Character=96) Then Character=0
           If Keyed=(44) And (Character>=0) Then Character:-1
           If (Character=(255)) Then Character=95
           FlushKeys()
           '
       End If
       '
    End Function
    '
    '
    Function CreateDefaultGlphys:TImageFont()
       '
       For Local n:Int=0 Until 96
          Local glyph:TImageGlyph=New TImageGlyph
          font._glyphs[n]=glyph
          glyph._advance=8
          glyph._w=8
          glyph._h=16
          font._glyphs[n]._image=TImage(GlyphImage[n])
       Next
       '
       Return font
       '
    End Function
    '
    '
    Function Create96GlyphImages()
       '
       For Local n:Byte=0 Until 96
          '
          ' .Window is like a [Viewport 8*16]
          GlyphImage[n]=TImage.Load(FontPixMap1.Window(n*8,0,8,16).Copy(),0,0,0,0)
          '
       Next
       '
    End Function
    '
    '
    Function DrawGlyph(Character:Byte)
       '
       Local p:Byte Ptr=IncbinPtr( "blitzfont.bin" )
       '
       For Local y:Byte=0 Until 16
         '
         Local bits:Byte=swapBits(p[Character])
         '
         DrawText(RSet(Bin(bits),8).Replace("0",".").Replace("1","#")+" = "+(RSet(bits, 3).Replace(" ", "0")),88,(y+6)*14-4)
         '
         p:+96
         '
        Next
        '
    End Function
    '
    '
    Function CreateGlyphPixmap()
       '
       Local p:Byte Ptr=IncbinPtr( "blitzfont.bin" )
       '
       For Local y:Byte=0 Until 16
          '
          For Local x:Byte=0 Until 96
             '
             Local b:Byte=p[x], b2:Byte=p[x]     
             Local bits:Byte=swapBits(p[x])
             '
                If X=57 Then ' This is the "Y" Character
                    '
                    Select True
                       '
                       Case (y=2)  ; b2=102 ' Row of Character byte 0 to 15
                       Case (y=3)  ; b2=102
                       Case (y=4)  ; b2=102
                       Case (y=5)  ; b2=102
                       Case (Y=6)  ; b2=36
                       Case (Y=7)  ; b2=24
                       Case (Y=8)  ; b2=24
                       Case (Y=9)  ; b2=24
                       Case (Y=10) ; b2=24
                       '
                    End Select
                    '
                 End If
             '
             DrawText(Right(Bin(bits),8)+" = "+(RSet(bits, 3).Replace(" ", "0")),20,(y+5)*14)
             'Print "P is "+p+" ... "+Right(Bin(b),8)+"  "+b
             For Local n:Byte=0 Until 8
               '
               If b & (1 Shl n)
                      FontPixMap1.WritePixel x*8+n,y,(-1)
                  Else
                      FontPixMap1.WritePixel x*8+n,y,0
               EndIf
               '
               If b2 & (1 Shl n)
                      FontPixMap2.WritePixel x*8+n,y,(-1)
                  Else
                      FontPixMap2.WritePixel x*8+n,y,0
               EndIf
               '
             Next
             '
          Next
          '
          p:+96
          '
     Next
     '
    End Function
    '
    '
    Function SwapBits:Byte(ByteIn:Byte)
       '
       Local LeftBit:Byte=7, RightBit:Byte=0
       '
       For Local loop:Byte=1 To 4
           '
           Select loop
           '
               Case 1 ' Swap Bits 7 And 0
                      LeftBit=(ByteIn & 128) <> 0
                      RightBit=(ByteIn & 1) <> 0
                      '
                      ' Now Exchange Bit's
                      If RightBit=1 Then ByteIn=(ByteIn|128) Else ByteIn=(ByteIn&127)
                      If LeftBit=1 Then ByteIn=(ByteIn | 1) Else ByteIn=(ByteIn & 254)
                      '
               Case 2 ' Swap Bits 6 And 1
                      LeftBit=(ByteIn & 64) <> 0
                      RightBit=(ByteIn & 2) <> 0
                      '
                      ' Now Exchange Bit's
                      If RightBit=1 Then ByteIn=(ByteIn | 64) Else ByteIn=(ByteIn & 191)
                      If LeftBit=1 Then ByteIn=(ByteIn | 2) Else ByteIn=(ByteIn & 253)
                      ' 
               Case 3 ' Swap Bits 5 And 2
                      LeftBit=(ByteIn & 32) <> 0
                      RightBit=(ByteIn & 4) <> 0
                      '
                      ' Now Exchange Bit's
                      If RightBit=1 Then ByteIn=(ByteIn | 32) Else ByteIn=(ByteIn & 223)
                      If LeftBit=1 Then ByteIn=(ByteIn | 4) Else ByteIn=(ByteIn & 251)
                      '
               Case 4 ' Swap Bits 4 And 3
                      LeftBit=(ByteIn & 16) <> 0
                      RightBit=(ByteIn & 8) <> 0
                      '
                      ' Now Exchange Bit's
                      If RightBit=1 Then ByteIn=(ByteIn | 16) Else ByteIn=(ByteIn & 239)
                      If LeftBit=1 Then ByteIn=(ByteIn | 8) Else ByteIn=(ByteIn & 247)
                      '
            End Select
            '
        Next
        '
        Return ByteIn
        '
    End Function
    '
    '
    Type GetKey
        '
        Global TextInputEnabled:Int = False
        Field TextInput:String, NewText:String
        Field CursorBlink:Int = False
        Field Height:Int, Width:Int, X:Int, Y:Int, MaxNumberOFcharacters:Int, LocalTime:Int = MilliSecs()
        Field CursorText:String
        '   
        Method Input_:String(X:Int, Y:Int, InpuText:String, NumberORtext:Int, MAXcharacters:Int)
            '
            GetText.X=X
            GetText.Y=Y
            GetText.TextInput=TextInput
            GetText.Width=TextWidth(TextInput+InpuText)
            GetText.Height=TextHeight(TextInput)
            GetText.CursorText=InpuText
            GetText.MaxNumberOFcharacters=MAXcharacters
            '
            If NumberORtext=0 Then
                  DebugMsg="Number INPUT ONLY!"
                  Return NUM_()
              Else
                  DebugMsg="Text INPUT ONLY!"
                  Return TEXT_() ' Always TRAPS to TEXT() INPUT! If NumberORtext <> "0"
            End If
            '
        End Method
        '
        '
        Method NUM_:String()
            '
            If TextInputEnabled Then
                'FlushKeys()
                Local Char:Int = GetChar()
                '
                If (Char>=48) And (Char<=57) Or (Char=8 Or Char=13) Then
                    '
                    DebugMsg="Char = "+Char
                    '
                    Select Char
                        '
                        Case 8  ' KEY_BACKSPACE
                                TextInput = Left(TextInput, Len(TextInput) - 1)
                        Case 13 ' KEY_ENTER
                                NewText=TextInput
                                TextInput=""
                                LastEvent=Event ; Event=0
                                TextInputEnabled=0
                                Return NewText
                        Default
                                If Not KeyDown(KEY_SPACE) Then
                                    If (Len(TextInput)<MaxNumberOFcharacters) Then TextInput:+ Chr(Char)
                                End If
                    End Select
                    '
                    Width = TextWidth(TextInput+CursorText)
                    CursorBlink = True
                    LocalTime = MilliSecs()
                    '
                End If
                '
                If MilliSecs()>Localtime+400 Then
                      CursorBlink = Not CursorBlink
                      LocalTime = MilliSecs()
                End If
                '
                If CursorBlink Then
                      SetColor 50,255,255
                      DrawLine ((X+Width+1),(Y+1),(X+Width+1),(Y+Height-3))
                      SetColor 255,255,255
                End If
                '
             End If
             '
             SetColor 255,255,255
             DrawText (CursorText+TextInput,X,Y)
             '
        End Method
        '
        '
        Method TEXT_:String()
            '
            If TextInputEnabled Then
                'FlushKeys()
                Char = GetChar()
                '
                If Char > 0 Then
                    '
                    DebugMsg="Char = "+Char
                    '
                    Select Char
                        '
                        Case 8  ' KEY_BACKSPACE
                                TextInput = Left(TextInput, Len(TextInput) - 1)
                        Case 9  ' KEY_TAB
                                TextInput:+ "  "
                        Case 13 ' KEY_ENTER
                                NewText=TextInput
                                TextInput=""
                                LastEvent=Event ; Event=0
                                TextInputEnabled=0
                                Return NewText
                        Default
                                If Not KeyDown(KEY_SPACE) Then TextInput:+ Chr(Char)
                    End Select
                    '
                    Width = TextWidth(TextInput+CursorText)
                    CursorBlink = True
                    LocalTime = MilliSecs()
                    '
                End If
                '
                If MilliSecs()>Localtime+400 Then
                      CursorBlink = Not CursorBlink
                      LocalTime = MilliSecs()
                End If
                '
                If CursorBlink Then
                      SetColor 50,255,255 ' Cyan
                      DrawLine ((X+Width+1),(Y+1),(X+Width+1),(Y+Height-3))
                      SetColor 255,255,255
                End If
                '
             End If
             '
             SetColor 255,255,255
             DrawText (CursorText+TextInput,X,Y)
             '
        End Method
        '   
   End Type

   
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

#17
Sorry if this appears as a double post! Just realized that moding a post dosent actually come up as something new has happened! Thought i was saving space on the server  :-X

So, Ive started to put together a "Character Designer" for the Drawtext() Command. This will lead to altering the Original "Blitzfont.bin" Which i can then Customize the Font in BlitzmaxNG

*** UPDATE Ver_1.04 *** Ive added the Function CreateDefaultGlyph:TImageFont()  passing back to setimagefont but have access violation?

I think its todo with this Function CreateDefaultGlphys:TImageFont() and this line font._glyphs[n]._image=TImage(GlyphImage[n])

'
    Function CreateDefaultGlphys:TImageFont()
       '
       For Local n:Int=0 Until 96
          Local glyph:TImageGlyph=New TImageGlyph
          font._glyphs[n]=glyph
          glyph._advance=8
          glyph._w=8
          glyph._h=16
          font._glyphs[n]._image=TImage(GlyphImage[n])
       Next
       '
       Return font
       '
    End Function
    '


Version 1.03  Ive added or rather created an old fashioned style text KEY input FUNCTION with Blinking cursor. Need to save value when entered and alter Glyph!

Version 1.02   Added, Button Checking all though im sort off using a console Window. Mouse Coords to help with this. Large Character for visual change! Key Input still to do?
                   Ive added a Flashing Cursor Function. Its more of a pulsing color effect rather than just a flash. All these little features will come in usefull for My C64 Emulator. Text     
                   input is something to work on?

Im using this to learn BlitzmaxNG I will be using the Functions created here to add USER Input to the ZX Spectrum and C64 Emulator's.

This is Runnable code in BlitzmaxNG

Code (blitzmax) Select

'
    SuperStrict
    '
    ' Version_1.04
    '
    AppTitle = "Drawtext() Character Designer"
    '   
    Graphics 800,600
    '
    Global FontPixMap1:TPixmap=TPixmap.Create(96*8,16,PF_RGBA8888)
    Global FontPixmap2:TPixmap=TPixmap.Create(96*8,16,PF_RGBA8888)
    Global font:TImageFont=New TImageFont
    Global GlyphImage:TImage[96]
    Global Character:Byte=57
    Global Time:Int=MilliSecs() , Flash:Byte=0 , BlinkRate:Int=700
    '
    Global GetText:Getkey = New Getkey
    '
    Global xpos:Int=0, ypos:Int=0
    '
    Global LastEvent:Int=0 , Event:Int=0
    Global DebugMsg:String="Nothing to say!"
    Global Quot:String=Chr 34
    Global _String:String=""
    Global Char:Int=0
    '
    CreateGlyphPixmap()
    Create96GlyphImages()
    '
    While Not AppTerminate() And Not KeyHit(KEY_ESCAPE)
       ' 
       Cls
       '
       DrawPixmap FontPixMap1,0,14
       SetColor 0,0,255
       DrawPixmap FontPixMap2,0,28
       '
       FlashGlyph()
       '
       Checkeys()
       DrawMousePosition()
       '
       SetColor 220,0,0
       DrawText("CHARACTER "+Character+"   ASCII "+(Character+32),8,56)
       '
       SetColor 255,255,255
       DrawGlyph(Character)
       ' Character , x,y Coords , ScaleX , ScaleY
       DrawBigGlyph(Character,8,132,8,8)
       Check_String()
       '
       'Print ~0 ' What is this?
       '
       '
       ' CODE HERE READY TO TURN INTO FUNCTION
       '
       
       '
       '
       'Print Event
       If MouseHit(1) And Event=0 Then
            xpos:Int=MouseX() ; ypos:Int=MouseY()
            CheckButtons()
         Else If Event<>0 Then
            CheckButtons()
       End If   
       '       
       'SetColor 255,100,200 ' Pink
       DrawTextStdFONT()
       SetColor 255,100,200  ' Magenta
       DrawText ("Debug Messaging ... "+DebugMsg,8,580)
       Flip(0)
       '
    Wend
    '
    '
    Function DrawTextStdFONT()
       '
       SetColor 50,255,255 ' Cyan
       DrawText("!"+Quot+"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVYXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}"+Chr(32+94)+Chr(32+95),14,520)
       SetColor 255,255,255
       '
    End Function
    '
    '
    Function Check_String()
           '
           If _String<>"" Then
               '
               Local Value:Int= _String.ToInt
               If Value<0 Or Value>255 Then ' Check to see if we have valid Byte
                   DebugMsg = "Invalid INPUT!" ; Return
               End If
               DebugMsg = "LastEvent="+LastEvent+"   "+_String
               '
               AlterGlyphImage(Character,LastEvent,Value)
               Event=0 ; _String=""
               '
           End If
           '
       End Function
    '
    '
    Function AlterGlyphImage(Character:Int, Row:Int, Value:Int)
        '
        ' We must deccrease Row by one This is todo with Event
        Row:-1
        '
        If Row>15 Return 'img
            Local pix:TPixmap=LockImage(GlyphImage[Character])
            Local bit:Int=128
                    For Local i:Int=0 To 7
                            If value & bit
                                 pix.WritePixel i,Row,$FFFFFFFF
                            Else
                                 pix.WritePixel i,Row,0
                            EndIf
                            bit = bit Shr 1
                    Next
            UnlockImage GlyphImage[Character]
        '
        ' Set Altered FONT
        SetImageFont CreateDefaultGlphys()
        '
    End Function
    '
    '
    Function CheckButtons()
        '
        'Local xpos:Int=MouseX(), ypos:Int=MouseY()
                '
                If (xpos>=176) And (xpos<=199) Then
                  '
                  Select True
                     '
                     Case (ypos>=82) And (ypos<=89) ' And (xpos>=176) And (xpos<=199)
                             '
                             DebugMsg = "first row"
                             GetText.TextInputEnabled=True ; Event=1
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,80,"",0,3)         
                             '
                     Case (ypos>=95) And (ypos<=102)
                             '
                             DebugMsg = "Second row"
                             GetText.TextInputEnabled=True ; Event=2
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,94,"",0,3)
                             '
                     Case (ypos>=110) And (ypos<=118)
                             '
                             DebugMsg = "Third row"
                             GetText.TextInputEnabled=True ; Event=3
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,108,"",0,3)
                             '
                     Case (ypos>=124) And (ypos<=134)
                             '
                             DebugMsg = "Fourth row"
                             GetText.TextInputEnabled=True ; Event=4
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,122,"",0,3)
                             '
                     Case (ypos>=137) And (ypos<=145)
                            '
                             DebugMsg = "Fifth row"
                             GetText.TextInputEnabled=True ; Event=5
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,136,"",0,3)
                             '
                     Case (ypos>=151) And (ypos<=159)
                             '
                             DebugMsg = "Sixth row"
                             GetText.TextInputEnabled=True ; Event=6
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             GetText.Input_(204,150,"",0,3)
                             '
                     Case (ypos>=167) And (ypos<=175)
                             '
                             DebugMsg = "Seventh row"
                             GetText.TextInputEnabled=True ; Event=7
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,164,"",0,3)
                             '
                     Case (ypos>=180) And (ypos<=188)
                             '
                             DebugMsg = "Eighth row"
                             GetText.TextInputEnabled=True ; Event=8
                             ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                             _String=GetText.Input_(204,178,"",0,3)
                             '
                     Case (ypos>=193) And (ypos<=201)
                            '
                            DebugMsg = "Nineth row"
                            GetText.TextInputEnabled=True ; Event=9
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,192,"",0,3)
                            '
                     Case (ypos>=208) And (ypos<=216)
                            '
                            DebugMsg = "Tenth row"
                            GetText.TextInputEnabled=True ; Event=10
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,206,"",0,3)
                            '
                     Case (ypos>=222) And (ypos<=230)
                            '
                            DebugMsg = "Eleventh row"
                            GetText.TextInputEnabled=True ; Event=11
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,220,"",0,3)
                            '
                     Case (ypos>=235) And (ypos<=243)
                            '
                            DebugMsg = "Twelveth row"
                            GetText.TextInputEnabled=True ; Event=12
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            GetText.Input_(204,234,"",0,3)
                            '
                     Case (ypos>=250) And (ypos<=258)
                            '
                            DebugMsg = "Thirteenth row"
                            GetText.TextInputEnabled=True ; Event=13
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,248,"",0,3)
                            '
                     Case (ypos>=263) And (ypos<=271)
                            '
                            DebugMsg = "Fourteenth row"
                            GetText.TextInputEnabled=True ; Event=14
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,262,"",0,3)
                            '
                     Case (ypos>=277) And (ypos<=285)
                            '
                            DebugMsg = "Fifteenth row"
                            GetText.TextInputEnabled=True ; Event=15
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,276,"",0,3)
                            '
                     Case (ypos>=292) And (ypos<=300)
                            '
                            DebugMsg = "Sixteenth row"
                            GetText.TextInputEnabled=True ; Event=16
                            ' x,y Coords , Question if needed! , 0 for Number Input or 1 for Text Input , 3 is Number of Max Characters
                            _String=GetText.Input_(204,290,"",0,3)
                            '
                     '
                     Default  DebugMsg="Nothing To say!"
                     '
                  End Select
                  '
                  Else
                       DebugMsg="Nothing To say!"
               End If 
               '
    End Function
    '
    '
    Function DrawMousePosition()
       '
       DrawText("USE X,Y Feedback to SETMOUSE Position  X="+MouseX()+"  Y="+MouseY(),8,318)
       '
    End Function
    '
    '
    Function DrawBigGlyph(character:Int,PosX:Int,PosY:Int,scaleX:Int,scaleY:Int)
    '
        SetColor 200,50,255
        SetScale(scaleX,scaleY) ; DrawText(Chr(Character+32),PosX,PosY) ;  SetScale(1,1)
    '
    End Function
    '
    '
    Function FlashGlyph()
    '
       ' Time is a difficult thing!
       '
       If MilliSecs()>(Time+BlinkRate) Then
            Flash = 1
            Time = MilliSecs()
         Else If (MilliSecs()>(Time+(BlinkRate/4))) And (MilliSecs()<(Time+(BlinkRate/2))) Then
            Flash = 2
         Else If (MilliSecs()>(Time+(BlinkRate/2))) And (MilliSecs()<(Time + BlinkRate)) Then
            Flash = 3
       End If
       '
       Select Flash
              Case 1 ; SetColor 150,0,0
              Case 2 ; SetColor 190,0,0
              Case 3 ; SetColor 255,0,0
       End Select
       '
       DrawImage GlyphImage[Character],(8*Character),42
       '
    End Function
    '
    '
    Function Checkeys()
       '
       If Not Getkey.TextInputEnabled Then
           '
           Local keyed:Int=GetChar()
           'Print keyed
           If Keyed=(46) And (Character<=95) Then Character:+1 ' Hmm? period is a fullstop!?
           If (Character=96) Then Character=0
           If Keyed=(44) And (Character>=0) Then Character:-1
           If (Character=(255)) Then Character=95
           FlushKeys()
           '
       End If
       '
    End Function
    '
    '
    Function CreateDefaultGlphys:TImageFont()
       '
       For Local n:Int=0 Until 96
          Local glyph:TImageGlyph=New TImageGlyph
          font._glyphs[n]=glyph
          glyph._advance=8
          glyph._w=8
          glyph._h=16
          font._glyphs[n]._image=TImage(GlyphImage[n])
       Next
       '
       Return font
       '
    End Function
    '
    '
    Function Create96GlyphImages()
       '
       For Local n:Byte=0 Until 96
          '
          ' .Window is like a [Viewport 8*16]
          GlyphImage[n]=TImage.Load(FontPixMap1.Window(n*8,0,8,16).Copy(),0,0,0,0)
          '
       Next
       '
    End Function
    '
    '
    Function DrawGlyph(Character:Byte)
       '
       Local p:Byte Ptr=IncbinPtr( "blitzfont.bin" )
       '
       For Local y:Byte=0 Until 16
         '
         Local bits:Byte=swapBits(p[Character])
         '
         DrawText(RSet(Bin(bits),8).Replace("0",".").Replace("1","#")+" = "+(RSet(bits, 3).Replace(" ", "0")),88,(y+6)*14-4)
         '
         p:+96
         '
        Next
        '
    End Function
    '
    '
    Function CreateGlyphPixmap()
       '
       Local p:Byte Ptr=IncbinPtr( "blitzfont.bin" )
       '
       For Local y:Byte=0 Until 16
          '
          For Local x:Byte=0 Until 96
             '
             Local b:Byte=p[x], b2:Byte=p[x]     
             Local bits:Byte=swapBits(p[x])
             '
                If X=57 Then ' This is the "Y" Character
                    '
                    Select True
                       '
                       Case (y=2)  ; b2=102 ' Row of Character byte 0 to 15
                       Case (y=3)  ; b2=102
                       Case (y=4)  ; b2=102
                       Case (y=5)  ; b2=102
                       Case (Y=6)  ; b2=36
                       Case (Y=7)  ; b2=24
                       Case (Y=8)  ; b2=24
                       Case (Y=9)  ; b2=24
                       Case (Y=10) ; b2=24
                       '
                    End Select
                    '
                 End If
             '
             DrawText(Right(Bin(bits),8)+" = "+(RSet(bits, 3).Replace(" ", "0")),20,(y+5)*14)
             'Print "P is "+p+" ... "+Right(Bin(b),8)+"  "+b
             For Local n:Byte=0 Until 8
               '
               If b & (1 Shl n)
                      FontPixMap1.WritePixel x*8+n,y,(-1)
                  Else
                      FontPixMap1.WritePixel x*8+n,y,0
               EndIf
               '
               If b2 & (1 Shl n)
                      FontPixMap2.WritePixel x*8+n,y,(-1)
                  Else
                      FontPixMap2.WritePixel x*8+n,y,0
               EndIf
               '
             Next
             '
          Next
          '
          p:+96
          '
     Next
     '
    End Function
    '
    '
    Function SwapBits:Byte(ByteIn:Byte)
       '
       Local LeftBit:Byte=7, RightBit:Byte=0
       '
       For Local loop:Byte=1 To 4
           '
           Select loop
           '
               Case 1 ' Swap Bits 7 And 0
                      LeftBit=(ByteIn & 128) <> 0
                      RightBit=(ByteIn & 1) <> 0
                      '
                      ' Now Exchange Bit's
                      If RightBit=1 Then ByteIn=(ByteIn|128) Else ByteIn=(ByteIn&127)
                      If LeftBit=1 Then ByteIn=(ByteIn | 1) Else ByteIn=(ByteIn & 254)
                      '
               Case 2 ' Swap Bits 6 And 1
                      LeftBit=(ByteIn & 64) <> 0
                      RightBit=(ByteIn & 2) <> 0
                      '
                      ' Now Exchange Bit's
                      If RightBit=1 Then ByteIn=(ByteIn | 64) Else ByteIn=(ByteIn & 191)
                      If LeftBit=1 Then ByteIn=(ByteIn | 2) Else ByteIn=(ByteIn & 253)
                      ' 
               Case 3 ' Swap Bits 5 And 2
                      LeftBit=(ByteIn & 32) <> 0
                      RightBit=(ByteIn & 4) <> 0
                      '
                      ' Now Exchange Bit's
                      If RightBit=1 Then ByteIn=(ByteIn | 32) Else ByteIn=(ByteIn & 223)
                      If LeftBit=1 Then ByteIn=(ByteIn | 4) Else ByteIn=(ByteIn & 251)
                      '
               Case 4 ' Swap Bits 4 And 3
                      LeftBit=(ByteIn & 16) <> 0
                      RightBit=(ByteIn & 8) <> 0
                      '
                      ' Now Exchange Bit's
                      If RightBit=1 Then ByteIn=(ByteIn | 16) Else ByteIn=(ByteIn & 239)
                      If LeftBit=1 Then ByteIn=(ByteIn | 8) Else ByteIn=(ByteIn & 247)
                      '
            End Select
            '
        Next
        '
        Return ByteIn
        '
    End Function
    '
    '
    Type GetKey
        '
        Global TextInputEnabled:Int = False
        Field TextInput:String, NewText:String
        Field CursorBlink:Int = False
        Field Height:Int, Width:Int, X:Int, Y:Int, MaxNumberOFcharacters:Int, LocalTime:Int = MilliSecs()
        Field CursorText:String
        '   
        Method Input_:String(X:Int, Y:Int, InpuText:String, NumberORtext:Int, MAXcharacters:Int)
            '
            GetText.X=X
            GetText.Y=Y
            GetText.TextInput=TextInput
            GetText.Width=TextWidth(TextInput+InpuText)
            GetText.Height=TextHeight(TextInput)
            GetText.CursorText=InpuText
            GetText.MaxNumberOFcharacters=MAXcharacters
            '
            If NumberORtext=0 Then
                  DebugMsg="Number INPUT ONLY!"
                  Return NUM_()
              Else
                  DebugMsg="Text INPUT ONLY!"
                  Return TEXT_() ' Always TRAPS to TEXT() INPUT! If NumberORtext <> "0"
            End If
            '
        End Method
        '
        '
        Method NUM_:String()
            '
            If TextInputEnabled Then
                'FlushKeys()
                Local Char:Int = GetChar()
                '
                If (Char>=48) And (Char<=57) Or (Char=8 Or Char=13) Then
                    '
                    DebugMsg="Char = "+Char
                    '
                    Select Char
                        '
                        Case 8  ' KEY_BACKSPACE
                                TextInput = Left(TextInput, Len(TextInput) - 1)
                        Case 13 ' KEY_ENTER
                                NewText=TextInput
                                TextInput=""
                                LastEvent=Event ; Event=0
                                TextInputEnabled=0
                                Return NewText
                        Default
                                If Not KeyDown(KEY_SPACE) Then
                                    If (Len(TextInput)<MaxNumberOFcharacters) Then TextInput:+ Chr(Char)
                                End If
                    End Select
                    '
                    Width = TextWidth(TextInput+CursorText)
                    CursorBlink = True
                    LocalTime = MilliSecs()
                    '
                End If
                '
                If MilliSecs()>Localtime+400 Then
                      CursorBlink = Not CursorBlink
                      LocalTime = MilliSecs()
                End If
                '
                If CursorBlink Then
                      SetColor 50,255,255
                      DrawLine ((X+Width+1),(Y+1),(X+Width+1),(Y+Height-3))
                      SetColor 255,255,255
                End If
                '
             End If
             '
             SetColor 255,255,255
             DrawText (CursorText+TextInput,X,Y)
             '
        End Method
        '
        '
        Method TEXT_:String()
            '
            If TextInputEnabled Then
                'FlushKeys()
                Char = GetChar()
                '
                If Char > 0 Then
                    '
                    DebugMsg="Char = "+Char
                    '
                    Select Char
                        '
                        Case 8  ' KEY_BACKSPACE
                                TextInput = Left(TextInput, Len(TextInput) - 1)
                        Case 9  ' KEY_TAB
                                TextInput:+ "  "
                        Case 13 ' KEY_ENTER
                                NewText=TextInput
                                TextInput=""
                                LastEvent=Event ; Event=0
                                TextInputEnabled=0
                                Return NewText
                        Default
                                If Not KeyDown(KEY_SPACE) Then TextInput:+ Chr(Char)
                    End Select
                    '
                    Width = TextWidth(TextInput+CursorText)
                    CursorBlink = True
                    LocalTime = MilliSecs()
                    '
                End If
                '
                If MilliSecs()>Localtime+400 Then
                      CursorBlink = Not CursorBlink
                      LocalTime = MilliSecs()
                End If
                '
                If CursorBlink Then
                      SetColor 50,255,255 ' Cyan
                      DrawLine ((X+Width+1),(Y+1),(X+Width+1),(Y+Height-3))
                      SetColor 255,255,255
                End If
                '
             End If
             '
             SetColor 255,255,255
             DrawText (CursorText+TextInput,X,Y)
             '
        End Method
        '   
   End Type

   
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Midimaster

to use a "home-made" blitzfont.bin you only need to store the returned value of your CreateDefault() into a new font-object.

Afterward you can set the font and use it with DrawText:

your old code:

Graphics 800,600
Global pixmap:TPixmap=TPixmap.Create( 96*8,16,PF_RGBA8888 )
Global glyph:TImageGlyph=New TImageGlyph
createdefault()

While Not AppTerminate() And Not KeyHit(KEY_ESCAPE)
   Cls
   DrawPixmap pixmap,0,0
   DrawPixmap glyph._glyphs[52]
  Flip(0)
Wend


now do this changes:
Code (BlitzMax) Select

Graphics 800,600
MyFont:TFont= createdefault()

SetFont MyFont
While Not AppTerminate() And Not KeyHit(KEY_ESCAPE)
   Cls
   DrawText "look at the Y: Y Y Y Y !!!",100,100
  Flip(0)
Wend
...back from North Pole.

Baggey

#19
Quote from: Midimaster on December 21, 2021, 16:12:07
to use a "home-made" blitzfont.bin you only need to store the returned value of your CreateDefault() into a new font-object.

Afterward you can set the font and use it with DrawText:

your old code:

Graphics 800,600
Global pixmap:TPixmap=TPixmap.Create( 96*8,16,PF_RGBA8888 )
Global glyph:TImageGlyph=New TImageGlyph
createdefault()

While Not AppTerminate() And Not KeyHit(KEY_ESCAPE)
   Cls
   DrawPixmap pixmap,0,0
   DrawPixmap glyph._glyphs[52]
  Flip(0)
Wend


now do this changes:
Code (BlitzMax) Select

Graphics 800,600
MyFont:TFont= createdefault()

SetFont MyFont
While Not AppTerminate() And Not KeyHit(KEY_ESCAPE)
   Cls
   DrawText "look at the Y: Y Y Y Y !!!",100,100
  Flip(0)
Wend


Im actually trying to write my own program that designs a "Home made FONT!" As i create it and alter the bytes for the font in realtime! Then i set the FONT from the Glyphs im creating. i do not have the Font already to use! until i have designed it?

I can not see how to implement your suggestions?

Have you tried my code?

Kindest Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Midimaster

#20
Here is a code that does the same in 120 code lines:
Code (BlitzMax) Select
SuperStrict

Graphics 400,600
Global offX%=100, offY%=200, Zoomf%=20
Global CurrentGlyph:Int=57

Global Myfont:TImagefont=TMax2DGraphics.default_font
Global Pixmap:TPixmap = LockImage(MyFont._glyphs[CurrentGlyph]._image)
Global Bytes:Int[16]
BinNumbers()

' change a glyph regular "Y" is    [0,0,99,99,99,99,63,3,3,99,62,0,0,0,0,0]
Myfont=ReplaceFont(MyFont,  57 , [255,0,99,99,99,99,63,3,3,99,62,0,0,0,0,0] )

Repeat
Cls
SetColor 255,255,255
SetScale 2,2
DrawImage LoadImage(PixMap), 100,100
SetScale 1,1
DrawText " look at this CHAR in context: M" + Chr(CurrentGlyph+32) + "M",30,150
DrawText "Click with LEFT mouse to place or remove pixels!",10,10
DrawText "Use cursor LEFT and RIGHT to change the glyphs!",10,30
Zoom
If MouseHit(1)
ChangePixel
EndIf
If KeyHit(KEY_LEFT)
ChangeCurrentGlyph(-1)
ElseIf KeyHit(KEY_RIGHT)
ChangeCurrentGlyph(+1)
EndIf
Flip
Until AppTerminate()


Function Zoom()
For Local y%=0 To 15
DrawText Bytes[y], offX+9*zoomf, offY+y*zoomf
Next
For Local x%=0 To 7
SetColor 255,255,255
For Local y%=0 To 15
If Pixmap.ReadPixel(x,y)=0
SetColor 111,111,111
Else
SetColor 255,255,255
EndIf
DrawRect offX+x*Zoomf+1, offY+y*Zoomf+1, zoomf-2, zoomf-2
Next
Next
End Function


Function ChangePixel()
Local x% = (MouseX()-offX)/Zoomf
Local y% = (MouseY()-offy)/Zoomf
If x<0 Or x>7 Return
If y<0 Or y>15 Return
pixmap= LockImage(MyFont._glyphs[CurrentGlyph]._image)
If Pixmap.ReadPixel(x,y)=0
pixmap.WritePixel(x,y,$FFFFFFFF)
Else
pixmap.WritePixel(x,y,0)
EndIf
BinNumbers()
CommandFromBytes CurrentGlyph, Bytes
End Function


Function BinNumbers()
For Local y%=0 To 15
Local BIT:Int =128
Bytes[y]=0
For Local x%=0 To 7
If Pixmap.ReadPixel(x,y)<>0
Bytes[y] = Bytes[y] + BIT
EndIf
BIT= BIT Shr 1
Next
Next
End Function


Function CommandFromBytes(who:Int, bytes:Int [])
Local command$= "Glyph No." + who + " is ["
For Local i%=0 To 14
command = command + bytes[i] + ","
Next
command = command + bytes[15] + "]"
Print Command$
End Function 


Function ReplaceFont:TImagefont(Font:TImagefont, Nr:Int, Bytes:Int[])
pixmap= LockImage(Font._glyphs[Nr]._image)
For Local y%=0 To 15
Local BIT:Int =128
Local locBytes:Int = Bytes[y]
For Local x%=0 To 7
If locBytes & BIT
Pixmap.WritePixel(x,y,$FFFFFFFF)
Else
Pixmap.WritePixel(x,y,0)
EndIf
BIT= BIT Shr 1
Next
Next
Return Font
End Function

Function ChangeCurrentGlyph(Dir:Int)
CurrentGlyph:+Dir
If CurrentGlyph<0 Then CurrentGlyph=0
If CurrentGlyph>95 Then CurrentGlyph=95
pixmap= LockImage(MyFont._glyphs[CurrentGlyph]._image)
BinNumbers()
CommandFromBytes CurrentGlyph, Bytes
End Function



You can edit the glyphs in the rectangle area with the mouse. As a direct result you see a Drawtext with already changed font.

Additional you get a PRINT of the related 16-element-Array which you can use as a command to manipulate the glyphs "by code".

The app starts with a manipulation of the "Y". You see, how I change the "Y" by setting row1=255. This means "adding a horizontal line on top of the glyph".

You can switch to the previous/next character with the LEFT and RIGHT cursor keys.





...back from North Pole.

Baggey

#21
Superb! Lots to learn  ;D

Once you've created/Designed your default font. How do you save them as a .bin file? So you can load them in and Set_as_Default font() for the future?

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!