Intended to be a superclass to the waterfall and spectrum plot classes. Currently...
authorwittend99 <wittend99@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 13 May 2012 19:08:16 +0000 (19:08 +0000)
committerwittend99 <wittend99@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 13 May 2012 19:08:16 +0000 (19:08 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@442 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/fdmdv2_plot.cpp [new file with mode: 0644]

diff --git a/fdmdv2/fdmdv2_plot.cpp b/fdmdv2/fdmdv2_plot.cpp
new file mode 100644 (file)
index 0000000..61c45b8
--- /dev/null
@@ -0,0 +1,196 @@
+//==========================================================================\r
+// Name:            fdmdv2_plot.cpp\r
+// Purpose:         Implements simple wxWidgets application with GUI.\r
+// Created:         Apr. 9, 2012
+// Initial author:  David Witten\r
+// License:         BSD License (other licenses may apply to other\r
+//                  components of this project)\r
+//==========================================================================\r
+#include <string.h>\r
+#include "wx/wx.h"\r
+#include "fdmdv2_main.h"\r
+#include "fdmdv2_plot.h"\r
+\r
+#define wxUSE_FILEDLG   1\r
+#define wxUSE_LIBPNG    1\r
+#define wxUSE_LIBJPEG   1\r
+#define wxUSE_GIF       1\r
+#define wxUSE_PCX       1\r
+#define wxUSE_LIBTIFF   1\r
+\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=\r
+// Class DrawPanel(wxFrame* parent) : wxPanel(parent)\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=\r
+DrawPanel::DrawPanel(wxFrame* parent) : wxPanel(parent)\r
+{\r
+    m_clip              = false;\r
+    m_bitmap            = true;\r
+    m_rubberBand        = false;\r
+    m_mouseDown         = false;\r
+    m_penShortDash      = wxPen(wxColor(0xA0, 0xA0, 0xA0), 1, wxPENSTYLE_SHORT_DASH);\r
+    m_penDotDash        = wxPen(wxColor(0xD0, 0xD0, 0xD0), 1, wxPENSTYLE_DOT_DASH);\r
+    m_gridLeftOffset    = 10;\r
+    m_gridRightOffset   = 10;\r
+    m_gridTopOffset     = 10;\r
+    m_gridBottomOffset  = 10;\r
+    paintNow();\r
+}\r
+\r
+BEGIN_EVENT_TABLE(DrawPanel, wxPanel)\r
+    EVT_PAINT           (DrawPanel::OnPaint)\r
+    EVT_MOTION          (DrawPanel::OnMouseMove)\r
+    EVT_LEFT_DOWN       (DrawPanel::OnMouseDown)\r
+    EVT_LEFT_UP         (DrawPanel::OnMouseUp)\r
+    EVT_MOUSEWHEEL      (DrawPanel::OnMouseWheelMoved)\r
+    EVT_SIZE            (DrawPanel::OnSize)\r
+    EVT_SHOW            (DrawPanel::OnShow)\r
+//    EVT_ERASE_BACKGROUND(DrawPanel::OnErase)\r
+END_EVENT_TABLE()\r
+\r
+//-------------------------------------------------------------------------\r
+// OnActivate()\r
+//-------------------------------------------------------------------------\r
+void DrawPanel::OnShow(wxShowEvent& event)\r
+{\r
+    paintNow();\r
+}\r
+\r
+//-------------------------------------------------------------------------\r
+// OnErase()\r
+//-------------------------------------------------------------------------\r
+void DrawPanel::OnErase(wxEraseEvent& event)\r
+{\r
+    event.Skip();\r
+}\r
+\r
+//-------------------------------------------------------------------------\r
+// OnSize()\r
+//-------------------------------------------------------------------------\r
+void DrawPanel::OnSize(wxSizeEvent& event)\r
+{\r
+    if(m_bitmap)\r
+    {\r
+        paintNow();\r
+    }\r
+}\r
+\r
+//-------------------------------------------------------------------------\r
+// OnMouseMove()\r
+//-------------------------------------------------------------------------\r
+void DrawPanel::OnMouseMove(wxMouseEvent& event)\r
+{\r
+//    if(m_mouseDown)\r
+//    {\r
+//        paintNow();\r
+//    }\r
+}\r
+\r
+//-------------------------------------------------------------------------\r
+// OnMouseDown()\r
+//-------------------------------------------------------------------------\r
+void DrawPanel::OnMouseDown(wxMouseEvent& event)\r
+{\r
+    m_mouseDown = true;\r
+}\r
+\r
+//-------------------------------------------------------------------------\r
+// OnMouseWheelMoved()\r
+//-------------------------------------------------------------------------\r
+void DrawPanel::OnMouseWheelMoved(wxMouseEvent& event)\r
+{\r
+}\r
+\r
+//-------------------------------------------------------------------------\r
+// OnMouseUp()\r
+//-------------------------------------------------------------------------\r
+void DrawPanel::OnMouseUp(wxMouseEvent& event)\r
+{\r
+    m_mouseDown = false;\r
+}\r
+\r
+#define PLOT_BORDER         10\r
+#define XLEFT_OFFSET        0\r
+#define YBOTTOM_OFFSET      25\r
+#define GRID_INCREMENT      100\r
+#define GREY_COLOR          wxColor(0x80, 0x80, 0x80)\r
+#define BLACK_COLOR         wxColor(0x00, 0x00, 0x00)\r
+\r
+//-------------------------------------------------------------------------\r
+// render() Temporary. Subclass for each view, overide this as needed.\r
+//-------------------------------------------------------------------------\r
+void DrawPanel::render(wxDC&  dc)\r
+{\r
+    m_rectCtrl  = GetClientRect();\r
+    m_rectGrid  = m_rectCtrl;\r
+\r
+    m_rectGrid.Deflate(PLOT_BORDER, (PLOT_BORDER + (YBOTTOM_OFFSET/2)));\r
+    m_rectGrid.Offset(PLOT_BORDER, PLOT_BORDER);\r
+\r
+    int h = m_rectGrid.GetHeight();\r
+    int w = m_rectGrid.GetWidth();\r
+\r
+    int p;\r
+    char buf[15];\r
+    wxString s;\r
+\r
+    dc.Clear();\r
+\r
+    // Draw a filled rectangle with aborder\r
+    dc.SetBrush(*wxBLUE_BRUSH);\r
+    dc.SetPen(wxPen(BLACK_COLOR, 2));\r
+    dc.DrawRectangle(PLOT_BORDER, PLOT_BORDER, w, h);\r
+\r
+    // Vertical gridlines\r
+    dc.SetPen(m_penShortDash);\r
+    for(p = (PLOT_BORDER + GRID_INCREMENT); p < w; p += GRID_INCREMENT)\r
+    {\r
+        dc.DrawLine(p, (h + PLOT_BORDER), p, PLOT_BORDER);\r
+    }\r
+    // Horizontal gridlines\r
+    dc.SetPen(m_penDotDash);\r
+    for(p = (h - GRID_INCREMENT); p > PLOT_BORDER; p -= GRID_INCREMENT)\r
+    {\r
+        dc.DrawLine(PLOT_BORDER, (p + PLOT_BORDER), (w + PLOT_BORDER), (p + PLOT_BORDER));\r
+    }\r
+    // Label the X-Axis\r
+    dc.SetPen(wxPen(GREY_COLOR, 1));\r
+    for(p = GRID_INCREMENT; p < (w - YBOTTOM_OFFSET); p += GRID_INCREMENT)\r
+    {\r
+        sprintf(buf, "%1.1f Hz",(double)(p / 10));\r
+        dc.DrawText(buf, p - PLOT_BORDER, h + YBOTTOM_OFFSET/2);\r
+    }\r
+}\r
+\r
+//-------------------------------------------------------------------------\r
+// paintEvent()\r
+//\r
+// Called by the system of by wxWidgets when the panel needs\r
+// to be redrawn. You can also trigger this call by calling\r
+// Refresh()/Update().\r
+//-------------------------------------------------------------------------\r
+void DrawPanel::OnPaint(wxPaintEvent & evt)\r
+{\r
+    wxPaintDC dc(this);\r
+    render(dc);\r
+}\r
+\r
+//-------------------------------------------------------------------------\r
+// paintNow()\r
+//\r
+// Alternatively, you can use a clientDC to paint on the panel\r
+// at any time. Using this generally does not free you from\r
+// catching paint events, since it is possible that e.g. the window\r
+// manager throws away your drawing when the window comes to the\r
+// background, and expects you will redraw it when the window comes\r
+// back (by sending a paint event).\r
+//\r
+// In most cases, this will not be needed at all; simply handling\r
+// paint events and calling Refresh() when a refresh is needed\r
+// will do the job.\r
+//-------------------------------------------------------------------------\r
+void DrawPanel::paintNow()\r
+{\r
+    wxClientDC dc(this);\r
+    render(dc);\r
+}\r
+\r