From: Shamus Hammons Date: Sat, 30 Aug 2008 18:35:28 +0000 (+0000) Subject: Repurposed code in bezier.h/cpp, added middle button scrolling X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=ttedit;a=commitdiff_plain;h=5c7c36b21d0f2a88accd8ff12c05dcc3004ce0e8 Repurposed code in bezier.h/cpp, added middle button scrolling --- diff --git a/Makefile b/Makefile index a9a0602..59b61f9 100755 --- a/Makefile +++ b/Makefile @@ -59,18 +59,18 @@ PROGRAM = ttedit # KO si sihT -OBJECTS = \ - obj/bezier.o \ - obj/charnames.o \ - obj/charwindow.o \ - obj/debug.o \ - obj/editwindow.o \ - obj/glyphpoints.o \ - obj/registry.o \ - obj/toolwindow.o \ - obj/ttf.o \ - obj/vector.o \ - obj/$(PROGRAM).o \ +OBJECTS = \ + obj/charnames.o \ + obj/charwindow.o \ + obj/debug.o \ + obj/editwindow.o \ + obj/glyphpoints.o \ + obj/graphicprimitives.o \ + obj/registry.o \ + obj/toolwindow.o \ + obj/ttf.o \ + obj/vector.o \ + obj/$(PROGRAM).o \ $(ICON) BIN_PROGRAM = $(PROGRAM)$(EXESUFFIX) diff --git a/src/bezier.cpp b/src/bezier.cpp deleted file mode 100755 index 415f381..0000000 --- a/src/bezier.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// -// Bezier curve fitter -// by James L. Hammons -// (C) 2005 Underground Software -// -// This function takes three points and draws a curve using a -// second order Bezier function. -// -// JLH = James L. Hammons -// -// Who When What -// --- ---------- ------------------------------------------------------------- -// JLH 03/14/1998 Created this file -// JLH 01/20/2005 Converted to use wxWidgets -// - -#include "bezier.h" - -double abs(double n) // Helper function -{ - return (n < 0 ? -n : n); -} - -void Bezier(wxDC &dc, point p1, point p2, point p3) -{ - double step = abs(p1.x - p3.x), tmp = abs(p1.y - p3.y); - step = (tmp > step ? tmp : step); // Get the larger of the two... - step = (step > 0 ? 1/step : 1); // & convert to valid step value - -// MoveToEx(hdc, (int)p1.x, (int)p1.y, NULL); - wxCoord prevX = (wxCoord)p1.x, prevY = (wxCoord)p1.y; - - for(double u=0; u<=1; u+=step) - { - double _2u = 2*u, _uu = u*u, _2uu = 2*_uu, - x = (p1.x * (1 - _2u + _uu)) + (p2.x * (_2u - _2uu)) + (p3.x * _uu), - y = (p1.y * (1 - _2u + _uu)) + (p2.y * (_2u - _2uu)) + (p3.y * _uu); -// LineTo(hdc, (int)x, (int)y); - dc.DrawLine(prevX, prevY, (wxCoord)x, (wxCoord)y); - prevX = (wxCoord)x, prevY = (wxCoord)y; - } - -// LineTo(hdc, (int)p3.x, (int)p3.y); - dc.DrawLine(prevX, prevY, (wxCoord)p3.x, (wxCoord)p3.y); -} diff --git a/src/bezier.h b/src/bezier.h deleted file mode 100755 index 4a5c5ee..0000000 --- a/src/bezier.h +++ /dev/null @@ -1,22 +0,0 @@ -// True Type Hack -// -// Bezier Curve fitter header -// -// This function takes three points and draws a curve using a -// second order Bezier function. - -#ifndef __BEZIER_H__ -#define __BEZIER_H__ - -#include // For device context - -struct point -{ - float x, y; - - point(float xx = 0, float yy = 0): x(xx), y(yy) {} -}; - -void Bezier(wxDC &, point, point, point); - -#endif // __BEZIER_H__ diff --git a/src/editwindow.cpp b/src/editwindow.cpp index 63e8b3f..e16cee9 100755 --- a/src/editwindow.cpp +++ b/src/editwindow.cpp @@ -24,7 +24,7 @@ #define DEBUGTP // Toolpalette debugging... #include "editwindow.h" -#include "bezier.h" +#include "graphicprimitives.h" #include "toolwindow.h" #include "debug.h" #include "vector.h" @@ -321,16 +321,33 @@ WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumP return; } - // Extract current point from lParam/calc offset from previous point + if (e.MiddleIsDown()) + { + // Calc offset from previous point + pt = e.GetPosition(); + ptOffset.x = pt.x - ptPrevious.x, + ptOffset.y = pt.y - ptPrevious.y; - pt = e.GetPosition(); - ptOffset.x = pt.x - ptPrevious.x, - ptOffset.y = pt.y - ptPrevious.y; +// Then multiply it by the scaling factor. Whee! + // This looks wacky because we're using screen coords for the offset... + // Otherwise, we would subtract both offsets! + offsetX -= ptOffset.x, offsetY += ptOffset.y; + Refresh(); + + return; + } // if (e.LeftIsDown()) // { +#if 0 if (tool == TOOLScroll) { + // Extract current point from lParam/calc offset from previous point + + pt = e.GetPosition(); + ptOffset.x = pt.x - ptPrevious.x, + ptOffset.y = pt.y - ptPrevious.y; + // NOTE: OffsetViewportOrg operates in DEVICE UNITS... //Seems there's no equivalent for this in wxWidgets...! @@ -348,7 +365,9 @@ WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumP offsetX -= ptOffset.x, offsetY += ptOffset.y; Refresh(); } - else if (tool == TOOLAddPt || tool == TOOLAddPoly || tool == TOOLSelect) + else +#endif + if (tool == TOOLAddPt || tool == TOOLAddPoly || tool == TOOLSelect) { if (tool != TOOLAddPt || pts.GetNumPoints() > 0)//yecch. { @@ -504,64 +523,6 @@ wxPoint TTEditWindow::GetAdjustedClientPosition(wxCoord x, wxCoord y) return wxPoint(dc.LogicalToDeviceX(x), dc.LogicalToDeviceY(y)); } -// -// Draw a round dot (5x5, centered on [x, y]) -// -void TTEditWindow::DrawRoundDot(wxDC &dc, int32 x, int32 y) -{ - wxPoint pt[8]; - - pt[0].x = x - 1, pt[0].y = y - 2; - pt[1].x = x + 1, pt[1].y = y - 2; - pt[2].x = x + 2, pt[2].y = y - 1; - pt[3].x = x + 2, pt[3].y = y + 1; - pt[4].x = x + 1, pt[4].y = y + 2; - pt[5].x = x - 1, pt[5].y = y + 2; - pt[6].x = x - 2, pt[6].y = y + 1; - pt[7].x = x - 2, pt[7].y = y - 1; - - dc.DrawPolygon(8, pt); -} - -// -// Draw a sqaure dot (5x5, centered on [x, y]) -// -void TTEditWindow::DrawSquareDot(wxDC &dc, int32 x, int32 y) -{ - wxPoint pt[4]; - - pt[0].x = x - 2, pt[0].y = y - 2; - pt[1].x = x + 2, pt[1].y = y - 2; - pt[2].x = x + 2, pt[2].y = y + 2; - pt[3].x = x - 2, pt[3].y = y + 2; - - dc.DrawPolygon(4, pt); -} - -// -// Draw a sqaure dot (nxn, centered on [x, y]) -// -void TTEditWindow::DrawSquareDotN(wxDC &dc, int32 x, int32 y, uint32 n) -{ - wxPoint pt[4]; - uint32 offset = (n - 1) / 2; - - pt[0].x = x - offset, pt[0].y = y - offset; - pt[1].x = x + offset, pt[1].y = y - offset; - pt[2].x = x + offset, pt[2].y = y + offset; - pt[3].x = x - offset, pt[3].y = y + offset; - - dc.DrawPolygon(4, pt); -} - -// -// Draw a round dot (nxn, centered on [x, y]) -// -void TTEditWindow::DrawRoundDotN(wxDC &dc, int32 x, int32 y, uint32 n) -{ - dc.DrawCircle(x, y, (n / 2) + 1); -} - #if 0 diff --git a/src/editwindow.h b/src/editwindow.h index 8034d7e..4d0a931 100755 --- a/src/editwindow.h +++ b/src/editwindow.h @@ -41,10 +41,6 @@ class TTEditWindow: public wxWindow protected: wxPoint GetAdjustedMousePosition(wxMouseEvent &e); wxPoint GetAdjustedClientPosition(wxCoord x, wxCoord y); - void DrawRoundDot(wxDC &, int32, int32); - void DrawSquareDot(wxDC &, int32, int32); - void DrawRoundDotN(wxDC &, int32, int32, uint32); - void DrawSquareDotN(wxDC &, int32, int32, uint32); DECLARE_EVENT_TABLE() }; diff --git a/src/graphicprimitives.cpp b/src/graphicprimitives.cpp new file mode 100755 index 0000000..9802347 --- /dev/null +++ b/src/graphicprimitives.cpp @@ -0,0 +1,107 @@ +// +// Graphics primitives +// +// Various graphic functions that are slightly more complex than those that +// come with various widget libraries. +// +// by James L. Hammons +// (C) 2005 Underground Software +// +// JLH = James L. Hammons +// +// Who When What +// --- ---------- ------------------------------------------------------------- +// JLH 03/14/1998 Created this file +// JLH 01/20/2005 Converted to use wxWidgets +// JLH 08/30/2008 Repurposed file to handle more than just bezier curves +// + +#include "graphicprimitives.h" + +double abs(double n) // Helper function +{ + return (n < 0 ? -n : n); +} + +// +// This function takes three points and draws a curve using a second order +// Bezier function. +// +void Bezier(wxDC &dc, point p1, point p2, point p3) +{ + double step = abs(p1.x - p3.x), tmp = abs(p1.y - p3.y); + step = (tmp > step ? tmp : step); // Get the larger of the two... + step = (step > 0 ? 1/step : 1); // & convert to valid step value + + wxCoord prevX = (wxCoord)p1.x, prevY = (wxCoord)p1.y; + + for(double u=0; u<=1; u+=step) + { + double _2u = 2*u, _uu = u*u, _2uu = 2*_uu; + double x = (p1.x * (1 - _2u + _uu)) + (p2.x * (_2u - _2uu)) + (p3.x * _uu); + double y = (p1.y * (1 - _2u + _uu)) + (p2.y * (_2u - _2uu)) + (p3.y * _uu); + + dc.DrawLine(prevX, prevY, (wxCoord)x, (wxCoord)y); + prevX = (wxCoord)x, prevY = (wxCoord)y; + } + + dc.DrawLine(prevX, prevY, (wxCoord)p3.x, (wxCoord)p3.y); +} + +// +// Draw a round dot (5x5, centered on [x, y]) +// +void DrawRoundDot(wxDC &dc, int32 x, int32 y) +{ + wxPoint pt[8]; + + pt[0].x = x - 1, pt[0].y = y - 2; + pt[1].x = x + 1, pt[1].y = y - 2; + pt[2].x = x + 2, pt[2].y = y - 1; + pt[3].x = x + 2, pt[3].y = y + 1; + pt[4].x = x + 1, pt[4].y = y + 2; + pt[5].x = x - 1, pt[5].y = y + 2; + pt[6].x = x - 2, pt[6].y = y + 1; + pt[7].x = x - 2, pt[7].y = y - 1; + + dc.DrawPolygon(8, pt); +} + +// +// Draw a sqaure dot (5x5, centered on [x, y]) +// +void DrawSquareDot(wxDC &dc, int32 x, int32 y) +{ + wxPoint pt[4]; + + pt[0].x = x - 2, pt[0].y = y - 2; + pt[1].x = x + 2, pt[1].y = y - 2; + pt[2].x = x + 2, pt[2].y = y + 2; + pt[3].x = x - 2, pt[3].y = y + 2; + + dc.DrawPolygon(4, pt); +} + +// +// Draw a sqaure dot (nxn, centered on [x, y]) +// +void DrawSquareDotN(wxDC &dc, int32 x, int32 y, uint32 n) +{ + wxPoint pt[4]; + uint32 offset = (n - 1) / 2; + + pt[0].x = x - offset, pt[0].y = y - offset; + pt[1].x = x + offset, pt[1].y = y - offset; + pt[2].x = x + offset, pt[2].y = y + offset; + pt[3].x = x - offset, pt[3].y = y + offset; + + dc.DrawPolygon(4, pt); +} + +// +// Draw a round dot (nxn, centered on [x, y]) +// +void DrawRoundDotN(wxDC &dc, int32 x, int32 y, uint32 n) +{ + dc.DrawCircle(x, y, (n / 2) + 1); +} diff --git a/src/graphicprimitives.h b/src/graphicprimitives.h new file mode 100755 index 0000000..dbc7a11 --- /dev/null +++ b/src/graphicprimitives.h @@ -0,0 +1,27 @@ +// +// Graphics primitives +// +// Various graphic functions that are slightly more complex than those that +// come with various widget libraries. +// + +#ifndef __GRAPHICPRIMITIVES_H__ +#define __GRAPHICPRIMITIVES_H__ + +#include // For device context +#include "types.h" // For int32 + +struct point +{ + float x, y; + + point(float xx = 0, float yy = 0): x(xx), y(yy) {} +}; + +void Bezier(wxDC &, point, point, point); +void DrawRoundDot(wxDC &, int32, int32); +void DrawSquareDot(wxDC &, int32, int32); +void DrawRoundDotN(wxDC &, int32, int32, uint32); +void DrawSquareDotN(wxDC &, int32, int32, uint32); + +#endif // __GRAPHICPRIMITIVES_H__