wxGenericCalendarCtrl slow drawing

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
rudolfninja
Earned some good credits
Earned some good credits
Posts: 107
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

wxGenericCalendarCtrl slow drawing

Post by rudolfninja »

Hi all,
The problem was found during testing of the DateTimePicker from this topic.
To localize the problem:
We've got wxGenericCalendarCtrl drawing on wxComboPopup (actually, it doesn't matter where to draw). In my case drawing of the calendar was too slow while on the clean sample it everything was OK.
I analyzed my application and found that when I use localization, then the problem occurs. I've tested it in calendar sample and the results were the same. I've just added

Code: Select all

    wxLocale locale;
    locale.Init(wxLANGUAGE_ENGLISH);
before the calendar's creating and it slowed the drawing of the calendar.

So the questions:
1) What the reason of such behavior?
2) How can I solve the problem? I need my application to be multi language as well as need possibility to change calendar's highlight color.

Thanks.
User avatar
doublemax
Moderator
Moderator
Posts: 19162
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGenericCalendarCtrl slow drawing

Post by doublemax »

before the calendar's creating and it slowed the drawing of the calendar.
Where exactly did you put this?

Define "slow". I added those two lines in several places and never noticed any difference.
Use the source, Luke!
rudolfninja
Earned some good credits
Earned some good credits
Posts: 107
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

Re: wxGenericCalendarCtrl slow drawing

Post by rudolfninja »

In calendar's sample from wxWidgets 3.0.4
file: calendar.cpp

Code: Select all

wxCalendarCtrlBase *MyPanel::DoCreateCalendar(const wxDateTime& dt, long style)
{
    wxCalendarCtrlBase *calendar;
#ifdef wxHAS_NATIVE_CALENDARCTRL
    if (m_usingGeneric)
        calendar = new wxGenericCalendarCtrl(this, Calendar_CalCtrl,
            dt,
            wxDefaultPosition,
            wxDefaultSize,
            style);
I changed to:

Code: Select all

wxCalendarCtrlBase *MyPanel::DoCreateCalendar(const wxDateTime& dt, long style)
{
    wxCalendarCtrlBase *calendar;
#ifdef wxHAS_NATIVE_CALENDARCTRL
    if (m_usingGeneric)
    {
        wxLocale locale;
        locale.Init(wxLANGUAGE_ENGLISH);
        calendar = new wxGenericCalendarCtrl(this, Calendar_CalCtrl,
            dt,
            wxDefaultPosition,
            wxDefaultSize,
            style);
    }
In terms of the wxCustomDateTimePicker it's just enough to add mentioned lines of code before creating the control (wxCustomDateTimePicker) in any place of the dialog (I tried in constructor) which is use wxCustomDateTimePicker control.
The problem occurs only with wxGenericCalendarCtrl while with simple wxCalendarCtrl everything is OK.
By "slow" I mean, that I see the process of drawing (redrawing).
I attached .gif file with the process of drawing.
In this case I placed wxCustomDateTimePicker inside of one of the dialogs from dialogs sample from wxWidgets 3.0.4 and add these strings before the dialog creation:

Code: Select all

void MyFrame::MessageBoxDialog(wxCommandEvent& WXUNUSED(event))
{
    wxLocale locale; // added
    locale.Init(wxLANGUAGE_ENGLISH); // added
    
    TestMessageBoxDialog dlg(this); // original string from the sample
    dlg.Create(); // original string from the sample
    dlg.ShowModal(); // original string from the sample
}
Attachments
calendarDrawing.gif
calendarDrawing.gif (266 KiB) Viewed 1212 times
User avatar
doublemax
Moderator
Moderator
Posts: 19162
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGenericCalendarCtrl slow drawing

Post by doublemax »

The effect i see the the sample is very subtle. It seems to flicker a bit more, so maybe it's a little slower, but it could also be my imagination.

Just as a text, can you try the same with the latest version from GIT?

BTW: What compiler are you using?

I remember there was a locale related slowdown with MinGW compilers, but i can't really remember what the solution was. I'll do some Googling and if i find it again, i post it here.
Use the source, Luke!
rudolfninja
Earned some good credits
Earned some good credits
Posts: 107
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

Re: wxGenericCalendarCtrl slow drawing

Post by rudolfninja »

I tried wxWidgets 3.1.1 and everything is OK here. However, there is no difference in the calendar's OnPaint() function.
User avatar
doublemax
Moderator
Moderator
Posts: 19162
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGenericCalendarCtrl slow drawing

Post by doublemax »

However, there is no difference in the calendar's OnPaint() function.
If the problem is locale related, it's probably somewhere in the wxDateTime code. Unfortunately i could not find the thread about that issue.
Use the source, Luke!
User avatar
doublemax
Moderator
Moderator
Posts: 19162
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGenericCalendarCtrl slow drawing

Post by doublemax »

Finally found the thread i was looking for, it was older than i thought.
https://groups.google.com/d/msg/wx-user ... fCNLI3lqkJ

This problem should be solved by now, so i'm not sure if it's still relevant. But you could try out the thing about:
just call setlocale(LC_ALL, "C") in your startup
Use the source, Luke!
rudolfninja
Earned some good credits
Earned some good credits
Posts: 107
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

Re: wxGenericCalendarCtrl slow drawing

Post by rudolfninja »

It didn't help.
I think I'll try to port the app on wxWidget 3.1.1
Post Reply