wxBufferedPaintDC() and flickering Topic is solved
wxBufferedPaintDC() and flickering
Hi guys,
This is a common problem and I have seen a number of posts about eliminating the flickering caused by wxDCs by using a buffer, but I have had a lot of trouble implementing it. I was hoping someone could post an example of using BufferedPaintDC() to draw an object without it flickering. I have attempted to do so myself in a project I am working on, but have been unable to resolve the issue. I implemented the BufferedPaintDC where I previously called PaintDC and also am intercepting erase events. Help and examples would be much appreciated. Thanks!
This is a common problem and I have seen a number of posts about eliminating the flickering caused by wxDCs by using a buffer, but I have had a lot of trouble implementing it. I was hoping someone could post an example of using BufferedPaintDC() to draw an object without it flickering. I have attempted to do so myself in a project I am working on, but have been unable to resolve the issue. I implemented the BufferedPaintDC where I previously called PaintDC and also am intercepting erase events. Help and examples would be much appreciated. Thanks!
Re: wxBufferedPaintDC() and flickering
There is nothing you can do wrong with wxBufferedPaintDC, just use it instead of wxPaintDC. If there is still flickering, it must come from somewhere else.
If you have a hierarchy of several panels, it sometimes helps to set an clearly visible, different background colors to the panels, like red, green or yellow. If one of them shines through, you know who's responsible for the flicker.
Also check this:
http://wiki.wxwidgets.org/Drawing_on_a_panel_with_a_DC
If that all doesn't help, you'll have to show some code.
If you have a hierarchy of several panels, it sometimes helps to set an clearly visible, different background colors to the panels, like red, green or yellow. If one of them shines through, you know who's responsible for the flicker.
Also check this:
http://wiki.wxwidgets.org/Drawing_on_a_panel_with_a_DC
If that all doesn't help, you'll have to show some code.
Use the source, Luke!
Re: wxBufferedPaintDC() and flickering
I have been trying to figure this out a bit and haven't really had much luck.
I have been calling wxBufferedPaintDC() like this
where render() is a massive function which basically can be simplified to
I have been calling wxBufferedPaintDC() like this
Code: Select all
wxBufferedPaintDC dc(this,wxBUFFER_VIRTUAL_AREA);
render(dc);
Code: Select all
void wxImagePanel::render(dc)
{
dc.DrawBitmap( image, 0, 0, false );
//using dc to draw a fairly large number of shapes on top of the bitmap
}
Re: wxBufferedPaintDC() and flickering
Flickering usually means that a background gets cleared and then other content is drawn on top. With the code you posted that can't happen. So there must be something else causing the flicker.
Read what i wrote before again and/or post more complete code. Maybe even a minimal compilable sample that shows the problem.
Read what i wrote before again and/or post more complete code. Maybe even a minimal compilable sample that shows the problem.
Use the source, Luke!
Re: wxBufferedPaintDC() and flickering
I know it will be in my wxImagePanel class. so here it is:
I will be looking through trying to figure out what it is. Basically my program uses a data.txt file to find the statuses of various items and then updates the images on the map accordingly.
Code: Select all
#ifndef SIMPLEIMAGE_H
#define SIMPLEIMAGE_H
#include "basic.h"
#include <wx/wx.h>
#include <wx/sizer.h>
#include <wx/event.h>
#include <wx/string.h>
#include <string.h>
#include <wx/dcbuffer.h>
#include <wx/textfile.h>
class wxImagePanel : public wxPanel
{
wxTextFile myfile;
wxBitmap image;
wxFrame* parent1;
bool pressedDown, found;
wxString text, line;
int x, y,color;
static const int RMbuttonWidth = 20;
static const int RMbuttonHeight = 20;
static const int RUbuttonrad = 5;
static const int MUbuttonrad = 15;
public:
wxImagePanel(wxFrame* parent, wxString file, wxBitmapType format);
void paintEvent(wxPaintEvent & evt);
void paintNow();
int getstatus(wxString target);
void render(wxDC& dc);
// some useful events
void mouseMoved(wxMouseEvent& event);
void mouseDown(wxMouseEvent& event);
void mouseWheelMoved(wxMouseEvent& event);
void mouseReleased(wxMouseEvent& event);
void rightClick(wxMouseEvent& event);
void mouseLeftWindow(wxMouseEvent& event);
void keyPressed(wxKeyEvent& event);
void keyReleased(wxKeyEvent& event);
void donothing(wxEraseEvent& event);
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxImagePanel, wxPanel)
// some useful events
EVT_MOTION(wxImagePanel::mouseMoved)
EVT_LEFT_DOWN(wxImagePanel::mouseDown)
EVT_LEFT_UP(wxImagePanel::mouseReleased)
EVT_RIGHT_DOWN(wxImagePanel::rightClick)
EVT_LEAVE_WINDOW(wxImagePanel::mouseLeftWindow)
EVT_KEY_DOWN(wxImagePanel::keyPressed)
EVT_KEY_UP(wxImagePanel::keyReleased)
EVT_MOUSEWHEEL(wxImagePanel::mouseWheelMoved)
EVT_ERASE_BACKGROUND(wxImagePanel::donothing)
// catch paint events
EVT_PAINT(wxImagePanel::paintEvent)
END_EVENT_TABLE()
wxImagePanel::wxImagePanel(wxFrame* parent, wxString file, wxBitmapType format) :
wxPanel(parent)
{
parent1=parent;
SetMinSize( wxSize(RMbuttonWidth, RMbuttonHeight));
this->text=text;
pressedDown= false;
if(image.LoadFile(file, format))
{
}
else
wxMessageBox("Error Could not Open File");
}
/*
* Called by the system of by wxWidgets when the panel needs
* to be redrawn. You can also trigger this call by
* calling Refresh()/Update().
*/
void wxImagePanel::paintEvent(wxPaintEvent & evt)
{
// depending on your system you may need to look at double-buffered dcs
wxBufferedPaintDC dc(this, wxBUFFER_VIRTUAL_AREA);
render(dc);
}
/*
* Alternatively, you can use a clientDC to paint on the panel
* at any time. Using this generally does not free you from
* catching paint events, since it is possible that e.g. the window
* manager throws away your drawing when the window comes to the
* background, and expects you will redraw it when the window comes
* back (by sending a paint event).
*/
int wxImagePanel::getstatus(wxString target)
{
myfile.Open( wxT("C:\\Dev-Cpp\\BART\\Data.txt"));
if (myfile.IsOpened())
{
for(line=myfile.GetFirstLine(); !myfile.Eof(); line=myfile.GetNextLine())
{;
found=false;
if (line==target)
{
line=myfile.GetNextLine();
line=myfile.GetNextLine();
line=myfile.GetNextLine();
if (line.Find("0")!=wxNOT_FOUND)
{
myfile.Close();
return 0;
}
if (line.Find("1")!=wxNOT_FOUND)
{
myfile.Close();
return 1;
}
if (line.Find("2")!=wxNOT_FOUND)
{
myfile.Close();
return 2;
}
if (line.Find("3")!=wxNOT_FOUND)
{
myfile.Close();
return 3;
}
if (line.Find("4")!=wxNOT_FOUND)
{
myfile.Close();
return 4;
}
}
}
}
myfile.Close();
}
void wxImagePanel::donothing(wxEraseEvent& event)
{
}
void wxImagePanel::paintNow()
{
// depending on your system you may need to look at double-buffered dcs
wxBufferedPaintDC dc(this,wxBUFFER_VIRTUAL_AREA);
render(dc);
}
/*
* Here we do the actual rendering. I put it in a separate
* method so that it can work no matter what type of DC
* (e.g. wxPaintDC or wxClientDC) is used.
*/
void wxImagePanel::render(wxDC& dc)
{
dc.DrawBitmap( image, 0, 0, false );
dc.DrawText(wxString("0,250"),0,250);
dc.DrawText(wxString("0,500"),0,500);
dc.DrawText(wxString("0,750"),0,750);
dc.DrawText(wxString("0,1000"),0,1000);
dc.DrawText(wxString("250,0"),250,0);
dc.DrawText(wxString("500,0"),500,0);
dc.DrawText(wxString("750,0"),750,0);
dc.DrawText(wxString("1000,0"),1000,0);
dc.DrawText(wxString("1250,0"),1250,0);
dc.SetBrush( *wxGREY_BRUSH);
dc.DrawCircle(1215,620, MUbuttonrad);
dc.DrawCircle(1215,705, RUbuttonrad);
dc.DrawRectangle(1205,655,RMbuttonWidth,RMbuttonHeight);
dc.SetBrush( *wxRED_BRUSH);
//
// MU BUTTONS
//
dc.DrawCircle(500,300, MUbuttonrad); // MU 1
dc.DrawCircle(185, 500, MUbuttonrad); // MU 2
dc.DrawCircle(310,750, MUbuttonrad); // MU 3
dc.DrawCircle(375,75, MUbuttonrad); // MU 4
dc.DrawCircle(600,110, MUbuttonrad); // MU 5
dc.DrawText(wxString("MU"),493.5,293);
dc.DrawText(wxString("MU"),178.5, 493);
dc.DrawText(wxString("MU"),303.5,743);
dc.DrawText(wxString("MU"),368.5,68);
dc.DrawText(wxString("MU"),593.5,103);
//
//END OF MU BUTTONS
//
//
// RM BUTTONS
//
//
color= getstatus(wxT("RM 1"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(335,310, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 2"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(160,390, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 3"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(140,390, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 4"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(95,475, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 5"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(440,310, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 6"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(430,255, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 7"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(400,155, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 8"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(330,50, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 9"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(465,235, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 10"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(575,170, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 11"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(100,540, RMbuttonWidth, RMbuttonHeight);
color=getstatus(wxT("RM 12"));
if ( color==0)
dc.SetBrush(*wxGREEN_BRUSH);
if (color==1)
dc.SetBrush(*wxBLUE_BRUSH);
if (color==2)
dc.SetBrush(*wxYELLOW_BRUSH);
if (color==3)
dc.SetBrush(*wxCYAN_BRUSH);
if (color==4)
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(260,710, RMbuttonWidth, RMbuttonHeight);
dc.DrawText(wxString("RM"),337.5,313);
dc.DrawText(wxString("RM"),162.5,393);
dc.DrawText(wxString("RM"),142.5,393);
dc.DrawText(wxString("RM"),97.5,478);
dc.DrawText(wxString("RM"),442.5,313);
dc.DrawText(wxString("RM"),432.5,258);
dc.DrawText(wxString("RM"),402.5,158);
dc.DrawText(wxString("RM"),332.5,53);
dc.DrawText(wxString("RM"),467.5,238);
dc.DrawText(wxString("RM"),577.5,173);
dc.DrawText(wxString("RM"),102.5,543);
dc.DrawText(wxString("RM"),262.5,713);
//
// END RM BUTTONS
//
//
// RU BUTTONS
//
//M Line
dc.DrawCircle(402,315, RUbuttonrad); //RU1
dc.DrawCircle(392,315, RUbuttonrad); //RU2
dc.DrawCircle(383,312, RUbuttonrad); //RU3
dc.DrawCircle(374,308, RUbuttonrad); //RU4
dc.DrawCircle(365,304, RUbuttonrad); //RU5
dc.DrawCircle(355,303, RUbuttonrad); //RU6
dc.DrawCircle(345,301.5, RUbuttonrad); //RU7
dc.DrawCircle(335,300.5, RUbuttonrad); //RU8
dc.DrawCircle(325,300, RUbuttonrad); //RU9
dc.DrawCircle(315,300, RUbuttonrad); //RU10
dc.DrawCircle(305,301, RUbuttonrad); //RU11
dc.DrawCircle(295,302.5, RUbuttonrad); //RU12
dc.DrawCircle(285,304.5, RUbuttonrad); //RU13
dc.DrawCircle(275,306.2, RUbuttonrad); //RU14
dc.DrawCircle(265,308, RUbuttonrad); //RU15
dc.DrawCircle(256.5,313.5, RUbuttonrad); //RU16
dc.DrawCircle(248,317, RUbuttonrad); //RU17
dc.DrawCircle(239.5,322, RUbuttonrad); //RU18
dc.DrawCircle(230,327, RUbuttonrad); //RU19
dc.DrawCircle(222,333.5, RUbuttonrad); //RU20
dc.DrawCircle(215,341, RUbuttonrad); //RU21
dc.DrawCircle(208,348.5, RUbuttonrad); //RU22
dc.DrawCircle(201,356, RUbuttonrad); //RU23
dc.DrawCircle(194,363.5, RUbuttonrad); //RU24
dc.DrawCircle(194.5,374, RUbuttonrad); //RU25
dc.DrawCircle(195,384, RUbuttonrad); //RU26
dc.DrawCircle(196,394, RUbuttonrad); //RU27
dc.DrawCircle(197,404, RUbuttonrad); //RU28
dc.DrawCircle(196,414, RUbuttonrad); //RU29
dc.DrawCircle(194,423, RUbuttonrad); //RU30
dc.DrawCircle(187,430, RUbuttonrad); //RU31
dc.DrawCircle(180,437, RUbuttonrad); //RU32
dc.DrawCircle(173,444, RUbuttonrad); //RU33
//A LINE
dc.DrawCircle(448,340, RUbuttonrad); //RU34
dc.DrawCircle(440,335, RUbuttonrad); //RU35
dc.DrawCircle(432,329, RUbuttonrad); //RU36
dc.DrawCircle(424.5,324, RUbuttonrad); //RU37
dc.DrawCircle(417,318, RUbuttonrad); //RU38
// C LINE WYE
dc.DrawCircle(410,312, RUbuttonrad); //RU39
dc.DrawCircle(413,303, RUbuttonrad); //RU40
dc.DrawCircle(417,294, RUbuttonrad); //RU41
dc.DrawCircle(413,286, RUbuttonrad); //RU42
// BERKELEY
dc.DrawCircle(413,238, RUbuttonrad); //RU43
dc.DrawCircle(412,228, RUbuttonrad); //RU44
dc.DrawCircle(415,220, RUbuttonrad); //RU45
dc.DrawCircle(418.5,211, RUbuttonrad); //RU46
dc.DrawCircle(417,201, RUbuttonrad); //RU47
dc.DrawCircle(416.5,191, RUbuttonrad); //RU48
dc.DrawCircle(416,181, RUbuttonrad); //RU49
dc.DrawCircle(406,182, RUbuttonrad); //RU50
dc.DrawCircle(396,181, RUbuttonrad); //RU51
//Berkeley Hills
dc.DrawCircle(465,220, RUbuttonrad); //RU52
dc.DrawCircle(473,215, RUbuttonrad); //RU53
dc.DrawCircle(481,210, RUbuttonrad); //RU54
dc.DrawCircle(489,205, RUbuttonrad); //RU55
dc.DrawCircle(497,200, RUbuttonrad); //RU56
dc.DrawCircle(505,195, RUbuttonrad); //RU57
dc.DrawCircle(513,190, RUbuttonrad); //RU58
dc.DrawCircle(521,185, RUbuttonrad); //RU59
dc.DrawCircle(529,180, RUbuttonrad); //RU60
// Colma
dc.DrawCircle(137,540, RUbuttonrad); //RU61
dc.DrawCircle(145,545, RUbuttonrad); //RU62
dc.DrawCircle(149,554, RUbuttonrad); //RU63
dc.DrawCircle(157,560, RUbuttonrad); //RU64
dc.DrawCircle(163,568, RUbuttonrad); //RU65
dc.DrawCircle(170,575.5, RUbuttonrad); //RU66
dc.DrawCircle(177,583, RUbuttonrad); //RU67
dc.DrawCircle(185,589, RUbuttonrad); //RU68
dc.DrawCircle(191,596, RUbuttonrad); //RU69
dc.DrawCircle(197,603.5, RUbuttonrad); //RU70
dc.DrawCircle(199,612, RUbuttonrad); //RU71
dc.DrawCircle(205,620, RUbuttonrad); //RU72
dc.DrawCircle(209,629, RUbuttonrad); //RU73
dc.DrawCircle(214,636, RUbuttonrad); //RU74
dc.DrawCircle(218,644, RUbuttonrad); //RU75
dc.DrawCircle(124,500, RUbuttonrad); //RU76
dc.DrawCircle(638,520, RUbuttonrad); //RU77
dc.DrawCircle(420,260, RUbuttonrad); //RU78
dc.DrawCircle(720,95, RUbuttonrad); //RU79
//
// END RU BUTTONS
//
}
void wxImagePanel::mouseDown(wxMouseEvent& event)
{
pressedDown = true;
x=event.GetX();
y=event.GetY();
paintNow();
}
void wxImagePanel::mouseReleased(wxMouseEvent& event)
{
pressedDown = false;
paintNow();
// BUTTON SELECTION
if (x>=250&&x<=270&&y>=450&&y<=470)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM1);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=90&&x<=110&&y>=520&&y<=540)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM2);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=70&&x<=90&&y>=520&&y<=540)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM3);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=50&&x<=70&&y>=585&&y<=605)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM4);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=370&&x<=390&&y>=440&&y<=460)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM5);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=365&&x<=385&&y>=395&&y<=415)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM6);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=325&&x<=345&&y>=280&&y<=300)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM7);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=305&&x<=325&&y>=220&&y<=240)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM8);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=410&&x<=430&&y>=345&&y<=365)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM9);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=455&&x<=475&&y>=325&&y<=345)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM10);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=30&&x<=50&&y>=700&&y<=720)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM11);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
if (x>=175&&x<=195&&y>=860&&y<=880)
{
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, RM12);
evt.SetEventObject(this);
GetParent()->GetEventHandler()->AddPendingEvent(evt);
}
// END OF RM BUTTONS
}
void wxImagePanel::mouseLeftWindow(wxMouseEvent& event)
{
if (pressedDown)
{
pressedDown = false;
paintNow();
}
}
void wxImagePanel::mouseMoved(wxMouseEvent& event) {}
void wxImagePanel::mouseWheelMoved(wxMouseEvent& event) {}
void wxImagePanel::rightClick(wxMouseEvent& event) {}
void wxImagePanel::keyPressed(wxKeyEvent& event) {}
void wxImagePanel::keyReleased(wxKeyEvent& event) {}
#endif
Re: wxBufferedPaintDC() and flickering
Code: Select all
void wxImagePanel::paintNow()
{
// depending on your system you may need to look at double-buffered dcs
wxBufferedPaintDC dc(this,wxBUFFER_VIRTUAL_AREA);
render(dc);
}
Use the source, Luke!
Re: wxBufferedPaintDC() and flickering
I will give that a shot when I get into work. I will let you know how it goes. Thanks so much for looking into this for me.
Re: wxBufferedPaintDC() and flickering
I'm having a bit of difficulty setting up wxBufferedDC();
I read the constructor wxBufferedDC(wxDC *dc, const wxSize& area, int style = wxBUFFER_CLIENT_AREA), but don't know what to pass for the first argument. Do I need to make a dc first then implement a buffered dc or what? sorry for the noob questions, most of my emphasis is in hardware :/
I read the constructor wxBufferedDC(wxDC *dc, const wxSize& area, int style = wxBUFFER_CLIENT_AREA), but don't know what to pass for the first argument. Do I need to make a dc first then implement a buffered dc or what? sorry for the noob questions, most of my emphasis is in hardware :/
Re: wxBufferedPaintDC() and flickering
Code: Select all
wxClientDC cdc(this);
wxBufferedDC bcd( cdc, cdc.Getsize() );
Use the source, Luke!
Re: wxBufferedPaintDC() and flickering
yeah I think that would probably be a smarter way of handling this. Thanks for the help! I think that will resolve the flickering problem; I will update in a bit .
Re: wxBufferedPaintDC() and flickering
A little late to reply to such a old post - but it's still in 2021 on first position in Google searching for "wxBufferedPaintDC flicker".
I solved it reading this realy helpful guide:
https://wiki.wxwidgets.org/Flicker-Free_Drawing
Implementing an empty background-erase-event function did the trick for me.
Thanks for the hint having a red background while checking flicker. Now I call Refresh() 10 times per second without any flicker.
I solved it reading this realy helpful guide:
https://wiki.wxwidgets.org/Flicker-Free_Drawing
Implementing an empty background-erase-event function did the trick for me.
Thanks for the hint having a red background while checking flicker. Now I call Refresh() 10 times per second without any flicker.
Code: Select all
EVT_PAINT(myClass::paintEvent)
EVT_ERASE_BACKGROUND(myClass::eraseBackgroundEvent)
Code: Select all
void myClass::paintEvent(wxPaintEvent &evt) {
wxAutoBufferedPaintDC dc(this);
render(dc);
}
void myClass::eraseBackgroundEvent(wxEraseEvent& evt) {
// intentionally left blank
}
Re: wxBufferedPaintDC() and flickering
For completeness' sake: While using an empty wxEVT_ERASE_BACKGROUND event handler still works, the current wxWidgets version supports a faster and easier way:
https://docs.wxwidgets.org/trunk/classw ... f9fd6594ec
Code: Select all
SetBackgroundStyle( wxBG_STYLE_PAINT );
Use the source, Luke!