Scrolling Window doesn't scroll

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
ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Scrolling Window doesn't scroll

Post by ninja9578 » Tue Apr 14, 2009 7:38 pm

I was hoping one of you wxGeniuses could tell me what I'm doing wrong. My scrolled window lets me drag the scroll bars, but the image inside of it doesn't move, and as soon as I let go of the scrollbar, they shoot back to the origin.

Code: Select all

void ScrolledDrawingWindow::OnScroll(wxScrollWinEvent & event){
    Redisplay();   
}

void ScrolledDrawingWindow::Redisplay(void){
//dc is declared in the header as ClientDC
//mdc is declared in the header as a MemoryDC
//bitmap and memorydc are fine, they just don't scroll
     #ifdef __WXMSW__
        pthread_mutex_lock(myData -> CanDraw);
        DoPrepareDC(*dc);
        dc -> Blit(0, 0, myData -> bitmap -> GetWidth(), myData -> bitmap -> GetHeight(), myData -> mdc, 0, 0);
        pthread_mutex_unlock(myData -> CanDraw);      
     #else
        pthread_mutex_lock(myData -> CanDraw);
        wxPaintDC ddc(this);
        DoPrepareDC(ddc);
        ddc.Blit(0, 0, myData -> bitmap -> GetWidth(), myData -> bitmap -> GetHeight(), myData -> mdc, 0, 0);
        pthread_mutex_unlock(myData -> CanDraw);
     #endif
}

void ScrolledDrawingWindow::ConnectEvents(void){
    Connect(wxEVT_MOTION, wxMouseEventHandler(ScrolledDrawingWindow::OnMotion));                               
    Connect(wxEVT_LEFT_UP, wxMouseEventHandler(ScrolledDrawingWindow::OnClick));                               
    Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ScrolledDrawingWindow::OnDown));                               
    Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(ScrolledDrawingWindow::OnDClick));
    
    Connect(wxEVT_SCROLLWIN_TOP, wxScrollWinEventHandler(ScrolledDrawingWindow::OnScroll));    
    Connect(wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEventHandler(ScrolledDrawingWindow::OnScroll));    
    Connect(wxEVT_SCROLLWIN_LINEUP, wxScrollWinEventHandler(ScrolledDrawingWindow::OnScroll));    
    Connect(wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEventHandler(ScrolledDrawingWindow::OnScroll));    
    Connect(wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEventHandler(ScrolledDrawingWindow::OnScroll));    
    Connect(wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEventHandler(ScrolledDrawingWindow::OnScroll));    
    Connect(wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEventHandler(ScrolledDrawingWindow::OnScroll));    
    Connect(wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEventHandler(ScrolledDrawingWindow::OnScroll));
}
Oh, I tried with ScrollEvent too and didn't get anything :)

Elmi
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Thu Mar 12, 2009 3:23 pm
Location: Germany
Contact:

Post by Elmi » Wed Apr 15, 2009 6:29 am

I don't know what you are doing with the events and within the event handlers but normally all that is not necessary. When you place e.g. a wxPanel inside your wxScrolledWindow and set the scrolling parameters using SetScrollbars() the whole thing is done.

Elmi

van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Re: Scrolling Window doesn't scroll

Post by van_user » Wed Apr 15, 2009 6:50 am

ninja9578 wrote:

Code: Select all

void ScrolledDrawingWindow::OnScroll(wxScrollWinEvent & event){
    Redisplay();   
}

void ScrolledDrawingWindow::Redisplay(void){
//dc is declared in the header as ClientDC
//mdc is declared in the header as a MemoryDC
//bitmap and memorydc are fine, they just don't scroll
     #ifdef __WXMSW__
        pthread_mutex_lock(myData -> CanDraw);
        DoPrepareDC(*dc);
        dc -> Blit(0, 0, myData -> bitmap -> GetWidth(), myData -> bitmap -> GetHeight(), myData -> mdc, 0, 0);
        pthread_mutex_unlock(myData -> CanDraw);      
     #else
        pthread_mutex_lock(myData -> CanDraw);
        wxPaintDC ddc(this);
        DoPrepareDC(ddc);
        ddc.Blit(0, 0, myData -> bitmap -> GetWidth(), myData -> bitmap -> GetHeight(), myData -> mdc, 0, 0);
        pthread_mutex_unlock(myData -> CanDraw);
     #endif
}
Where is you use offset for display scrolled image( after scroll by 5 pixels you should copy original image with offset = 5 pixels)?
As i suppose there are may be another parametrs for blit:
not ( 0, 0, Width, Height, 0, 0) but ( 0, 0, Width, Height, scrolled_x, scrolled_y).
Sorry for my English.
Win XP (SP0), mingw, wx 2.9.0

ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Post by ninja9578 » Wed Apr 15, 2009 1:41 pm

I thought DoPrepareDC does that?

So I should put a panel inside of the window? I wasn't doing that, I was drawing directly to the window.

van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Post by van_user » Wed Apr 15, 2009 2:02 pm

Sorry, I miss that.
Win XP (SP0), mingw, wx 2.9.0

van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Post by van_user » Thu Apr 16, 2009 6:56 am

ninja9578 wrote:I thought DoPrepareDC does that?
Hmm...
I was hurried yesterday. So today I inspect thread one again and:

DoPrepareDc has called with dc ( ClientDC). So you got right output region. But when you copy image from source to the window you should consider offset in source. Maybe I am wrong, but take a look on that.
Win XP (SP0), mingw, wx 2.9.0

dav1d_b
In need of some credit
In need of some credit
Posts: 1
Joined: Wed Oct 10, 2012 10:32 pm

Re: Scrolling Window doesn't scroll

Post by dav1d_b » Wed Oct 10, 2012 10:44 pm

Sorry for resurrecting an old thread but this thread would have been super useful to me if someone had answered the wxPanel question..... In my app I wanted to handle painting of the window myself, by trapping the window paint event handler.... First I tried stuffing a wxScrolledWindow into a wxFrame, writing to wxScrolledWindow.... I could sort of make it work, but it would screw up the rendering when scrolling, and when using DoPrepareDC to handle all the scrolling offsets I couldn't actually draw outside of the size of my parent wxFrame.....

Now I have a wxFrame parenting a wxScrolledWindow parenting a wxPanel.... I draw to the wxPanel directly, and all the scrolling is handle auto-magically....

In the OnPaint event handler I am using wxBufferedPaintDC, with no DoPrepareDC.... To make real time updates to the screen I use a 'paintNow()' function which uses wxClientDC and wxBufferedDC with no DoPrepareDC to render my viewport... Works beautifully, no flicker, no hand calculating of scroll offsets.... I'm using wxWidgets 2.9.11 on a Win7 x64 machine (app running as 32bit).

Hope this saves someone the day it would have saved me! Cheers!
-David

Post Reply