1999-05-15 09:33:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: drawing.cpp
|
1999-05-17 10:10:12 -04:00
|
|
|
// Purpose: shows and tests wxDC features
|
1999-05-15 09:33:55 -04:00
|
|
|
// Author: Robert Roebling
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Robert Roebling
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
2000-01-25 19:02:15 -05:00
|
|
|
|
2002-08-31 18:31:03 -04:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
1999-05-17 10:10:12 -04:00
|
|
|
#pragma implementation "drawing.cpp"
|
|
|
|
#pragma interface "drawing.cpp"
|
1999-05-15 09:33:55 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
|
|
|
// need because it includes almost all "standard" wxWindows headers
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
1999-05-17 10:10:12 -04:00
|
|
|
#include "wx/colordlg.h"
|
2000-01-29 09:36:21 -05:00
|
|
|
#include "wx/image.h"
|
2002-03-23 19:21:26 -05:00
|
|
|
#include "wx/artprov.h"
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// ressources
|
|
|
|
// ----------------------------------------------------------------------------
|
2000-01-25 19:02:15 -05:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
// the application icon
|
2002-02-13 03:38:54 -05:00
|
|
|
#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
|
1999-05-15 09:33:55 -04:00
|
|
|
#include "mondrian.xpm"
|
|
|
|
#endif
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// what do we show on screen (there are too many shapes to put them all on
|
|
|
|
// screen simultaneously)
|
|
|
|
enum ScreenToShow
|
|
|
|
{
|
|
|
|
Show_Default,
|
|
|
|
Show_Text,
|
|
|
|
Show_Lines,
|
2002-01-02 19:13:35 -05:00
|
|
|
Show_Brushes,
|
2000-01-25 19:02:15 -05:00
|
|
|
Show_Polygons,
|
2000-02-05 20:30:21 -05:00
|
|
|
Show_Mask,
|
2000-03-02 14:18:45 -05:00
|
|
|
Show_Ops,
|
2000-07-15 15:51:35 -04:00
|
|
|
Show_Regions,
|
|
|
|
Show_Circles
|
2000-01-25 19:02:15 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// global variables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
static wxBitmap *gs_bmpNoMask = NULL,
|
|
|
|
*gs_bmpWithColMask = NULL,
|
|
|
|
*gs_bmpMask = NULL,
|
|
|
|
*gs_bmpWithMask = NULL,
|
|
|
|
*gs_bmp4 = NULL,
|
|
|
|
*gs_bmp4_mono = NULL,
|
|
|
|
*gs_bmp36 = NULL;
|
2000-01-25 19:02:15 -05:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a new application type, each program should derive a class from wxApp
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// override base class virtuals
|
|
|
|
// ----------------------------
|
|
|
|
|
|
|
|
// this one is called on application startup and is a good place for the app
|
|
|
|
// initialization (doing it here and not in the ctor allows to have an error
|
|
|
|
// return: if OnInit() returns false, the application terminates)
|
|
|
|
virtual bool OnInit();
|
2000-01-25 19:02:15 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
virtual int OnExit() { DeleteBitmaps(); return 0; }
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
protected:
|
2000-07-15 15:51:35 -04:00
|
|
|
void DeleteBitmaps();
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
bool LoadImages();
|
1999-05-15 09:33:55 -04:00
|
|
|
};
|
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
class MyCanvas;
|
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
// Define a new frame type: this is going to be our main frame
|
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor(s)
|
|
|
|
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
|
|
|
|
|
|
|
// event handlers (these functions should _not_ be virtual)
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
2002-06-12 12:15:41 -04:00
|
|
|
void OnClip(wxCommandEvent& event);
|
2000-01-25 19:02:15 -05:00
|
|
|
void OnShow(wxCommandEvent &event);
|
1999-05-15 09:33:55 -04:00
|
|
|
void OnOption(wxCommandEvent &event);
|
|
|
|
|
1999-05-17 10:35:48 -04:00
|
|
|
wxColour SelectColour();
|
|
|
|
void PrepareDC(wxDC& dc);
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
int m_backgroundMode;
|
2000-02-09 23:56:16 -05:00
|
|
|
int m_textureBackground;
|
1999-07-22 11:05:52 -04:00
|
|
|
int m_mapMode;
|
|
|
|
double m_xUserScale;
|
|
|
|
double m_yUserScale;
|
|
|
|
int m_xLogicalOrigin;
|
|
|
|
int m_yLogicalOrigin;
|
|
|
|
bool m_xAxisReversed,
|
|
|
|
m_yAxisReversed;
|
|
|
|
wxColour m_colourForeground, // these are _text_ colours
|
|
|
|
m_colourBackground;
|
|
|
|
wxBrush m_backgroundBrush;
|
|
|
|
MyCanvas *m_canvas;
|
1999-05-15 09:33:55 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// any class wishing to process wxWindows events must use this macro
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
// define a scrollable canvas for drawing onto
|
|
|
|
class MyCanvas: public wxScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyCanvas( MyFrame *parent );
|
1999-07-22 16:20:42 -04:00
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
void OnPaint(wxPaintEvent &event);
|
1999-10-10 14:42:43 -04:00
|
|
|
void OnMouseMove(wxMouseEvent &event);
|
2000-01-25 11:33:06 -05:00
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void ToShow(ScreenToShow show) { m_show = show; Refresh(); }
|
2000-01-25 19:02:15 -05:00
|
|
|
|
2002-06-12 12:15:41 -04:00
|
|
|
// set or remove the clipping region
|
|
|
|
void Clip(bool clip) { m_clip = clip; Refresh(); }
|
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
protected:
|
2000-01-25 19:02:15 -05:00
|
|
|
void DrawTestLines( int x, int y, int width, wxDC &dc );
|
2002-01-02 19:13:35 -05:00
|
|
|
void DrawTestPoly(wxDC& dc);
|
|
|
|
void DrawTestBrushes(wxDC& dc);
|
2000-01-25 19:02:15 -05:00
|
|
|
void DrawText(wxDC& dc);
|
|
|
|
void DrawImages(wxDC& dc);
|
2000-02-05 20:30:21 -05:00
|
|
|
void DrawWithLogicalOps(wxDC& dc);
|
2000-03-02 14:18:45 -05:00
|
|
|
void DrawRegions(wxDC& dc);
|
2000-07-15 15:51:35 -04:00
|
|
|
void DrawCircles(wxDC& dc);
|
2000-01-25 19:02:15 -05:00
|
|
|
void DrawDefault(wxDC& dc);
|
2000-01-25 11:33:06 -05:00
|
|
|
|
2002-01-31 19:25:07 -05:00
|
|
|
void DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime);
|
2001-06-17 09:25:55 -04:00
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
private:
|
2000-01-25 19:02:15 -05:00
|
|
|
MyFrame *m_owner;
|
|
|
|
|
|
|
|
ScreenToShow m_show;
|
2000-02-21 13:01:02 -05:00
|
|
|
wxBitmap m_smile_bmp;
|
|
|
|
wxIcon m_std_icon;
|
2002-06-12 12:15:41 -04:00
|
|
|
bool m_clip;
|
2000-01-25 19:02:15 -05:00
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// menu items
|
2000-01-25 19:02:15 -05:00
|
|
|
File_Quit = 1,
|
|
|
|
File_About,
|
|
|
|
|
|
|
|
MenuShow_First,
|
|
|
|
File_ShowDefault = MenuShow_First,
|
|
|
|
File_ShowText,
|
|
|
|
File_ShowLines,
|
2002-01-02 19:13:35 -05:00
|
|
|
File_ShowBrushes,
|
2000-01-25 19:02:15 -05:00
|
|
|
File_ShowPolygons,
|
|
|
|
File_ShowMask,
|
2000-02-05 20:30:21 -05:00
|
|
|
File_ShowOps,
|
2000-03-02 14:18:45 -05:00
|
|
|
File_ShowRegions,
|
2000-07-15 15:51:35 -04:00
|
|
|
File_ShowCircles,
|
|
|
|
MenuShow_Last = File_ShowCircles,
|
1999-05-17 10:10:12 -04:00
|
|
|
|
2002-06-12 12:15:41 -04:00
|
|
|
File_Clip,
|
|
|
|
|
1999-05-17 10:10:12 -04:00
|
|
|
MenuOption_First,
|
|
|
|
|
|
|
|
MapMode_Text = MenuOption_First,
|
1999-05-15 09:33:55 -04:00
|
|
|
MapMode_Lometric,
|
|
|
|
MapMode_Twips,
|
|
|
|
MapMode_Points,
|
|
|
|
MapMode_Metric,
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
UserScale_StretchHoriz,
|
|
|
|
UserScale_ShrinkHoriz,
|
|
|
|
UserScale_StretchVertic,
|
|
|
|
UserScale_ShrinkVertic,
|
1999-05-17 10:10:12 -04:00
|
|
|
UserScale_Restore,
|
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
AxisMirror_Horiz,
|
|
|
|
AxisMirror_Vertic,
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
LogicalOrigin_MoveDown,
|
|
|
|
LogicalOrigin_MoveUp,
|
|
|
|
LogicalOrigin_MoveLeft,
|
|
|
|
LogicalOrigin_MoveRight,
|
2002-02-02 11:08:48 -05:00
|
|
|
LogicalOrigin_Set,
|
|
|
|
LogicalOrigin_Restore,
|
1999-05-17 10:10:12 -04:00
|
|
|
|
|
|
|
Colour_TextForeground,
|
|
|
|
Colour_TextBackground,
|
|
|
|
Colour_Background,
|
|
|
|
Colour_BackgroundMode,
|
2000-02-09 23:56:16 -05:00
|
|
|
Colour_TextureBackgound,
|
1999-05-17 10:10:12 -04:00
|
|
|
|
2000-02-09 23:56:16 -05:00
|
|
|
MenuOption_Last = Colour_TextureBackgound
|
1999-05-15 09:33:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables and other macros for wxWindows
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
// Create a new application object: this macro will allow wxWindows to create
|
|
|
|
// the application object during program execution (it's better than using a
|
|
|
|
// static object for many reasons) and also declares the accessor function
|
|
|
|
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
|
|
|
|
// not wxApp)
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the application class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
bool MyApp::LoadImages()
|
|
|
|
{
|
2000-07-15 15:51:35 -04:00
|
|
|
gs_bmpNoMask = new wxBitmap;
|
|
|
|
gs_bmpWithColMask = new wxBitmap;
|
|
|
|
gs_bmpMask = new wxBitmap;
|
|
|
|
gs_bmpWithMask = new wxBitmap;
|
|
|
|
gs_bmp4 = new wxBitmap;
|
|
|
|
gs_bmp4_mono = new wxBitmap;
|
|
|
|
gs_bmp36 = new wxBitmap;
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
wxPathList pathList;
|
2002-12-14 13:13:27 -05:00
|
|
|
pathList.Add(_T("."));
|
|
|
|
pathList.Add(_T(".."));
|
2000-01-25 19:02:15 -05:00
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
wxString path = pathList.FindValidPath(_T("pat4.bmp"));
|
2000-01-25 19:02:15 -05:00
|
|
|
if ( !path )
|
|
|
|
return FALSE;
|
2000-07-15 15:51:35 -04:00
|
|
|
|
2000-03-04 11:23:26 -05:00
|
|
|
/* 4 colour bitmap */
|
2000-07-15 15:51:35 -04:00
|
|
|
gs_bmp4->LoadFile(path, wxBITMAP_TYPE_BMP);
|
2000-03-04 11:23:26 -05:00
|
|
|
/* turn into mono-bitmap */
|
2000-07-15 15:51:35 -04:00
|
|
|
gs_bmp4_mono->LoadFile(path, wxBITMAP_TYPE_BMP);
|
|
|
|
wxMask* mask4 = new wxMask(*gs_bmp4_mono, *wxBLACK);
|
|
|
|
gs_bmp4_mono->SetMask(mask4);
|
2000-01-25 19:02:15 -05:00
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
path = pathList.FindValidPath(_T("pat36.bmp"));
|
2000-01-25 19:02:15 -05:00
|
|
|
if ( !path )
|
|
|
|
return FALSE;
|
2000-07-15 15:51:35 -04:00
|
|
|
gs_bmp36->LoadFile(path, wxBITMAP_TYPE_BMP);
|
|
|
|
wxMask* mask36 = new wxMask(*gs_bmp36, *wxBLACK);
|
|
|
|
gs_bmp36->SetMask(mask36);
|
2000-01-25 19:02:15 -05:00
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
path = pathList.FindValidPath(_T("image.bmp"));
|
2000-01-25 19:02:15 -05:00
|
|
|
if ( !path )
|
|
|
|
return FALSE;
|
2000-07-15 15:51:35 -04:00
|
|
|
gs_bmpNoMask->LoadFile(path, wxBITMAP_TYPE_BMP);
|
|
|
|
gs_bmpWithMask->LoadFile(path, wxBITMAP_TYPE_BMP);
|
|
|
|
gs_bmpWithColMask->LoadFile(path, wxBITMAP_TYPE_BMP);
|
2000-01-25 19:02:15 -05:00
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
path = pathList.FindValidPath(_T("mask.bmp"));
|
2000-01-25 19:02:15 -05:00
|
|
|
if ( !path )
|
|
|
|
return FALSE;
|
2000-07-15 15:51:35 -04:00
|
|
|
gs_bmpMask->LoadFile(path, wxBITMAP_TYPE_BMP);
|
2000-01-28 21:34:46 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
wxMask *mask = new wxMask(*gs_bmpMask, *wxBLACK);
|
|
|
|
gs_bmpWithMask->SetMask(mask);
|
2000-01-25 19:02:15 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
mask = new wxMask(*gs_bmpWithColMask, *wxWHITE);
|
|
|
|
gs_bmpWithColMask->SetMask(mask);
|
2000-01-25 19:02:15 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
// `Main program' equivalent: the program execution "starts" here
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
|
|
|
// Create the main application window
|
2002-12-14 13:13:27 -05:00
|
|
|
MyFrame *frame = new MyFrame(_T("Drawing sample"),
|
1999-07-22 11:05:52 -04:00
|
|
|
wxPoint(50, 50), wxSize(550, 340));
|
1999-05-15 09:33:55 -04:00
|
|
|
|
|
|
|
// Show it and tell the application that it's our main window
|
|
|
|
frame->Show(TRUE);
|
|
|
|
SetTopWindow(frame);
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
if ( !LoadImages() )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogError(wxT("Can't load one of the bitmap files needed ")
|
|
|
|
wxT("for this sample from the current or parent ")
|
|
|
|
wxT("directory, please copy them there."));
|
2000-01-25 19:02:15 -05:00
|
|
|
|
|
|
|
// stop here
|
2000-07-15 15:51:35 -04:00
|
|
|
DeleteBitmaps();
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ok, continue
|
1999-05-15 09:33:55 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
void MyApp::DeleteBitmaps()
|
|
|
|
{
|
|
|
|
delete gs_bmpNoMask;
|
|
|
|
delete gs_bmpWithColMask;
|
|
|
|
delete gs_bmpMask;
|
|
|
|
delete gs_bmpWithMask;
|
|
|
|
delete gs_bmp4;
|
|
|
|
delete gs_bmp4_mono;
|
|
|
|
delete gs_bmp36;
|
2001-12-24 11:34:51 -05:00
|
|
|
|
|
|
|
gs_bmpNoMask = NULL;
|
|
|
|
gs_bmpWithColMask = NULL;
|
|
|
|
gs_bmpMask = NULL;
|
|
|
|
gs_bmpWithMask = NULL;
|
|
|
|
gs_bmp4 = NULL;
|
|
|
|
gs_bmp4_mono = NULL;
|
|
|
|
gs_bmp36 = NULL;
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-07-22 11:05:52 -04:00
|
|
|
// MyCanvas
|
1999-05-15 09:33:55 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
// the event tables connect the wxWindows events with the functions (event
|
|
|
|
// handlers) which process them.
|
|
|
|
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
|
|
|
EVT_PAINT (MyCanvas::OnPaint)
|
1999-10-10 14:42:43 -04:00
|
|
|
EVT_MOTION (MyCanvas::OnMouseMove)
|
1999-07-22 11:05:52 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2001-06-17 09:14:20 -04:00
|
|
|
#include "smile.xpm"
|
2000-02-21 13:01:02 -05:00
|
|
|
|
2001-06-17 09:14:20 -04:00
|
|
|
MyCanvas::MyCanvas(MyFrame *parent)
|
|
|
|
: wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxHSCROLL | wxVSCROLL | wxNO_FULL_REPAINT_ON_RESIZE)
|
1999-07-22 11:05:52 -04:00
|
|
|
{
|
2000-01-24 11:46:40 -05:00
|
|
|
m_owner = parent;
|
2000-01-25 19:02:15 -05:00
|
|
|
m_show = Show_Default;
|
2000-02-21 13:01:02 -05:00
|
|
|
m_smile_bmp = wxBitmap(smile_xpm);
|
2002-03-23 19:21:26 -05:00
|
|
|
m_std_icon = wxArtProvider::GetIcon(wxART_INFORMATION);
|
2002-08-21 11:56:42 -04:00
|
|
|
m_clip = FALSE;
|
2000-01-24 11:46:40 -05:00
|
|
|
}
|
|
|
|
|
2002-01-02 19:13:35 -05:00
|
|
|
void MyCanvas::DrawTestBrushes(wxDC& dc)
|
2000-01-24 11:46:40 -05:00
|
|
|
{
|
2002-01-02 19:13:35 -05:00
|
|
|
static const wxCoord WIDTH = 200;
|
|
|
|
static const wxCoord HEIGHT = 80;
|
|
|
|
|
|
|
|
wxCoord x = 10,
|
|
|
|
y = 10;
|
|
|
|
|
|
|
|
dc.SetBrush(wxBrush(*wxGREEN, wxSOLID));
|
|
|
|
dc.DrawRectangle(x, y, WIDTH, HEIGHT);
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("Solid green"), x + 10, y + 10);
|
2002-01-02 19:13:35 -05:00
|
|
|
|
|
|
|
y += HEIGHT;
|
|
|
|
dc.SetBrush(wxBrush(*wxRED, wxCROSSDIAG_HATCH));
|
|
|
|
dc.DrawRectangle(x, y, WIDTH, HEIGHT);
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("Hatched red"), x + 10, y + 10);
|
2002-01-02 19:13:35 -05:00
|
|
|
|
|
|
|
y += HEIGHT;
|
|
|
|
dc.SetBrush(wxBrush(*gs_bmpMask));
|
|
|
|
dc.DrawRectangle(x, y, WIDTH, HEIGHT);
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("Stipple mono"), x + 10, y + 10);
|
2002-01-02 19:13:35 -05:00
|
|
|
|
|
|
|
y += HEIGHT;
|
|
|
|
dc.SetBrush(wxBrush(*gs_bmpNoMask));
|
|
|
|
dc.DrawRectangle(x, y, WIDTH, HEIGHT);
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("Stipple colour"), x + 10, y + 10);
|
2002-01-02 19:13:35 -05:00
|
|
|
}
|
2000-01-24 11:46:40 -05:00
|
|
|
|
2002-01-02 19:13:35 -05:00
|
|
|
void MyCanvas::DrawTestPoly(wxDC& dc)
|
|
|
|
{
|
|
|
|
wxBrush brushHatch(*wxRED, wxFDIAGONAL_HATCH);
|
|
|
|
dc.SetBrush(brushHatch);
|
|
|
|
|
|
|
|
wxPoint star[5];
|
|
|
|
star[0] = wxPoint(100, 60);
|
|
|
|
star[1] = wxPoint(60, 150);
|
|
|
|
star[2] = wxPoint(160, 100);
|
|
|
|
star[3] = wxPoint(40, 100);
|
|
|
|
star[4] = wxPoint(140, 150);
|
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("You should see two (irregular) stars below, the left one ")
|
|
|
|
_T("hatched"), 10, 10);
|
|
|
|
dc.DrawText(_T("except for the central region and the right ")
|
|
|
|
_T("one entirely hatched"), 10, 30);
|
2004-02-29 18:31:02 -05:00
|
|
|
dc.DrawText(_T("The third star only has a hatched outline"), 10, 50);
|
|
|
|
|
|
|
|
dc.DrawPolygon(WXSIZEOF(star), star, 0, 30);
|
|
|
|
dc.DrawPolygon(WXSIZEOF(star), star, 160, 30, wxWINDING_RULE);
|
|
|
|
|
|
|
|
wxPoint star2[10];
|
|
|
|
star2[0] = wxPoint(0, 100);
|
|
|
|
star2[1] = wxPoint(-59, -81);
|
|
|
|
star2[2] = wxPoint(95, 31);
|
|
|
|
star2[3] = wxPoint(-95, 31);
|
|
|
|
star2[4] = wxPoint(59, -81);
|
|
|
|
star2[5] = wxPoint(0, 80);
|
|
|
|
star2[6] = wxPoint(-47, -64);
|
|
|
|
star2[7] = wxPoint(76, 24);
|
|
|
|
star2[8] = wxPoint(-76, 24);
|
|
|
|
star2[9] = wxPoint(47, -64);
|
|
|
|
int count[2] = {5, 5};
|
|
|
|
|
|
|
|
dc.DrawPolyPolygon(WXSIZEOF(count), count, star2, 450, 150);
|
1999-07-22 11:05:52 -04:00
|
|
|
}
|
|
|
|
|
1999-07-22 16:20:42 -04:00
|
|
|
void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc )
|
1999-07-22 11:05:52 -04:00
|
|
|
{
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxSOLID) );
|
1999-07-22 16:20:42 -04:00
|
|
|
dc.SetBrush( *wxRED_BRUSH );
|
2001-09-21 16:21:44 -04:00
|
|
|
dc.DrawText(wxString::Format(wxT("Testing lines of width %d"), width), x + 10, y - 10);
|
1999-12-08 03:19:45 -05:00
|
|
|
dc.DrawRectangle( x+10, y+10, 100, 190 );
|
2000-01-25 11:33:06 -05:00
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("Solid/dot/short dash/long dash/dot dash"), x + 150, y + 10);
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxSOLID) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+20, 100, y+20 );
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxDOT) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+30, 100, y+30 );
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxSHORT_DASH) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+40, 100, y+40 );
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxLONG_DASH) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+50, 100, y+50 );
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxDOT_DASH) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+60, 100, y+60 );
|
1999-07-22 16:20:42 -04:00
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("Misc hatches"), x + 150, y + 70);
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxBDIAGONAL_HATCH) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+70, 100, y+70 );
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxCROSSDIAG_HATCH) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+80, 100, y+80 );
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxFDIAGONAL_HATCH) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+90, 100, y+90 );
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxCROSS_HATCH) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+100, 100, y+100 );
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxHORIZONTAL_HATCH) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+110, 100, y+110 );
|
2001-11-22 04:11:33 -05:00
|
|
|
dc.SetPen( wxPen( wxT("black"), width, wxVERTICAL_HATCH) );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+120, 100, y+120 );
|
1999-07-22 16:20:42 -04:00
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("User dash"), x + 150, y + 140);
|
2001-11-22 04:11:33 -05:00
|
|
|
wxPen ud( wxT("black"), width, wxUSER_DASH );
|
2003-04-11 10:02:32 -04:00
|
|
|
wxDash dash1[6];
|
|
|
|
dash1[0] = 8; // Long dash <---------+
|
|
|
|
dash1[1] = 2; // Short gap |
|
|
|
|
dash1[2] = 3; // Short dash |
|
|
|
|
dash1[3] = 2; // Short gap |
|
|
|
|
dash1[4] = 3; // Short dash |
|
|
|
|
dash1[5] = 2; // Short gap and repeat +
|
|
|
|
ud.SetDashes( 6, dash1 );
|
|
|
|
dc.SetPen( ud );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+140, 100, y+140 );
|
2003-04-11 10:02:32 -04:00
|
|
|
dash1[0] = 5; // Make first dash shorter
|
|
|
|
ud.SetDashes( 6, dash1 );
|
|
|
|
dc.SetPen( ud );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+150, 100, y+150 );
|
2003-04-11 10:02:32 -04:00
|
|
|
dash1[2] = 5; // Make second dash longer
|
|
|
|
ud.SetDashes( 6, dash1 );
|
|
|
|
dc.SetPen( ud );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+160, 100, y+160 );
|
2003-04-11 10:02:32 -04:00
|
|
|
dash1[4] = 5; // Make third dash longer
|
|
|
|
ud.SetDashes( 6, dash1 );
|
|
|
|
dc.SetPen( ud );
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawLine( x+20, y+170, 100, y+170 );
|
1999-07-22 11:05:52 -04:00
|
|
|
}
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
void MyCanvas::DrawDefault(wxDC& dc)
|
1999-07-22 11:05:52 -04:00
|
|
|
{
|
|
|
|
// mark the origin
|
|
|
|
dc.DrawCircle(0, 0, 10);
|
2002-04-01 16:47:02 -05:00
|
|
|
|
|
|
|
//flood fill using brush, starting at 1,1 and replacing whatever colour we find there
|
|
|
|
dc.SetBrush(wxBrush(wxColour(128,128,0), wxSOLID));
|
|
|
|
wxColour tmpColour ;
|
|
|
|
dc.GetPixel(1,1, &tmpColour);
|
|
|
|
dc.FloodFill(1,1, tmpColour, wxFLOOD_SURFACE);
|
1999-07-22 11:05:52 -04:00
|
|
|
|
2000-02-17 07:53:36 -05:00
|
|
|
dc.DrawCheckMark(5, 80, 15, 15);
|
|
|
|
dc.DrawCheckMark(25, 80, 30, 30);
|
|
|
|
dc.DrawCheckMark(60, 80, 60, 60);
|
|
|
|
|
2000-02-21 13:01:02 -05:00
|
|
|
// this is the test for "blitting bitmap into DC damages selected brush" bug
|
|
|
|
wxCoord rectSize = m_std_icon.GetWidth() + 10;
|
2000-02-17 07:53:36 -05:00
|
|
|
wxCoord x = 100;
|
2000-02-07 20:07:48 -05:00
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
dc.SetBrush( *wxGREEN_BRUSH );
|
2000-02-17 07:53:36 -05:00
|
|
|
dc.DrawRectangle(x, 10, rectSize, rectSize);
|
2000-02-21 13:01:02 -05:00
|
|
|
dc.DrawBitmap(m_std_icon, x + 5, 15, TRUE);
|
2000-02-17 07:53:36 -05:00
|
|
|
x += rectSize + 10;
|
|
|
|
dc.DrawRectangle(x, 10, rectSize, rectSize);
|
2000-02-21 13:01:02 -05:00
|
|
|
dc.DrawIcon(m_std_icon, x + 5, 15);
|
2000-02-17 07:53:36 -05:00
|
|
|
x += rectSize + 10;
|
|
|
|
dc.DrawRectangle(x, 10, rectSize, rectSize);
|
2000-02-07 20:07:48 -05:00
|
|
|
|
|
|
|
// test for "transparent" bitmap drawing (it intersects with the last
|
|
|
|
// rectangle above)
|
|
|
|
//dc.SetBrush( *wxTRANSPARENT_BRUSH );
|
2000-02-17 15:36:52 -05:00
|
|
|
|
2000-02-21 13:01:02 -05:00
|
|
|
if (m_smile_bmp.Ok())
|
|
|
|
dc.DrawBitmap(m_smile_bmp, x + rectSize - 20, rectSize - 10, TRUE);
|
2000-01-29 09:36:21 -05:00
|
|
|
|
2000-01-26 14:26:02 -05:00
|
|
|
dc.SetBrush( *wxBLACK_BRUSH );
|
2000-01-29 09:36:21 -05:00
|
|
|
dc.DrawRectangle( 0, 160, 1000, 300 );
|
|
|
|
|
|
|
|
// draw lines
|
|
|
|
wxBitmap bitmap(20,70);
|
|
|
|
wxMemoryDC memdc;
|
|
|
|
memdc.SelectObject( bitmap );
|
|
|
|
memdc.SetBrush( *wxBLACK_BRUSH );
|
|
|
|
memdc.SetPen( *wxWHITE_PEN );
|
|
|
|
memdc.DrawRectangle(0,0,20,70);
|
|
|
|
memdc.DrawLine( 10,0,10,70 );
|
2000-02-05 20:30:21 -05:00
|
|
|
|
2000-01-29 11:50:15 -05:00
|
|
|
// to the right
|
2000-01-29 20:33:02 -05:00
|
|
|
wxPen pen = *wxRED_PEN;
|
|
|
|
memdc.SetPen(pen);
|
2000-01-29 09:36:21 -05:00
|
|
|
memdc.DrawLine( 10, 5,10, 5 );
|
|
|
|
memdc.DrawLine( 10,10,11,10 );
|
|
|
|
memdc.DrawLine( 10,15,12,15 );
|
|
|
|
memdc.DrawLine( 10,20,13,20 );
|
2000-02-05 20:30:21 -05:00
|
|
|
|
2000-01-29 11:50:15 -05:00
|
|
|
/*
|
|
|
|
memdc.SetPen(*wxRED_PEN);
|
2000-01-29 09:36:21 -05:00
|
|
|
memdc.DrawLine( 12, 5,12, 5 );
|
|
|
|
memdc.DrawLine( 12,10,13,10 );
|
|
|
|
memdc.DrawLine( 12,15,14,15 );
|
|
|
|
memdc.DrawLine( 12,20,15,20 );
|
2000-01-29 11:50:15 -05:00
|
|
|
*/
|
2000-02-05 20:30:21 -05:00
|
|
|
|
2000-01-29 09:36:21 -05:00
|
|
|
// same to the left
|
|
|
|
memdc.DrawLine( 10,25,10,25 );
|
|
|
|
memdc.DrawLine( 10,30, 9,30 );
|
|
|
|
memdc.DrawLine( 10,35, 8,35 );
|
|
|
|
memdc.DrawLine( 10,40, 7,40 );
|
|
|
|
|
|
|
|
// XOR draw lines
|
2000-01-29 11:50:15 -05:00
|
|
|
dc.SetPen(*wxWHITE_PEN);
|
2000-01-29 09:36:21 -05:00
|
|
|
memdc.SetLogicalFunction( wxINVERT );
|
|
|
|
memdc.SetPen( *wxWHITE_PEN );
|
|
|
|
memdc.DrawLine( 10,50,10,50 );
|
|
|
|
memdc.DrawLine( 10,55,11,55 );
|
|
|
|
memdc.DrawLine( 10,60,12,60 );
|
|
|
|
memdc.DrawLine( 10,65,13,65 );
|
2000-02-05 20:30:21 -05:00
|
|
|
|
2000-01-29 09:36:21 -05:00
|
|
|
memdc.DrawLine( 12,50,12,50 );
|
|
|
|
memdc.DrawLine( 12,55,13,55 );
|
|
|
|
memdc.DrawLine( 12,60,14,60 );
|
|
|
|
memdc.DrawLine( 12,65,15,65 );
|
2000-02-05 20:30:21 -05:00
|
|
|
|
2000-01-29 09:36:21 -05:00
|
|
|
memdc.SelectObject( wxNullBitmap );
|
|
|
|
dc.DrawBitmap( bitmap, 10, 170 );
|
2002-03-23 19:21:26 -05:00
|
|
|
wxImage image = bitmap.ConvertToImage();
|
2000-01-29 09:36:21 -05:00
|
|
|
image.Rescale( 60,210 );
|
2002-03-23 19:21:26 -05:00
|
|
|
bitmap = wxBitmap(image);
|
2000-01-29 09:36:21 -05:00
|
|
|
dc.DrawBitmap( bitmap, 50, 170 );
|
2000-02-05 20:30:21 -05:00
|
|
|
|
2000-01-28 21:34:46 -05:00
|
|
|
// test the rectangle outline drawing - there should be one pixel between
|
2000-01-26 14:26:02 -05:00
|
|
|
// the rect and the lines
|
|
|
|
dc.SetPen(*wxWHITE_PEN);
|
|
|
|
dc.SetBrush( *wxTRANSPARENT_BRUSH );
|
|
|
|
dc.DrawRectangle(150, 170, 49, 29);
|
2000-01-29 09:36:21 -05:00
|
|
|
dc.DrawRectangle(200, 170, 49, 29);
|
2000-01-26 14:26:02 -05:00
|
|
|
dc.SetPen(*wxWHITE_PEN);
|
2000-01-29 09:36:21 -05:00
|
|
|
dc.DrawLine(250, 210, 250, 170);
|
|
|
|
dc.DrawLine(260, 200, 150, 200);
|
2000-01-28 21:34:46 -05:00
|
|
|
|
|
|
|
// test the rectangle filled drawing - there should be one pixel between
|
2000-01-26 14:26:02 -05:00
|
|
|
// the rect and the lines
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
dc.SetBrush( *wxWHITE_BRUSH );
|
|
|
|
dc.DrawRectangle(300, 170, 49, 29);
|
2000-01-25 19:02:15 -05:00
|
|
|
dc.DrawRectangle(350, 170, 49, 29);
|
2000-01-26 14:26:02 -05:00
|
|
|
dc.SetPen(*wxWHITE_PEN);
|
2000-01-28 21:34:46 -05:00
|
|
|
dc.DrawLine(400, 170, 400, 210);
|
|
|
|
dc.DrawLine(300, 200, 410, 200);
|
|
|
|
|
2000-02-21 09:16:32 -05:00
|
|
|
// a few more tests of this kind
|
|
|
|
dc.SetPen(*wxRED_PEN);
|
|
|
|
dc.SetBrush( *wxWHITE_BRUSH );
|
|
|
|
dc.DrawRectangle(300, 220, 1, 1);
|
|
|
|
dc.DrawRectangle(310, 220, 2, 2);
|
|
|
|
dc.DrawRectangle(320, 220, 3, 3);
|
|
|
|
dc.DrawRectangle(330, 220, 4, 4);
|
|
|
|
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
dc.SetBrush( *wxWHITE_BRUSH );
|
|
|
|
dc.DrawRectangle(300, 230, 1, 1);
|
|
|
|
dc.DrawRectangle(310, 230, 2, 2);
|
|
|
|
dc.DrawRectangle(320, 230, 3, 3);
|
|
|
|
dc.DrawRectangle(330, 230, 4, 4);
|
|
|
|
|
2000-01-28 21:34:46 -05:00
|
|
|
// and now for filled rect with outline
|
|
|
|
dc.SetPen(*wxRED_PEN);
|
|
|
|
dc.SetBrush( *wxWHITE_BRUSH );
|
|
|
|
dc.DrawRectangle(500, 170, 49, 29);
|
|
|
|
dc.DrawRectangle(550, 170, 49, 29);
|
|
|
|
dc.SetPen(*wxWHITE_PEN);
|
|
|
|
dc.DrawLine(600, 170, 600, 210);
|
|
|
|
dc.DrawLine(500, 200, 610, 200);
|
|
|
|
|
|
|
|
// test the rectangle outline drawing - there should be one pixel between
|
2000-01-26 14:26:02 -05:00
|
|
|
// the rect and the lines
|
|
|
|
dc.SetPen(*wxWHITE_PEN);
|
|
|
|
dc.SetBrush( *wxTRANSPARENT_BRUSH );
|
|
|
|
dc.DrawRoundedRectangle(150, 270, 49, 29, 6);
|
2000-01-29 09:36:21 -05:00
|
|
|
dc.DrawRoundedRectangle(200, 270, 49, 29, 6);
|
2000-01-26 14:26:02 -05:00
|
|
|
dc.SetPen(*wxWHITE_PEN);
|
2000-01-29 09:36:21 -05:00
|
|
|
dc.DrawLine(250, 270, 250, 310);
|
|
|
|
dc.DrawLine(150, 300, 260, 300);
|
2000-01-28 21:34:46 -05:00
|
|
|
|
|
|
|
// test the rectangle filled drawing - there should be one pixel between
|
2000-01-26 14:26:02 -05:00
|
|
|
// the rect and the lines
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
dc.SetBrush( *wxWHITE_BRUSH );
|
|
|
|
dc.DrawRoundedRectangle(300, 270, 49, 29, 6);
|
|
|
|
dc.DrawRoundedRectangle(350, 270, 49, 29, 6);
|
|
|
|
dc.SetPen(*wxWHITE_PEN);
|
2000-01-28 21:34:46 -05:00
|
|
|
dc.DrawLine(400, 270, 400, 310);
|
|
|
|
dc.DrawLine(300, 300, 410, 300);
|
2000-01-26 14:26:02 -05:00
|
|
|
|
2000-02-17 06:04:26 -05:00
|
|
|
// Added by JACS to demonstrate bizarre behaviour.
|
|
|
|
// With a size of 70, we get a missing red RHS,
|
|
|
|
// and the hight is too small, so we get yellow
|
|
|
|
// showing. With a size of 40, it draws as expected:
|
|
|
|
// it just shows a white rectangle with red outline.
|
|
|
|
int totalWidth = 70;
|
|
|
|
int totalHeight = 70;
|
|
|
|
wxBitmap bitmap2(totalWidth, totalHeight);
|
|
|
|
|
|
|
|
wxMemoryDC memdc2;
|
|
|
|
memdc2.SelectObject(bitmap2);
|
|
|
|
|
2000-02-17 15:36:52 -05:00
|
|
|
wxBrush yellowBrush(wxColour(255, 255, 0), wxSOLID);
|
|
|
|
memdc2.SetBackground(yellowBrush);
|
|
|
|
memdc2.Clear();
|
2000-02-17 06:04:26 -05:00
|
|
|
|
2000-02-17 15:36:52 -05:00
|
|
|
wxPen yellowPen(wxColour(255, 255, 0), 1, wxSOLID);
|
2000-02-17 06:04:26 -05:00
|
|
|
|
|
|
|
// Now draw a white rectangle with red outline. It should
|
|
|
|
// entirely eclipse the yellow background.
|
|
|
|
memdc2.SetPen(*wxRED_PEN);
|
|
|
|
memdc2.SetBrush(*wxWHITE_BRUSH);
|
|
|
|
|
|
|
|
memdc2.DrawRectangle(0, 0, totalWidth, totalHeight);
|
|
|
|
|
|
|
|
memdc2.SetPen(wxNullPen);
|
|
|
|
memdc2.SetBrush(wxNullBrush);
|
2000-02-17 07:53:36 -05:00
|
|
|
memdc2.SelectObject(wxNullBitmap);
|
2000-02-17 06:04:26 -05:00
|
|
|
|
|
|
|
dc.DrawBitmap(bitmap2, 500, 270);
|
2000-02-17 15:36:52 -05:00
|
|
|
|
|
|
|
// Repeat, but draw directly on dc
|
|
|
|
// Draw a yellow rectangle filling the bitmap
|
|
|
|
|
|
|
|
x = 600; int y = 270;
|
|
|
|
dc.SetPen(yellowPen);
|
|
|
|
dc.SetBrush(yellowBrush);
|
|
|
|
dc.DrawRectangle(x, y, totalWidth, totalHeight);
|
|
|
|
|
|
|
|
// Now draw a white rectangle with red outline. It should
|
|
|
|
// entirely eclipse the yellow background.
|
|
|
|
dc.SetPen(*wxRED_PEN);
|
|
|
|
dc.SetBrush(*wxWHITE_BRUSH);
|
|
|
|
|
|
|
|
dc.DrawRectangle(x, y, totalWidth, totalHeight);
|
2000-01-25 19:02:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyCanvas::DrawText(wxDC& dc)
|
|
|
|
{
|
1999-12-08 03:19:45 -05:00
|
|
|
// set underlined font for testing
|
|
|
|
dc.SetFont( wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, TRUE) );
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText( _T("This is text"), 110, 10 );
|
|
|
|
dc.DrawRotatedText( _T("That is text"), 20, 10, -45 );
|
1999-12-08 03:19:45 -05:00
|
|
|
|
2001-08-23 18:08:58 -04:00
|
|
|
// use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated
|
|
|
|
// under Win9x (it is not TrueType)
|
|
|
|
dc.SetFont( *wxSWISS_FONT );
|
1999-07-22 11:05:52 -04:00
|
|
|
|
1999-12-06 19:09:40 -05:00
|
|
|
wxString text;
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.SetBackgroundMode(wxTRANSPARENT);
|
1999-12-06 19:09:40 -05:00
|
|
|
|
|
|
|
for ( int n = -180; n < 180; n += 30 )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
text.Printf(wxT(" %d rotated text"), n);
|
1999-12-06 19:09:40 -05:00
|
|
|
dc.DrawRotatedText(text , 400, 400, n);
|
|
|
|
}
|
1999-12-06 04:35:27 -05:00
|
|
|
|
1999-10-26 14:40:50 -04:00
|
|
|
dc.SetFont( wxFont( 18, wxSWISS, wxNORMAL, wxNORMAL ) );
|
1999-07-23 14:50:12 -04:00
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText( _T("This is Swiss 18pt text."), 110, 40 );
|
1999-07-23 14:50:12 -04:00
|
|
|
|
|
|
|
long length;
|
|
|
|
long height;
|
|
|
|
long descent;
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.GetTextExtent( _T("This is Swiss 18pt text."), &length, &height, &descent );
|
2001-09-21 16:21:44 -04:00
|
|
|
text.Printf( wxT("Dimensions are length %ld, height %ld, descent %ld"), length, height, descent );
|
1999-07-23 14:50:12 -04:00
|
|
|
dc.DrawText( text, 110, 80 );
|
|
|
|
|
2001-09-21 16:21:44 -04:00
|
|
|
text.Printf( wxT("CharHeight() returns: %d"), dc.GetCharHeight() );
|
1999-07-23 14:50:12 -04:00
|
|
|
dc.DrawText( text, 110, 120 );
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
dc.DrawRectangle( 100, 40, 4, height );
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
// test the logical function effect
|
|
|
|
wxCoord y = 150;
|
|
|
|
dc.SetLogicalFunction(wxINVERT);
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText( _T("There should be no text below"), 110, 150 );
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.DrawRectangle( 110, y, 100, height );
|
|
|
|
|
|
|
|
// twice drawn inverted should result in invisible
|
|
|
|
y += height;
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText( _T("Invisible text"), 110, y );
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.DrawRectangle( 110, y, 100, height );
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText( _T("Invisible text"), 110, y );
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.DrawRectangle( 110, y, 100, height );
|
|
|
|
dc.SetLogicalFunction(wxCOPY);
|
|
|
|
|
|
|
|
y += height;
|
|
|
|
dc.DrawRectangle( 110, y, 100, height );
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText( _T("Visible text"), 110, y );
|
2000-01-25 19:02:15 -05:00
|
|
|
}
|
|
|
|
|
2000-02-05 20:30:21 -05:00
|
|
|
static const struct
|
2000-01-25 19:02:15 -05:00
|
|
|
{
|
2000-02-05 20:30:21 -05:00
|
|
|
const wxChar *name;
|
|
|
|
int rop;
|
|
|
|
} rasterOperations[] =
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
{ wxT("wxAND"), wxAND },
|
|
|
|
{ wxT("wxAND_INVERT"), wxAND_INVERT },
|
|
|
|
{ wxT("wxAND_REVERSE"), wxAND_REVERSE },
|
|
|
|
{ wxT("wxCLEAR"), wxCLEAR },
|
|
|
|
{ wxT("wxCOPY"), wxCOPY },
|
|
|
|
{ wxT("wxEQUIV"), wxEQUIV },
|
|
|
|
{ wxT("wxINVERT"), wxINVERT },
|
|
|
|
{ wxT("wxNAND"), wxNAND },
|
|
|
|
{ wxT("wxNO_OP"), wxNO_OP },
|
|
|
|
{ wxT("wxOR"), wxOR },
|
|
|
|
{ wxT("wxOR_INVERT"), wxOR_INVERT },
|
|
|
|
{ wxT("wxOR_REVERSE"), wxOR_REVERSE },
|
|
|
|
{ wxT("wxSET"), wxSET },
|
|
|
|
{ wxT("wxSRC_INVERT"), wxSRC_INVERT },
|
|
|
|
{ wxT("wxXOR"), wxXOR },
|
2000-02-05 20:30:21 -05:00
|
|
|
};
|
2000-01-25 19:02:15 -05:00
|
|
|
|
2000-02-05 20:30:21 -05:00
|
|
|
void MyCanvas::DrawImages(wxDC& dc)
|
|
|
|
{
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("original image"), 0, 0);
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.DrawBitmap(*gs_bmpNoMask, 0, 20, 0);
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("with colour mask"), 0, 100);
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.DrawBitmap(*gs_bmpWithColMask, 0, 120, TRUE);
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("the mask image"), 0, 200);
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.DrawBitmap(*gs_bmpMask, 0, 220, 0);
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("masked image"), 0, 300);
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.DrawBitmap(*gs_bmpWithMask, 0, 320, TRUE);
|
2000-01-25 19:02:15 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
int cx = gs_bmpWithColMask->GetWidth(),
|
|
|
|
cy = gs_bmpWithColMask->GetHeight();
|
2000-01-25 19:02:15 -05:00
|
|
|
|
|
|
|
wxMemoryDC memDC;
|
|
|
|
for ( size_t n = 0; n < WXSIZEOF(rasterOperations); n++ )
|
|
|
|
{
|
|
|
|
wxCoord x = 120 + 150*(n%4),
|
|
|
|
y = 20 + 100*(n/4);
|
2000-01-25 11:33:06 -05:00
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
dc.DrawText(rasterOperations[n].name, x, y - 20);
|
2000-07-15 15:51:35 -04:00
|
|
|
memDC.SelectObject(*gs_bmpWithColMask);
|
2000-01-25 19:02:15 -05:00
|
|
|
dc.Blit(x, y, cx, cy, &memDC, 0, 0, rasterOperations[n].rop, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-05 20:30:21 -05:00
|
|
|
void MyCanvas::DrawWithLogicalOps(wxDC& dc)
|
|
|
|
{
|
|
|
|
static const wxCoord w = 60;
|
|
|
|
static const wxCoord h = 60;
|
|
|
|
|
|
|
|
// reuse the text colour here
|
|
|
|
dc.SetPen(wxPen(m_owner->m_colourForeground, 1, wxSOLID));
|
2000-02-07 20:07:48 -05:00
|
|
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
2000-02-05 20:30:21 -05:00
|
|
|
|
2000-02-15 18:57:33 -05:00
|
|
|
size_t n;
|
|
|
|
for ( n = 0; n < WXSIZEOF(rasterOperations); n++ )
|
2000-02-05 20:30:21 -05:00
|
|
|
{
|
|
|
|
wxCoord x = 20 + 150*(n%4),
|
|
|
|
y = 20 + 100*(n/4);
|
|
|
|
|
|
|
|
dc.DrawText(rasterOperations[n].name, x, y - 20);
|
|
|
|
dc.SetLogicalFunction(rasterOperations[n].rop);
|
2000-02-07 20:07:48 -05:00
|
|
|
dc.DrawRectangle(x, y, w, h);
|
2000-02-05 20:30:21 -05:00
|
|
|
dc.DrawLine(x, y, x + w, y + h);
|
|
|
|
dc.DrawLine(x + w, y, x, y + h);
|
|
|
|
}
|
2000-02-15 10:21:59 -05:00
|
|
|
|
|
|
|
// now some filled rectangles
|
|
|
|
dc.SetBrush(wxBrush(m_owner->m_colourForeground, wxSOLID));
|
|
|
|
|
2000-02-15 18:57:33 -05:00
|
|
|
for ( n = 0; n < WXSIZEOF(rasterOperations); n++ )
|
2000-02-15 10:21:59 -05:00
|
|
|
{
|
|
|
|
wxCoord x = 20 + 150*(n%4),
|
|
|
|
y = 500 + 100*(n/4);
|
|
|
|
|
|
|
|
dc.DrawText(rasterOperations[n].name, x, y - 20);
|
|
|
|
dc.SetLogicalFunction(rasterOperations[n].rop);
|
|
|
|
dc.DrawRectangle(x, y, w, h);
|
|
|
|
}
|
2000-02-05 20:30:21 -05:00
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
void MyCanvas::DrawCircles(wxDC& dc)
|
|
|
|
{
|
|
|
|
int x = 100,
|
|
|
|
y = 100,
|
|
|
|
r = 20;
|
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("Some circles"), 0, y);
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.DrawCircle(x, y, r);
|
|
|
|
dc.DrawCircle(x + 2*r, y, r);
|
|
|
|
dc.DrawCircle(x + 4*r, y, r);
|
|
|
|
|
|
|
|
y += 2*r;
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("And ellipses"), 0, y);
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.DrawEllipse(x - r, y, 2*r, r);
|
|
|
|
dc.DrawEllipse(x + r, y, 2*r, r);
|
|
|
|
dc.DrawEllipse(x + 3*r, y, 2*r, r);
|
|
|
|
|
|
|
|
y += 2*r;
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("And arcs"), 0, y);
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.DrawArc(x - r, y, x + r, y, x, y);
|
|
|
|
dc.DrawArc(x + 4*r, y, x + 2*r, y, x + 3*r, y);
|
|
|
|
dc.DrawArc(x + 5*r, y, x + 5*r, y, x + 6*r, y);
|
|
|
|
|
|
|
|
y += 2*r;
|
|
|
|
dc.DrawEllipticArc(x - r, y, 2*r, r, 0, 90);
|
|
|
|
dc.DrawEllipticArc(x + r, y, 2*r, r, 90, 180);
|
|
|
|
dc.DrawEllipticArc(x + 3*r, y, 2*r, r, 180, 270);
|
|
|
|
dc.DrawEllipticArc(x + 5*r, y, 2*r, r, 270, 360);
|
|
|
|
}
|
|
|
|
|
2000-03-02 14:18:45 -05:00
|
|
|
void MyCanvas::DrawRegions(wxDC& dc)
|
|
|
|
{
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("You should see a red rect partly covered by a cyan one ")
|
|
|
|
_T("on the left"), 10, 5);
|
|
|
|
dc.DrawText(_T("and 5 smileys from which 4 are partially clipped on the right"),
|
2001-06-17 09:25:55 -04:00
|
|
|
10, 5 + dc.GetCharHeight());
|
2002-12-14 13:13:27 -05:00
|
|
|
dc.DrawText(_T("The second copy should be identical but right part of it ")
|
|
|
|
_T("should be offset by 10 pixels."),
|
2002-01-31 19:25:07 -05:00
|
|
|
10, 5 + 2*dc.GetCharHeight());
|
2001-06-17 09:25:55 -04:00
|
|
|
|
2002-01-31 19:25:07 -05:00
|
|
|
DrawRegionsHelper(dc, 10, TRUE);
|
|
|
|
DrawRegionsHelper(dc, 350, FALSE);
|
2001-06-17 09:25:55 -04:00
|
|
|
}
|
2001-06-17 09:14:20 -04:00
|
|
|
|
2002-01-31 19:25:07 -05:00
|
|
|
void MyCanvas::DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime)
|
2001-06-17 09:25:55 -04:00
|
|
|
{
|
2002-01-31 19:25:07 -05:00
|
|
|
wxCoord y = 100;
|
|
|
|
|
2001-06-17 09:25:55 -04:00
|
|
|
dc.DestroyClippingRegion();
|
2000-03-02 14:18:45 -05:00
|
|
|
dc.SetBrush( *wxWHITE_BRUSH );
|
|
|
|
dc.SetPen( *wxTRANSPARENT_PEN );
|
2002-01-31 19:25:07 -05:00
|
|
|
dc.DrawRectangle( x, y, 310, 310 );
|
2001-06-17 09:14:20 -04:00
|
|
|
|
2002-01-31 19:25:07 -05:00
|
|
|
dc.SetClippingRegion( x + 10, y + 10, 100, 270 );
|
2001-06-17 09:14:20 -04:00
|
|
|
|
2000-03-02 14:18:45 -05:00
|
|
|
dc.SetBrush( *wxRED_BRUSH );
|
2002-01-31 19:25:07 -05:00
|
|
|
dc.DrawRectangle( x, y, 310, 310 );
|
2001-06-17 09:14:20 -04:00
|
|
|
|
2002-01-31 19:25:07 -05:00
|
|
|
dc.SetClippingRegion( x + 10, y + 10, 100, 100 );
|
2000-03-04 04:24:17 -05:00
|
|
|
|
|
|
|
dc.SetBrush( *wxCYAN_BRUSH );
|
2002-01-31 19:25:07 -05:00
|
|
|
dc.DrawRectangle( x, y, 310, 310 );
|
|
|
|
|
|
|
|
dc.DestroyClippingRegion();
|
|
|
|
|
|
|
|
wxRegion region(x + 110, y + 20, 100, 270);
|
2002-06-20 07:46:58 -04:00
|
|
|
#if !defined(__WXMOTIF__) && !defined(__WXMAC__)
|
2002-01-31 19:25:07 -05:00
|
|
|
if ( !firstTime )
|
|
|
|
region.Offset(10, 10);
|
2002-04-22 07:19:11 -04:00
|
|
|
#endif
|
2002-01-31 19:25:07 -05:00
|
|
|
dc.SetClippingRegion(region);
|
2001-06-17 09:14:20 -04:00
|
|
|
|
2000-03-02 14:18:45 -05:00
|
|
|
dc.SetBrush( *wxGREY_BRUSH );
|
2002-01-31 19:25:07 -05:00
|
|
|
dc.DrawRectangle( x, y, 310, 310 );
|
2001-06-17 09:14:20 -04:00
|
|
|
|
2000-03-03 15:09:19 -05:00
|
|
|
if (m_smile_bmp.Ok())
|
|
|
|
{
|
2002-01-31 19:25:07 -05:00
|
|
|
dc.DrawBitmap( m_smile_bmp, x + 150, y + 150, TRUE );
|
|
|
|
dc.DrawBitmap( m_smile_bmp, x + 130, y + 10, TRUE );
|
|
|
|
dc.DrawBitmap( m_smile_bmp, x + 130, y + 280, TRUE );
|
|
|
|
dc.DrawBitmap( m_smile_bmp, x + 100, y + 70, TRUE );
|
|
|
|
dc.DrawBitmap( m_smile_bmp, x + 200, y + 70, TRUE );
|
2000-03-03 15:09:19 -05:00
|
|
|
}
|
2000-03-02 14:18:45 -05:00
|
|
|
}
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
PrepareDC(dc);
|
2001-06-17 09:14:20 -04:00
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
m_owner->PrepareDC(dc);
|
|
|
|
|
|
|
|
dc.SetBackgroundMode( m_owner->m_backgroundMode );
|
|
|
|
if ( m_owner->m_backgroundBrush.Ok() )
|
|
|
|
dc.SetBackground( m_owner->m_backgroundBrush );
|
|
|
|
if ( m_owner->m_colourForeground.Ok() )
|
|
|
|
dc.SetTextForeground( m_owner->m_colourForeground );
|
|
|
|
if ( m_owner->m_colourBackground.Ok() )
|
|
|
|
dc.SetTextBackground( m_owner->m_colourBackground );
|
2000-01-25 11:33:06 -05:00
|
|
|
|
2000-02-09 23:56:16 -05:00
|
|
|
if ( m_owner->m_textureBackground) {
|
2000-02-10 00:00:06 -05:00
|
|
|
if ( ! m_owner->m_backgroundBrush.Ok() ) {
|
2000-02-09 23:56:16 -05:00
|
|
|
wxBrush b(wxColour(0,128,0), wxSOLID);
|
|
|
|
dc.SetBackground(b);
|
|
|
|
}
|
2000-02-10 00:00:06 -05:00
|
|
|
}
|
|
|
|
|
2002-06-12 12:15:41 -04:00
|
|
|
if ( m_clip )
|
|
|
|
dc.SetClippingRegion(100, 100, 100, 100);
|
|
|
|
|
2000-03-04 11:23:26 -05:00
|
|
|
dc.Clear();
|
2000-02-09 23:56:16 -05:00
|
|
|
|
2002-06-12 12:15:41 -04:00
|
|
|
if ( m_owner->m_textureBackground )
|
|
|
|
{
|
2000-02-09 23:56:16 -05:00
|
|
|
dc.SetPen(*wxMEDIUM_GREY_PEN);
|
2002-06-12 12:15:41 -04:00
|
|
|
for ( int i = 0; i < 200; i++ )
|
2000-02-09 23:56:16 -05:00
|
|
|
dc.DrawLine(0, i*10, i*10, 0);
|
|
|
|
}
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
switch ( m_show )
|
|
|
|
{
|
|
|
|
case Show_Default:
|
|
|
|
DrawDefault(dc);
|
|
|
|
break;
|
1999-07-22 16:20:42 -04:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
case Show_Circles:
|
|
|
|
DrawCircles(dc);
|
|
|
|
break;
|
|
|
|
|
2000-03-02 14:18:45 -05:00
|
|
|
case Show_Regions:
|
|
|
|
DrawRegions(dc);
|
|
|
|
break;
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
case Show_Text:
|
|
|
|
DrawText(dc);
|
|
|
|
break;
|
1999-07-22 16:20:42 -04:00
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
case Show_Lines:
|
|
|
|
DrawTestLines( 0, 100, 0, dc );
|
2000-07-15 15:51:35 -04:00
|
|
|
DrawTestLines( 0, 320, 1, dc );
|
|
|
|
DrawTestLines( 0, 540, 2, dc );
|
|
|
|
DrawTestLines( 0, 760, 6, dc );
|
2000-01-25 19:02:15 -05:00
|
|
|
break;
|
1999-07-22 16:20:42 -04:00
|
|
|
|
2002-01-02 19:13:35 -05:00
|
|
|
case Show_Brushes:
|
|
|
|
DrawTestBrushes(dc);
|
|
|
|
break;
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
case Show_Polygons:
|
2002-01-02 19:13:35 -05:00
|
|
|
DrawTestPoly(dc);
|
2000-01-25 19:02:15 -05:00
|
|
|
break;
|
1999-07-22 16:20:42 -04:00
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
case Show_Mask:
|
|
|
|
DrawImages(dc);
|
|
|
|
break;
|
2000-02-05 20:30:21 -05:00
|
|
|
|
|
|
|
case Show_Ops:
|
|
|
|
DrawWithLogicalOps(dc);
|
|
|
|
break;
|
2000-01-25 19:02:15 -05:00
|
|
|
}
|
1999-07-22 11:05:52 -04:00
|
|
|
}
|
|
|
|
|
1999-10-10 14:42:43 -04:00
|
|
|
void MyCanvas::OnMouseMove(wxMouseEvent &event)
|
|
|
|
{
|
|
|
|
wxClientDC dc(this);
|
|
|
|
PrepareDC(dc);
|
|
|
|
m_owner->PrepareDC(dc);
|
|
|
|
|
|
|
|
wxPoint pos = event.GetPosition();
|
|
|
|
long x = dc.DeviceToLogicalX( pos.x );
|
|
|
|
long y = dc.DeviceToLogicalY( pos.y );
|
|
|
|
wxString str;
|
2001-09-21 16:21:44 -04:00
|
|
|
str.Printf( wxT("Current mouse position: %d,%d"), (int)x, (int)y );
|
1999-10-10 14:42:43 -04:00
|
|
|
m_owner->SetStatusText( str );
|
|
|
|
}
|
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// the event tables connect the wxWindows events with the functions (event
|
|
|
|
// handlers) which process them. It can be also done at run-time, but for the
|
|
|
|
// simple menu events like this the static method is much simpler.
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2000-01-25 19:02:15 -05:00
|
|
|
EVT_MENU (File_Quit, MyFrame::OnQuit)
|
|
|
|
EVT_MENU (File_About, MyFrame::OnAbout)
|
2002-06-12 12:15:41 -04:00
|
|
|
EVT_MENU (File_Clip, MyFrame::OnClip)
|
2000-01-25 19:02:15 -05:00
|
|
|
|
|
|
|
EVT_MENU_RANGE(MenuShow_First, MenuShow_Last, MyFrame::OnShow)
|
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
EVT_MENU_RANGE(MenuOption_First, MenuOption_Last, MyFrame::OnOption)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
// frame constructor
|
|
|
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
2001-06-17 09:14:20 -04:00
|
|
|
: wxFrame((wxFrame *)NULL, -1, title, pos, size,
|
|
|
|
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
|
1999-05-15 09:33:55 -04:00
|
|
|
{
|
|
|
|
// set the frame icon
|
|
|
|
SetIcon(wxICON(mondrian));
|
|
|
|
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
2002-12-14 13:13:27 -05:00
|
|
|
menuFile->Append(File_ShowDefault, _T("&Default screen\tF1"));
|
|
|
|
menuFile->Append(File_ShowText, _T("&Text screen\tF2"));
|
|
|
|
menuFile->Append(File_ShowLines, _T("&Lines screen\tF3"));
|
|
|
|
menuFile->Append(File_ShowBrushes, _T("&Brushes screen\tF4"));
|
|
|
|
menuFile->Append(File_ShowPolygons, _T("&Polygons screen\tF5"));
|
|
|
|
menuFile->Append(File_ShowMask, _T("&Mask screen\tF6"));
|
|
|
|
menuFile->Append(File_ShowOps, _T("&ROP screen\tF7"));
|
|
|
|
menuFile->Append(File_ShowRegions, _T("Re&gions screen\tF8"));
|
|
|
|
menuFile->Append(File_ShowCircles, _T("&Circles screen\tF9"));
|
2000-01-25 19:02:15 -05:00
|
|
|
menuFile->AppendSeparator();
|
2002-12-14 13:13:27 -05:00
|
|
|
menuFile->AppendCheckItem(File_Clip, _T("&Clip\tCtrl-C"), _T("Clip/unclip drawing"));
|
2002-06-12 12:15:41 -04:00
|
|
|
menuFile->AppendSeparator();
|
2002-12-14 13:13:27 -05:00
|
|
|
menuFile->Append(File_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
|
1999-05-15 09:33:55 -04:00
|
|
|
menuFile->AppendSeparator();
|
2002-12-14 13:13:27 -05:00
|
|
|
menuFile->Append(File_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
wxMenu *menuMapMode = new wxMenu;
|
2002-12-14 13:13:27 -05:00
|
|
|
menuMapMode->Append( MapMode_Text, _T("&TEXT map mode") );
|
|
|
|
menuMapMode->Append( MapMode_Lometric, _T("&LOMETRIC map mode") );
|
|
|
|
menuMapMode->Append( MapMode_Twips, _T("T&WIPS map mode") );
|
|
|
|
menuMapMode->Append( MapMode_Points, _T("&POINTS map mode") );
|
|
|
|
menuMapMode->Append( MapMode_Metric, _T("&METRIC map mode") );
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
wxMenu *menuUserScale = new wxMenu;
|
2002-12-14 13:13:27 -05:00
|
|
|
menuUserScale->Append( UserScale_StretchHoriz, _T("Stretch &horizontally\tCtrl-H") );
|
|
|
|
menuUserScale->Append( UserScale_ShrinkHoriz, _T("Shrin&k horizontally\tCtrl-G") );
|
|
|
|
menuUserScale->Append( UserScale_StretchVertic, _T("Stretch &vertically\tCtrl-V") );
|
|
|
|
menuUserScale->Append( UserScale_ShrinkVertic, _T("&Shrink vertically\tCtrl-W") );
|
1999-05-17 10:10:12 -04:00
|
|
|
menuUserScale->AppendSeparator();
|
2002-12-14 13:13:27 -05:00
|
|
|
menuUserScale->Append( UserScale_Restore, _T("&Restore to normal\tCtrl-0") );
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
wxMenu *menuAxis = new wxMenu;
|
2002-12-14 13:13:27 -05:00
|
|
|
menuAxis->Append( AxisMirror_Horiz, _T("Mirror horizontally\tCtrl-M"), _T(""), TRUE );
|
|
|
|
menuAxis->Append( AxisMirror_Vertic, _T("Mirror vertically\tCtrl-N"), _T(""), TRUE );
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
wxMenu *menuLogical = new wxMenu;
|
2002-12-14 13:13:27 -05:00
|
|
|
menuLogical->Append( LogicalOrigin_MoveDown, _T("Move &down\tCtrl-D") );
|
|
|
|
menuLogical->Append( LogicalOrigin_MoveUp, _T("Move &up\tCtrl-U") );
|
|
|
|
menuLogical->Append( LogicalOrigin_MoveLeft, _T("Move &right\tCtrl-L") );
|
|
|
|
menuLogical->Append( LogicalOrigin_MoveRight, _T("Move &left\tCtrl-R") );
|
2002-02-02 11:08:48 -05:00
|
|
|
menuLogical->AppendSeparator();
|
2002-12-14 13:13:27 -05:00
|
|
|
menuLogical->Append( LogicalOrigin_Set, _T("Set to (&100, 100)\tShift-Ctrl-1") );
|
|
|
|
menuLogical->Append( LogicalOrigin_Restore, _T("&Restore to normal\tShift-Ctrl-0") );
|
1999-05-15 09:33:55 -04:00
|
|
|
|
1999-05-17 10:10:12 -04:00
|
|
|
wxMenu *menuColour = new wxMenu;
|
2002-12-14 13:13:27 -05:00
|
|
|
menuColour->Append( Colour_TextForeground, _T("Text &foreground...") );
|
|
|
|
menuColour->Append( Colour_TextBackground, _T("Text &background...") );
|
|
|
|
menuColour->Append( Colour_Background, _T("Background &colour...") );
|
|
|
|
menuColour->Append( Colour_BackgroundMode, _T("&Opaque/transparent\tCtrl-B"), _T(""), TRUE );
|
|
|
|
menuColour->Append( Colour_TextureBackgound, _T("Draw textured back&ground\tCtrl-T"), _T(""), TRUE);
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
// now append the freshly created menu to the menu bar...
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
2002-12-14 13:13:27 -05:00
|
|
|
menuBar->Append(menuFile, _T("&File"));
|
|
|
|
menuBar->Append(menuMapMode, _T("&Mode"));
|
|
|
|
menuBar->Append(menuUserScale, _T("&Scale"));
|
|
|
|
menuBar->Append(menuAxis, _T("&Axis"));
|
|
|
|
menuBar->Append(menuLogical, _T("&Origin"));
|
|
|
|
menuBar->Append(menuColour, _T("&Colours"));
|
1999-05-15 09:33:55 -04:00
|
|
|
|
|
|
|
// ... and attach this menu bar to the frame
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
|
|
|
// create a status bar just for fun (by default with 1 pane only)
|
|
|
|
CreateStatusBar(2);
|
2002-12-14 13:13:27 -05:00
|
|
|
SetStatusText(_T("Welcome to wxWindows!"));
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-05-15 09:33:55 -04:00
|
|
|
m_mapMode = wxMM_TEXT;
|
|
|
|
m_xUserScale = 1.0;
|
|
|
|
m_yUserScale = 1.0;
|
|
|
|
m_xLogicalOrigin = 0;
|
|
|
|
m_yLogicalOrigin = 0;
|
1999-05-17 10:10:12 -04:00
|
|
|
m_xAxisReversed =
|
|
|
|
m_yAxisReversed = FALSE;
|
|
|
|
m_backgroundMode = wxSOLID;
|
2000-01-24 11:46:40 -05:00
|
|
|
m_colourForeground = *wxRED;
|
|
|
|
m_colourBackground = *wxBLUE;
|
2000-02-09 23:56:16 -05:00
|
|
|
m_textureBackground = FALSE;
|
1999-05-15 09:33:55 -04:00
|
|
|
|
1999-07-22 11:05:52 -04:00
|
|
|
m_canvas = new MyCanvas( this );
|
2000-01-24 11:46:40 -05:00
|
|
|
m_canvas->SetScrollbars( 10, 10, 100, 240 );
|
1999-07-22 11:05:52 -04:00
|
|
|
}
|
1999-05-15 09:33:55 -04:00
|
|
|
|
|
|
|
// event handlers
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// TRUE is to force the frame to close
|
|
|
|
Close(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxString msg;
|
2000-02-17 16:17:54 -05:00
|
|
|
msg.Printf( wxT("This is the about dialog of the drawing sample.\n")
|
|
|
|
wxT("This sample tests various primitive drawing functions\n")
|
2002-01-02 19:13:35 -05:00
|
|
|
wxT("(without any attempts to prevent flicker).\n")
|
2000-02-17 16:17:54 -05:00
|
|
|
wxT("Copyright (c) Robert Roebling 1999")
|
1999-05-15 09:33:55 -04:00
|
|
|
);
|
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
wxMessageBox(msg, _T("About Drawing"), wxOK | wxICON_INFORMATION, this);
|
1999-05-15 09:33:55 -04:00
|
|
|
}
|
|
|
|
|
2002-06-12 12:15:41 -04:00
|
|
|
void MyFrame::OnClip(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
m_canvas->Clip(event.IsChecked());
|
|
|
|
}
|
|
|
|
|
2000-01-25 19:02:15 -05:00
|
|
|
void MyFrame::OnShow(wxCommandEvent& event)
|
|
|
|
{
|
2003-12-11 06:25:46 -05:00
|
|
|
m_canvas->ToShow((ScreenToShow)(event.GetId() - MenuShow_First));
|
2000-01-25 19:02:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnOption(wxCommandEvent& event)
|
1999-05-15 09:33:55 -04:00
|
|
|
{
|
2000-08-08 02:11:51 -04:00
|
|
|
switch (event.GetId())
|
1999-05-15 09:33:55 -04:00
|
|
|
{
|
|
|
|
case MapMode_Text:
|
1999-05-16 15:04:45 -04:00
|
|
|
m_mapMode = wxMM_TEXT;
|
1999-05-17 10:10:12 -04:00
|
|
|
break;
|
1999-05-15 09:33:55 -04:00
|
|
|
case MapMode_Lometric:
|
|
|
|
m_mapMode = wxMM_LOMETRIC;
|
1999-05-17 10:10:12 -04:00
|
|
|
break;
|
|
|
|
case MapMode_Twips:
|
1999-05-15 09:33:55 -04:00
|
|
|
m_mapMode = wxMM_TWIPS;
|
1999-05-17 10:10:12 -04:00
|
|
|
break;
|
|
|
|
case MapMode_Points:
|
1999-05-15 09:33:55 -04:00
|
|
|
m_mapMode = wxMM_POINTS;
|
1999-05-17 10:10:12 -04:00
|
|
|
break;
|
|
|
|
case MapMode_Metric:
|
1999-05-15 09:33:55 -04:00
|
|
|
m_mapMode = wxMM_METRIC;
|
1999-05-17 10:10:12 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LogicalOrigin_MoveDown:
|
|
|
|
m_yLogicalOrigin += 10;
|
|
|
|
break;
|
|
|
|
case LogicalOrigin_MoveUp:
|
|
|
|
m_yLogicalOrigin -= 10;
|
|
|
|
break;
|
|
|
|
case LogicalOrigin_MoveLeft:
|
|
|
|
m_xLogicalOrigin += 10;
|
|
|
|
break;
|
|
|
|
case LogicalOrigin_MoveRight:
|
|
|
|
m_xLogicalOrigin -= 10;
|
|
|
|
break;
|
2002-02-02 11:08:48 -05:00
|
|
|
case LogicalOrigin_Set:
|
|
|
|
m_xLogicalOrigin =
|
|
|
|
m_yLogicalOrigin = -100;
|
|
|
|
break;
|
|
|
|
case LogicalOrigin_Restore:
|
|
|
|
m_xLogicalOrigin =
|
|
|
|
m_yLogicalOrigin = 0;
|
|
|
|
break;
|
1999-05-17 10:10:12 -04:00
|
|
|
|
|
|
|
case UserScale_StretchHoriz:
|
|
|
|
m_xUserScale *= 1.10;
|
|
|
|
break;
|
|
|
|
case UserScale_ShrinkHoriz:
|
|
|
|
m_xUserScale /= 1.10;
|
|
|
|
break;
|
|
|
|
case UserScale_StretchVertic:
|
|
|
|
m_yUserScale *= 1.10;
|
|
|
|
break;
|
|
|
|
case UserScale_ShrinkVertic:
|
|
|
|
m_yUserScale /= 1.10;
|
|
|
|
break;
|
|
|
|
case UserScale_Restore:
|
|
|
|
m_xUserScale =
|
|
|
|
m_yUserScale = 1.0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AxisMirror_Vertic:
|
|
|
|
m_yAxisReversed = !m_yAxisReversed;
|
|
|
|
break;
|
|
|
|
case AxisMirror_Horiz:
|
|
|
|
m_xAxisReversed = !m_xAxisReversed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Colour_TextForeground:
|
|
|
|
m_colourForeground = SelectColour();
|
|
|
|
break;
|
|
|
|
case Colour_TextBackground:
|
|
|
|
m_colourBackground = SelectColour();
|
|
|
|
break;
|
|
|
|
case Colour_Background:
|
|
|
|
{
|
|
|
|
wxColour col = SelectColour();
|
|
|
|
if ( col.Ok() )
|
|
|
|
{
|
|
|
|
m_backgroundBrush.SetColour(col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Colour_BackgroundMode:
|
|
|
|
m_backgroundMode = m_backgroundMode == wxSOLID ? wxTRANSPARENT
|
|
|
|
: wxSOLID;
|
|
|
|
break;
|
|
|
|
|
2000-02-09 23:56:16 -05:00
|
|
|
case Colour_TextureBackgound:
|
|
|
|
m_textureBackground = ! m_textureBackground;
|
|
|
|
break;
|
|
|
|
|
1999-05-17 10:10:12 -04:00
|
|
|
default:
|
|
|
|
// skip Refresh()
|
|
|
|
return;
|
1999-05-15 09:33:55 -04:00
|
|
|
}
|
1999-05-17 10:10:12 -04:00
|
|
|
|
1999-07-22 16:20:42 -04:00
|
|
|
m_canvas->Refresh();
|
1999-05-15 09:33:55 -04:00
|
|
|
}
|
|
|
|
|
1999-05-17 10:35:48 -04:00
|
|
|
void MyFrame::PrepareDC(wxDC& dc)
|
1999-05-15 09:33:55 -04:00
|
|
|
{
|
1999-05-17 10:10:12 -04:00
|
|
|
dc.SetLogicalOrigin( m_xLogicalOrigin, m_yLogicalOrigin );
|
1999-05-17 11:13:24 -04:00
|
|
|
dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed );
|
2002-02-02 11:08:48 -05:00
|
|
|
dc.SetUserScale( m_xUserScale, m_yUserScale );
|
|
|
|
dc.SetMapMode( m_mapMode );
|
1999-05-17 10:35:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
wxColour MyFrame::SelectColour()
|
1999-05-17 10:10:12 -04:00
|
|
|
{
|
|
|
|
wxColour col;
|
|
|
|
wxColourData data;
|
|
|
|
wxColourDialog dialog(this, &data);
|
|
|
|
|
|
|
|
if ( dialog.ShowModal() == wxID_OK )
|
|
|
|
{
|
1999-05-17 11:13:24 -04:00
|
|
|
col = dialog.GetColourData().GetColour();
|
1999-05-17 10:10:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return col;
|
1999-05-15 09:33:55 -04:00
|
|
|
}
|
2003-06-07 07:19:28 -04:00
|
|
|
|