Changes mostly as a result of __WXSTUBS__ compilation. The stubs code now

compiles under Windows with VC++. Also OGL enhancements espec. wxDrawnShape.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@540 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1998-08-15 00:23:28 +00:00
parent 853b255a6b
commit 34138703c3
229 changed files with 2990 additions and 1225 deletions

View File

@@ -37,9 +37,6 @@
// in the application itself.
IMPLEMENT_APP(MyApp)
// This statement initialises the whole application
MyApp myApp;
MyApp::MyApp(void)
{
frame = NULL;
@@ -116,7 +113,7 @@ bool MyApp::OnInit(void)
menu_bar->Append(help_menu, "&Help");
frame->canvas = frame->CreateCanvas(NULL, frame);
frame->palette = myApp.CreatePalette(frame);
frame->palette = wxGetApp().CreatePalette(frame);
myDocManager->CreateDocument("", wxDOC_NEW);
//// Associate the menu bar with the frame
@@ -206,6 +203,6 @@ MyCanvas *MyFrame::CreateCanvas(wxView *view, wxFrame *parent)
MyFrame *GetMainFrame(void)
{
return myApp.frame;
return wxGetApp().frame;
}

View File

@@ -860,8 +860,8 @@ void wxShape::FindRegionNames(wxStringList& list)
void wxShape::AssignNewIds()
{
if (m_id == 0)
m_id = NewId();
// if (m_id == 0)
m_id = NewId();
wxNode *node = m_children.First();
while (node)
{
@@ -1535,7 +1535,13 @@ void wxShape::WritePrologAttributes(wxExpr *clause)
clause->AddAttributeValue("pen_style", (long)penStyle);
wxString penColour = wxTheColourDatabase->FindName(m_pen->GetColour());
if ((penColour != "") && (penColour != "BLACK"))
if (penColour == "")
{
wxString hex(oglColourToHex(m_pen->GetColour()));
hex = wxString("#") + hex;
clause->AddAttributeValueString("pen_colour", hex);
}
else if (penColour != "BLACK")
clause->AddAttributeValueString("pen_colour", penColour);
}
@@ -1543,7 +1549,13 @@ void wxShape::WritePrologAttributes(wxExpr *clause)
{
wxString brushColour = wxTheColourDatabase->FindName(m_brush->GetColour());
if ((brushColour != "") && (brushColour != "WHITE"))
if (brushColour == "")
{
wxString hex(oglColourToHex(m_brush->GetColour()));
hex = wxString("#") + hex;
clause->AddAttributeValueString("brush_colour", hex);
}
else if (brushColour != "WHITE")
clause->AddAttributeValueString("brush_colour", brushColour);
if (m_brush->GetStyle() != wxSOLID)
@@ -1795,11 +1807,25 @@ void wxShape::ReadPrologAttributes(wxExpr *clause)
if (brush_string == "")
brush_string = "WHITE";
m_pen = wxThePenList->FindOrCreatePen(pen_string, pen_width, pen_style);
if (pen_string[0] == '#')
{
wxColour col(oglHexToColour(pen_string.After('#')));
m_pen = wxThePenList->FindOrCreatePen(col, pen_width, pen_style);
}
else
m_pen = wxThePenList->FindOrCreatePen(pen_string, pen_width, pen_style);
if (!m_pen)
m_pen = wxBLACK_PEN;
m_brush = wxTheBrushList->FindOrCreateBrush(brush_string, brush_style);
if (brush_string[0] == '#')
{
wxColour col(oglHexToColour(brush_string.After('#')));
m_brush = wxTheBrushList->FindOrCreateBrush(col, brush_style);
}
else
m_brush = wxTheBrushList->FindOrCreateBrush(brush_string, brush_style);
if (!m_brush)
m_brush = wxWHITE_BRUSH;

View File

@@ -555,6 +555,8 @@ class wxRectangleShape: public wxShape
inline float GetWidth() const { return m_width; }
inline float GetHeight() const { return m_height; }
inline void SetWidth(float w) { m_width = w; }
inline void SetHeight(float h) { m_height = h; }
protected:
float m_width;

View File

@@ -532,15 +532,18 @@ void wxPolygonShape::OnDraw(wxDC& dc)
void wxPolygonShape::OnDrawOutline(wxDC& dc, float x, float y, float w, float h)
{
dc.SetBrush(wxTRANSPARENT_BRUSH);
// Multiply all points by proportion of new size to old size
float x_proportion = (float)(fabs(w/m_originalWidth));
float y_proportion = (float)(fabs(h/m_originalHeight));
int n = m_points->Number();
int n = m_originalPoints->Number();
wxPoint *intPoints = new wxPoint[n];
int i;
for (i = 0; i < n; i++)
{
wxRealPoint* point = (wxRealPoint*) m_points->Nth(i)->Data();
intPoints[i].x = (int) point->x;
intPoints[i].y = (int) point->y;
wxRealPoint* point = (wxRealPoint*) m_originalPoints->Nth(i)->Data();
intPoints[i].x = (int) (x_proportion * point->x);
intPoints[i].y = (int) (y_proportion * point->y);
}
dc.DrawPolygon(n, intPoints, x, y);
delete[] intPoints;
@@ -1699,6 +1702,21 @@ wxPolygonControlPoint::~wxPolygonControlPoint()
{
}
// Calculate what new size would be, at end of resize
void wxPolygonControlPoint::CalculateNewSize(float x, float y)
{
float bound_x;
float bound_y;
GetShape()->GetBoundingBoxMin(&bound_x, &bound_y);
float dist = (float)sqrt((x - m_shape->GetX())*(x - m_shape->GetX()) +
(y - m_shape->GetY())*(y - m_shape->GetY()));
m_newSize.x = (float)(dist/this->m_originalDistance)*this->m_originalSize.x;
m_newSize.y = (float)(dist/this->m_originalDistance)*this->m_originalSize.y;
}
// Implement resizing polygon or moving the vertex.
void wxPolygonControlPoint::OnDragLeft(bool draw, float x, float y, int keys, int attachment)
{
@@ -1730,18 +1748,11 @@ void wxPolygonShape::OnSizingDragLeft(wxControlPoint* pt, bool draw, float x, fl
dc.SetPen(dottedPen);
dc.SetBrush((* wxTRANSPARENT_BRUSH));
float bound_x;
float bound_y;
this->GetBoundingBoxMin(&bound_x, &bound_y);
/*
float new_width = (float)(2.0*fabs(x - this->GetX()));
float new_height = (float)(2.0*fabs(y - this->GetY()));
*/
float dist = (float)sqrt((x - this->GetX())*(x - this->GetX()) +
(y - this->GetY())*(y - this->GetY()));
if (keys & KEY_CTRL)
if (0) // keys & KEY_CTRL)
{
// TODO: mend this code. Currently we rely on altering the
// actual points, but we should assume we're not, as per
// the normal sizing case.
m_canvas->Snap(&x, &y);
// Move point
@@ -1754,15 +1765,11 @@ void wxPolygonShape::OnSizingDragLeft(wxControlPoint* pt, bool draw, float x, fl
}
else
{
float new_width = (float)(dist/ppt->m_originalDistance)*ppt->m_originalSize.x;
float new_height = (float)(dist/ppt->m_originalDistance)*ppt->m_originalSize.y;
// Non-recursive SetSize for speed
this->SetSize(new_width, new_height, FALSE);
ppt->CalculateNewSize(x, y);
}
float w, h;
this->GetBoundingBoxMax(&w, &h);
this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(), w, h);
this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(),
ppt->GetNewSize().x, ppt->GetNewSize().y);
}
void wxPolygonShape::OnSizingBeginDragLeft(wxControlPoint* pt, float x, float y, int keys, int attachment)
@@ -1782,7 +1789,6 @@ void wxPolygonShape::OnSizingBeginDragLeft(wxControlPoint* pt, float x, float y,
float dist = (float)sqrt((x - this->GetX())*(x - this->GetX()) +
(y - this->GetY())*(y - this->GetY()));
ppt->m_originalDistance = dist;
ppt->m_originalSize.x = bound_x;
ppt->m_originalSize.y = bound_y;
@@ -1793,8 +1799,11 @@ void wxPolygonShape::OnSizingBeginDragLeft(wxControlPoint* pt, float x, float y,
dc.SetPen(dottedPen);
dc.SetBrush((* wxTRANSPARENT_BRUSH));
if (keys & KEY_CTRL)
if (0) // keys & KEY_CTRL)
{
// TODO: mend this code. Currently we rely on altering the
// actual points, but we should assume we're not, as per
// the normal sizing case.
m_canvas->Snap(&x, &y);
// Move point
@@ -1807,22 +1816,19 @@ void wxPolygonShape::OnSizingBeginDragLeft(wxControlPoint* pt, float x, float y,
}
else
{
float new_width = (float)(dist/ppt->m_originalDistance)*ppt->m_originalSize.x;
float new_height = (float)(dist/ppt->m_originalDistance)*ppt->m_originalSize.y;
// Non-recursive SetSize for speed
this->SetSize(new_width, new_height, FALSE);
ppt->CalculateNewSize(x, y);
}
float w, h;
this->GetBoundingBoxMax(&w, &h);
this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(), w, h);
this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(),
ppt->GetNewSize().x, ppt->GetNewSize().y);
m_canvas->CaptureMouse();
}
void wxPolygonShape::OnSizingEndDragLeft(wxControlPoint* pt, float x, float y, int keys, int attachment)
{
wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt;
wxClientDC dc(GetCanvas());
GetCanvas()->PrepareDC(dc);
@@ -1835,6 +1841,10 @@ void wxPolygonShape::OnSizingEndDragLeft(wxControlPoint* pt, float x, float y, i
((wxPolygonShape *)this)->CalculateBoundingBox();
((wxPolygonShape *)this)->UpdateOriginalPoints();
}
else
{
SetSize(ppt->GetNewSize().x, ppt->GetNewSize().y);
}
((wxPolygonShape *)this)->CalculateBoundingBox();
((wxPolygonShape *)this)->CalculatePolygonCentre();

View File

@@ -102,10 +102,17 @@ class wxPolygonControlPoint: public wxControlPoint
void OnBeginDragLeft(float x, float y, int keys=0, int attachment = 0);
void OnEndDragLeft(float x, float y, int keys=0, int attachment = 0);
// Calculate what new size would be, at end of resize
virtual void CalculateNewSize(float x, float y);
// Get new size
inline wxRealPoint GetNewSize() const { return m_newSize; };
public:
wxRealPoint* m_polygonVertex;
wxRealPoint m_originalSize;
float m_originalDistance;
wxRealPoint m_newSize;
};
/*

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,7 @@
#include "basic.h"
class wxDrawnShape;
class wxPseudoMetaFile: public wxObject
{
DECLARE_DYNAMIC_CLASS(wxPseudoMetaFile)
@@ -48,11 +49,47 @@ class wxPseudoMetaFile: public wxObject
void GetBounds(float *minX, float *minY, float *maxX, float *maxY);
// Calculate size from current operations
void CalculateSize(wxDrawnShape* shape);
inline wxList& GetOutlineColours() const { return (wxList&) m_outlineColours; }
inline wxList& GetFillColours() const { return (wxList&) m_fillColours; }
inline void SetRotateable(bool rot) { m_rotateable = rot; }
inline bool GetRotateable() const { return m_rotateable; }
inline void SetSize(float w, float h) { m_width = w; m_height = h; }
inline void SetFillBrush(wxBrush* brush) { m_fillBrush = brush; }
inline wxBrush* GetFillBrush() const { return m_fillBrush; }
inline void SetOutlinePen(wxPen* pen) { m_outlinePen = pen; }
inline wxPen* GetOutlinePen() const { return m_outlinePen; }
public:
/// Set of functions for drawing into a pseudo metafile.
/// They use integers, but doubles are used internally for accuracy
/// when scaling.
virtual void DrawLine(const wxPoint& pt1, const wxPoint& pt2);
virtual void DrawRectangle(const wxRect& rect);
virtual void DrawRoundedRectangle(const wxRect& rect, double radius);
virtual void DrawEllipse(const wxRect& rect);
virtual void DrawPoint(const wxPoint& pt);
virtual void DrawText(const wxString& text, const wxPoint& pt);
virtual void DrawLines(int n, wxPoint pts[]);
virtual void DrawPolygon(int n, wxPoint pts[]);
virtual void DrawSpline(int n, wxPoint pts[]);
virtual void SetClippingRect(const wxRect& rect);
virtual void DestroyClippingRect();
virtual void SetPen(wxPen* pen, bool isOutline = FALSE); // TODO: eventually, just store GDI object attributes, not actual
virtual void SetBrush(wxBrush* brush, bool isFill = FALSE); // pens/brushes etc.
virtual void SetFont(wxFont* font);
virtual void SetTextColour(const wxColour& colour);
virtual void SetBackgroundColour(const wxColour& colour);
virtual void SetBackgroundMode(int mode);
public:
bool m_rotateable;
float m_width;
@@ -102,13 +139,40 @@ class wxDrawnShape: public wxRectangleShape
inline void SetSaveToFile(bool save) { m_saveToFile = save; }
inline wxPseudoMetaFile& GetMetaFile() const { return (wxPseudoMetaFile&) m_metafile; }
/// Set of functions for drawing into a pseudo metafile.
/// They use integers, but doubles are used internally for accuracy
/// when scaling.
virtual void DrawLine(const wxPoint& pt1, const wxPoint& pt2);
virtual void DrawRectangle(const wxRect& rect);
virtual void DrawRoundedRectangle(const wxRect& rect, double radius);
virtual void DrawEllipse(const wxRect& rect);
virtual void DrawPoint(const wxPoint& pt);
virtual void DrawText(const wxString& text, const wxPoint& pt);
virtual void DrawLines(int n, wxPoint pts[]);
virtual void DrawPolygon(int n, wxPoint pts[]);
virtual void DrawSpline(int n, wxPoint pts[]);
virtual void SetClippingRect(const wxRect& rect);
virtual void DestroyClippingRect();
virtual void SetPen(wxPen* pen, bool isOutline = FALSE); // TODO: eventually, just store GDI object attributes, not actual
virtual void SetBrush(wxBrush* brush, bool isFill = FALSE); // pens/brushes etc.
virtual void SetFont(wxFont* font);
virtual void SetTextColour(const wxColour& colour);
virtual void SetBackgroundColour(const wxColour& colour);
virtual void SetBackgroundMode(int mode);
// Set the width/height according to the shapes in the metafile.
// Call this after drawing into the shape.
inline void CalculateSize() { m_metafile.CalculateSize(this); }
private:
wxPseudoMetaFile m_metafile;
// Don't save all wxDrawnShape metafiles to file: sometimes
// we take the metafile data from a symbol library.
bool m_saveToFile;
};
#endif

View File

@@ -56,18 +56,22 @@
class wxDrawOp: public wxObject
{
public:
int op;
inline wxDrawOp(int theOp) { op = theOp; }
public:
inline wxDrawOp(int theOp) { m_op = theOp; }
inline ~wxDrawOp() {}
inline virtual void Scale(float xScale, float yScale) {};
inline virtual void Translate(float x, float y) {};
inline virtual void Rotate(float x, float y, float sinTheta, float cosTheta) {};
virtual void Do(wxDC& dc, float xoffset, float yoffset) = 0;
virtual wxDrawOp *Copy(wxPseudoMetaFile *newImage) = 0;
virtual wxExpr *WritewxExpr(wxPseudoMetaFile *image) = 0;
virtual void ReadwxExpr(wxPseudoMetaFile *image, wxExpr *expr) = 0;
virtual wxExpr *WriteExpr(wxPseudoMetaFile *image) = 0;
virtual void ReadExpr(wxPseudoMetaFile *image, wxExpr *expr) = 0;
int GetOp() const { return m_op; }
protected:
int m_op;
};
/*
@@ -78,17 +82,19 @@ class wxDrawOp: public wxObject
class wxOpSetGDI: public wxDrawOp
{
public:
int mode;
int gdiIndex;
wxPseudoMetaFile *image;
unsigned char r;
unsigned char g;
unsigned char b;
wxOpSetGDI(int theOp, wxPseudoMetaFile *theImage, int theGdiIndex, int theMode = 0);
void Do(wxDC& dc, float xoffset, float yoffset);
wxDrawOp *Copy(wxPseudoMetaFile *newImage);
wxExpr *WritewxExpr(wxPseudoMetaFile *image);
void ReadwxExpr(wxPseudoMetaFile *image, wxExpr *expr);
wxExpr *WriteExpr(wxPseudoMetaFile *image);
void ReadExpr(wxPseudoMetaFile *image, wxExpr *expr);
public:
int m_mode;
int m_gdiIndex;
wxPseudoMetaFile* m_image;
unsigned char m_r;
unsigned char m_g;
unsigned char m_b;
};
/*
@@ -98,18 +104,20 @@ class wxOpSetGDI: public wxDrawOp
class wxOpSetClipping: public wxDrawOp
{
public:
float x1;
float y1;
float x2;
float y2;
public:
wxOpSetClipping(int theOp, float theX1, float theY1, float theX2, float theY2);
void Do(wxDC& dc, float xoffset, float yoffset);
void Scale(float xScale, float yScale);
void Translate(float x, float y);
wxDrawOp *Copy(wxPseudoMetaFile *newImage);
wxExpr *WritewxExpr(wxPseudoMetaFile *image);
void ReadwxExpr(wxPseudoMetaFile *image, wxExpr *expr);
wxExpr *WriteExpr(wxPseudoMetaFile *image);
void ReadExpr(wxPseudoMetaFile *image, wxExpr *expr);
public:
float m_x1;
float m_y1;
float m_x2;
float m_y2;
};
/*
@@ -120,14 +128,6 @@ class wxOpSetClipping: public wxDrawOp
class wxOpDraw: public wxDrawOp
{
public:
float x1;
float y1;
float x2;
float y2;
float x3;
float radius;
char *textString;
wxOpDraw(int theOp, float theX1, float theY1, float theX2, float theY2,
float radius = 0.0, char *s = NULL);
~wxOpDraw();
@@ -136,8 +136,18 @@ class wxOpDraw: public wxDrawOp
void Translate(float x, float y);
void Rotate(float x, float y, float sinTheta, float cosTheta);
wxDrawOp *Copy(wxPseudoMetaFile *newImage);
wxExpr *WritewxExpr(wxPseudoMetaFile *image);
void ReadwxExpr(wxPseudoMetaFile *image, wxExpr *expr);
wxExpr *WriteExpr(wxPseudoMetaFile *image);
void ReadExpr(wxPseudoMetaFile *image, wxExpr *expr);
public:
float m_x1;
float m_y1;
float m_x2;
float m_y2;
float m_x3;
float m_radius;
char* m_textString;
};
/*
@@ -147,10 +157,7 @@ class wxOpDraw: public wxDrawOp
class wxOpPolyDraw: public wxDrawOp
{
public:
wxRealPoint *points;
int noPoints;
public:
wxOpPolyDraw(int theOp, int n, wxRealPoint *thePoints);
~wxOpPolyDraw();
void Do(wxDC& dc, float xoffset, float yoffset);
@@ -158,8 +165,13 @@ class wxOpPolyDraw: public wxDrawOp
void Translate(float x, float y);
void Rotate(float x, float y, float sinTheta, float cosTheta);
wxDrawOp *Copy(wxPseudoMetaFile *newImage);
wxExpr *WritewxExpr(wxPseudoMetaFile *image);
void ReadwxExpr(wxPseudoMetaFile *image, wxExpr *expr);
wxExpr *WriteExpr(wxPseudoMetaFile *image);
void ReadExpr(wxPseudoMetaFile *image, wxExpr *expr);
public:
wxRealPoint* m_points;
int m_noPoints;
};
#endif

View File

@@ -1650,7 +1650,7 @@ void wxLineShape::Copy(wxShape& copy)
// Override select, to create/delete temporary label-moving objects
void wxLineShape::Select(bool select, wxDC* dc)
{
wxShape::Select(select);
wxShape::Select(select, dc);
if (select)
{
for (int i = 0; i < 3; i++)

View File

@@ -58,6 +58,7 @@ class wxArrowHead: public wxObject
inline WXTYPE _GetType() const { return m_arrowType; }
inline int GetPosition() const { return m_arrowEnd; }
inline void SetPosition(int pos) { m_arrowEnd = pos; }
inline float GetXOffset() const { return m_xOffset; }
inline float GetYOffset() const { return m_yOffset; }
inline float GetSpacing() const { return m_spacing; }
@@ -200,7 +201,7 @@ class wxLineShape: public wxShape
// Does the copying for this object
void Copy(wxShape& copy);
// New OGL stuff
// Add an arrowhead.
wxArrowHead *AddArrow(WXTYPE type, int end = ARROW_POSITION_END,
float arrowSize = 10.0, float xOffset = 0.0, const wxString& name = "",
wxPseudoMetaFile *mf = NULL, long arrowId = -1);
@@ -226,6 +227,7 @@ class wxLineShape: public wxShape
bool DeleteArrowHead(long arrowId);
void DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool proportionalOffset);
inline void SetIgnoreOffsets(bool ignore) { m_ignoreArrowOffsets = ignore; }
inline wxList& GetArrows() const { return (wxList&) m_arcArrows; }
// Find horizontal width for drawing a line with
// arrows in minimum space. Assume arrows at

View File

@@ -62,7 +62,7 @@ void wxOGLInitialize()
{
GraphicsBullseyeCursor = new wxCursor(wxCURSOR_BULLSEYE);
g_oglNormalFont = new wxFont(12, wxMODERN, wxNORMAL, wxNORMAL);
g_oglNormalFont = new wxFont(10, wxSWISS, wxNORMAL, wxNORMAL);
black_pen = new wxPen("BLACK", 1, wxSOLID);
@@ -834,4 +834,71 @@ void UpdateListBox(wxListBox *item, wxList *list)
}
}
/*
* Hex<->Dec conversion
*/
// Array used in DecToHex conversion routine.
static char sg_HexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
'C', 'D', 'E', 'F' };
// Convert 2-digit hex number to decimal
unsigned int oglHexToDec(char* buf)
{
int firstDigit, secondDigit;
if (buf[0] >= 'A')
firstDigit = buf[0] - 'A' + 10;
else
firstDigit = buf[0] - '0';
if (buf[1] >= 'A')
secondDigit = buf[1] - 'A' + 10;
else
secondDigit = buf[1] - '0';
return firstDigit * 16 + secondDigit;
}
// Convert decimal integer to 2-character hex string
void oglDecToHex(unsigned int dec, char *buf)
{
int firstDigit = (int)(dec/16.0);
int secondDigit = (int)(dec - (firstDigit*16.0));
buf[0] = sg_HexArray[firstDigit];
buf[1] = sg_HexArray[secondDigit];
buf[2] = 0;
}
// 3-digit hex to wxColour
wxColour oglHexToColour(const wxString& hex)
{
if (hex.Length() == 6)
{
char buf[7];
strncpy(buf, hex, 7);
unsigned int r = oglHexToDec((char *)buf);
unsigned int g = oglHexToDec((char *)(buf+2));
unsigned int b = oglHexToDec((char *)(buf+4));
return wxColour(r, g, b);
}
else
return wxColour(0,0,0);
}
// RGB to 3-digit hex
wxString oglColourToHex(const wxColour& colour)
{
char buf[7];
unsigned int red = colour.Red();
unsigned int green = colour.Green();
unsigned int blue = colour.Blue();
oglDecToHex(red, buf);
oglDecToHex(green, buf+2);
oglDecToHex(blue, buf+4);
return wxString(buf);
}

View File

@@ -103,5 +103,11 @@ extern wxCursor *GraphicsBullseyeCursor;
extern wxFont *MatchFont(int point_size);
extern wxString oglColourToHex(const wxColour& colour);
extern wxColour oglHexToColour(const wxString& hex);
extern void oglDecToHex(unsigned int dec, char *buf);
extern unsigned int oglHexToDec(char* buf);
#endif
// _OGL_MISC_H_