Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:45 09 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Font scaling bug in 5.0302

Author Message
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 01:13am 07 Mar 2017
Copy link to clipboard 
Print this post

A fellow forum member has been working on a fairly involved project for quite some time. I have contributed in a small way to his project with some specific extensions and also testing form time to time. The following is one such test where a number pad routine fails (completely, actually freezes the cpu, power cycle is the only way to rescue). The cpu is a uMite Plus using a SPI display ILI9341 2.8"

The same routine used to work in version 5.2 but fails in 5.0302. The failure occurs when the ENTer Key is pressed specifically in the line for the Highlite ( Text x + bw/2 + 4, y + bh/2 + 6, cap(btn - 1), CM, 2,2, 0, RGB(cyan)).
The problem occurs when the Font is scaled as in the line above however if a larger font is used with no scaling its ok. This same routine when used under 5.2 worked OK when scaling was used.
If the same routine is run on the same CPU but configured with a 4.3" SSD1963 display
the routine does NOT fail.
The keypad is being used as large as possible due to the application.

As you can imagine the problem took quite some time to pin down so hopefully this report may save others some head scratching.

To demonstrate the issue run the following code snippets his program, under 5.0302, comment out the drawkeypad1 or 2 to choose the keypad routine 1 with scaling or 2 without.



Do
gettestcar
loop
'
'
sub drawkeypad p
drawkeypad1 p
'drawkeypad2 p
end sub
'
Sub GetTestCar caption As String, var As Float
Const bw = MM.HRes\4, bh = MM.VRes\5
' these are the captions on each key
Local String cap(15) = ("7","8","9","","4","5","6","","1","2","3","Can","X","0","Del","ENT")
Local Integer key, keydwn
Local Integer x, y, xt, yellowt, btn
Local String s
CarNo$ = "Car No: "
Penalty$ = "Penalty: "
If QQQ = 1 Then Ident$ = CarNo$
If QQQ = 2 Then Ident$ = Penalty$
CLS 0
If QQQ = 0 Then
Text 0, 9, caption + "Test No: ", , 2, 2, RGB(yellow), 0
Else
Text 0, 10, caption + Ident$, , 2, 2, RGB(yellow), 0
End If
' draw the entire keypad (99 means draw them all)
DrawKeypad 99
Do
If Touch(x) <> -1 And Not keydwn Then
' if the panel is touched
keydwn = 1
xt = Touch(x)
yellowt = Touch(y)
btn = 1
For y = bh To MM.VRes - bh Step bh
For x = 0 To MM.HRes - bw Step bw
If cap(btn-1) <> "" And xt > x And xt < x+bw And yellowt > y And yellowt < y+bh Then
x = 1000 : y = 1000 ' exit both loops
Else
btn = btn + 1
EndIf
Next x
Next y
' continue looping if the touch was not on a key
If btn > 16 Then Continue do
' special handling for the +, - and . keys
If (btn = 4 Or btn = 8) And s <> "" Then Continue do
'If btn = 13 And Instr(s, "X") > 0 Then Continue do
' draw the key as pressed
DrawKeypad btn
' special processing for Can (cancel), Del and Ent (enter)
If btn = 12 Or btn = 16 Then Continue do
If btn = 15 Then
If s <> "" Then s = Left$(s, Len(s) - 1)
Else
s = s + cap(btn - 1) ' add the key to our entered string
EndIf
Text Len(caption + " : ") * 16, 8, s + " ", , 2, 2, RGB(yellow), 0
EndIf
' if a key is currently down check if it has been released
If Touch(x) = -1 And keydwn Then
' yes, the key has been released
' draw the key as normal (ie, not pressed)
keydwn = 0
DrawKeypad -btn
' if ENT return the value
If QQQ = 0 Then
If btn = 16 And s <> "" Then TestNo = Val(s)
End If
If QQQ = 1 Then
If btn = 16 And s <> "" Then
Car(num) = Val(s)
cart$ = s
End If
End If
If QQQ = 2 Then
If btn = 16 And s <> "" Then
Penaltyst(num) = Val(s)
End If
End If
' if Can just return
If btn = 12 Or btn = 16 Then Exit Sub
EndIf
Loop
End Sub


'
'This is the sub out of version 15 and will not work under version 5.3 it freezes
'Yet it works fine under version 5.2
Sub DrawKeypad1 btndwn As Integer
Const bw = MM.HRes\4, bh = MM.VRes\5
Local String cap(15) = ("7","8","9","","4","5","6","","1","2","3","Can","X","0","Del","ENt")
Local Integer x, y, btn
btn = 1
For y = bh To MM.VRes - bh Step bh
For x = 0 To MM.HRes - bw Step bw
If cap(btn - 1) <> "" Then
If btn = btndwn Then
' draw the key as touched (ie, reverse video)
RBox x + 5, y + 5, bw - 5, bh - 5, , RGB(cyan), RGB(cyan)
Text x + bw/2 + 4, y + bh/2 + 6, cap(btn - 1), CM, 2,2, 0, RGB(cyan)
ElseIf -btn = btndwn Or btndwn = 99 Then
' draw the key as normal
RBox x + 5, y + 5, bw - 5, bh - 5, , RGB(cyan), 0
Text x + bw/2, y + bh/2 + 2, cap(btn - 1), CM, 2,2, RGB(cyan), 0
EndIf
EndIf
btn = btn + 1
Next x
Next y
End Sub
'
'Font changed but no scaling
Sub DrawKeypad2 btndwn As Integer
Const bw = MM.HRes\4, bh = MM.VRes\5
Local String cap(15) = ("7","8","9","","4","5","6","","1","2","3","Can","X","0","Del","ENt")
Local Integer x, y, btn
btn = 1
For y = bh To MM.VRes - bh Step bh
For x = 0 To MM.HRes - bw Step bw
If cap(btn - 1) <> "" Then
If btn = btndwn Then
' draw the key as touched (ie, reverse video)
RBox x + 5, y + 5, bw - 5, bh - 5, , RGB(cyan), RGB(cyan)
Text x + bw/2 + 4, y + bh/2 + 6, cap(btn - 1), CM, 5,1, 0, RGB(cyan)
ElseIf -btn = btndwn Or btndwn = 99 Then
' draw the key as normal
RBox x + 5, y + 5, bw - 5, bh - 5, , RGB(cyan), 0
Text x + bw/2, y + bh/2 + 2, cap(btn - 1), CM, 5,1, RGB(cyan), 0
EndIf
EndIf
btn = btn + 1
Next x
Next y
End Sub

Edited by MikeO 2017-03-08
Codenquilts
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1116
Posted: 08:31pm 07 Mar 2017
Copy link to clipboard 
Print this post

Hi Mike,

Had a play with your program and I believe the problem is not scaling as such but when you scale font 2 by 2 you get characters that are 24 x 40 and the 40 deep puts them outside the button box.

If you set the font to 1 with a scaling of 2, it works fine so scaling is not the issue.

Not sure why it didn't fail in 5.2 but you would expect it to fail although it might be nice to fail a bit more politely Might be something for Geoff or Peter to look at.

I tested on a Sil Chip Backpack 64 with 2.8" screen running 5.03.02

Regards,
Doug.

... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 12:41am 08 Mar 2017
Copy link to clipboard 
Print this post

Hi Panky, thanks for your post. Actually the height of the button box (by my reckoning)is bh = MM.VRes\5 = 240/5=48 so it should not have been out of the box. Also the text has already been successfully drawn in all the other boxes by the time the problem occurs, which is when you press the Enter Key and the button gets redrawn in highlight .

HOWEVER! since your post and rechecking the code I have just noticed a change in the Highlight text line bh/2 + 6, the + 6 will effect the vertical positioning of the char in the "Enter" box pushing it over the Vertical resolution of the display. So its not the fact that it's out of the box BUT rather its greater that the 240 vertical pixels.

Thanks for making me look more critically

MikeEdited by MikeO 2017-03-09
Codenquilts
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 04:50am 08 Mar 2017
Copy link to clipboard 
Print this post

Thanks for the detective work. I will investigate this for the next version.

Geoff
Geoff Graham - http://geoffg.net
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025