XusinboyBekchanov / VisualFBEditor

IDE for FreeBasic
Other
176 stars 39 forks source link

Examples\ChineseCalendar behaves in a wrong way #579

Closed retsyo closed 10 months ago

retsyo commented 11 months ago

I am using latest official FreeBASIC-1.10.0-win64, latest-cloned https://github.com/XusinboyBekchanov/VisualFBEditor and https://github.com/XusinboyBekchanov/MyFbFramework

I run ChineseCalendar64.exe, shrink the window size, drag it to right corner of my windows 10 64 bits. After a long time ~ 1 hour, I find that the digitals freeze. If I try to resize the window, I get the following window, i.e. the window does not scale up correctly so there is some black region. The author of Examples\ChineseCalendar and I think there is some memory leaks in https://github.com/XusinboyBekchanov/MyFbFramework bug

XusinboyBekchanov commented 11 months ago

Fixed: Memory Leaks of Canvas: https://github.com/XusinboyBekchanov/MyFbFramework/commit/4e8d3eb35251e7b05c1e167a569e2cce952adcc5

Improved: ChineseCalendar Example: https://github.com/XusinboyBekchanov/VisualFBEditor/commit/d0f14725d939e6fbac0e343e9228ca533cb8545e

Thanks.

chunmingwang commented 11 months ago

I am using latest official FreeBASIC-1.10.0-win64, latest-cloned https://github.com/XusinboyBekchanov/VisualFBEditor and https://github.com/XusinboyBekchanov/MyFbFramework

I run ChineseCalendar64.exe, shrink the window size, drag it to right corner of my windows 10 64 bits. After a long time ~ 1 hour, I find that the digitals freeze. If I try to resize the window, I get the following window, i.e. the window does not scale up correctly so there is some black region. The author of Examples\ChineseCalendar and I think there is some memory leaks in https://github.com/XusinboyBekchanov/MyFbFramework bug

Yes, I have discovered this issue sometimes either, But I can't find the root cause of the issue.

chunmingwang commented 11 months ago

Fixed: Memory Leaks of Canvas: XusinboyBekchanov/MyFbFramework@4e8d3eb

Improved: ChineseCalendar Example: d0f1472

Thanks.

I wrote a sample code to test Canvas. Please see as attachment. The issue can still be reproduced after running a long time

testCanvas.zip

Private Sub Form1Type.TimerComponent1_Timer(ByRef Sender As TimerComponent)
    Dim dt As String = Format(Now, "yyyy-mm-dd hh:mm:ss")
    Dim w As Integer = Canvas.TextWidth(dt)
    Dim h As Integer = Canvas.TextHeight(dt)
    Canvas.Brush.Color = &h404040
    Canvas.Pen.Color = &hff0000
    Canvas.Line 0, 0, ClientWidth, ClientHeight, &h0 , "F"
    Canvas.TextOut((ClientWidth - w) / 2 , (ClientHeight - h) / 2, dt, &hff00, &H808080)
End Sub
hustbeef commented 11 months ago

Yes. The control did not consider the image as background and now add this fuction. and we must change the default backcolor to the third color like blue apply to all control and testing. The default forecolor should testing the same also.

hustbeef commented 11 months ago

I run the TestCanvas32.EXE after a while it is slow down my laptop now.

hustbeef commented 11 months ago

Before using the Cavas, You must add the code Canvas.HandleSetted = True Canvas.Handle = Dc
and ending with Canvas.HandleSetted = False. The Question is : How to stop this happen? Or default add this code in canvas like GetDevice , ReleaseDevice

XusinboyBekchanov commented 11 months ago

Fixed: Memory Leaks in Canvas: https://github.com/XusinboyBekchanov/MyFbFramework/commit/ff36fad843b805726b2a6518dfe194be973586d6

XusinboyBekchanov commented 11 months ago

The Question is : How to stop this happen? Or default add this code in canvas like GetDevice , ReleaseDevice

HandleSetted is needed to avoid calling GetDC and ReleaseDC for each command

hustbeef commented 11 months ago

So no need to add the code Canvas.HandleSetted = True Before using the Cavas? Or it must be

XusinboyBekchanov commented 11 months ago

Updated: Canvas.bas https://github.com/XusinboyBekchanov/MyFbFramework/commit/e4dbd10215321ffcf4159c5641c5b0f38bc82d9a

So no need to add the code Canvas.HandleSetted = True Before using the Cavas? Or it must be

In Timer you can do this:

Private Sub Form1Type.TimerComponent1_Timer(ByRef Sender As TimerComponent)
    Dim As Any Ptr CanvasHandle = Canvas.GetDevice
    Canvas.HandleSetted = True
    Dim dt As String = Format(Now, "yyyy-mm-dd hh:mm:ss")
    Dim w As Integer = Canvas.TextWidth(dt)
    Dim h As Integer = Canvas.TextHeight(dt)
    Canvas.Brush.Color = &h404040
    Canvas.Pen.Color = &hff0000
    Canvas.Line 0, 0, ClientWidth, ClientHeight, &h0 , "F"
    Canvas.TextOut((ClientWidth - w) / 2 , (ClientHeight - h) / 2, dt, &hff00, &H808080)
    Canvas.HandleSetted = False
    Canvas.ReleaseDevice CanvasHandle
End Sub

Then GetDC and ReleaseDC are not called for every command. Without these commands (Canvas.HandleSetted = True, Canvas.HandleSetted = False), GetDC and ReleaseDC are called for each call to the Canvas methods.

XusinboyBekchanov commented 11 months ago

In the Paint event, the library itself sets Canvas.Handle, Canvas.HandleSetted = True and Canvas.HandleSetted = False, that is, there is no need to set this in this event. In other non-Paint cases, if you want you can just call the Repaint method (and not call the Canvas methods in those places) of the desired control, then you can paint by calling the Canvas methods in one place, in the Paint event.

XusinboyBekchanov commented 11 months ago

I will see from this place whether there is a leak of GDI objects or not: image

If there is a leak of GDI objects then the number of GDI objects increases, when the number reaches 10,000, then the program will start drawing incorrectly.

Now I will see the number of GDI objects at the beginning and until the end of the program it shows only one number - 25.

hustbeef commented 11 months ago

There is a blink after updated the seconds in frmClock. Could you please help this no blink even updated every 10 mSec. the Repaint need to improve also.

```

Private Sub Control.Repaint

ifdef __USE_GTK__

            If GTK_IS_WIDGET(widget) Then gtk_widget_queue_draw(widget)
        #elseif defined(__USE_WINAPI__)
            If FHandle Then
                'If Parent->ClassName <> "Picture" AndAlso Parent->ClassName <> "Panel" Then
                'If ClassName <> "Picture" AndAlso ClassName <> "Panel" Then
                    RedrawWindow FHandle, 0, 0, RDW_INVALIDATE Or RDW_ALLCHILDREN
                    Update
                'Else
                '   ShowWindow(FHandle, SW_HIDE)
                '   ShowWindow(FHandle, SW_SHOW)
                'End If
            End If
        #endif 
XusinboyBekchanov commented 11 months ago

There is a blink after updated the seconds in frmClock. Could you please help this no blink even updated every 10 mSec.

This doesn't appear to me. Only when you click on the Month calendar there is a blink.

the Repaint need to improve also.

What change do you propose?

XusinboyBekchanov commented 11 months ago

the Repaint need to improve also.

Fixed: Control Repaint method: https://github.com/XusinboyBekchanov/MyFbFramework/commit/1113c2a2ff2522138c67253234bfb4b88eebfd27

Only when you click on the Month calendar there is a blink.

Improved: Month Calendar of Chinese Calendar Example: https://github.com/XusinboyBekchanov/VisualFBEditor/commit/a9dbb7fbae5fc4287dd99bf9cb82cf5b587ef9eb

Now Month Calendar of Chinese Calendar Example works without blinks.

XusinboyBekchanov commented 11 months ago

There is a blink after updated the seconds in frmClock. Could you please help this no blink even updated every 10 mSec.

Improved: Clock of Chinese Calendar Example: https://github.com/XusinboyBekchanov/VisualFBEditor/commit/78598f35e82d4ed37a3ccc34852cdf328141e79b

Now try it.

XusinboyBekchanov commented 11 months ago

Update Panel.bas: https://github.com/XusinboyBekchanov/MyFbFramework/commit/507ca7966747340bd97a492b5ca1a800a63790c6

After this change, with DoubleBuffered = True in the BackColor <> -1 option there will also be no blinking.

hustbeef commented 11 months ago

The ChineseCalendar and Clock is a very good Examples which should working in all OS. We can improve the APP Examples and move to MyFbFramework. Add LED numbers?

XusinboyBekchanov commented 11 months ago

LED numbers is an example?

hustbeef commented 11 months ago

Not must be. But it is better for a clock. image QT have a control QLCDNumber. It is easy for us also.

hustbeef commented 11 months ago

But it must be running under OS Linux.

XusinboyBekchanov commented 11 months ago

Yes, you can add. To work on Linux, you need to add #ifdef to the Chinese Calendar example where WinAPI is used.

hustbeef commented 11 months ago

Have a small bar after hide the caption in high DPI screen. but is the same even the picture1.Top=-5
image

XusinboyBekchanov commented 11 months ago

Have a small bar after hide the caption in high DPI screen. but is the same even the picture1.Top=-5

It is impossible to hide it. This is how OS hides Caption. If you want you can make BorderStyle = None. Then it will be impossible to change the boundaries.

XusinboyBekchanov commented 11 months ago

This is what mine looks like: image

hustbeef commented 11 months ago

Yes, the small bar has a different color, so we can change the backcolor to match Picture1.backcolor. Another solution is to draw on the forms.

hustbeef commented 11 months ago

This example has a lot of functions. Now we need localized functions. So it is better to move the sub ML() to SysUtils.bas or create a new type Language?

retsyo commented 11 months ago

if possible, please add more features in https://digitalclock4.sourceforge.io/ (which is in QT, as a result, has a big file size) or https://www.appinn.com/ct-clock/ (which is in ASM and for windows only, but has not been updated for a very long time)

thanks

hustbeef commented 11 months ago

We need everyone to join in and add some functionality to the code, not just send the request.

XusinboyBekchanov commented 11 months ago

Yes, the small bar has a different color, so we can change the backcolor to match Picture1.backcolor. Another solution is to draw on the forms.

This doesn't bother me because it's an OS decoration. Some people like it and some don't.

This example has a lot of functions. Now we need localized functions. So it is better to move the sub ML() to SysUtils.bas or create a new type Language?

We can add it as a separate file or in SysUtils as you said.

We need everyone to join in and add some functionality to the code, not just send the request.

I agree with you. The more hands the better.

chunmingwang commented 11 months ago

I found an issue in the recent update of Canvas

Panel.ClientHeight <> Panel.Canvas.Height Panel.ClientWidth <> Panel.Canvas.Width

It will case inconsistent size between display area and drawing area:

1701654742943

XusinboyBekchanov commented 11 months ago

Returned to the previous one.

Update Canvas.bas: https://github.com/XusinboyBekchanov/MyFbFramework/commit/ebac54a16759ef25aa9aea0d7483f308e7455866

It shows the same for me.

chunmingwang commented 11 months ago

Returned to the previous one.

Update Canvas.bas: XusinboyBekchanov/MyFbFramework@ebac54a

It shows the same for me.

Thanks.

chunmingwang commented 11 months ago

Add Time Announce and Speech for ChineseCalendar Example https://github.com/XusinboyBekchanov/VisualFBEditor/pull/580

XusinboyBekchanov commented 11 months ago

Have a small bar after hide the caption in high DPI screen. but is the same even the picture1.Top=-5

This is how you can hide it:

Improved: ChineseCalendar Example Hide Caption function: https://github.com/XusinboyBekchanov/VisualFBEditor/commit/54cf0a9d373ff0a69a8cbb1099a9eef858d2ba9a

chunmingwang commented 11 months ago

1701856503466

XusinboyBekchanov commented 11 months ago

Are you using Transparent and TransparentColor?

chunmingwang commented 11 months ago

Are you using Transparent and TransparentColor?

Yes, I have corrected the Transparent option and add Opacity option.

chunmingwang commented 11 months ago

Update PR https://github.com/XusinboyBekchanov/VisualFBEditor/pull/581

chunmingwang commented 10 months ago

I think the Memory Leaks of Canvas can be closed