Added OGL to contrib

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6407 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2000-03-03 11:25:10 +00:00
parent b14391d1c8
commit 1fc25a89ac
221 changed files with 30863 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
#
# File: Makefile
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright: (c) 2000 Julian Smart
#
# Makefile for OGL demo (GTK version)
#
# This makefile requires wxWindows/GTK to be
# installed (possibly using "make install")
# on your system.
#
CPP = gcc
CC = gcc
WXCONFIG=../../../../wx-config
WXINCLUDE=-I../../../../include -I../../../include
WXLIB=-L../../../../lib -L../../../lib
OBJECTS=ogledit.o palette.o doc.o view.o
ogledit: $(OBJECTS)
$(CPP) -o ogledit $(OBJECTS) `$(WXCONFIG) --libs` $(WXLIB) -logl
ogledit.o: ogledit.cpp
$(CPP) `$(WXCONFIG) --cflags` -I../../src $(WXINCLUDE) -c ogledit.cpp
palette.o: palette.cpp
$(CPP) `$(WXCONFIG) --cflags` -I../../src $(WXINCLUDE) -c palette.cpp
doc.o: doc.cpp
$(CPP) `$(WXCONFIG) --cflags` -I../../src $(WXINCLUDE) -c doc.cpp
view.o: view.cpp
$(CPP) `$(WXCONFIG) --cflags` -I../../src $(WXINCLUDE) -c view.cpp
clean:
rm -f *.o ogledit

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

View File

@@ -0,0 +1,44 @@
/* XPM */
static char *arrow_xpm[] = {
/* columns rows colors chars-per-pixel */
"22 22 16 1",
" c Gray0",
". c #bf0000",
"X c #00bf00",
"o c #bfbf00",
"O c #0000bf",
"+ c #bf00bf",
"@ c #00bfbf",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"######################",
"######################",
"######################",
"######################",
"######################",
"####### ##############",
"####### #############",
"####### ############",
"####### ###########",
"####### ##########",
"####### #########",
"####### ########",
"####### #######",
"####### ##########",
"####### # ##########",
"####### ### #########",
"########### #########",
"############ ########",
"############ ########",
"######################",
"######################",
"######################"
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

View File

@@ -0,0 +1,44 @@
/* XPM */
static char *tool1_xpm[] = {
/* columns rows colors chars-per-pixel */
"22 22 16 1",
" c Gray0",
". c #bf0000",
"X c #00bf00",
"o c #bfbf00",
"O c #0000bf",
"+ c #bf00bf",
"@ c #00bfbf",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"######################",
"######################",
"# ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ##",
"######################",
"######################",
"######################"
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

View File

@@ -0,0 +1,44 @@
/* XPM */
static char *tool2_xpm[] = {
/* columns rows colors chars-per-pixel */
"22 22 16 1",
" c Gray0",
". c #bf0000",
"X c #00bf00",
"o c #bfbf00",
"O c #0000bf",
"+ c #bf00bf",
"@ c #00bfbf",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"######################",
"######################",
"#### #####",
"### ::::::::::::: ####",
"## ::::::::::::::: ###",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"## ::::::::::::::: ###",
"### ::::::::::::: ####",
"#### #####",
"######################",
"######################",
"######################"
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

View File

@@ -0,0 +1,44 @@
/* XPM */
static char *tool3_xpm[] = {
/* columns rows colors chars-per-pixel */
"22 22 16 1",
" c Gray0",
". c #bf0000",
"X c #00bf00",
"o c #bfbf00",
"O c #0000bf",
"+ c #bf00bf",
"@ c #00bfbf",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"######################",
"######################",
"######################",
"######################",
"####### ########",
"#### ::::::: #####",
"### ::::::::::::: ####",
"## ::::::::::::::: ###",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"# ::::::::::::::::: ##",
"## ::::::::::::::: ###",
"### ::::::::::::: ####",
"#### ::::::: #####",
"###### ########",
"######################",
"######################",
"######################",
"######################",
"######################",
"######################"
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

View File

@@ -0,0 +1,44 @@
/* XPM */
static char *tool4_xpm[] = {
/* columns rows colors chars-per-pixel */
"22 22 16 1",
" c Gray0",
". c #bf0000",
"X c #00bf00",
"o c #bfbf00",
"O c #0000bf",
"+ c #bf00bf",
"@ c #00bfbf",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"######################",
"######################",
"######################",
"########## ##########",
"######### :: #########",
"######## :::: ########",
"####### :::::: #######",
"###### :::::::: ######",
"##### :::::::::: #####",
"#### :::::::::::: ####",
"### :::::::::::::: ###",
"### :::::::::::::: ###",
"#### :::::::::::: ####",
"##### :::::::::: #####",
"###### :::::::: ######",
"####### :::::: #######",
"######## :::: ########",
"######### :: #########",
"########## ##########",
"######################",
"######################",
"######################"
};

View File

@@ -0,0 +1,611 @@
/////////////////////////////////////////////////////////////////////////////
// Name: doc.cpp
// Purpose: Implements document functionality in OGLEdit
// Author: Julian Smart
// Modified by:
// Created: 12/07/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
// #pragma implementation
#endif
// For compilers that support precompilation, includes "wx.h".
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#if !wxUSE_DOC_VIEW_ARCHITECTURE
#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h!
#endif
#include <wx/wxexpr.h>
#include "ogledit.h"
#include "doc.h"
#include "view.h"
#if wxUSE_STD_IOSTREAM
#include <iostream.h>
#endif
IMPLEMENT_DYNAMIC_CLASS(DiagramDocument, wxDocument)
DiagramDocument::DiagramDocument(void)
{
}
DiagramDocument::~DiagramDocument(void)
{
}
bool DiagramDocument::OnCloseDocument(void)
{
diagram.DeleteAllShapes();
return TRUE;
}
#if wxUSE_STD_IOSTREAM
ostream& DiagramDocument::SaveObject(ostream& stream)
{
wxDocument::SaveObject(stream);
char buf[400];
(void) wxGetTempFileName("diag", buf);
diagram.SaveFile(buf);
wxTransferFileToStream(buf, stream);
wxRemoveFile(buf);
return stream;
}
istream& DiagramDocument::LoadObject(istream& stream)
{
wxDocument::LoadObject(stream);
char buf[400];
(void) wxGetTempFileName("diag", buf);
wxTransferStreamToFile(stream, buf);
diagram.DeleteAllShapes();
diagram.LoadFile(buf);
wxRemoveFile(buf);
return stream;
}
#else
wxOutputStream& DiagramDocument::SaveObject(wxOutputStream& stream)
{
wxDocument::SaveObject(stream);
char buf[400];
(void) wxGetTempFileName("diag", buf);
diagram.SaveFile(buf);
wxTransferFileToStream(buf, stream);
wxRemoveFile(buf);
return stream;
}
wxInputStream& DiagramDocument::LoadObject(wxInputStream& stream)
{
wxDocument::LoadObject(stream);
char buf[400];
(void) wxGetTempFileName("diag", buf);
wxTransferStreamToFile(stream, buf);
diagram.DeleteAllShapes();
diagram.LoadFile(buf);
wxRemoveFile(buf);
return stream;
}
#endif
/*
* Implementation of drawing command
*/
DiagramCommand::DiagramCommand(char *name, int command, DiagramDocument *ddoc, wxClassInfo *info, double xx, double yy,
bool sel, wxShape *theShape, wxShape *fs, wxShape *ts):
wxCommand(TRUE, name)
{
doc = ddoc;
cmd = command;
shape = theShape;
fromShape = fs;
toShape = ts;
shapeInfo = info;
shapeBrush = NULL;
shapePen = NULL;
x = xx;
y = yy;
selected = sel;
deleteShape = FALSE;
}
DiagramCommand::DiagramCommand(char *name, int command, DiagramDocument *ddoc, wxBrush *backgroundColour, wxShape *theShape):
wxCommand(TRUE, name)
{
doc = ddoc;
cmd = command;
shape = theShape;
fromShape = NULL;
toShape = NULL;
shapeInfo = NULL;
x = 0.0;
y = 0.0;
selected = FALSE;
deleteShape = FALSE;
shapeBrush = backgroundColour;
shapePen = NULL;
}
DiagramCommand::DiagramCommand(char *name, int command, DiagramDocument *ddoc, const wxString& lab, wxShape *theShape):
wxCommand(TRUE, name)
{
doc = ddoc;
cmd = command;
shape = theShape;
fromShape = NULL;
toShape = NULL;
shapeInfo = NULL;
x = 0.0;
y = 0.0;
selected = FALSE;
deleteShape = FALSE;
shapeBrush = NULL;
shapePen = NULL;
shapeLabel = lab;
}
DiagramCommand::~DiagramCommand(void)
{
if (shape && deleteShape)
{
shape->SetCanvas(NULL);
delete shape;
}
}
bool DiagramCommand::Do(void)
{
switch (cmd)
{
case OGLEDIT_CUT:
{
if (shape)
{
deleteShape = TRUE;
shape->Select(FALSE);
// Generate commands to explicitly remove each connected line.
RemoveLines(shape);
doc->GetDiagram()->RemoveShape(shape);
if (shape->IsKindOf(CLASSINFO(wxLineShape)))
{
wxLineShape *lineShape = (wxLineShape *)shape;
fromShape = lineShape->GetFrom();
toShape = lineShape->GetTo();
}
shape->Unlink();
doc->Modify(TRUE);
doc->UpdateAllViews();
}
break;
}
case OGLEDIT_ADD_SHAPE:
{
wxShape *theShape = NULL;
if (shape)
theShape = shape; // Saved from undoing the shape
else
{
theShape = (wxShape *)shapeInfo->CreateObject();
theShape->AssignNewIds();
theShape->SetEventHandler(new MyEvtHandler(theShape, theShape, wxString("")));
theShape->SetCentreResize(FALSE);
theShape->SetPen(wxBLACK_PEN);
theShape->SetBrush(wxCYAN_BRUSH);
theShape->SetSize(60, 60);
}
doc->GetDiagram()->AddShape(theShape);
theShape->Show(TRUE);
wxClientDC dc(theShape->GetCanvas());
theShape->GetCanvas()->PrepareDC(dc);
theShape->Move(dc, x, y);
shape = theShape;
deleteShape = FALSE;
doc->Modify(TRUE);
doc->UpdateAllViews();
break;
}
case OGLEDIT_ADD_LINE:
{
wxShape *theShape = NULL;
if (shape)
theShape = shape; // Saved from undoing the line
else
{
theShape = (wxShape *)shapeInfo->CreateObject();
theShape->AssignNewIds();
theShape->SetEventHandler(new MyEvtHandler(theShape, theShape, wxString("")));
theShape->SetPen(wxBLACK_PEN);
theShape->SetBrush(wxRED_BRUSH);
wxLineShape *lineShape = (wxLineShape *)theShape;
// Yes, you can have more than 2 control points, in which case
// it becomes a multi-segment line.
lineShape->MakeLineControlPoints(2);
lineShape->AddArrow(ARROW_ARROW, ARROW_POSITION_END, 10.0, 0.0, "Normal arrowhead");
}
doc->GetDiagram()->AddShape(theShape);
fromShape->AddLine((wxLineShape *)theShape, toShape);
theShape->Show(TRUE);
wxClientDC dc(theShape->GetCanvas());
theShape->GetCanvas()->PrepareDC(dc);
// It won't get drawn properly unless you move both
// connected images
fromShape->Move(dc, fromShape->GetX(), fromShape->GetY());
toShape->Move(dc, toShape->GetX(), toShape->GetY());
shape = theShape;
deleteShape = FALSE;
doc->Modify(TRUE);
doc->UpdateAllViews();
break;
}
case OGLEDIT_CHANGE_BACKGROUND_COLOUR:
{
if (shape)
{
wxClientDC dc(shape->GetCanvas());
shape->GetCanvas()->PrepareDC(dc);
wxBrush *oldBrush = shape->GetBrush();
shape->SetBrush(shapeBrush);
shapeBrush = oldBrush;
shape->Draw(dc);
doc->Modify(TRUE);
doc->UpdateAllViews();
}
break;
}
case OGLEDIT_EDIT_LABEL:
{
if (shape)
{
MyEvtHandler *myHandler = (MyEvtHandler *)shape->GetEventHandler();
wxString oldLabel(myHandler->label);
myHandler->label = shapeLabel;
shapeLabel = oldLabel;
wxClientDC dc(shape->GetCanvas());
shape->GetCanvas()->PrepareDC(dc);
shape->FormatText(dc, (char*) (const char*) myHandler->label);
shape->Draw(dc);
doc->Modify(TRUE);
doc->UpdateAllViews();
}
break;
}
}
return TRUE;
}
bool DiagramCommand::Undo(void)
{
switch (cmd)
{
case OGLEDIT_CUT:
{
if (shape)
{
doc->GetDiagram()->AddShape(shape);
shape->Show(TRUE);
if (shape->IsKindOf(CLASSINFO(wxLineShape)))
{
wxLineShape *lineShape = (wxLineShape *)shape;
fromShape->AddLine(lineShape, toShape);
}
if (selected)
shape->Select(TRUE);
deleteShape = FALSE;
}
doc->Modify(TRUE);
doc->UpdateAllViews();
break;
}
case OGLEDIT_ADD_SHAPE:
case OGLEDIT_ADD_LINE:
{
if (shape)
{
wxClientDC dc(shape->GetCanvas());
shape->GetCanvas()->PrepareDC(dc);
shape->Select(FALSE, &dc);
doc->GetDiagram()->RemoveShape(shape);
shape->Unlink();
deleteShape = TRUE;
}
doc->Modify(TRUE);
doc->UpdateAllViews();
break;
}
case OGLEDIT_CHANGE_BACKGROUND_COLOUR:
{
if (shape)
{
wxClientDC dc(shape->GetCanvas());
shape->GetCanvas()->PrepareDC(dc);
wxBrush *oldBrush = shape->GetBrush();
shape->SetBrush(shapeBrush);
shapeBrush = oldBrush;
shape->Draw(dc);
doc->Modify(TRUE);
doc->UpdateAllViews();
}
break;
}
case OGLEDIT_EDIT_LABEL:
{
if (shape)
{
MyEvtHandler *myHandler = (MyEvtHandler *)shape->GetEventHandler();
wxString oldLabel(myHandler->label);
myHandler->label = shapeLabel;
shapeLabel = oldLabel;
wxClientDC dc(shape->GetCanvas());
shape->GetCanvas()->PrepareDC(dc);
shape->FormatText(dc, (char*) (const char*) myHandler->label);
shape->Draw(dc);
doc->Modify(TRUE);
doc->UpdateAllViews();
}
break;
}
}
return TRUE;
}
// Remove each individual line connected to a shape by sending a command.
void DiagramCommand::RemoveLines(wxShape *shape)
{
wxNode *node = shape->GetLines().First();
while (node)
{
wxLineShape *line = (wxLineShape *)node->Data();
doc->GetCommandProcessor()->Submit(new DiagramCommand("Cut", OGLEDIT_CUT, doc, NULL, 0.0, 0.0, line->Selected(), line));
node = shape->GetLines().First();
}
}
/*
* MyEvtHandler: an event handler class for all shapes
*/
void MyEvtHandler::OnLeftClick(double x, double y, int keys, int attachment)
{
wxClientDC dc(GetShape()->GetCanvas());
GetShape()->GetCanvas()->PrepareDC(dc);
if (keys == 0)
{
// Selection is a concept the library knows about
if (GetShape()->Selected())
{
GetShape()->Select(FALSE, &dc);
GetShape()->GetCanvas()->Redraw(dc); // Redraw because bits of objects will be are missing
}
else
{
// Ensure no other shape is selected, to simplify Undo/Redo code
bool redraw = FALSE;
wxNode *node = GetShape()->GetCanvas()->GetDiagram()->GetShapeList()->First();
while (node)
{
wxShape *eachShape = (wxShape *)node->Data();
if (eachShape->GetParent() == NULL)
{
if (eachShape->Selected())
{
eachShape->Select(FALSE, &dc);
redraw = TRUE;
}
}
node = node->Next();
}
GetShape()->Select(TRUE, &dc);
if (redraw)
GetShape()->GetCanvas()->Redraw(dc);
}
}
else if (keys & KEY_CTRL)
{
// Do something for CONTROL
}
else
{
wxGetApp().frame->SetStatusText(label);
}
}
/*
* Implement connection of two shapes by right-dragging between them.
*/
void MyEvtHandler::OnBeginDragRight(double x, double y, int keys, int attachment)
{
// Force attachment to be zero for now. Eventually we can deal with
// the actual attachment point, e.g. a rectangle side if attachment mode is on.
attachment = 0;
wxClientDC dc(GetShape()->GetCanvas());
GetShape()->GetCanvas()->PrepareDC(dc);
wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
dc.SetLogicalFunction(OGLRBLF);
dc.SetPen(dottedPen);
double xp, yp;
GetShape()->GetAttachmentPosition(attachment, &xp, &yp);
dc.DrawLine((long) xp, (long) yp, (long) x, (long) y);
GetShape()->GetCanvas()->CaptureMouse();
}
void MyEvtHandler::OnDragRight(bool draw, double x, double y, int keys, int attachment)
{
// Force attachment to be zero for now
attachment = 0;
wxClientDC dc(GetShape()->GetCanvas());
GetShape()->GetCanvas()->PrepareDC(dc);
wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
dc.SetLogicalFunction(OGLRBLF);
dc.SetPen(dottedPen);
double xp, yp;
GetShape()->GetAttachmentPosition(attachment, &xp, &yp);
dc.DrawLine((long) xp, (long) yp, (long) x, (long) y);
}
void MyEvtHandler::OnEndDragRight(double x, double y, int keys, int attachment)
{
GetShape()->GetCanvas()->ReleaseMouse();
MyCanvas *canvas = (MyCanvas *)GetShape()->GetCanvas();
// Check if we're on an object
int new_attachment;
wxShape *otherShape = canvas->FindFirstSensitiveShape(x, y, &new_attachment, OP_DRAG_RIGHT);
if (otherShape && !otherShape->IsKindOf(CLASSINFO(wxLineShape)))
{
canvas->view->GetDocument()->GetCommandProcessor()->Submit(
new DiagramCommand("wxLineShape", OGLEDIT_ADD_LINE, (DiagramDocument *)canvas->view->GetDocument(), CLASSINFO(wxLineShape),
0.0, 0.0, FALSE, NULL, GetShape(), otherShape));
}
}
void MyEvtHandler::OnEndSize(double x, double y)
{
wxClientDC dc(GetShape()->GetCanvas());
GetShape()->GetCanvas()->PrepareDC(dc);
GetShape()->FormatText(dc, (char*) (const char*) label);
}
/*
* Diagram
*/
bool MyDiagram::OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr)
{
wxDiagram::OnShapeSave(db, shape, expr);
MyEvtHandler *handler = (MyEvtHandler *)shape.GetEventHandler();
expr.AddAttributeValueString("label", handler->label);
return TRUE;
}
bool MyDiagram::OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr)
{
wxDiagram::OnShapeLoad(db, shape, expr);
char *label = NULL;
expr.AssignAttributeValue("label", &label);
MyEvtHandler *handler = new MyEvtHandler(&shape, &shape, wxString(label));
shape.SetEventHandler(handler);
if (label)
delete[] label;
return TRUE;
}
/*
* New shapes
*/
IMPLEMENT_DYNAMIC_CLASS(wxRoundedRectangleShape, wxRectangleShape)
wxRoundedRectangleShape::wxRoundedRectangleShape(double w, double h):
wxRectangleShape(w, h)
{
// 0.3 of the smaller rectangle dimension
SetCornerRadius((double) -0.3);
}
IMPLEMENT_DYNAMIC_CLASS(wxDiamondShape, wxPolygonShape)
wxDiamondShape::wxDiamondShape(double w, double h):
wxPolygonShape()
{
// wxPolygonShape::SetSize relies on the shape having non-zero
// size initially.
if (w == 0.0)
w = 60.0;
if (h == 0.0)
h = 60.0;
wxList *thePoints = new wxList;
wxRealPoint *point = new wxRealPoint(0.0, (-h/2.0));
thePoints->Append((wxObject*) point);
point = new wxRealPoint((w/2.0), 0.0);
thePoints->Append((wxObject*) point);
point = new wxRealPoint(0.0, (h/2.0));
thePoints->Append((wxObject*) point);
point = new wxRealPoint((-w/2.0), 0.0);
thePoints->Append((wxObject*) point);
Create(thePoints);
}

View File

@@ -0,0 +1,182 @@
/////////////////////////////////////////////////////////////////////////////
// Name: doc.h
// Purpose: Document classes
// Author: Julian Smart
// Modified by:
// Created: 12/07/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _OGLSAMPLE_DOC_H_
#define _OGLSAMPLE_DOC_H_
#ifdef __GNUG__
// #pragma interface
#endif
#include <wx/docview.h>
#include <wx/string.h>
#include <wx/wxexpr.h>
#include <wx/ogl/ogl.h>
#if wxUSE_STD_IOSTREAM
class ostream;
class istream;
#endif
/*
* Override a few members for this application
*/
class MyDiagram: public wxDiagram
{
public:
MyDiagram(void) {}
bool OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
bool OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
};
/*
* A few new shape classes so we have a 1:1 mapping
* between palette symbol and unique class
*/
class wxRoundedRectangleShape: public wxRectangleShape
{
DECLARE_DYNAMIC_CLASS(wxRoundedRectangleShape)
private:
public:
wxRoundedRectangleShape(double w = 0.0, double h = 0.0);
};
class wxDiamondShape: public wxPolygonShape
{
DECLARE_DYNAMIC_CLASS(wxDiamondShape)
private:
public:
wxDiamondShape(double w = 0.0, double h = 0.0);
};
/*
* All shape event behaviour is routed through this handler, so we don't
* have to derive from each shape class. We plug this in to each shape.
*/
class MyEvtHandler: public wxShapeEvtHandler
{
public:
wxString label;
MyEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL, const wxString& lab = ""):wxShapeEvtHandler(prev, shape)
{
label = lab;
}
~MyEvtHandler(void)
{
}
void OnLeftClick(double x, double y, int keys = 0, int attachment = 0);
void OnBeginDragRight(double x, double y, int keys = 0, int attachment = 0);
void OnDragRight(bool draw, double x, double y, int keys = 0, int attachment = 0);
void OnEndDragRight(double x, double y, int keys = 0, int attachment = 0);
void OnEndSize(double x, double y);
};
/*
* A diagram document, which contains a diagram.
*/
class DiagramDocument: public wxDocument
{
DECLARE_DYNAMIC_CLASS(DiagramDocument)
private:
public:
MyDiagram diagram;
DiagramDocument(void);
~DiagramDocument(void);
#if wxUSE_STD_IOSTREAM
virtual ostream& SaveObject(ostream& stream);
virtual istream& LoadObject(istream& stream);
#else
virtual wxOutputStream& SaveObject(wxOutputStream& stream);
virtual wxInputStream& LoadObject(wxInputStream& stream);
#endif
inline wxDiagram *GetDiagram() { return &diagram; }
bool OnCloseDocument(void);
};
/*
* Most user interface commands are routed through this, to give us the
* Undo/Redo mechanism. If you add more commands, such as changing the shape colour,
* you will need to add members to 'remember' what the user applied (for 'Do') and what the
* previous state was (for 'Undo').
* You can have one member for each property to be changed. Assume we also have
* a pointer member wxShape *shape, which is set to the shape being changed.
* Let's assume we're changing the shape colour. Our member for this is shapeColour.
*
* - In 'Do':
* o Set a temporary variable 'temp' to the current colour for 'shape'.
* o Change the colour to the new colour.
* o Set shapeColour to the _old_ colour, 'temp'.
* - In 'Undo':
* o Set a temporary variable 'temp' to the current colour for 'shape'.
* o Change the colour to shapeColour (the old colour).
* o Set shapeColour to 'temp'.
*
* So, as long as we have a pointer to the shape being changed,
* we only need one member variable for each property.
*
* PROBLEM: when an Add shape command is redone, the 'shape' pointer changes.
* Assume, as here, that we keep a pointer to the old shape so we reuse it
* when we recreate.
*/
class DiagramCommand: public wxCommand
{
protected:
DiagramDocument *doc;
int cmd;
wxShape *shape; // Pointer to the shape we're acting on
wxShape *fromShape;
wxShape *toShape;
wxClassInfo *shapeInfo;
double x;
double y;
bool selected;
bool deleteShape;
// Storage for property commands
wxBrush *shapeBrush;
wxPen *shapePen;
wxString shapeLabel;
public:
// Multi-purpose constructor for creating, deleting shapes
DiagramCommand(char *name, int cmd, DiagramDocument *ddoc, wxClassInfo *shapeInfo = NULL,
double x = 0.0, double y = 0.0, bool sel = FALSE, wxShape *theShape = NULL, wxShape *fs = NULL, wxShape *ts = NULL);
// Property-changing command constructors
DiagramCommand(char *name, int cmd, DiagramDocument *ddoc, wxBrush *backgroundColour, wxShape *theShape);
DiagramCommand(char *name, int cmd, DiagramDocument *ddoc, const wxString& lab, wxShape *theShape);
~DiagramCommand(void);
bool Do(void);
bool Undo(void);
inline void SetShape(wxShape *s) { shape = s; }
inline wxShape *GetShape(void) { return shape; }
inline wxShape *GetFromShape(void) { return fromShape; }
inline wxShape *GetToShape(void) { return toShape; }
inline wxClassInfo *GetShapeInfo(void) { return shapeInfo; }
inline bool GetSelected(void) { return selected; }
void RemoveLines(wxShape *shape);
};
#endif
// _OGLSAMPLE_DOC_H_

View File

@@ -0,0 +1,18 @@
#
# File: makefile.b32
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright:
#
# Makefile : Builds sample for 32-bit BC++
WXDIR = $(WXWIN)
TARGET=ogledit
EXTRALIBS=$(WXDIR)\contrib\lib\ogl.lib
# EXTRACPPFLAGS=-I$(WXDIR)\utils\ogl\src
OBJECTS = $(TARGET).obj doc.obj view.obj palette.obj
!include $(WXDIR)\src\makeprog.b32

View File

@@ -0,0 +1,21 @@
#
# File: makefile.bcc
# Author: Julian Smart
# Created: 1998
# Updated:
#
# Builds a BC++ 16-bit sample
!if "$(WXWIN)" == ""
!error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx
!endif
WXDIR = $(WXWIN)
TARGET=ogledit
EXTRALIBS=$(WXDIR)\contrib\lib\ogl.lib
# EXTRACPPFLAGS=-I$(WXDIR)\utils\ogl\src
OBJECTS = $(TARGET).obj doc.obj view.obj palette.obj
!include $(WXDIR)\src\makeprog.b32

View File

@@ -0,0 +1,88 @@
#
# File: makefile.dos
# Author: Julian Smart
# Created: 1995
# Updated:
# Copyright: (c) 1995, AIAI, University of Edinburgh
#
# "%W% %G%"
#
# Makefile : Builds OGLEdit example (MSVC++ 1.5).
# Use FINAL=1 argument to nmake to build final version with no debugging
# info
WXDIR = $(WXWIN)
!include $(WXDIR)\src\makemsc.env
THISDIR = $(WXDIR)\contrib\samples\ogl\ogledit
WXLIB = $(WXDIR)\contrib\lib\wx.lib
OGLLIB = $(WXDIR)\contrib\lib\ogl.lib
LIBS=$(WXLIB) $(OGLLIB) oldnames libw llibcew commdlg shell ddeml
OBJECTS = ogledit.obj doc.obj view.obj palette.obj
all: ogledit.exe
wx:
cd $(WXDIR)\src\msw
nmake -f makefile.dos
cd $(THISDIR)
wxclean:
cd $(WXDIR)\src\msw
nmake -f makefile.dos clean
cd $(THISDIR)
ogl:
cd $(OGLDIR)\src
nmake -f makefile.dos FINAL=$(FINAL)
cd $(THISDIR)
prologio:
cd $(PROLOGDIR)\src
nmake -f makefile.dos FINAL=$(FINAL)
cd $(THISDIR)
ogledit.exe: $(WXDIR)\src\msw\dummy.obj $(WXLIB) $(OBJECTS) $(OGLLIB) ogledit.def ogledit.res
link $(LINKFLAGS) @<<
$(WXDIR)\src\msw\dummy.obj $(OBJECTS),
ogledit,
NUL,
$(LIBS),
ogledit.def
;
<<
rc -30 -K ogledit.res
ogledit.obj: ogledit.h ogledit.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
view.obj: view.h view.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
doc.obj: doc.h doc.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
palette.obj: view.h doc.h ogledit.h palette.$(SRCSUFF) $(DUMMYOBJ)
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
ogledit.res : ogledit.rc $(WXDIR)\include\msw\wx.rc
rc -r /dFAFA_LIB /i$(WXDIR)\include /i$(WXDIR)\contrib\include ogledit
clean:
-erase *.obj
-erase *.exe
-erase *.res
-erase *.map
-erase *.sbr
-erase *.pdb

View File

@@ -0,0 +1,18 @@
#
# File: makefile.g95
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright: (c) Julian Smart, 1999
#
# Makefile for wxWindows sample (Cygwin/Mingw32).
WXDIR = ../../../..
TARGET=ogledit
# EXTRACPPFLAGS=-I../../src
EXTRALIBS=-logl
OBJECTS = $(TARGET).o doc.o view.o palette.o
include $(WXDIR)/src/makeprog.g95

View File

@@ -0,0 +1,20 @@
#
# File: makefile.unx
# Author: Julian Smart
# Created: 1998
# Updated:
# Copyright: (c) 1998 Julian Smart
#
# "%W% %G%"
#
# Makefile for OGLEdit example (UNIX).
PROGRAM=ogledit
OBJECTS=$(PROGRAM).o doc.o view.o palette.o
# EXTRACPPFLAGS=-I$(WXDIR)/contrib/include
EXTRALDLIBS=-logl$(GUISUFFIX)
include ../../../../src/makeprog.env

View File

@@ -0,0 +1,29 @@
#
# File: makefile.vc
# Author: Julian Smart
# Created: 1993
# Updated:
# Copyright: (c) 1993, AIAI, University of Edinburgh
#
# "%W% %G%"
#
# Makefile : Builds ogledit example (MS VC++).
# Use FINAL=1 argument to nmake to build final version with no debugging
# info
# Set WXDIR for your system
WXDIR = $(WXWIN)
PROGRAM=ogledit
FINAL=0
!if "$(FINAL)" == "0"
EXTRALIBS=$(WXDIR)\contrib\lib\ogl_d.lib
!else
EXTRALIBS=$(WXDIR)\contrib\lib\ogl.lib
!endif
OBJECTS = $(PROGRAM).obj doc.obj view.obj palette.obj
!include $(WXDIR)\src\makeprog.vc

View File

@@ -0,0 +1,44 @@
#************************************************************************
# Makefile for DOCVIEW under VMS
# by Stefan Hammes
# (incomplete) update history:
# 09.06.95
#************************************************************************
#************************************************************************
# Definition section
# (cave: definitions and includes must begin with ',')
#************************************************************************
APPOPTS =
APPDEFS =
APPINCS =
#************************************************************************
# Module section
#************************************************************************
# Name of main module
MAIN = docview
# Object modules of the application.
OBJS = docview.obj view.obj doc.obj
OBJLIST =docview.obj,view.obj,doc.obj
.include [--.src]makevms.env
# main dependency
$(MAIN).exe : $(OBJS)
$(LINK) $(LINKFLAGS) /exec=$(MAIN).exe $(OBJLIST),$(WXLIB)/lib,$(OPTSFILE)/option
- purge *.exe
#************************************************************************
# Header file depedencies following
#************************************************************************
docview.$(OBJSUFF) : docview.$(SRCSUFF) docview.h doc.h view.h
doc.$(OBJSUFF) : doc.$(SRCSUFF) doc.h
view.$(OBJSUFF) : view.$(SRCSUFF) view.h

View File

@@ -0,0 +1,15 @@
#
# Makefile for WATCOM
#
# Created by D.Chubraev, chubraev@iem.ee.ethz.ch
# 8 Nov 1994
#
WXDIR = $(%WXWIN)
PROGRAM = ogledit
EXTRALIBS = $(WXDIR)\contrib\lib\ogl.lib
OBJECTS = $(PROGRAM).obj doc.obj view.obj palette.obj
!include $(WXDIR)\src\makeprog.wat

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

View File

@@ -0,0 +1,45 @@
/* XPM */
static char * ogl_xpm[] = {
/* width height ncolors chars_per_pixel */
"32 32 7 1",
/* colors */
" s None c None",
". c #000000",
"+ c #000080",
"@ c #ff0000",
"# c #00ff00",
"$ c #00ffff",
"% c #ffffff",
/* pixels */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"%............%%%%%%........%%%%%",
"%.@@@@@@@@@@.%%%%..$$$$$$$$..%%%",
"%.@@@@@@@@@@.%%%.$$$$$$$$$$$$.%%",
"%.@@@@@@@@@@.+++.$$$$$$$$$$$$.%%",
"%.@@@@@@@@@@.+++.$$$$$$$$$$$$.%%",
"%.@@@@@@@@@@.%%%.$$$$$$$$$$$$.%%",
"%.@@@@@@@@@@.%%%%..$$$$$$$$..%%%",
"%............%%%%%.........%%%%%",
"%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%",
"%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%",
"%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%",
"%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%",
"%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%",
"%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%",
"%%%%%%+.%%%%%%%%%%%%%%++%%%%%%%%",
"%%%%%%.+.%%%%%%%%%%%%.++..%%%%%%",
"%%%%%.+++.%%%%%%%%%..#####..%%%%",
"%%%%.+++++.%%%%%%%.#########.%%%",
"%%%.+++++++.%%%%%%.#########.%%%",
"%%.+++++++++.%%%%.###########.%%",
"%.+++++++++++.++++###########.%%",
"%%.+++++++++.+++++###########.%%",
"%%%.+++++++.%%%%%%.#########.%%%",
"%%%%.+++++.%%%%%%%.#########.%%%",
"%%%%%.+++.%%%%%%%%%..#####..%%%%",
"%%%%%%.+.%%%%%%%%%%%%.....%%%%%%",
"%%%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"};

View File

@@ -0,0 +1,213 @@
/////////////////////////////////////////////////////////////////////////////
// Name: ogledit.cpp
// Purpose: OGLEdit sample app
// Author: Julian Smart
// Modified by:
// Created: 12/07/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
// #pragma implementation
#endif
// For compilers that support precompilation, includes "wx.h".
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#if !wxUSE_DOC_VIEW_ARCHITECTURE
#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h!
#endif
#include "ogledit.h"
#include "palette.h"
#include "doc.h"
#include "view.h"
#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "ogl.xpm"
#endif
// A macro needed for some compilers (AIX) that need 'main' to be defined
// in the application itself.
IMPLEMENT_APP(MyApp)
MyApp::MyApp(void)
{
frame = NULL;
myDocManager= NULL;
}
// The `main program' equivalent, creating the windows and returning the
// main frame
bool MyApp::OnInit(void)
{
wxOGLInitialize();
//// Create a document manager
myDocManager = new wxDocManager;
//// Create a template relating drawing documents to their views
(void) new wxDocTemplate(myDocManager, "Diagram", "*.dia", "", "dia", "Diagram Doc", "Diagram View",
CLASSINFO(DiagramDocument), CLASSINFO(DiagramView));
// If we've only got one window, we only get to edit
// one document at a time.
myDocManager->SetMaxDocsOpen(1);
//// Create the main frame window
frame = new MyFrame(myDocManager, NULL, "OGLEdit Demo", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
//// Give it an icon
frame->SetIcon(wxICON(ogl));
//// Make a menubar
wxMenu *file_menu = new wxMenu;
wxMenu *edit_menu = NULL;
file_menu->Append(wxID_NEW, "&New...");
file_menu->Append(wxID_OPEN, "&Open...");
file_menu->Append(wxID_CLOSE, "&Close");
file_menu->Append(wxID_SAVE, "&Save");
file_menu->Append(wxID_SAVEAS, "Save &As...");
file_menu->AppendSeparator();
file_menu->Append(wxID_PRINT, "&Print...");
file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
file_menu->Append(wxID_PREVIEW, "Print Pre&view");
edit_menu = new wxMenu;
edit_menu->Append(wxID_UNDO, "&Undo");
edit_menu->Append(wxID_REDO, "&Redo");
edit_menu->AppendSeparator();
edit_menu->Append(OGLEDIT_CUT, "&Cut");
edit_menu->AppendSeparator();
edit_menu->Append(OGLEDIT_CHANGE_BACKGROUND_COLOUR, "Change &background colour");
edit_menu->Append(OGLEDIT_EDIT_LABEL, "Edit &label");
frame->editMenu = edit_menu;
file_menu->AppendSeparator();
file_menu->Append(wxID_EXIT, "E&xit");
// A nice touch: a history of files visited. Use this menu.
myDocManager->FileHistoryUseMenu(file_menu);
wxMenu *help_menu = new wxMenu;
help_menu->Append(OGLEDIT_ABOUT, "&About");
wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, "&File");
if (edit_menu)
menu_bar->Append(edit_menu, "&Edit");
menu_bar->Append(help_menu, "&Help");
frame->canvas = frame->CreateCanvas(NULL, frame);
frame->palette = wxGetApp().CreatePalette(frame);
myDocManager->CreateDocument("", wxDOC_NEW);
//// Associate the menu bar with the frame
frame->SetMenuBar(menu_bar);
frame->CreateStatusBar(1);
frame->Centre(wxBOTH);
frame->Show(TRUE);
return TRUE;
}
int MyApp::OnExit(void)
{
wxOGLCleanUp();
delete myDocManager;
return 0;
}
/*
* This is the top-level window of the application.
*/
IMPLEMENT_CLASS(MyFrame, wxDocParentFrame)
BEGIN_EVENT_TABLE(MyFrame, wxDocParentFrame)
EVT_MENU(OGLEDIT_ABOUT, MyFrame::OnAbout)
EVT_SIZE(MyFrame::OnSize)
EVT_CLOSE(MyFrame::OnCloseWindow)
END_EVENT_TABLE()
MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title,
const wxPoint& pos, const wxSize& size, long type):
wxDocParentFrame(manager, frame, -1, title, pos, size, type)
{
canvas = NULL;
palette = NULL;
editMenu = NULL;
}
void MyFrame::OnSize(wxSizeEvent& event)
{
if (canvas && palette)
{
int cw, ch;
GetClientSize(&cw, &ch);
int paletteX = 0;
int paletteY = 0;
int paletteW = 30;
int paletteH = ch;
int canvasX = paletteX + paletteW;
int canvasY = 0;
int canvasW = cw - paletteW;
int canvasH = ch;
palette->SetSize(paletteX, paletteY, paletteW, paletteH);
canvas->SetSize(canvasX, canvasY, canvasW, canvasH);
}
}
void MyFrame::OnCloseWindow(wxCloseEvent& event)
{
wxDocParentFrame::OnCloseWindow(event);
if (!event.GetVeto())
{
wxOGLCleanUp();
}
}
// Intercept menu commands
void MyFrame::OnAbout(wxCommandEvent& event)
{
(void)wxMessageBox("OGLEdit Demo\nTo draw a shape, select a shape on the toolbar and left-click on the canvas.\nTo draw a line, right-drag between shapes.\nFor further details, see the OGL manual.\n (c) Julian Smart 1996", "About OGLEdit");
}
// Creates a canvas. Called by OnInit as a child of the main window
MyCanvas *MyFrame::CreateCanvas(wxView *view, wxFrame *parent)
{
int width, height;
parent->GetClientSize(&width, &height);
// Non-retained canvas
MyCanvas *canvas = new MyCanvas(view, parent, -1, wxPoint(0, 0), wxSize(width, height), 0);
canvas->SetCursor(wxCursor(wxCURSOR_HAND));
// Give it scrollbars
canvas->SetScrollbars(20, 20, 50, 50);
return canvas;
}
MyFrame *GetMainFrame(void)
{
return wxGetApp().frame;
}

View File

@@ -0,0 +1,8 @@
NAME OGLEdit
DESCRIPTION 'OGL Editor Sample'
EXETYPE WINDOWS
STUB 'WINSTUB.EXE'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 1024
STACKSIZE 8192

View File

@@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////
// Name: ogledit.h
// Purpose: OGL sample
// Author: Julian Smart
// Modified by:
// Created: 12/07/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
// #pragma interface
#endif
#ifndef _OGLSAMPLE_OGLEDIT_H_
#define _OGLSAMPLE_OGLEDIT_H_
#include <wx/docview.h>
// Define a new application
class MyFrame;
class EditorToolPalette;
class MyApp: public wxApp
{
public:
MyFrame *frame;
wxDocManager* myDocManager;
MyApp(void);
bool OnInit(void);
int OnExit(void);
// Palette stuff
EditorToolPalette *CreatePalette(wxFrame *parent);
};
DECLARE_APP(MyApp)
// Define a new frame
class MyCanvas;
class MyFrame: public wxDocParentFrame
{
DECLARE_CLASS(MyFrame)
public:
wxMenu *editMenu;
MyCanvas *canvas;
EditorToolPalette *palette;
MyFrame(wxDocManager *manager, wxFrame *parent, const wxString& title,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE);
MyCanvas *CreateCanvas(wxView *view, wxFrame *parent);
void OnSize(wxSizeEvent& event);
void OnCloseWindow(wxCloseEvent& event);
void OnAbout(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
extern MyFrame *GetMainFrame(void);
// Menu/undo/redo commands
#define OGLEDIT_CUT 1
#define OGLEDIT_ADD_SHAPE 2
#define OGLEDIT_ADD_LINE 3
#define OGLEDIT_EDIT_LABEL 4
#define OGLEDIT_CHANGE_BACKGROUND_COLOUR 5
#define OGLEDIT_ABOUT 100
#endif
// _OGLSAMPLE_OGLEDIT_H_

View File

@@ -0,0 +1,10 @@
ogl ICON ogl.ico
TOOL1 BITMAP "bitmaps/tool1.bmp"
TOOL2 BITMAP "bitmaps/tool2.bmp"
TOOL3 BITMAP "bitmaps/tool3.bmp"
TOOL4 BITMAP "bitmaps/tool4.bmp"
ARROWTOOL BITMAP "bitmaps/arrow.bmp"
#include "wx/msw/wx.rc"

View File

@@ -0,0 +1,121 @@
/////////////////////////////////////////////////////////////////////////////
// Name: palette.cpp
// Purpose: OGLEdit palette
// Author: Julian Smart
// Modified by:
// Created: 12/07/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
// #pragma implementation
#endif
// For compilers that support precompilation, includes "wx.h".
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/toolbar.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include "doc.h"
#include "view.h"
#include "ogledit.h"
#include "palette.h"
// Include pixmaps
#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "bitmaps/arrow.xpm"
#include "bitmaps/tool1.xpm"
#include "bitmaps/tool2.xpm"
#include "bitmaps/tool3.xpm"
#include "bitmaps/tool4.xpm"
#endif
/*
* Object editor tool palette
*
*/
EditorToolPalette::EditorToolPalette(wxWindow* parent, const wxPoint& pos, const wxSize& size,
long style):
TOOLPALETTECLASS(parent, -1, pos, size, style)
{
currentlySelected = -1;
#if 1 // ndef __WXGTK__
SetMaxRowsCols(1000, 1);
#endif
}
bool EditorToolPalette::OnLeftClick(int toolIndex, bool toggled)
{
// BEGIN mutual exclusivity code
if (toggled && (currentlySelected != -1) && (toolIndex != currentlySelected))
ToggleTool(currentlySelected, FALSE);
if (toggled)
currentlySelected = toolIndex;
else if (currentlySelected == toolIndex)
currentlySelected = -1;
// END mutual exclusivity code
return TRUE;
}
void EditorToolPalette::OnMouseEnter(int toolIndex)
{
}
void EditorToolPalette::SetSize(int x, int y, int width, int height, int sizeFlags)
{
TOOLPALETTECLASS::SetSize(x, y, width, height, sizeFlags);
}
EditorToolPalette *MyApp::CreatePalette(wxFrame *parent)
{
// Load palette bitmaps
#ifdef __WXMSW__
wxBitmap PaletteTool1("TOOL1");
wxBitmap PaletteTool2("TOOL2");
wxBitmap PaletteTool3("TOOL3");
wxBitmap PaletteTool4("TOOL4");
wxBitmap PaletteArrow("ARROWTOOL");
#elif defined(__WXGTK__) || defined(__WXMOTIF__)
wxBitmap PaletteTool1(tool1_xpm);
wxBitmap PaletteTool2(tool2_xpm);
wxBitmap PaletteTool3(tool3_xpm);
wxBitmap PaletteTool4(tool4_xpm);
wxBitmap PaletteArrow(arrow_xpm);
#endif
EditorToolPalette *palette = new EditorToolPalette(parent, wxPoint(0, 0), wxSize(-1, -1), wxTB_HORIZONTAL);
palette->SetMargins(2, 2);
palette->SetToolBitmapSize(wxSize(22, 22));
palette->AddTool(PALETTE_ARROW, PaletteArrow, wxNullBitmap, TRUE, 0, -1, NULL, "Pointer");
palette->AddTool(PALETTE_TOOL1, PaletteTool1, wxNullBitmap, TRUE, 0, -1, NULL, "Tool 1");
palette->AddTool(PALETTE_TOOL2, PaletteTool2, wxNullBitmap, TRUE, 0, -1, NULL, "Tool 2");
palette->AddTool(PALETTE_TOOL3, PaletteTool3, wxNullBitmap, TRUE, 0, -1, NULL, "Tool 3");
palette->AddTool(PALETTE_TOOL4, PaletteTool4, wxNullBitmap, TRUE, 0, -1, NULL, "Tool 4");
palette->Realize();
palette->ToggleTool(PALETTE_ARROW, TRUE);
palette->currentlySelected = PALETTE_ARROW;
return palette;
}

View File

@@ -0,0 +1,66 @@
/////////////////////////////////////////////////////////////////////////////
// Name: palette.h
// Purpose: OGL sample palette
// Author: Julian Smart
// Modified by:
// Created: 12/07/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _OGLSAMPLE_PALETTE_H_
#define _OGLSAMPLE_PALETTE_H_
#ifdef __GNUG__
// #pragma interface
#endif
#include <wx/wx.h>
#include <wx/string.h>
#if 0 // def __WXGTK__
#include <wx/toolbar.h>
#else
#include <wx/tbarsmpl.h>
#endif
/*
* Object editor tool palette
*
*/
// TODO for wxWin: wxToolBar95 cannot be moved to a non-0,0 position!
// Needs to have a parent window...
// So use a simple toolbar at present.
#if 0 // def __WXGTK__
#define TOOLPALETTECLASS wxToolBar
#else
#define TOOLPALETTECLASS wxToolBarSimple
#endif
class EditorToolPalette: public TOOLPALETTECLASS
{
public:
int currentlySelected;
EditorToolPalette(wxWindow *parent, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTB_VERTICAL);
bool OnLeftClick(int toolIndex, bool toggled);
void OnMouseEnter(int toolIndex);
void SetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
};
#define PALETTE_TOOL1 1
#define PALETTE_TOOL2 2
#define PALETTE_TOOL3 3
#define PALETTE_TOOL4 4
#define PALETTE_TOOL5 5
#define PALETTE_TOOL6 6
#define PALETTE_TOOL7 7
#define PALETTE_TOOL8 8
#define PALETTE_TOOL9 9
#define PALETTE_ARROW 10
#endif
// _OGLSAMPLE_PALETTE_H_

View File

@@ -0,0 +1,337 @@
/////////////////////////////////////////////////////////////////////////////
// Name: view.cpp
// Purpose: Implements view functionality in OGLEdit
// Author: Julian Smart
// Modified by:
// Created: 12/07/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
// #pragma implementation
#endif
// For compilers that support precompilation, includes "wx.h".
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/colordlg.h>
#if !wxUSE_DOC_VIEW_ARCHITECTURE
#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h!
#endif
#include "ogledit.h"
#include "doc.h"
#include "view.h"
#include "palette.h"
IMPLEMENT_DYNAMIC_CLASS(DiagramView, wxView)
BEGIN_EVENT_TABLE(DiagramView, wxView)
EVT_MENU(OGLEDIT_CUT, DiagramView::OnCut)
EVT_MENU(OGLEDIT_CHANGE_BACKGROUND_COLOUR, DiagramView::OnChangeBackgroundColour)
EVT_MENU(OGLEDIT_EDIT_LABEL, DiagramView::OnEditLabel)
END_EVENT_TABLE()
// What to do when a view is created. Creates actual
// windows for displaying the view.
bool DiagramView::OnCreate(wxDocument *doc, long flags)
{
frame = GetMainFrame();
canvas = GetMainFrame()->canvas;
canvas->view = this;
SetFrame(frame);
Activate(TRUE);
// Initialize the edit menu Undo and Redo items
doc->GetCommandProcessor()->SetEditMenu(((MyFrame *)frame)->editMenu);
doc->GetCommandProcessor()->Initialize();
wxShapeCanvas *shapeCanvas = (wxShapeCanvas *)canvas;
DiagramDocument *diagramDoc = (DiagramDocument *)doc;
shapeCanvas->SetDiagram(diagramDoc->GetDiagram());
diagramDoc->GetDiagram()->SetCanvas(shapeCanvas);
return TRUE;
}
#define CENTER FALSE // Place the drawing to the center of the page
// Sneakily gets used for default print/preview
// as well as drawing on the screen.
void DiagramView::OnDraw(wxDC *dc)
{
/* You might use THIS code if you were scaling
* graphics of known size to fit on the page.
*/
int w, h;
// We need to adjust for the graphic size, a formula will be added
float maxX = 900;
float maxY = 700;
// A better way of find the maxium values would be to search through
// the linked list
// Let's have at least 10 device units margin
float marginX = 10;
float marginY = 10;
// Add the margin to the graphic size
maxX += (2 * marginX);
maxY += (2 * marginY);
// Get the size of the DC in pixels
dc->GetSize (&w, &h);
// Calculate a suitable scaling factor
float scaleX = (float) (w / maxX);
float scaleY = (float) (h / maxY);
// Use x or y scaling factor, whichever fits on the DC
float actualScale = wxMin (scaleX, scaleY);
float posX, posY;
// Calculate the position on the DC for centring the graphic
if (CENTER == TRUE) // center the drawing
{
posX = (float) ((w - (200 * actualScale)) / 2.0);
posY = (float) ((h - (200 * actualScale)) / 2.0);
}
else // Use defined presets
{
posX = 10;
posY = 35;
}
// Set the scale and origin
dc->SetUserScale (actualScale, actualScale);
dc->SetDeviceOrigin ((long) posX, (long) posY);
// This part was added to preform the print preview and printing functions
dc->BeginDrawing(); // Allows optimization of drawing code under MS Windows.
wxDiagram *diagram_p=((DiagramDocument*)GetDocument())->GetDiagram(); // Get the current diagram
if (diagram_p->GetShapeList())
{
wxCursor *old_cursor = NULL;
wxNode *current = diagram_p->GetShapeList()->First();
while (current) // Loop through the entire list of shapes
{
wxShape *object = (wxShape *)current->Data();
if (!object->GetParent())
{
object->Draw(* dc); // Draw the shape onto our printing dc
}
current = current->Next(); // Procede to the next shape in the list
}
}
dc->EndDrawing(); // Allows optimization of drawing code under MS Windows.
}
void DiagramView::OnUpdate(wxView *sender, wxObject *hint)
{
if (canvas)
canvas->Refresh();
}
// Clean up windows used for displaying the view.
bool DiagramView::OnClose(bool deleteWindow)
{
if (!GetDocument()->Close())
return FALSE;
DiagramDocument *diagramDoc = (DiagramDocument *)GetDocument();
diagramDoc->GetDiagram()->SetCanvas(NULL);
canvas->Clear();
canvas->SetDiagram(NULL);
canvas->view = NULL;
canvas = NULL;
wxString s = wxTheApp->GetAppName();
if (frame)
frame->SetTitle(s);
SetFrame(NULL);
Activate(FALSE);
return TRUE;
}
wxShape *DiagramView::FindSelectedShape(void)
{
DiagramDocument *doc = (DiagramDocument *)GetDocument();
wxShape *theShape = NULL;
wxNode *node = doc->GetDiagram()->GetShapeList()->First();
while (node)
{
wxShape *eachShape = (wxShape *)node->Data();
if ((eachShape->GetParent() == NULL) && eachShape->Selected())
{
theShape = eachShape;
node = NULL;
}
else node = node->Next();
}
return theShape;
}
void DiagramView::OnCut(wxCommandEvent& event)
{
DiagramDocument *doc = (DiagramDocument *)GetDocument();
wxShape *theShape = FindSelectedShape();
if (theShape)
doc->GetCommandProcessor()->Submit(new DiagramCommand("Cut", OGLEDIT_CUT, doc, NULL, 0.0, 0.0, TRUE, theShape));
}
void DiagramView::OnChangeBackgroundColour(wxCommandEvent& event)
{
DiagramDocument *doc = (DiagramDocument *)GetDocument();
wxShape *theShape = FindSelectedShape();
if (theShape)
{
wxColourData data;
data.SetChooseFull(TRUE);
data.SetColour(theShape->GetBrush()->GetColour());
wxColourDialog *dialog = new wxColourDialog(frame, &data);
wxBrush *theBrush = NULL;
if (dialog->ShowModal() == wxID_OK)
{
wxColourData retData = dialog->GetColourData();
wxColour col = retData.GetColour();
theBrush = wxTheBrushList->FindOrCreateBrush(col, wxSOLID);
}
dialog->Close();
if (theBrush)
doc->GetCommandProcessor()->Submit(new DiagramCommand("Change colour", OGLEDIT_CHANGE_BACKGROUND_COLOUR, doc,
theBrush, theShape));
}
}
void DiagramView::OnEditLabel(wxCommandEvent& event)
{
wxShape *theShape = FindSelectedShape();
if (theShape)
{
wxString newLabel = wxGetTextFromUser("Enter new label", "Shape Label", ((MyEvtHandler *)theShape->GetEventHandler())->label);
GetDocument()->GetCommandProcessor()->Submit(new DiagramCommand("Edit label", OGLEDIT_EDIT_LABEL, (DiagramDocument*) GetDocument(), newLabel, theShape));
}
}
/*
* Window implementations
*/
BEGIN_EVENT_TABLE(MyCanvas, wxShapeCanvas)
EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent)
EVT_PAINT(MyCanvas::OnPaint)
END_EVENT_TABLE()
// Define a constructor for my canvas
MyCanvas::MyCanvas(wxView *v, wxWindow *parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style):
wxShapeCanvas(parent, id, pos, size, style)
{
SetBackgroundColour(*wxWHITE);
view = v;
}
MyCanvas::~MyCanvas(void)
{
}
void MyCanvas::OnLeftClick(double x, double y, int keys)
{
EditorToolPalette *palette = wxGetApp().frame->palette;
wxClassInfo *info = NULL;
switch (palette->currentlySelected)
{
case PALETTE_TOOL1:
{
info = CLASSINFO(wxRectangleShape);
break;
}
case PALETTE_TOOL2:
{
info = CLASSINFO(wxRoundedRectangleShape);
break;
}
case PALETTE_TOOL3:
{
info = CLASSINFO(wxEllipseShape);
break;
}
case PALETTE_TOOL4:
{
info = CLASSINFO(wxDiamondShape);
break;
}
default:
break;
}
if (info)
{
view->GetDocument()->GetCommandProcessor()->Submit(new DiagramCommand(info->GetClassName(), OGLEDIT_ADD_SHAPE, (DiagramDocument *)view->GetDocument(), info,
x, y));
}
}
void MyCanvas::OnRightClick(double x, double y, int keys)
{
}
void MyCanvas::OnDragLeft(bool draw, double x, double y, int keys)
{
}
void MyCanvas::OnBeginDragLeft(double x, double y, int keys)
{
}
void MyCanvas::OnEndDragLeft(double x, double y, int keys)
{
}
void MyCanvas::OnDragRight(bool draw, double x, double y, int keys)
{
}
void MyCanvas::OnBeginDragRight(double x, double y, int keys)
{
}
void MyCanvas::OnEndDragRight(double x, double y, int keys)
{
}
void MyCanvas::OnMouseEvent(wxMouseEvent& event)
{
wxShapeCanvas::OnMouseEvent(event);
}
void MyCanvas::OnPaint(wxPaintEvent& event)
{
// if (GetDiagram())
wxShapeCanvas::OnPaint(event);
}

View File

@@ -0,0 +1,79 @@
/////////////////////////////////////////////////////////////////////////////
// Name: view.h
// Purpose: View-related classes
// Author: Julian Smart
// Modified by:
// Created: 12/07/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _OGLSAMPLE_VIEW_H_
#define _OGLSAMPLE_VIEW_H_
#ifdef __GNUG__
// #pragma interface "view.h"
#endif
#include "doc.h"
#include <wx/ogl/ogl.h>
class MyCanvas: public wxShapeCanvas
{
// DECLARE_DYNAMIC_CLASS(wxShapeCanvas)
protected:
public:
wxView *view;
MyCanvas(wxView *view, wxWindow *parent = NULL, wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxRETAINED);
~MyCanvas(void);
void OnMouseEvent(wxMouseEvent& event);
void OnPaint(wxPaintEvent& event);
virtual void OnLeftClick(double x, double y, int keys = 0);
virtual void OnRightClick(double x, double y, int keys = 0);
virtual void OnDragLeft(bool draw, double x, double y, int keys=0); // Erase if draw false
virtual void OnBeginDragLeft(double x, double y, int keys=0);
virtual void OnEndDragLeft(double x, double y, int keys=0);
virtual void OnDragRight(bool draw, double x, double y, int keys=0); // Erase if draw false
virtual void OnBeginDragRight(double x, double y, int keys=0);
virtual void OnEndDragRight(double x, double y, int keys=0);
DECLARE_EVENT_TABLE()
};
class DiagramView: public wxView
{
DECLARE_DYNAMIC_CLASS(DiagramView)
private:
public:
wxFrame *frame;
MyCanvas *canvas;
DiagramView(void) { canvas = NULL; frame = NULL; };
~DiagramView(void) {};
bool OnCreate(wxDocument *doc, long flags);
void OnDraw(wxDC *dc);
void OnUpdate(wxView *sender, wxObject *hint = NULL);
bool OnClose(bool deleteWindow = TRUE);
wxShape *FindSelectedShape(void);
// void OnMenuCommand(int cmd);
void OnCut(wxCommandEvent& event);
void OnChangeBackgroundColour(wxCommandEvent& event);
void OnEditLabel(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
#endif
// _OGLSAMPLE_VIEW_H_