Skip to content

Commit

Permalink
GUI: fixed refreshing problem
Browse files Browse the repository at this point in the history
  • Loading branch information
wojdyr committed Apr 4, 2011
1 parent cd82158 commit 7b4e6d7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 34 deletions.
9 changes: 3 additions & 6 deletions src/wxgui/aplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ AuxPlot::AuxPlot(wxWindow *parent, FPlot *master, wxString const& name)

void AuxPlot::OnPaint(wxPaintEvent&)
{
overlay.reset();
update_buffer_and_blit();
//draw, if necessary, vertical lines
overlay.draw();
}

namespace {
Expand Down Expand Up @@ -359,7 +356,7 @@ void AuxPlot::OnLeftDown (wxMouseEvent &event)
else {
downX = X;
overlay.start_mode(Overlay::kVRange, downX, 0);
overlay.draw();
overlay.draw_overlay();
SetCursor(wxCURSOR_SIZEWE);
frame->set_status_text("Select x range and release button to zoom...");
CaptureMouse();
Expand All @@ -379,7 +376,7 @@ void AuxPlot::cancel_mouse_left_press()

frame->set_status_text("");
overlay.switch_mode(Overlay::kVLine);
overlay.draw();
overlay.draw_overlay();
frame->plot_pane()->draw_vertical_lines(-1, -1, this);
}

Expand All @@ -401,7 +398,7 @@ void AuxPlot::OnLeftUp (wxMouseEvent &event)
}
else {
frame->set_status_text("");
overlay.draw();
overlay.draw_overlay();
frame->plot_pane()->draw_vertical_lines(event.GetX(), -1, this);
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/wxgui/mplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,7 @@ MainPlot::~MainPlot()

void MainPlot::OnPaint(wxPaintEvent&)
{
overlay.reset();
update_buffer_and_blit();
//draw, if necessary, vertical lines
overlay.draw();
}

double y_of_data_for_draw_data(vector<Point>::const_iterator i,
Expand Down Expand Up @@ -959,7 +956,7 @@ void MainPlot::set_mouse_mode(MouseModeEnum m)
|| visible_peaktops(old) != visible_peaktops(mode_))
refresh();
else
overlay.draw();
overlay.draw_overlay();
}

// update mouse hint on status bar
Expand Down Expand Up @@ -1029,7 +1026,7 @@ void MainPlot::OnMouseMove(wxMouseEvent &event)
if (event.AltDown() || event.CmdDown()) {
if (overlay.mode() == Overlay::kVLine) {
overlay.switch_mode(get_normal_ovmode());
overlay.draw();
overlay.draw_overlay();
}
}
else
Expand Down Expand Up @@ -1137,7 +1134,7 @@ void MainPlot::OnButtonDown (wxMouseEvent &event)
// if one button is already down, pressing other button cancels action
cancel_mouse_press();
overlay.change_pos(event.GetX(), event.GetY());
overlay.draw();
overlay.draw_overlay();
frame->plot_pane()->draw_vertical_lines(-1, -1, this);
return;
}
Expand Down Expand Up @@ -1316,7 +1313,7 @@ void MainPlot::OnButtonUp (wxMouseEvent &event)
mouse_op_ == kActivateRect || mouse_op_ == kDisactivateRect ||
mouse_op_ == kAddPeakTriangle || mouse_op_ == kAddPeakInRange)) {
frame->set_status_text("");
overlay.draw();
overlay.draw_overlay();
return;
}

Expand Down Expand Up @@ -1348,7 +1345,7 @@ void MainPlot::OnButtonUp (wxMouseEvent &event)
if (!cmd.empty())
ftk->exec(cmd);
else {
overlay.draw();
overlay.draw_overlay();
frame->set_status_text("");
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/wxgui/mplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class MainPlot : public FPlot
void OnPeakDelete(wxCommandEvent& event);
void OnPeakGuess(wxCommandEvent &event);
// function called when Esc is pressed
virtual void cancel_action() { cancel_mouse_press(); overlay.draw(); }
virtual void cancel_action()
{ cancel_mouse_press(); overlay.draw_overlay(); }
void cancel_mouse_press();
void save_settings(wxConfigBase *cf) const;
void read_settings(wxConfigBase *cf);
Expand Down
17 changes: 8 additions & 9 deletions src/wxgui/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ void Overlay::bg_color_updated(const wxColor& bg)
color_.Set(64, 64, 64);
}

void Overlay::draw()
void Overlay::draw_overlay()
{
if (mode_ == kFunction)
// function is drawn by calling draw_lines()
return;

wxClientDC dc(window_) ;
window_->PrepareDC(dc) ;
wxDCOverlay overlaydc(wxoverlay_, &dc);
overlaydc.Clear();
wxClientDC dc(panel_) ;
panel_->blit(dc);

dc.SetPen(wxPen(color_, 1, wxPENSTYLE_SHORT_DASH));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
switch (mode_) {
Expand Down Expand Up @@ -129,10 +128,8 @@ void Overlay::draw()

void Overlay::draw_lines(int n, wxPoint points[])
{
wxClientDC dc(window_) ;
window_->PrepareDC(dc) ;
wxDCOverlay overlaydc(wxoverlay_, &dc);
overlaydc.Clear();
wxClientDC dc(panel_) ;
panel_->blit(dc);
if (n <= 0)
return;
dc.SetPen(wxPen(color_, 1, wxPENSTYLE_SHORT_DASH));
Expand Down Expand Up @@ -319,6 +316,8 @@ double FPlot::get_max_abs_y (double (*compute_y)(vector<Point>::const_iterator,
static
void stroke_lines(wxDC& dc, wxGraphicsContext *gc, int n, wxPoint2DDouble *pp)
{
if (n < 2)
return;
if (gc) {
gc->StrokeLines(n, pp);
}
Expand Down
14 changes: 6 additions & 8 deletions src/wxgui/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <limits.h>
#include <vector>
#include <wx/config.h>
#include <wx/overlay.h>
#include "../data.h" //Point
#include "uplot.h" //BufferedPanel
#include "cmn.h" // compatibility with wx2.8 (defined wxPenStyle, etc.)
Expand Down Expand Up @@ -104,20 +103,19 @@ class Overlay
kVRange,
kHRange
};
Overlay(wxWindow *window) : window_(window), mode_(kNone),
color_(192,192,192) {}
Overlay(BufferedPanel *panel) : panel_(panel), mode_(kNone),
color_(192,192,192) {}
void start_mode(Mode m, int x1, int y1) { mode_=m; x1_=x2_=x1; y1_=y2_=y1; }
void switch_mode(Mode m) { mode_=m; }
void change_pos(int x2,int y2) { x2_=x2; y2_=y2; if (mode_!=kNone) draw(); }
void draw();
void reset() { wxoverlay_.Reset(); }
void change_pos(int x2,int y2)
{ x2_=x2; y2_=y2; if (mode_!=kNone) draw_overlay(); }
void draw_overlay();
void draw_lines(int n, wxPoint points[]);
Mode mode() const { return mode_; }
void bg_color_updated(const wxColour& bg);

private:
wxWindow *window_;
wxOverlay wxoverlay_;
BufferedPanel *panel_;
Mode mode_;
wxColour color_;
int x1_, x2_, y1_, y2_;
Expand Down
7 changes: 5 additions & 2 deletions src/wxgui/uplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ void BufferedPanel::update_buffer_and_blit()
if (GetUpdateRegion().GetBox().GetSize() == pdc.GetSize())
dirty_ = false;
}
blit(pdc);
}

// copy bitmap to window
pdc.Blit(0, 0, buffer_.GetWidth(), buffer_.GetHeight(), &memory_dc_, 0, 0);
void BufferedPanel::blit(wxDC& dc)
{
dc.Blit(0, 0, buffer_.GetWidth(), buffer_.GetHeight(), &memory_dc_, 0, 0);
}

void BufferedPanel::OnIdle(wxIdleEvent&)
Expand Down
2 changes: 2 additions & 0 deletions src/wxgui/uplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class BufferedPanel : public wxPanel
/// called from wxPaint event handler
/// updates buffer only if the window size is changed or if dirty_
void update_buffer_and_blit();
/// copy bitmap to window
void blit(wxDC& dc);
/// plotting function called to refresh buffer
virtual void draw(wxDC &dc, bool monochrome=false) = 0;
/// get bitmap buffer
Expand Down

0 comments on commit 7b4e6d7

Please sign in to comment.