Trying to understand wxCanvas.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8812 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2000-11-24 20:19:39 +00:00
parent c8b7a961ff
commit f9032263ab
21 changed files with 1151 additions and 194 deletions

View File

@@ -0,0 +1,23 @@
#
# File: Makefile.in
# Author: Julian Smart
# Created: 2000
# Updated:
# Copyright: (c) 2000 Julian Smart
#
# "%W% %G%"
#
# Makefile for the multicell example (UNIX).
top_srcdir = @top_srcdir@/..
top_builddir = ../../../..
program_dir = contrib/samples/canvas/simple
PROGRAM=simple
OBJECTS=simple.o
APPEXTRALIBS=$(top_builddir)/lib/libcanvas.@WX_TARGET_LIBRARY_TYPE@
APPEXTRADEFS=-I$(top_srcdir)/contrib/include
include $(top_builddir)/src/makeprog.env

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

View File

@@ -0,0 +1,44 @@
/* XPM */
static char *mondrian_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 6 1",
" c Black",
". c Blue",
"X c #00bf00",
"o c Red",
"O c Yellow",
"+ c Gray100",
/* pixels */
" ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" "
};

View File

@@ -0,0 +1,147 @@
/////////////////////////////////////////////////////////////////////////////
// Name: simple.cpp
// Author: XX
// Created: XX/XX/XX
// Copyright:
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "simple.cpp"
#endif
// For compilers that support precompilation
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// Include private headers
#include "simple.h"
// Include icon header
#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "mondrian.xpm"
#endif
// Include image
#include "smile.xpm"
// WDR: class implementations
//------------------------------------------------------------------------------
// MyFrame
//------------------------------------------------------------------------------
// WDR: event table for MyFrame
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
EVT_MENU(ID_QUIT, MyFrame::OnQuit)
EVT_CLOSE(MyFrame::OnCloseWindow)
END_EVENT_TABLE()
MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &position, const wxSize& size, long style ) :
wxFrame( parent, id, title, position, size, style )
{
CreateMyMenuBar();
CreateStatusBar(1);
SetStatusText( "Welcome!" );
SetIcon(wxICON(mondrian));
// wxCanvas from here
m_admin = new wxCanvasAdmin;
wxCanvas *canvas = new wxCanvas( m_admin, this, -1 );
m_admin->Append( canvas );
m_admin->SetActive( canvas );
wxCanvasObjectGroup *root = new wxCanvasObjectGroup(0,0);
root->DeleteContents( TRUE );
wxCanvasRect *rect;
rect = new wxCanvasRect( 120,10,120,140 );
rect->SetBrush( *wxRED_BRUSH );
root->Append( rect );
/*
wxBitmap bitmap( smile_xpm );
wxImage image( bitmap );
m_smile1 = new wxCanvasImage( image, 0,70,32,32 );
root->Append( m_smile1 );
int i;
for (i = 10; i < 300; i+=10)
{
wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
r->SetBrush( *wxRED_BRUSH );
root->Append( r );
}
m_smile2 = new wxCanvasImage( image, 0,110,32,32 );
root->Append( m_smile2 );
for (i = 15; i < 300; i+=10)
{
wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
r->SetBrush( *wxRED_BRUSH );
root->Append( r );
}
*/
canvas->SetRoot( root );
}
void MyFrame::CreateMyMenuBar()
{
wxMenu *file_menu = new wxMenu;
file_menu->Append( ID_QUIT, "Quit...", "Quit program" );
wxMenuBar *menu_bar = new wxMenuBar();
menu_bar->Append( file_menu, "File" );
SetMenuBar( menu_bar );
}
// WDR: handler implementations for MyFrame
void MyFrame::OnQuit( wxCommandEvent &event )
{
Close( TRUE );
}
void MyFrame::OnCloseWindow( wxCloseEvent &event )
{
// if ! saved changes -> return
Destroy();
}
//------------------------------------------------------------------------------
// MyApp
//------------------------------------------------------------------------------
IMPLEMENT_APP(MyApp)
MyApp::MyApp()
{
}
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( NULL, -1, "SuperApp", wxPoint(20,20), wxSize(500,340) );
frame->Show( TRUE );
return TRUE;
}
int MyApp::OnExit()
{
return 0;
}

View File

@@ -0,0 +1,76 @@
/////////////////////////////////////////////////////////////////////////////
// Name: simple.h
// Author: XX
// Created: XX/XX/XX
// Copyright:
/////////////////////////////////////////////////////////////////////////////
#ifndef __simple_H__
#define __simple_H__
#ifdef __GNUG__
#pragma interface "simple.cpp"
#endif
// Include wxWindows' headers
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "wx/canvas/canvas.h"
//----------------------------------------------------------------------------
// constants
//----------------------------------------------------------------------------
#define ID_QUIT 101
// WDR: class declarations
//----------------------------------------------------------------------------
// MyFrame
//----------------------------------------------------------------------------
class MyFrame: public wxFrame
{
public:
// constructors and destructors
MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE );
private:
// WDR: method declarations for MyFrame
void CreateMyMenuBar();
private:
// WDR: member variable declarations for MyFrame
wxCanvasImage *m_smile1;
wxCanvasImage *m_smile2;
wxCanvasAdmin *m_admin;
private:
// WDR: handler declarations for MyFrame
void OnQuit( wxCommandEvent &event );
void OnCloseWindow( wxCloseEvent &event );
private:
DECLARE_EVENT_TABLE()
};
//----------------------------------------------------------------------------
// MyApp
//----------------------------------------------------------------------------
class MyApp: public wxApp
{
public:
MyApp();
virtual bool OnInit();
virtual int OnExit();
};
#endif

View File

@@ -0,0 +1,3 @@
#include "wx/msw/wx.rc"

Binary file not shown.

View File

@@ -0,0 +1,42 @@
/* XPM */
static char * smile_xpm[] = {
/* width height ncolors chars_per_pixel */
"32 32 4 1",
/* colors */
" s None c None",
". c #000000",
"+ c #ff0000",
"@ c #ffff00",
/* pixels */
" ........ ",
" ...@@@@@@@@... ",
" ..@@@@@@@@@@@@@@.. ",
" ..@@@@@@@@@@@@@@@@.. ",
" .@@@@@@@@@@@@@@@@@@@@. ",
" .@@@@@@@@@@@@@@@@@@@@@@. ",
" .@@@@@@@@@@@@@@@@@@@@@@@@. ",
" ..@@@@@@@@@@@@@@@@@@@@@@@@.. ",
" .@@@@@@@@ @@@@@@ @@@@@@@@. ",
" .@@@@@@@@ @@@@ @@@@@@@@. ",
" .@@@@@@@@ @@@@ @@@@@@@@. ",
" .@@@@@@@@ @@@@ @@@@@@@@. ",
".@@@@@@@@@ @@@@ @@@@@@@@@.",
".@@@@@@@@@ @@@@ @@@@@@@@@.",
".@@@@@@@@@@ @@@@@@ @@@@@@@@@@.",
".@@@@@@@.@@@@@@@@@@@@@@.@@@@@@@.",
".@@@@@@@.@@@@@@@@@@@@@@.@@@@@@@.",
".@@@@@@.@@@@@@@@@@@@@@@@.@@@@@@.",
".@@@....@@@@@@@@@@@@@@@@....@@@.",
".@@@@@@@.@@@@@@@@@@@@@@.@@@@@@@.",
" .@@@@@@@.@@@@@@@@@@@@.@@@@@@@. ",
" .@@@@@@@..@@@@@@@@@@..@@@@@@@. ",
" .@@@@@@@@...@@@@@@...@@@@@@@@. ",
" .@@@@@@@@.+......+.@@@@@@@@. ",
" ..@@@@@@@@.++++++.@@@@@@@@.. ",
" .@@@@@@@@@.++++.@@@@@@@@@. ",
" .@@@@@@@@@....@@@@@@@@@. ",
" .@@@@@@@@@@@@@@@@@@@@. ",
" ..@@@@@@@@@@@@@@@@.. ",
" ..@@@@@@@@@@@@@@.. ",
" ...@@@@@@@@... ",
" ........ "};