From: Robert Roebling Date: Mon, 17 Jan 2000 19:56:42 +0000 (+0000) Subject: Add draft wxPlotWindow X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/981b25083e41288f142e717f917e709347c34a02 Add draft wxPlotWindow git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5483 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/Makefile.in b/Makefile.in index b8339831e8..897017bf3a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,5 +1,5 @@ # -# This file was automatically generated by tmake at 21:14, 2000/01/16 +# This file was automatically generated by tmake at 20:27, 2000/01/17 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE UNX.T! # @@ -304,6 +304,7 @@ WX_HEADERS = \ panel.h \ paper.h \ pen.h \ + plot.h \ print.h \ printdlg.h \ prntbase.h \ @@ -691,6 +692,7 @@ GENERIC_HEADERS = \ generic/msgdlgg.h \ generic/notebook.h \ generic/panelg.h \ + generic/plot.h \ generic/printps.h \ generic/prntdlgg.h \ generic/progdlgg.h \ @@ -744,6 +746,7 @@ GTK_GENERICOBJS = \ msgdlgg.o \ numdlgg.o \ panelg.o \ + plot.o \ printps.o \ prntdlgg.o \ progdlgg.o \ @@ -781,6 +784,7 @@ GTK_GENERICDEPS = \ msgdlgg.d \ numdlgg.d \ panelg.d \ + plot.d \ printps.d \ prntdlgg.d \ progdlgg.d \ @@ -1136,6 +1140,7 @@ MOTIF_GENERICOBJS = \ notebook.o \ numdlgg.o \ panelg.o \ + plot.o \ printps.o \ prntdlgg.o \ progdlgg.o \ @@ -1176,6 +1181,7 @@ MOTIF_GENERICDEPS = \ notebook.d \ numdlgg.d \ panelg.d \ + plot.d \ printps.d \ prntdlgg.d \ progdlgg.d \ @@ -1510,6 +1516,7 @@ MSW_GENERICOBJS = \ logg.o \ numdlgg.o \ panelg.o \ + plot.o \ progdlgg.o \ prop.o \ propform.o \ @@ -1533,6 +1540,7 @@ MSW_GENERICDEPS = \ logg.d \ numdlgg.d \ panelg.d \ + plot.d \ progdlgg.d \ prop.d \ propform.d \ @@ -1947,6 +1955,7 @@ PM_GENERICOBJS = \ msgdlgg.o \ numdlgg.o \ panelg.o \ + plot.o \ printps.o \ prntdlgg.o \ progdlgg.o \ @@ -1982,6 +1991,7 @@ PM_GENERICDEPS = \ msgdlgg.d \ numdlgg.d \ panelg.d \ + plot.d \ printps.d \ prntdlgg.d \ progdlgg.d \ diff --git a/distrib/msw/tmake/filelist.txt b/distrib/msw/tmake/filelist.txt index 62344e0b67..4534fa3dca 100644 --- a/distrib/msw/tmake/filelist.txt +++ b/distrib/msw/tmake/filelist.txt @@ -80,6 +80,7 @@ logg.cpp G msgdlgg.cpp G G notebook.cpp G 16,R,P panelg.cpp G +plot.cpp G printps.cpp G PS prntdlgg.cpp G PS,U progdlgg.cpp G @@ -639,6 +640,7 @@ palette.h W panel.h W paper.h W pen.h W +plot.h W print.h W printdlg.h W prntbase.h W @@ -1064,6 +1066,7 @@ listctrl.h N 16 msgdlgg.h N notebook.h N panelg.h N +plot.h N printps.h N prntdlgg.h N progdlgg.h N diff --git a/include/wx/generic/plot.h b/include/wx/generic/plot.h new file mode 100644 index 0000000000..dc6faebba3 --- /dev/null +++ b/include/wx/generic/plot.h @@ -0,0 +1,104 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: plot.h +// Purpose: wxPlotWindow +// Author: Robert Roebling +// Modified by: +// Created: 12/1/2000 +// Copyright: (c) Robert Roebling +// RCS-ID: $Id$ +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_PLOT_H_ +#define _WX_PLOT_H_ + +#ifdef __GNUG__ +#pragma interface "plot.h" +#endif + +#include "wx/scrolwin.h" + +//----------------------------------------------------------------------------- +// classes +//----------------------------------------------------------------------------- + +class wxPlotCurve; +class wxPlotArea; +class wxPlotWindow; + +//----------------------------------------------------------------------------- +// wxPlotCurve +//----------------------------------------------------------------------------- + +class WXDLLEXPORT wxPlotCurve: public wxObject +{ +public: + wxPlotCurve( int offsetY ); + + virtual wxInt32 GetStartX() = 0; + virtual wxInt32 GetEndX() = 0; + + int GetOffsetY() + { return m_offsetY; } + + virtual double GetY( wxInt32 x ) = 0; + +private: + int m_offsetY; + + DECLARE_ABSTRACT_CLASS(wxPlotCurve) +}; + +//----------------------------------------------------------------------------- +// wxPlotArea +//----------------------------------------------------------------------------- + +class WXDLLEXPORT wxPlotArea: public wxWindow +{ +public: + wxPlotArea() {} + wxPlotArea( wxPlotWindow *parent ); + + void OnPaint( wxPaintEvent &event ); + void OnMouse( wxMouseEvent &event ); + +private: + wxPlotWindow *m_owner; + + DECLARE_CLASS(wxPlotArea) + DECLARE_EVENT_TABLE() +}; + +//----------------------------------------------------------------------------- +// wxPlotWindow +//----------------------------------------------------------------------------- + +class WXDLLEXPORT wxPlotWindow: public wxScrolledWindow +{ +public: + wxPlotWindow() {} + wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flags ); + ~wxPlotWindow(); + + void Add( wxPlotCurve *curve ); + size_t GetCount(); + wxPlotCurve *GetAt( size_t n ); + + void SetCurrent( wxPlotCurve* current ); + wxPlotCurve *GetCurrent(); + + void OnPaint( wxPaintEvent &event ); + +private: + friend wxPlotArea; + + wxList m_curves; + wxPlotArea *m_area; + wxPlotCurve *m_current; + + DECLARE_CLASS(wxPlotWindow) + DECLARE_EVENT_TABLE() +}; + +#endif + // _WX_PLOT_H_ diff --git a/include/wx/plot.h b/include/wx/plot.h new file mode 100644 index 0000000000..6fa9d621b8 --- /dev/null +++ b/include/wx/plot.h @@ -0,0 +1,7 @@ +#ifndef _WX_PLOT_H_BASE_ +#define _WX_PLOT_H_BASE_ + +#include "wx/generic/plot.h" + +#endif + // _WX_PLOT_H_BASE_ diff --git a/samples/plot/Makefile.in b/samples/plot/Makefile.in new file mode 100644 index 0000000000..322ee11510 --- /dev/null +++ b/samples/plot/Makefile.in @@ -0,0 +1,21 @@ +# +# File: Makefile.in +# Author: Julian Smart +# Created: 1998 +# Updated: +# Copyright: (c) 1998 Julian Smart +# +# "%W% %G%" +# +# Makefile for plot example (UNIX). + +top_srcdir = @top_srcdir@ +top_builddir = ../.. +program_dir = samples/plot + +PROGRAM=plot + +OBJECTS=$(PROGRAM).o + +include ../../src/makeprog.env + diff --git a/samples/plot/makefile.unx b/samples/plot/makefile.unx new file mode 100644 index 0000000000..5c773f552c --- /dev/null +++ b/samples/plot/makefile.unx @@ -0,0 +1,27 @@ +# +# File: Makefile for samples +# Author: Robert Roebling +# Created: 1999 +# Updated: +# Copyright: (c) 1998 Robert Roebling +# +# This makefile requires a Unix version of wxWindows +# to be installed on your system. This is most often +# done typing "make install" when using the complete +# sources of wxWindows or by installing the two +# RPM packages wxGTK.XXX.rpm and wxGTK-devel.XXX.rpm +# under Linux. +# + +CC = gcc + +PROGRAM = plot + +$(PROGRAM): $(PROGRAM).o + $(CC) -o $(PROGRAM) $(PROGRAM).o `wx-config --libs` + +$(PROGRAM).o: $(PROGRAM).cpp + $(CC) `wx-config --cflags` -c $(PROGRAM).cpp + +clean: + rm -f *.o $(PROGRAM) diff --git a/samples/plot/plot.cpp b/samples/plot/plot.cpp new file mode 100644 index 0000000000..760c941451 --- /dev/null +++ b/samples/plot/plot.cpp @@ -0,0 +1,160 @@ +/* + * Program: wxPlotWindow + * + * Author: Robert Roebling + * + * Copyright: (C) 1999, Robert Roebling + * + */ + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#include "wx/plot.h" + +#include "wx/image.h" +#include "wx/listctrl.h" +#include "wx/sizer.h" +#include "wx/log.h" +#include "wx/intl.h" + +#include + +// derived classes + +class MyPlotCurve; +class MyFrame; +class MyApp; + +// MyPlotCurve + +class MyPlotCurve: public wxPlotCurve +{ +public: + MyPlotCurve( int offsetY ) : + wxPlotCurve( offsetY ) {} + + virtual wxInt32 GetStartX() + { return 0; } + virtual wxInt32 GetEndX() + { return 10000; } + + virtual double GetY( wxInt32 x ) + { + double dx = x; + dx /= 100; + return sin( dx )+1; + } +}; + +// MyFrame + +class MyFrame: public wxFrame +{ +public: + MyFrame(); + + void OnAbout( wxCommandEvent &event ); + void OnQuit( wxCommandEvent &event ); + + wxPlotWindow *m_plot; + wxTextCtrl *m_log; + +private: + DECLARE_DYNAMIC_CLASS(MyFrame) + DECLARE_EVENT_TABLE() +}; + +// MyApp + +class MyApp: public wxApp +{ +public: + virtual bool OnInit(); +}; + +// main program + +IMPLEMENT_APP(MyApp) + +// MyFrame + +const int ID_QUIT = 108; +const int ID_ABOUT = 109; + +IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) + +BEGIN_EVENT_TABLE(MyFrame,wxFrame) + EVT_MENU (ID_ABOUT, MyFrame::OnAbout) + EVT_MENU (ID_QUIT, MyFrame::OnQuit) +END_EVENT_TABLE() + +MyFrame::MyFrame() + : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample", + wxPoint(20,20), wxSize(470,500) ) +{ + wxMenu *file_menu = new wxMenu(); + file_menu->Append( ID_ABOUT, "&About.."); + file_menu->Append( ID_QUIT, "E&xit\tAlt-X"); + + wxMenuBar *menu_bar = new wxMenuBar(); + menu_bar->Append(file_menu, "&File"); + + SetMenuBar( menu_bar ); + + CreateStatusBar(2); + int widths[] = { -1, 100 }; + SetStatusWidths( 2, widths ); + + m_plot = new wxPlotWindow( this, -1, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER ); + m_plot->SetScrollbars( 10, 10, 500, 0 ); + + m_plot->Add( new MyPlotCurve(100) ); + m_plot->Add( new MyPlotCurve(40) ); + m_plot->Add( new MyPlotCurve(30) ); + + m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE ); + wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) ); + delete old_log; + + wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); + + topsizer->Add( m_plot, 1, wxEXPAND ); + topsizer->Add( m_log, 0, wxEXPAND ); + + SetAutoLayout( TRUE ); + SetSizer( topsizer ); +} + +void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) +{ + Close( TRUE ); +} + +void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) +{ + (void)wxMessageBox( "wxScroll demo II\n" + "Robert Roebling (c) 1998", + "About wxScroll II Demo", wxICON_INFORMATION | wxOK ); +} + +//----------------------------------------------------------------------------- +// MyApp +//----------------------------------------------------------------------------- + +bool MyApp::OnInit() +{ + wxFrame *frame = new MyFrame(); + frame->Show( TRUE ); + + return TRUE; +} + diff --git a/src/generic/plot.cpp b/src/generic/plot.cpp new file mode 100644 index 0000000000..ca02719c09 --- /dev/null +++ b/src/generic/plot.cpp @@ -0,0 +1,278 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: plot.cpp +// Purpose: wxPlotWindow +// Author: Robert Roebling +// Modified by: +// Created: 12/01/2000 +// RCS-ID: $Id$ +// Copyright: (c) Robert Roebling +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "plot.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/object.h" +#include "wx/font.h" +#include "wx/colour.h" +#include "wx/settings.h" +#include "wx/sizer.h" +#include "wx/log.h" +#include "wx/intl.h" +#include "wx/dcclient.h" +#endif + +#include "wx/generic/plot.h" + +//----------------------------------------------------------------------------- +// wxPlotCurve +//----------------------------------------------------------------------------- + +IMPLEMENT_ABSTRACT_CLASS(wxPlotCurve, wxObject) + +wxPlotCurve::wxPlotCurve( int offsetY ) +{ + m_offsetY = offsetY; +} + +//----------------------------------------------------------------------------- +// wxPlotArea +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxPlotArea, wxWindow) + +BEGIN_EVENT_TABLE(wxPlotArea, wxWindow) + EVT_PAINT( wxPlotArea::OnPaint) + EVT_LEFT_DOWN( wxPlotArea::OnMouse) +END_EVENT_TABLE() + +wxPlotArea::wxPlotArea( wxPlotWindow *parent ) + : wxWindow( parent, -1, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER, "plotarea" ) +{ + m_owner = parent; + + SetBackgroundColour( *wxWHITE ); +} + +void wxPlotArea::OnMouse( wxMouseEvent &event ) +{ + int client_width; + int client_height; + GetClientSize( &client_width, &client_height); + int view_x; + int view_y; + m_owner->GetViewStart( &view_x, &view_y ); + view_x *= 10; + view_y *= 10; + + int x = event.GetX(); + int y = event.GetY(); + x += view_x; + y += view_y; + + wxNode *node = m_owner->m_curves.First(); + while (node) + { + wxPlotCurve *curve = (wxPlotCurve*)node->Data(); + + wxCoord offset_y = client_height - curve->GetOffsetY(); + + double dy = curve->GetY( x ); + int curve_y = (wxCoord)(-dy * 100) + offset_y - 1; + if ((y-curve_y < 4) && (y-curve_y > -4)) + { + m_owner->SetCurrent( curve ); + return; + } + + node = node->Next(); + } +} + +void wxPlotArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) +{ + int client_width; + int client_height; + GetClientSize( &client_width, &client_height); + int view_x; + int view_y; + m_owner->GetViewStart( &view_x, &view_y ); + view_x *= 10; + view_y *= 10; + + wxPaintDC dc( this ); + m_owner->PrepareDC( dc ); + + wxRegionIterator upd( GetUpdateRegion() ); + + while (upd) + { + int update_x = upd.GetX(); + int update_y = upd.GetY(); + int update_width = upd.GetWidth(); + + update_x += view_x; + update_y += view_y; + + if (m_owner->m_current) + { + dc.SetPen( *wxLIGHT_GREY_PEN ); + int base_line = client_height - m_owner->m_current->GetOffsetY(); + dc.DrawLine( update_x-1, base_line-1, update_x+update_width+2, base_line-1 ); + } + + wxNode *node = m_owner->m_curves.First(); + while (node) + { + wxPlotCurve *curve = (wxPlotCurve*)node->Data(); + + if (curve == m_owner->GetCurrent()) + dc.SetPen( *wxBLACK_PEN ); + else + dc.SetPen( *wxLIGHT_GREY_PEN ); + wxCoord offset_y = client_height - curve->GetOffsetY(); + + int start_x = wxMax( update_x-1, curve->GetStartX() ); + int end_x = wxMin( update_x+update_width+2, curve->GetEndX() ); + + wxCoord y=0,last_y=0; + for (int x = start_x; x < end_x; x++) + { + double dy = curve->GetY( x ); + y = (wxCoord)(-dy * 100) + offset_y - 1; + + if (x != start_x) + dc.DrawLine( x-1, last_y, x, y ); + + last_y = y; + } + node = node->Next(); + } + upd ++; + } +} + +//----------------------------------------------------------------------------- +// wxPlotWindow +//----------------------------------------------------------------------------- + +#define ID_ENLARGE_100 1000 +#define ID_ENLARGE_50 1001 +#define ID_SHRINK_33 1002 +#define ID_SHRINK_50 1003 + +#define ID_MOVE_UP 1006 +#define ID_MOVE_DOWN 1007 + + +IMPLEMENT_DYNAMIC_CLASS(wxPlotWindow, wxScrolledWindow) + +BEGIN_EVENT_TABLE(wxPlotWindow, wxScrolledWindow) + EVT_PAINT( wxPlotWindow::OnPaint) +END_EVENT_TABLE() + +wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag ) + : wxScrolledWindow( parent, id, pos, size, flag, "plotcanvas" ) +{ + m_area = new wxPlotArea( this ); + + wxBoxSizer *mainsizer = new wxBoxSizer( wxHORIZONTAL ); + + wxBoxSizer *buttonlist = new wxBoxSizer( wxVERTICAL ); + buttonlist->Add( new wxButton( this, ID_ENLARGE_100, _("+ 100%") ), 0, wxEXPAND|wxALL, 5 ); + buttonlist->Add( new wxButton( this, ID_ENLARGE_50, _("+ 50%") ), 0, wxEXPAND|wxALL, 5 ); + buttonlist->Add( new wxButton( this, ID_SHRINK_33, _("- 33%") ), 0, wxEXPAND|wxALL, 5 ); + buttonlist->Add( new wxButton( this, ID_SHRINK_50, _("- 50%") ), 0, wxEXPAND|wxALL, 5 ); + buttonlist->Add( 20,20, 0 ); + buttonlist->Add( new wxButton( this, ID_MOVE_UP, _("Up") ), 0, wxEXPAND|wxALL, 5 ); + buttonlist->Add( new wxButton( this, ID_MOVE_DOWN, _("Down") ), 0, wxEXPAND|wxALL, 5 ); + buttonlist->Add( 20,20, 1 ); + + mainsizer->Add( buttonlist, 0, wxEXPAND ); + + mainsizer->Add( m_area, 1, wxEXPAND|wxLEFT, 50 ); + + SetAutoLayout( TRUE ); + SetSizer( mainsizer ); + + SetTargetWindow( m_area ); + + SetBackgroundColour( *wxWHITE ); + + m_current = (wxPlotCurve*) NULL; +} + +wxPlotWindow::~wxPlotWindow() +{ +} + +void wxPlotWindow::Add( wxPlotCurve *curve ) +{ + m_curves.Append( curve ); + if (!m_current) m_current = curve; +} + +size_t wxPlotWindow::GetCount() +{ + return m_curves.GetCount(); +} + +wxPlotCurve *wxPlotWindow::GetAt( size_t n ) +{ + wxNode *node = m_curves.Nth( n ); + if (!node) + return (wxPlotCurve*) NULL; + + return (wxPlotCurve*) node->Data(); +} + +void wxPlotWindow::SetCurrent( wxPlotCurve* current ) +{ + m_current = current; + m_area->Refresh( TRUE ); + + wxPoint pos( m_area->GetPosition() ); + + int client_width; + int client_height; + GetClientSize( &client_width, &client_height); + wxRect rect(pos.x-40,0,40,client_height); + Refresh(TRUE,&rect); +} + +wxPlotCurve *wxPlotWindow::GetCurrent() +{ + return m_current; +} + +void wxPlotWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) +{ + wxPaintDC dc( this ); + + if (!m_current) return; + + int client_width; + int client_height; + GetClientSize( &client_width, &client_height); + + dc.SetPen( *wxBLACK_PEN ); + + wxPoint pos( m_area->GetPosition() ); + + dc.DrawLine( pos.x-15, 5, pos.x-15, client_height-5 ); + dc.DrawLine( pos.x-19, 9, pos.x-15, 5 ); + dc.DrawLine( pos.x-10, 10, pos.x-15, 5 ); + + int y = client_height - m_current->GetOffsetY() - 1; + dc.DrawLine( pos.x-15, y, pos.x-7, y ); +} +