From 180178b5ec3a1217a3fa03a332a889f2df318e73 Mon Sep 17 00:00:00 2001 From: Rene Hopf Date: Sun, 21 Sep 2014 03:04:29 +0200 Subject: [PATCH] term aufgeteilt --- term/basicdrawpane.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++ term/basicdrawpane.hpp | 28 ++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 term/basicdrawpane.cpp create mode 100644 term/basicdrawpane.hpp diff --git a/term/basicdrawpane.cpp b/term/basicdrawpane.cpp new file mode 100644 index 00000000..877f11ec --- /dev/null +++ b/term/basicdrawpane.cpp @@ -0,0 +1,86 @@ +#include "basicdrawpane.hpp" + +BasicDrawPane::BasicDrawPane(wxFrame* parent) : wxPanel(parent){ + Bind(wxEVT_PAINT, &BasicDrawPane::paintEvent, this); + xpos = 0; + for (int i = 0; i<1024/2; i++) { + data.push_back(0); + } +} + +/* + * 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 BasicDrawPane::paintEvent(wxPaintEvent & evt) +{ + wxPaintDC dc(this); + 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). + * + * In most cases, this will not be needed at all; simply handling + * paint events and calling Refresh() when a refresh is needed + * will do the job. + */ +void BasicDrawPane::paintNow() +{ + wxClientDC dc(this); + render(dc); +} + +void BasicDrawPane::plotvalue(int value) +{ + std::cout << "data:" << value << std::endl; + //data.at(xpos) += 0.1; + + data.at(xpos) = (float)value/64; + xpos = (xpos+1)%data.size(); + Refresh(); + //oder + //Update(); +} + +/* + * 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 BasicDrawPane::render(wxDC& dc) +{ + wxCoord w,h; + dc.GetSize(&w, &h); + + // ursprung oben links + // draw some text + //dc.DrawText(wxT("Testing"), 40, 60); + + dc.SetBrush(*wxTRANSPARENT_BRUSH); + + dc.SetPen(*wxRED_PEN); + dc.DrawLine( 0, h/2, w, h/2 ); + + dc.SetPen(*wxBLACK_PEN); + + x = 0; + y = h/2; + xstep = w/(data.size()-1); + for(auto point : data){ + xold = x; + yold = y; + y = h/2-point*h/2; + dc.DrawLine( xold-xstep, yold, x, y ); + x += xstep; + } + + // Look at the wxDC docs to learn how to draw other stuff +} diff --git a/term/basicdrawpane.hpp b/term/basicdrawpane.hpp new file mode 100644 index 00000000..5bf1ddf6 --- /dev/null +++ b/term/basicdrawpane.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class BasicDrawPane : public wxPanel +{ +public: + BasicDrawPane(wxFrame* parent); + void paintEvent(wxPaintEvent & evt); + void paintNow(); + void plotvalue(int); + void render(wxDC& dc); +private: + std::vector data; + int x,y,xold,yold,xpos,xstep; +};