]> Shamusworld >> Repos - ttedit/commitdiff
Too many changes between last commit and here. I forgot that
authorShamus Hammons <jlhamm@acm.org>
Fri, 29 Aug 2008 19:21:29 +0000 (19:21 +0000)
committerShamus Hammons <jlhamm@acm.org>
Fri, 29 Aug 2008 19:21:29 +0000 (19:21 +0000)
I had made an SVN repository for this project. Basically,
made a good stab at converting the app to wxWidgets, and fixed
a nasty bug in the tool palette. Hopefully forthcoming commits
will be more erudite.

18 files changed:
Makefile
res/cur1.xpm
res/cur2.xpm
res/cur3.xpm
res/cur4.xpm
res/cur5.xpm
res/cur6.xpm
res/cur7.xpm
res/cur8.xpm
res/tool1.xpm
res/tool2.xpm
res/tool3.xpm
res/toolpal1.xpm
res/ttedit.xpm
src/list.h
src/ttedit.cpp
src/ttedit.h
src/types.h

index 75a82fa4e59631229f59b51632e29bb2ec99f378..a9a0602cb2f087cb8ac7c6917c3954263f15b30f 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -50,7 +50,7 @@ WX_VERSION = $(WX_RELEASE).0
 # This is OK
 
 # Note that the -MMD flag is what gives us our automagic dependency information (*.d files)
-# Add -g to compile in debuggin information
+# Add -g to compile in debugging information
 CXXFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -O2 `wx-config --cxxflags` -g
 INCS = -I.
 LIBS = `wx-config --libs`
@@ -62,9 +62,12 @@ PROGRAM = ttedit
 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  \
index 46c1adfc3567531dba5a1ec8c6eb9e34e11fa24b..b69ef60fac07caf8c473ae79e71d095faa8df8a6 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * cur1_xpm[] = {\r
+static const char * cur1_xpm[] = {\r
 "32 32 2 1",\r
 "      g #000000",\r
 ".     g #FFFFFF",\r
index 4a33bca3b17ce16e56f56a8c8b86b74158da3f8e..956ddf4987f2b79457d14522e3350d884a48af07 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * cur2_xpm[] = {\r
+static const char * cur2_xpm[] = {\r
 "32 32 2 1",\r
 "      g #000000",\r
 ".     g #FFFFFF",\r
index 595a36090aa48dad217f6825aaf7df19e0043c58..881e009b94633f80e23a99ecfc0f577e10a7beb7 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * cur3_xpm[] = {\r
+static const char * cur3_xpm[] = {\r
 "32 32 2 1",\r
 "      g #FFFFFF",\r
 ".     g #000000",\r
index 86c21413382c1ac74067d13d420b8ca46f5ad3f0..d4fec81772a64040a70c01d0a9cbfd8b23ad6629 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * cur4_xpm[] = {\r
+static const char * cur4_xpm[] = {\r
 "32 32 2 1",\r
 "      g #FFFFFF",\r
 ".     g #000000",\r
index 9bc1b357364f3e48f62db2121352a5a135493910..cebcfc5ce9c14b24f327bd2c6c0f258488466c64 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * cur5_xpm[] = {\r
+static const char * cur5_xpm[] = {\r
 "32 32 2 1",\r
 "      g #000000",\r
 ".     g #FFFFFF",\r
@@ -16,9 +16,9 @@ static char * cur5_xpm[] = {
 "           .....................",\r
 "            ....................",\r
 "       .........................",\r
-"       .........................",\r
-"   ..   ........................",\r
-"  ...   ........................",\r
+"       ...... ..................",\r
+"   ..   ....   .................",\r
+"  ...   ..... ..................",\r
 " .....   .......................",\r
 "......   .....    ..............",\r
 ".......   ...      .............",\r
index bf24733124e09c9a4aa90eaa5e21a96197f939ea..e0f44c7e974e8edf3468f6219b7fbd364a4f47ac 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * cur6_xpm[] = {\r
+static const char * cur6_xpm[] = {\r
 "32 32 2 1",\r
 "      g #000000",\r
 ".     g #FFFFFF",\r
index 1c9fb67e8e0c733cf3a5a7a3abdf4d4d043ae8c5..0f7d04d919f42bd3d8357e389d58a6313565da1c 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * cur7_xpm[] = {\r
+static const char * cur7_xpm[] = {\r
 "32 32 2 1",\r
 "      g #000000",\r
 ".     g #FFFFFF",\r
index 91d96a53a7b19be4e519ff1164f508fd4ab75cf0..edb642264ef09819336d26f5f3a32e035f00afd7 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * cur8_xpm[] = {\r
+static const char * cur8_xpm[] = {\r
 "32 32 2 1",\r
 "      g #000000",\r
 ".     g #FFFFFF",\r
index 200b8c6311a0ed5fd01733a2d9028c6dff598b56..a0703fd7d91bd39fc4141a4beba4c452c4b6ad51 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * tool1_xpm[] = {\r
+static const char * tool1_xpm[] = {\r
 "16 15 3 1",\r
 "      c None",\r
 ".     c #A0A0A0",\r
index 934388919a2ca8e72a2cfbb7a27de031eb015a98..e73fc450f4d603cb5de60404a7a75aa7bcf80eb8 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * tool2_xpm[] = {\r
+static const char * tool2_xpm[] = {\r
 "16 15 3 1",\r
 "      c None",\r
 ".     c #C0C0C0",\r
index 06d0c069b7eda3516694febab1bed980d0cd3dee..885a87027b0280f8cd0f405a40554c82e325ced2 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * tool3_xpm[] = {\r
+static const char * tool3_xpm[] = {\r
 "16 15 3 1",\r
 "      c None",\r
 ".     c #C0C0C0",\r
index a11c7a94057666a7fabf8151e8d89ff706eb2731..5f29c6de50f9fd43775b013aa96bc4e65f9d46b6 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */\r
-static char * toolpal1_xpm[] = {\r
+static const char * toolpal1_xpm[] = {\r
 "96 48 2 1",\r
 "      c #000000",\r
 ".     c #FFFFFF",\r
index 9828fe077f6ca1b8e96723cdd6a4352670ce2975..6d065293a6f6b8f93cfbec5889cb50936b139b14 100755 (executable)
@@ -1,5 +1,5 @@
 /* XPM */
-static char *ttedit_xpm[]={
+static const char *ttedit_xpm[]={
 "32 32 11 1",
 ". c None",
 "d c #0000ff",
index 4e516c13202f66823dea4e58f200e0199d3f7363..da0501f6e863cb1d75fe0914c0b0cf8067a0c1a3 100755 (executable)
@@ -26,9 +26,7 @@ template <class T> class Node
        friend class List<T>;\r
 \r
        public:\r
-//             Node(void)                         { next = NULL; }\r
                Node(void): next(NULL) {}\r
-//             Node(const T d, Node * ptr = NULL) { data = d;  next = ptr; }\r
                Node(const T d, Node * ptr = NULL): data(d), next(ptr) {}\r
 \r
        private:\r
index cb19ce2b298c993208ff1a6468c0a3aba1760ab3..3c31541a8934d42c68804eac35c8e504ddb97afd 100755 (executable)
 // JLH  05/10/2004  Translated file from ASM to CPP\r
 // JLH  05/14/2004  Added rudimentary editing capability to tool palette tools\r
 // JLH  11/18/2006  Initial port to Linux\r
+// JLH  08/27/2008  Fixed tool palette focus problems\r
+// JLH  08/28/2008  Split out classes defined here into separate files\r
 //\r
 \r
+// FIXED:\r
+//\r
+// - Fix problem with tool palette not getting focus 1st time it's called up [DONE]\r
+// - Split out windows/classes defined here into their own files [DONE]\r
+//\r
 // STILL TO BE DONE:\r
 //\r
 // - Fix bug in Glyphpoints when dragging on an empty canvas or loading a font\r
 \r
 // Uncomment this for debugging...\r
 #define DEBUG\r
-#define DEBUGFOO            // Various tool debugging...\r
-\r
-#include <math.h>\r
-#include "types.h"\r
-#include "tte_res.h"\r
-#include "ttf.h"\r
-#include "registry.h"\r
-#include "bezier.h"\r
-#include "glyphpoints.h"\r
-#include "vector.h"\r
+#define DEBUGFOO                       // Various tool debugging...\r
+#define DEBUGTP                                // Toolpalette debugging...\r
+\r
+#include "ttedit.h"\r
+#include "charwindow.h"\r
+#include "toolwindow.h"\r
+#include "editwindow.h"\r
+#include "tte_res.h"                                                   // Resource IDs\r
 #ifdef DEBUG\r
 #include "debug.h"\r
 #endif\r
-#include "ttedit.h"                                                            // Usually not necessary, but here we are...\r
-#include <wx/confbase.h>\r
-#include <wx/fileconf.h>\r
-#include <wx/image.h>\r
 \r
-#include "res/ttedit.xpm"                                              // *nix only, but small enough to not matter\r
-#include "res/toolpal1.xpm"                                            // Docs say this is portable... Let's see!\r
+// Pixmap resouces\r
+\r
 #include "res/cur1.xpm"\r
 #include "res/cur2.xpm"\r
 #include "res/cur3.xpm"\r
 #include "res/cur6.xpm"\r
 #include "res/cur7.xpm"\r
 #include "res/cur8.xpm"\r
+#include "res/ttedit.xpm"                                              // *nix only, but small enough to not matter\r
 #include "res/tool1.xpm"\r
 #include "res/tool2.xpm"\r
 #include "res/tool3.xpm"\r
 \r
-//\r
-// E Q U A T E S\r
-//\r
-#define TOOLSelect                     0x00                            // The "selection" tool\r
-#define TOOLPolySelect         0x01                            // Polygon selection tool\r
-#define TOOLScroll                     0x02                            // Scroll window tool\r
-#define TOOLZoom                       0x03                            // Zoom window tool\r
-#define TOOLAddPt                      0x04                            // Add point tool\r
-#define TOOLAddPoly                    0x05                            // Polygon creation tool\r
-#define TOOLDelPt                      0x06                            // Delete point tool\r
-#define TOOLDelPoly                    0x07                            // Delete polygon tool\r
-\r
-//\r
-// Function and Procedure Prototypes\r
-//\r
-//BOOL CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM);\r
-//void MiscCenterWnd(HWND, HWND);\r
-//bool OnlyOneInstance(void);\r
-void CreateResources(void);\r
-bool Initialization(void);\r
-void DeallocateResources(void);\r
-void SaveAppState(void);\r
-void DrawRoundDot(wxDC &, int32, int32);\r
-void DrawSquareDot(wxDC &, int32, int32);\r
-void DrawRoundDotN(wxDC &, int32, int32, uint32);\r
-void DrawSquareDotN(wxDC &, int32, int32, uint32);\r
-void CreateNewDoc(void);\r
-bool SaveChanges(void);\r
-\r
-// Global constant data\r
-\r
-//const char className[] = "TTEDIT";\r
-//const char CNCharWin[] = "US_CHARWIN";\r
-//const char CNToolPal[] = "US_TOOLPALETTE";\r
-//const char CNStatus[] = "msctls_statusbar32";\r
-const char filter[] = "Font Files (*.TTF)\0*.TTF\0All Files (*.*)\0*.*\0";\r
-const char defExt[] = "ttf";\r
-//const char mtitle[] = "Character Window!";\r
-const char zoom[] = "Zoom: %u%%";\r
-\r
-/*const TBBUTTON tbButtons[4] = {\r
-       { 0, ID_TBLEFT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 },\r
-       { 1, ID_TBRIGHT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 },\r
-       { 0, 0, 0, TBSTYLE_SEP, 0, 0 },\r
-       { 2, ID_TBCHARWIN, TBSTATE_ENABLED | TBSTATE_CHECKED, TBSTYLE_CHECK, 0, 0 }\r
-};*/\r
-\r
-\r
-//\r
-// U N I N I T I A L I Z E D    D A T A\r
-//\r
-/*\r
-szSaveChanges  SBYTE   "Save changes to the following file?", 0Ah, 0Ah\r
-szFile         SBYTE   MAX_PATH DUP (0)\r
-szWindowName   SBYTE   (MAX_PATH + 10h) DUP (0)\r
-fScaleFactor   REAL4   1.0                     // Window scaling factor\r
-\r
-*/\r
-\r
-//HINSTANCE hInst;\r
-int nCmdShow;\r
-//HWND hMainWnd, hStatusBar, hToolBar, hCharWnd, hToolPalWnd;\r
-char statusBarTxt[64];\r
-char toolTipTxt[16];\r
-char strBuf[1024];\r
-\r
-//HCURSOR hCur[8];\r
-wxCursor * cur[8];\r
-\r
-//HBITMAP hBMToolPal1;\r
-//HPEN hRedPen1, hBluePen1, hGreenPen1, hBlackPen1;\r
-//HBRUSH hNullBrush;\r
-\r
-//POINT sizeStamp, sizeTPBM, ptPrevious;\r
-//PTSTRUCT aPts[16];\r
-//uint32 numPts = 0;\r
-GlyphPoints pts;\r
-int32 ptHighlight = -1, oldPtHighlight = -1, ptNextHighlight = -1, oldPtNextHighlight = -1;\r
-int32 currentTool = TOOLSelect;                                        // Current tool is "selection" tool\r
-bool mouseDown = false;                                                        // Mouse down flag\r
-bool NCMouseDown;\r
-//POINT ptWinOffset;\r
-uint32 zoomWndWidth;\r
-bool polyFirstPoint = true;\r
-\r
-char curCharName[] = "Own3d W1nd0w";                   // Need to make this a buffer w/default\r
-\r
-//WINDOWPLACEMENT wpM, wpC;\r
-//POINT ptVPM;\r
-\r
-\r
 \r
 IMPLEMENT_APP(TTEditApp)                                               // Run the main application loop\r
 \r
@@ -163,15 +74,19 @@ bool TTEditApp::OnInit()
        charWin = NULL;\r
        toolPalette = NULL;\r
 \r
+//Shouldn't we check to see if it was successful? This just assumes\r
        CreateResources();\r
 \r
        mainFrame = new TTEditFrame(NULL, _("TTEdit"), wxPoint(155, 165), wxSize(300, 300),\r
                wxDEFAULT_FRAME_STYLE | wxFULL_REPAINT_ON_RESIZE);\r
 //             wxMINIMIZE_BOX | wxRESIZE_BOX | wxMAXIMIZE_BOX | | wxSYSTEM_MENU | wxCAPTION);\r
 \r
-       charWin = new CharWindow(NULL);//, _T("Own3d W1nd0w"), wxDefaultPosition, wxDefaultSize);\r
+//     charWin = new CharWindow(NULL);//, _T("Own3d W1nd0w"), wxDefaultPosition, wxDefaultSize);\r
+       charWin = new CharWindow(mainFrame, _("Own3d W1nd0w"), wxDefaultPosition, wxDefaultSize,\r
+               wxCAPTION | wxRESIZE_BORDER);\r
+\r
        toolPalette = new ToolWindow(mainFrame, _(""), wxDefaultPosition, wxDefaultSize,\r
-               wxNO_BORDER | wxFRAME_NO_TASKBAR);\r
+               wxBORDER_NONE | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT);\r
 \r
        return true;\r
 }\r
@@ -185,6 +100,53 @@ int TTEditApp::OnExit()
        return 0;\r
 }\r
 \r
+void TTEditApp::CreateResources(void)\r
+{\r
+       // This is a sucky way to create cursors, but at least it's cross-platform...\r
+       // NOTE: Need to fix hotspots on a few... !!! FIX !!!\r
+\r
+       wxBitmap cursorBM1(cur1_xpm);\r
+       wxImage cursorImage1 = cursorBM1.ConvertToImage();\r
+       cursorImage1.SetMaskFromImage(cursorImage1, 0xFF, 0xFF, 0xFF);\r
+       cur[0] = new wxCursor(cursorImage1);\r
+\r
+       wxBitmap cursorBM2(cur2_xpm);\r
+       wxImage cursorImage2 = cursorBM2.ConvertToImage();\r
+       cursorImage2.SetMaskFromImage(cursorImage2, 0xFF, 0xFF, 0xFF);\r
+       cur[1] = new wxCursor(cursorImage2);\r
+\r
+       wxBitmap cursorBM3(cur3_xpm);\r
+       wxImage cursorImage3 = cursorBM3.ConvertToImage();\r
+       cursorImage3.SetMaskFromImage(cursorImage3, 0xFF, 0xFF, 0xFF);\r
+       cur[2] = new wxCursor(cursorImage3);\r
+\r
+       wxBitmap cursorBM4(cur4_xpm);\r
+       wxImage cursorImage4 = cursorBM4.ConvertToImage();\r
+       cursorImage4.SetMaskFromImage(cursorImage4, 0xFF, 0xFF, 0xFF);\r
+       cur[3] = new wxCursor(cursorImage4);\r
+\r
+       wxBitmap cursorBM5(cur5_xpm);\r
+       wxImage cursorImage5 = cursorBM5.ConvertToImage();\r
+       cursorImage5.SetMaskFromImage(cursorImage5, 0xFF, 0xFF, 0xFF);\r
+       cur[4] = new wxCursor(cursorImage5);\r
+\r
+       wxBitmap cursorBM6(cur6_xpm);\r
+       wxImage cursorImage6 = cursorBM6.ConvertToImage();\r
+       cursorImage6.SetMaskFromImage(cursorImage6, 0xFF, 0xFF, 0xFF);\r
+       cur[5] = new wxCursor(cursorImage6);\r
+\r
+       wxBitmap cursorBM7(cur7_xpm);\r
+       wxImage cursorImage7 = cursorBM7.ConvertToImage();\r
+       cursorImage7.SetMaskFromImage(cursorImage7, 0xFF, 0xFF, 0xFF);\r
+       cur[6] = new wxCursor(cursorImage7);\r
+\r
+       wxBitmap cursorBM8(cur8_xpm);\r
+       wxImage cursorImage8 = cursorBM8.ConvertToImage();\r
+       cursorImage8.SetMaskFromImage(cursorImage8, 0xFF, 0xFF, 0xFF);\r
+       cur[7] = new wxCursor(cursorImage8);\r
+}\r
+\r
+\r
 BEGIN_EVENT_TABLE(TTEditFrame, wxFrame)\r
        EVT_MENU(IDM_OPEN, TTEditFrame::OnOpen)\r
        EVT_MENU(IDM_EXIT, TTEditFrame::OnExit)\r
@@ -193,14 +155,14 @@ BEGIN_EVENT_TABLE(TTEditFrame, wxFrame)
 END_EVENT_TABLE()\r
 \r
 TTEditFrame::TTEditFrame(wxFrame * parent, const wxString &title, const wxPoint &pos,\r
-       const wxSize &size, long style): wxFrame(parent, -1, title, pos, size, style), app(wxGetApp())\r
+       const wxSize &size, long style): wxFrame(parent, -1, title, pos, size, style), app(wxGetApp()), mainWindow(NULL)\r
 {\r
        // Initialize child subwindow members (and hopefully avoid subtle bugs)\r
-       mainWindow = NULL;\r
+//     mainWindow = NULL;\r
 \r
        SetIcon(wxICON(ttedit));\r
 //     CreateStatusBar(2);                                                     // Create 2 panes\r
-       int widths[2] = { -1, 100 };\r
+       int widths[2] = { -1, 120 };\r
        wxStatusBar * sb = CreateStatusBar(2, 0);       // Create 2 panes\r
        sb->SetStatusWidths(2, widths);\r
        wxToolBar * tb = CreateToolBar();\r
@@ -267,1795 +229,18 @@ void TTEditFrame::OnOpen(wxCommandEvent &e)
 \r
 void TTEditFrame::OnAbout(wxCommandEvent &e)\r
 {\r
-       wxMessageDialog dlg(NULL, _("TrueType Edit v1.0.0\n\nA handy tool for editing TrueType fonts!\nby James \"Shamus\" Hammons\n(C) 2006 Underground Software"), _("About TrueType Edit"), wxOK | wxICON_INFORMATION);\r
+       wxMessageDialog dlg(NULL, _("TrueType Edit v1.0.1\n\nA handy tool for editing TrueType fonts!\nby James \"Shamus\" Hammons\n(C) 2006 Underground Software"), _("About TrueType Edit"), wxOK | wxICON_INFORMATION);\r
        dlg.ShowModal();\r
 }\r
 \r
 void TTEditFrame::OnExit(wxCommandEvent &e)\r
 {\r
-       wxGetApp().toolPalette->Destroy();\r
+       app.toolPalette->Destroy();\r
        this->Destroy();\r
 }\r
 \r
 void TTEditFrame::OnCloseWindow(wxCloseEvent &e)\r
 {\r
-       wxGetApp().toolPalette->Destroy();\r
+       app.toolPalette->Destroy();\r
        this->Destroy();\r
 }\r
-\r
-BEGIN_EVENT_TABLE(TTEditWindow, wxWindow)\r
-       EVT_PAINT(TTEditWindow::OnPaint)\r
-       EVT_MOUSE_EVENTS(TTEditWindow::OnMouseEvent)\r
-END_EVENT_TABLE()\r
-\r
-TTEditWindow::TTEditWindow(wxFrame * parent, const wxPoint &pos, const wxSize &size, long style):\r
-       wxWindow(parent, -1, pos, size, style), app(wxGetApp())\r
-{ \r
-       bmp = NULL;\r
-       scale = 1.0;\r
-       offsetX = offsetY = -10;\r
-\r
-       SetCursor(*cur[currentTool]);\r
-       SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF));\r
-\r
-       wxString s;\r
-       s.Printf(_("Zoom: %.2f%%"), scale * 100.0);\r
-       parent->SetStatusText(s, 1);\r
-}\r
-\r
-TTEditWindow::~TTEditWindow(void)\r
-{\r
-       if (bmp)\r
-               delete bmp;\r
-}\r
-\r
-void TTEditWindow::OnPaint(wxPaintEvent &e)\r
-{\r
-/*     wxPaintDC dc(this);\r
-\r
-       // Insert your drawing code here.\r
-       if (!bmp)\r
-       {\r
-               bmp = new wxBitmap(field_width * x_cell * X_UNIT + 1, field_height * y_cell * Y_UNIT + 1);\r
-\r
-               if (bmp)\r
-               {\r
-                       wxMemoryDC memDC;\r
-                       memDC.SelectObject(*bmp);\r
-                       DrawField(&memDC, 0, 0, field_width - 1, field_height - 1);\r
-                       memDC.SelectObject(wxNullBitmap);\r
-               }\r
-       }\r
-\r
-       if (bmp)\r
-       {\r
-               wxMemoryDC memDC;\r
-               memDC.SelectObject(* bmp);\r
-               dc.Blit(0, 0, field_width * x_cell * X_UNIT + 1, field_height * y_cell * Y_UNIT + 1,\r
-                       &memDC, 0, 0, wxCOPY);\r
-               memDC.SelectObject(wxNullBitmap);\r
-       }\r
-       else\r
-               DrawField(&dc, 0, 0, field_width - 1, field_height - 1);*/\r
-\r
-       wxPaintDC dc(this);\r
-//Doesn't do crap!\r
-//dc.SetBackground(*wxWHITE_BRUSH);\r
-\r
-// Due to the screwiness of wxWidgets coord system, the origin is ALWAYS\r
-// the upper left corner--regardless of axis orientation, etc...\r
-       wxCoord width, height;\r
-       dc.GetSize(&width, &height);\r
-\r
-       dc.SetDeviceOrigin(-offsetX, height - (-offsetY));\r
-       dc.SetAxisOrientation(true, true);\r
-\r
-// Scrolling can be done by using OffsetViewportOrgEx\r
-// Scaling can be done by adjusting SetWindowExtEx (it's denominator of txform)\r
-// you'd use: % = ViewportExt / WindowExt\r
-// But it makes the window look like crap: fuggetuboutit.\r
-// Instead, we have to scale EVERYTHING by hand. Crap!\r
-// It's not *that* bad, but not as convenient either...\r
-\r
-       dc.SetPen(*(wxThePenList->FindOrCreatePen(wxColour(0x00, 0x00, 0xFF), 1, wxDOT)));\r
-//     dc.DrawLine(0, 0, 10, 10);\r
-\r
-    // Draw coordinate axes\r
-\r
-       dc.CrossHair(0, 0);\r
-\r
-    // Draw points\r
-\r
-       for(int i=0; i<pts.GetNumPoints(); i++)\r
-       {\r
-               if (i == ptHighlight)\r
-               {\r
-                       dc.SetPen(*(wxThePenList->FindOrCreatePen(wxColour(0xFF, 0x00, 0x00), 1, wxSOLID)));\r
-//                     SelectObject(hdc, hRedPen1);\r
-\r
-                       if (pts.GetOnCurve(i))\r
-                       {\r
-                               DrawSquareDotN(dc, pts.GetX(i), pts.GetY(i), 7);\r
-                               DrawSquareDotN(dc, pts.GetX(i), pts.GetY(i), 9);\r
-                       }\r
-                       else\r
-                       {\r
-                               DrawRoundDotN(dc, pts.GetX(i), pts.GetY(i), 7);\r
-                               DrawRoundDotN(dc, pts.GetX(i), pts.GetY(i), 9);\r
-                       }\r
-               }\r
-               else if ((i == ptHighlight || i == ptNextHighlight) && currentTool == TOOLAddPt)\r
-               {\r
-                       dc.SetPen(*(wxThePenList->FindOrCreatePen(wxColour(0x00, 0xAF, 0x00), 1, wxSOLID)));\r
-//                     SelectObject(hdc, hGreenPen1);\r
-\r
-                       if (pts.GetOnCurve(i))\r
-                       {\r
-                               DrawSquareDotN(dc, pts.GetX(i), pts.GetY(i), 7);\r
-                               DrawSquareDotN(dc, pts.GetX(i), pts.GetY(i), 9);\r
-                       }\r
-                       else\r
-                       {\r
-                               DrawRoundDotN(dc, pts.GetX(i), pts.GetY(i), 7);\r
-                               DrawRoundDotN(dc, pts.GetX(i), pts.GetY(i), 9);\r
-                       }\r
-               }\r
-               else\r
-               {\r
-                       dc.SetPen(*(wxThePenList->FindOrCreatePen(wxColour(0x00, 0x00, 0x00), 1, wxSOLID)));\r
-//                     SelectObject(hdc, hBlackPen1);\r
-\r
-                       if (pts.GetOnCurve(i))\r
-                               DrawSquareDot(dc, pts.GetX(i), pts.GetY(i));\r
-                       else\r
-                               DrawRoundDot(dc, pts.GetX(i), pts.GetY(i));\r
-               }\r
-\r
-               if (currentTool == TOOLDelPt && i == ptHighlight)\r
-               {\r
-                       dc.SetPen(*(wxThePenList->FindOrCreatePen(wxColour(0xFF, 0x00, 0x00), 1, wxSOLID)));\r
-//                     SelectObject(hdc, hRedPen1);\r
-//                     MoveToEx(hdc, pts.GetX(i) - 5, pts.GetY(i) - 5, NULL);\r
-//                     LineTo(hdc, pts.GetX(i) + 5, pts.GetY(i) + 5);\r
-//                     LineTo(hdc, pts.GetX(i) - 5, pts.GetY(i) - 5);//Lameness!\r
-//                     MoveToEx(hdc, pts.GetX(i) - 5, pts.GetY(i) + 5, NULL);\r
-//                     LineTo(hdc, pts.GetX(i) + 5, pts.GetY(i) - 5);\r
-//                     LineTo(hdc, pts.GetX(i) - 5, pts.GetY(i) + 5);//More lameness!!\r
-                       dc.DrawLine(pts.GetX(i) - 5, pts.GetY(i) - 5, pts.GetX(i) + 5, pts.GetY(i) + 5);\r
-                       dc.DrawLine(pts.GetX(i) + 5, pts.GetY(i) - 5, pts.GetX(i) - 5, pts.GetY(i) + 5);\r
-               }\r
-       }\r
-\r
-//             SelectObject(hdc, hBlackPen1);\r
-       dc.SetPen(*(wxThePenList->FindOrCreatePen(wxColour(0x00, 0x00, 0x00), 1, wxSOLID)));\r
-\r
-       // Draw curve formed by points\r
-\r
-       for(int poly=0; poly<pts.GetNumPolys(); poly++)\r
-       {\r
-               if (pts.GetNumPoints(poly) > 2)\r
-               {\r
-                       // Initial move...\r
-                       // If it's not on curve, then move to it, otherwise move to last point...\r
-\r
-                       wxCoord x, y;\r
-       \r
-                       if (pts.GetOnCurve(poly, pts.GetNumPoints(poly) - 1))\r
-                               x = (wxCoord)pts.GetX(poly, pts.GetNumPoints(poly) - 1), y = (wxCoord)pts.GetY(poly, pts.GetNumPoints(poly) - 1);\r
-                       else\r
-                               x = (wxCoord)pts.GetX(poly, 0), y = (wxCoord)pts.GetY(poly, 0);\r
-       \r
-                       for(int i=0; i<pts.GetNumPoints(poly); i++)\r
-                       {\r
-                               if (pts.GetOnCurve(poly, i))\r
-//                                     LineTo(hdc, pts.GetX(poly, i), pts.GetY(poly, i));\r
-                               {\r
-                                       dc.DrawLine(x, y, pts.GetX(poly, i), pts.GetY(poly, i));\r
-                                       x = (wxCoord)pts.GetX(poly, i), y = (wxCoord)pts.GetY(poly, i);\r
-                               }\r
-                               else\r
-                               {\r
-                                       uint32 prev = pts.GetPrev(poly, i), next = pts.GetNext(poly, i);\r
-                                       float px = pts.GetX(poly, prev), py = pts.GetY(poly, prev),\r
-                                               nx = pts.GetX(poly, next), ny = pts.GetY(poly, next);\r
-       \r
-                                       if (!pts.GetOnCurve(poly, prev))\r
-                                               px = (px + pts.GetX(poly, i)) / 2.0f,\r
-                                               py = (py + pts.GetY(poly, i)) / 2.0f;\r
-       \r
-                                       if (!pts.GetOnCurve(poly, next))\r
-                                               nx = (nx + pts.GetX(poly, i)) / 2.0f,\r
-                                               ny = (ny + pts.GetY(poly, i)) / 2.0f;\r
-       \r
-                                       Bezier(dc, point(px, py), point(pts.GetX(poly, i), pts.GetY(poly, i)), point(nx, ny));\r
-                                       x = (wxCoord)nx, y = (wxCoord)ny;\r
-       \r
-                                       if (pts.GetOnCurve(poly, next))\r
-                                               i++;                                    // Following point is on curve, so move past it\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-//             SelectObject(hdc, oldPen);                              // Restore the stuff we disrupted...\r
-       dc.SetPen(wxNullPen);\r
-//             SelectObject(hdc, oldBrush);\r
-//             EndPaint(hWnd, &ps);\r
-}\r
-\r
-void TTEditWindow::OnMouseEvent(wxMouseEvent &e)\r
-{\r
-       if (e.RightDown())\r
-       {\r
-               wxPoint pt = ClientToScreen(e.GetPosition());\r
-               wxGetApp().toolPalette->Move(pt);\r
-               wxGetApp().toolPalette->Show(true);\r
-               wxGetApp().toolPalette->SetFocus();\r
-               wxGetApp().toolPalette->CaptureMouse();\r
-               SetCursor(*wxSTANDARD_CURSOR);\r
-       }\r
-       else if (e.LeftDown())\r
-       {\r
-               if (currentTool == TOOLScroll || currentTool == TOOLZoom)\r
-                       CaptureMouse();                                         // Make sure we capture the mouse when in scroll/zoom mode\r
-               else if (currentTool == TOOLAddPt)              // "Add Point" tool\r
-               {\r
-                       if (pts.GetNumPoints() > 0)\r
-                       {\r
-                               wxPoint pt = GetAdjustedMousePosition(e);\r
-                               pts.InsertPoint(pts.GetNext(ptHighlight), pt.x, pt.y, (e.ShiftDown() | e.ControlDown() ? false : true));\r
-                               ptHighlight = ptNextHighlight;\r
-                               Refresh();\r
-                       }\r
-               }\r
-               else if (currentTool == TOOLAddPoly)    // "Add Poly" tool\r
-               {\r
-#ifdef DEBUGFOO\r
-WriteLogMsg("Adding point... # polys: %u, # points: %u", pts.GetNumPolys(), pts.GetNumPoints());\r
-#endif\r
-                       if (polyFirstPoint)\r
-                       {\r
-                               polyFirstPoint = false;\r
-                               pts.AddNewPolyAtEnd();\r
-                       }\r
-\r
-                       wxPoint pt = GetAdjustedMousePosition(e);\r
-                       // Append a point to the end of the structure\r
-                       pts += IPoint(pt.x, pt.y, (e.ShiftDown() | e.ControlDown() ? false : true));\r
-                       ptHighlight = pts.GetNumPoints() - 1;\r
-                       Refresh();\r
-#ifdef DEBUGFOO\r
-WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumPoints());\r
-#endif\r
-               }\r
-               else if (currentTool == TOOLSelect || currentTool == TOOLPolySelect)\r
-               {\r
-                       if (pts.GetNumPoints() > 0)\r
-                       {\r
-                               pt = GetAdjustedClientPosition(pts.GetX(ptHighlight), pts.GetY(ptHighlight));\r
-                               WarpPointer(pt.x, pt.y);\r
-\r
-                               if (e.ShiftDown() | e.ControlDown())\r
-                                       pts.SetOnCurve(ptHighlight, !pts.GetOnCurve(ptHighlight));\r
-                       }\r
-               }\r
-               else if (currentTool == TOOLDelPt)\r
-               {\r
-                       if (pts.GetNumPoints() > 0)\r
-//Or could use:\r
-//                     if (ptHighlight != -1)\r
-                       {\r
-//This assumes that WM_MOUSEMOVE happens before this!\r
-//The above commented out line should take care of this contingency... !!! FIX !!!\r
-                               pts.DeletePoint(ptHighlight);\r
-                               Refresh();\r
-                       }\r
-               }\r
-       }\r
-       else if (e.LeftUp())\r
-       {\r
-//             mouseDown = false;\r
-\r
-               if (currentTool == TOOLScroll || currentTool == TOOLZoom)\r
-//                     ReleaseCapture();\r
-                       ReleaseMouse();\r
-       }\r
-       else if (e.Dragging())\r
-       {\r
-//Do this here? Needed?                SetCursor(hCur[currentTool]);\r
-\r
-           // Extract current point from lParam/calc offset from previous point\r
-\r
-               pt = e.GetPosition();\r
-               ptOffset.x = pt.x - ptPrevious.x,\r
-               ptOffset.y = pt.y - ptPrevious.y;\r
-\r
-//             if (e.LeftIsDown())\r
-//             {\r
-                       if (currentTool == TOOLScroll)\r
-                       {\r
-                               // NOTE: OffsetViewportOrg operates in DEVICE UNITS...\r
-\r
-//Seems there's no equivalent for this in wxWidgets...!\r
-//!!! FIX !!!\r
-//                             hdc = GetDC(hWnd);\r
-//                             OffsetViewportOrgEx(hdc, ptOffset.x, ptOffset.y, NULL);\r
-//                             ReleaseDC(hWnd, hdc);\r
-\r
-// this shows that it works, so the logic above must be faulty...\r
-// And it is. It should convert the coords first, then do the subtraction to figure the offset...\r
-// Above: DONE\r
-// Then multiply it by the scaling factor. Whee!\r
-                               // This looks wacky because we're using screen coords for the offset...\r
-                               // Otherwise, we would subtract both offsets!\r
-                               offsetX -= ptOffset.x, offsetY += ptOffset.y;\r
-                               Refresh();\r
-                       }\r
-                       else if (currentTool == TOOLAddPt || currentTool == TOOLAddPoly || currentTool == TOOLSelect)\r
-                       {\r
-                               if (currentTool != TOOLAddPt || pts.GetNumPoints() > 0)//yecch.\r
-                               {\r
-                                       wxPoint pt2 = GetAdjustedMousePosition(e);\r
-                                       pts.SetXY(ptHighlight, pt2.x, pt2.y);\r
-                                       Refresh();\r
-                               }\r
-                       }\r
-                       else if (currentTool == TOOLPolySelect)\r
-                       {\r
-                               if (pts.GetNumPoints() > 0)\r
-                               {\r
-                                       wxPoint pt2 = GetAdjustedMousePosition(e);\r
-                                       // Should also set onCurve here as well, depending on keystate\r
-//Or should we?\r
-                                       pts.OffsetPoly(pts.GetPoly(ptHighlight), pt2.x - pts.GetX(ptHighlight), pt2.y - pts.GetY(ptHighlight));\r
-                                       Refresh();\r
-                               }\r
-                       }\r
-//             }\r
-\r
-               ptPrevious = pt;\r
-       }\r
-       else if (e.Moving())\r
-       {\r
-//             else    // Moving, not dragging...\r
-//             {\r
-                       if (currentTool == TOOLSelect || currentTool == TOOLDelPt || currentTool == TOOLAddPt\r
-                               || currentTool == TOOLPolySelect)// || currentTool == TOOLAddPoly)\r
-                       {\r
-                               wxPoint pt2 = GetAdjustedMousePosition(e);\r
-                               double closest = 1.0e+99;\r
-\r
-                               for(int i=0; i<pts.GetNumPoints(); i++)\r
-                               {\r
-                                       double dist = ((pt2.x - pts.GetX(i)) * (pt2.x - pts.GetX(i)))\r
-                                               + ((pt2.y - pts.GetY(i)) * (pt2.y - pts.GetY(i)));\r
-\r
-                                       if (dist < closest)\r
-                                               closest = dist, ptHighlight = i;\r
-                               }\r
-\r
-                               if (ptHighlight != oldPtHighlight)\r
-                               {\r
-                                       oldPtHighlight = ptHighlight;\r
-                                       Refresh();\r
-                               }\r
-\r
-                               // What follows here looks like voodoo, but is really simple. What we do is\r
-                               // check to see if the mouse point has a perpendicular intersection with any of\r
-                               // the line segments. If it does, calculate the length of the perpendicular\r
-                               // and choose the smallest length. If there is no perpendicular, then choose the\r
-                               // length of line connecting the closer of either the first endpoint or the\r
-                               // second and choose the smallest of those.\r
-\r
-                               // There is one bit of math that looks like voodoo to me ATM--will explain once\r
-                               // I understand it better (the calculation of the length of the perpendicular).\r
-\r
-                               if (pts.GetNumPoints() > 1 && currentTool == TOOLAddPt)\r
-                               {\r
-                                       double smallest = 1.0e+99;\r
-\r
-                                       for(int i=0; i<pts.GetNumPoints(); i++)\r
-                                       {\r
-                                               int32 p1x = pts.GetX(i), p1y = pts.GetY(i),\r
-                                                       p2x = pts.GetX(pts.GetNext(i)), p2y = pts.GetY(pts.GetNext(i));\r
-\r
-                                               vector ls(p2x, p2y, 0, p1x, p1y, 0), v1(pt2.x, pt2.y, 0, p1x, p1y, 0),\r
-                                                       v2(pt2.x, pt2.y, 0, p2x, p2y, 0);\r
-                                               double pp = ls.dot(v1) / ls.length(), dist;\r
-// Geometric interpretation:\r
-// pp is the paremeterized point on the vector ls where the perpendicular intersects ls.\r
-// If pp < 0, then the perpendicular lies beyond the 1st endpoint. If pp > length of ls,\r
-// then the perpendicular lies beyond the 2nd endpoint.\r
-\r
-                                               if (pp < 0.0)\r
-                                                       dist = v1.length();\r
-                                               else if (pp > ls.length())\r
-                                                       dist = v2.length();\r
-                                               else                                    // distance = ?Det?(ls, v1) / |ls|\r
-                                                       dist = fabs((ls.x * v1.y - v1.x * ls.y) / ls.length());\r
-\r
-//The answer to the above looks like it might be found here:\r
-//\r
-//If the segment endpoints are s and e, and the point is p, then the test for the perpendicular\r
-//intercepting the segment is equivalent to insisting that the two dot products {s-e}.{s-p} and\r
-//{e-s}.{e-p} are both non-negative.  Perpendicular distance from the point to the segment is\r
-//computed by first computing the area of the triangle the three points form, then dividing by the\r
-//length of the segment.  Distances are done just by the Pythagorean theorem.  Twice the area of the\r
-//triangle formed by three points is the determinant of the following matrix:\r
-//\r
-//sx sy 1\r
-//ex ey 1\r
-//px py 1\r
-//\r
-//(???) By translating the start point to the origin, this can be rewritten as:\r
-//By subtracting row 1 from all rows, you get the following:\r
-//\r
-//0         0         0\r
-//(ex - sx) (ey - sy) 0\r
-//(px - sx) (py - sy) 0\r
-//\r
-//which greatly simplifies the calculation of the determinant.\r
-\r
-                                               if (dist < smallest)\r
-                                                       smallest = dist, ptNextHighlight = pts.GetNext(i), ptHighlight = i;\r
-                                       }\r
-\r
-                                       if (ptNextHighlight != oldPtNextHighlight)\r
-                                       {\r
-                                               oldPtNextHighlight = ptNextHighlight;\r
-                                               Refresh();\r
-                                       }\r
-                               }\r
-                       }\r
-//             }\r
-\r
-               ptPrevious = e.GetPosition();\r
-       }\r
-}\r
-\r
-\r
-wxPoint TTEditWindow::GetAdjustedMousePosition(wxMouseEvent &e)\r
-{\r
-       wxCoord width, height;\r
-       wxClientDC dc(this);\r
-\r
-       dc.GetSize(&width, &height);\r
-       dc.SetDeviceOrigin(-offsetX, height - (-offsetY));\r
-       dc.SetAxisOrientation(true, true);\r
-\r
-/*wxStatusBar * sb = ((wxFrame *)GetParent())->GetStatusBar();\r
-wxString s;\r
-s.Printf("Logical mouse pos: %d, %d (%d, %d)", pt.x, pt.y, width, height);\r
-sb->SetStatusText(s);//*/\r
-\r
-       return e.GetLogicalPosition(dc);\r
-}\r
-\r
-wxPoint TTEditWindow::GetAdjustedClientPosition(wxCoord x, wxCoord y)\r
-{\r
-       wxCoord width, height;\r
-       wxClientDC dc(this);\r
-\r
-       dc.GetSize(&width, &height);\r
-       dc.SetDeviceOrigin(-offsetX, height - (-offsetY));\r
-       dc.SetAxisOrientation(true, true);\r
-\r
-       return wxPoint(dc.LogicalToDeviceX(x), dc.LogicalToDeviceY(y));\r
-}\r
-\r
-//\r
-\r
-void CreateResources(void)\r
-{\r
-       // This is a sucky way to create cursors, but at least it's cross-platform...\r
-       // NOTE: Need to fix hotspots on a few... !!! FIX !!!\r
-\r
-       wxBitmap cursorBM1(cur1_xpm);\r
-       wxImage cursorImage1 = cursorBM1.ConvertToImage();\r
-       cursorImage1.SetMaskFromImage(cursorImage1, 0xFF, 0xFF, 0xFF);\r
-       cur[0] = new wxCursor(cursorImage1);\r
-\r
-       wxBitmap cursorBM2(cur2_xpm);\r
-       wxImage cursorImage2 = cursorBM2.ConvertToImage();\r
-       cursorImage2.SetMaskFromImage(cursorImage2, 0xFF, 0xFF, 0xFF);\r
-       cur[1] = new wxCursor(cursorImage2);\r
-\r
-       wxBitmap cursorBM3(cur3_xpm);\r
-       wxImage cursorImage3 = cursorBM3.ConvertToImage();\r
-       cursorImage3.SetMaskFromImage(cursorImage3, 0xFF, 0xFF, 0xFF);\r
-       cur[2] = new wxCursor(cursorImage3);\r
-\r
-       wxBitmap cursorBM4(cur4_xpm);\r
-       wxImage cursorImage4 = cursorBM4.ConvertToImage();\r
-       cursorImage4.SetMaskFromImage(cursorImage4, 0xFF, 0xFF, 0xFF);\r
-       cur[3] = new wxCursor(cursorImage4);\r
-\r
-       wxBitmap cursorBM5(cur5_xpm);\r
-       wxImage cursorImage5 = cursorBM5.ConvertToImage();\r
-       cursorImage5.SetMaskFromImage(cursorImage5, 0xFF, 0xFF, 0xFF);\r
-       cur[4] = new wxCursor(cursorImage5);\r
-\r
-       wxBitmap cursorBM6(cur6_xpm);\r
-       wxImage cursorImage6 = cursorBM6.ConvertToImage();\r
-       cursorImage6.SetMaskFromImage(cursorImage6, 0xFF, 0xFF, 0xFF);\r
-       cur[5] = new wxCursor(cursorImage6);\r
-\r
-       wxBitmap cursorBM7(cur7_xpm);\r
-       wxImage cursorImage7 = cursorBM7.ConvertToImage();\r
-       cursorImage7.SetMaskFromImage(cursorImage7, 0xFF, 0xFF, 0xFF);\r
-       cur[6] = new wxCursor(cursorImage7);\r
-\r
-       wxBitmap cursorBM8(cur8_xpm);\r
-       wxImage cursorImage8 = cursorBM8.ConvertToImage();\r
-       cursorImage8.SetMaskFromImage(cursorImage8, 0xFF, 0xFF, 0xFF);\r
-       cur[7] = new wxCursor(cursorImage8);\r
-}\r
-\r
-//\r
-// Draw a round dot (5x5, centered on [x, y])\r
-//\r
-void DrawRoundDot(wxDC &dc, int32 x, int32 y)\r
-{\r
-       wxPoint pt[8];\r
-\r
-       pt[0].x = x - 1, pt[0].y = y - 2;\r
-       pt[1].x = x + 1, pt[1].y = y - 2;\r
-       pt[2].x = x + 2, pt[2].y = y - 1;\r
-       pt[3].x = x + 2, pt[3].y = y + 1;\r
-       pt[4].x = x + 1, pt[4].y = y + 2;\r
-       pt[5].x = x - 1, pt[5].y = y + 2;\r
-       pt[6].x = x - 2, pt[6].y = y + 1;\r
-       pt[7].x = x - 2, pt[7].y = y - 1;\r
-\r
-       dc.DrawPolygon(8, pt);\r
-}\r
-\r
-//\r
-// Draw a sqaure dot (5x5, centered on [x, y])\r
-//\r
-void DrawSquareDot(wxDC &dc, int32 x, int32 y)\r
-{\r
-       wxPoint pt[4];\r
-\r
-       pt[0].x = x - 2, pt[0].y = y - 2;\r
-       pt[1].x = x + 2, pt[1].y = y - 2;\r
-       pt[2].x = x + 2, pt[2].y = y + 2;\r
-       pt[3].x = x - 2, pt[3].y = y + 2;\r
-\r
-       dc.DrawPolygon(4, pt);\r
-}\r
-\r
-//\r
-// Draw a sqaure dot (nxn, centered on [x, y])\r
-//\r
-void DrawSquareDotN(wxDC &dc, int32 x, int32 y, uint32 n)\r
-{\r
-       wxPoint pt[4];\r
-       uint32 offset = (n - 1) / 2;\r
-\r
-       pt[0].x = x - offset, pt[0].y = y - offset;\r
-       pt[1].x = x + offset, pt[1].y = y - offset;\r
-       pt[2].x = x + offset, pt[2].y = y + offset;\r
-       pt[3].x = x - offset, pt[3].y = y + offset;\r
-\r
-       dc.DrawPolygon(4, pt);\r
-}\r
-\r
-//\r
-// Draw a round dot (nxn, centered on [x, y])\r
-//\r
-void DrawRoundDotN(wxDC &dc, int32 x, int32 y, uint32 n)\r
-{\r
-       dc.DrawCircle(x, y, (n / 2) + 1);\r
-}\r
-\r
-\r
-BEGIN_EVENT_TABLE(CharWindow, wxWindow)\r
-//     EVT_PAINT(CharWindow::OnPaint)\r
-//     EVT_MOUSE_EVENTS(CharWindow::OnMouseEvent)\r
-END_EVENT_TABLE()\r
-\r
-CharWindow::CharWindow(wxFrame * parent, const wxPoint &pos, const wxSize &size, long style):\r
-       wxWindow(parent, -1, pos, size, style)\r
-{\r
-} \r
-\r
-CharWindow::~CharWindow()\r
-{\r
-}\r
-\r
-\r
-BEGIN_EVENT_TABLE(ToolWindow, wxWindow)\r
-       EVT_PAINT(ToolWindow::OnPaint)\r
-       EVT_MOUSE_EVENTS(ToolWindow::OnMouseEvent)\r
-END_EVENT_TABLE()\r
-\r
-ToolWindow::ToolWindow(wxFrame * parent, const wxString &title, const wxPoint &pos,\r
-       const wxSize &size, long style): wxFrame(parent, -1, title, pos, size, style)\r
-//ToolWindow::ToolWindow(wxFrame * parent, const wxPoint &pos, const wxSize &size, long style):\r
-//     wxWindow(parent, -1, pos, size, style)\r
-{\r
-       bmp = new wxBitmap(toolpal1_xpm);\r
-       prevTool = -1;\r
-\r
-       // Set up sizes\r
-\r
-       sizeTPBM.x = bmp->GetWidth(), sizeTPBM.y = bmp->GetHeight();\r
-       sizeStamp.x = sizeTPBM.x / 4, sizeStamp.y = sizeTPBM.y / 2;\r
-\r
-       SetSize(10, 10, sizeTPBM.x, sizeTPBM.y);\r
-       Show(false);\r
-}\r
-\r
-ToolWindow::~ToolWindow()\r
-{\r
-}\r
-\r
-void ToolWindow::OnPaint(wxPaintEvent &e)\r
-{\r
-       wxPaintDC dc(this);\r
-\r
-       wxMemoryDC memDC;\r
-       memDC.SelectObject(*bmp);\r
-       dc.Blit(0, 0, sizeTPBM.x, sizeTPBM.y, &memDC, 0, 0, wxCOPY);\r
-\r
-       int32 tool = FindSelectedTool();\r
-\r
-       if (tool != -1)\r
-       {\r
-           //need ul corner of bitmap, ul corner of dest, width/height\r
-               wxPoint pt(sizeStamp.x * (tool & 0x03), sizeStamp.y * (tool >> 2));\r
-               dc.Blit(pt.x, pt.y, sizeStamp.x, sizeStamp.y, &memDC, pt.x, pt.y, wxSRC_INVERT);\r
-       }\r
-\r
-       memDC.SelectObject(wxNullBitmap);\r
-}\r
-\r
-void ToolWindow::OnMouseEvent(wxMouseEvent &e)\r
-{\r
-//     if (e.Moving())\r
-       if (e.Dragging())\r
-       {\r
-               int32 tool = FindSelectedTool();\r
-\r
-               if (tool != prevTool)\r
-               {\r
-                       prevTool = tool;\r
-                       Refresh(false);\r
-               }\r
-       }\r
-\r
-       if (e.RightUp())\r
-       {\r
-               int32 tool = FindSelectedTool(), oldTool = currentTool;\r
-\r
-               if (tool != -1)\r
-                       currentTool = tool;\r
-\r
-               if (currentTool != TOOLSelect && currentTool != TOOLDelPt && currentTool != TOOLAddPt\r
-                       && currentTool != TOOLPolySelect)\r
-                       ptHighlight = -1;\r
-\r
-               if (currentTool != oldTool)\r
-                       Refresh(false);\r
-\r
-               if (currentTool == TOOLAddPoly)\r
-#ifdef DEBUGFOO\r
-{\r
-#endif\r
-                       polyFirstPoint = true;\r
-#ifdef DEBUGFOO\r
-sprintf(strBuf, "--> Selected poly tool, polyFirstPoint is %s\n", polyFirstPoint ? "true" : "false");\r
-WriteLogMsg(strBuf);\r
-}\r
-#endif\r
-\r
-               ReleaseMouse();\r
-               Show(false);\r
-               wxGetApp().mainFrame->mainWindow->SetCursor(*cur[currentTool]);\r
-               wxGetApp().mainFrame->mainWindow->SetFocus();   // Make sure the main wnd keeps focus!\r
-       }\r
-}\r
-\r
-//\r
-// Find which tool we're pointing at\r
-// Use: xcoord = mouse.x / (bmsize.x/4), ycoord = mouse.y / (bmsize.y/2)\r
-//\r
-int32 ToolWindow::FindSelectedTool(void)\r
-{\r
-       wxPoint pt = ScreenToClient(wxGetMousePosition());\r
-       uint32 x = (uint32)pt.x / sizeStamp.x, y = (uint32)pt.y / sizeStamp.y, tool = (uint32)-1;\r
-\r
-       if (x < 4 && y < 2)\r
-               tool = (y * 4) + x;\r
-\r
-       return tool;\r
-}\r
-\r
-\r
-/*\r
-LRESULT CALLBACK WndProc(HWND hWnd, UINT msgID, WPARAM wParam, LPARAM lParam)\r
-{\r
-       RECT rc1, rc2;\r
-       HDC hdc;\r
-       POINT pt, ptOffset;\r
-       SIZE sz;\r
-       PAINTSTRUCT ps;\r
-\r
-       switch (msgID)\r
-       {\r
-       case WM_CREATE:\r
-\r
-               MiscCenterWnd(hWnd, GetDesktopWindow());\r
-               InitCommonControls();\r
-               hStatusBar = CreateStatusWindow(WS_CHILD | WS_VISIBLE, statusBarTxt, hWnd, ID_STATUSBAR);\r
-\r
-               if (!hStatusBar)\r
-                       return -1;\r
-\r
-// clean this crap up!\r
-// well, the only crappy thing here is using a POINT as an int array, but otherwise, this is OK\r
-               wsprintf(strBuf, zoom, 1000);\r
-               hdc = GetDC(hWnd);\r
-               GetTextExtentPoint32(hdc, strBuf, lstrlen(strBuf), &sz);\r
-               ReleaseDC(hWnd, hdc);\r
-               zoomWndWidth = sz.cx;\r
-               wsprintf(strBuf, zoom, 100);\r
-\r
-               GetClientRect(hWnd, &rc1);\r
-               pt.x = rc1.right - zoomWndWidth, pt.y = -1;\r
-               SendMessage(hStatusBar, SB_SETPARTS, 2, (LPARAM)&pt);\r
-               SendMessage(hStatusBar, SB_SETTEXT, (0 | SBT_NOBORDERS), (LPARAM)statusBarTxt);\r
-               SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM)strBuf);\r
-\r
-               hToolBar = CreateToolbarEx(hWnd, WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_TOOLTIPS,\r
-                       IDR_TOOLBAR1, 3, hInst, IDB_TOOLBAR1, tbButtons, 4, 16, 16, 16, 16, sizeof(TBBUTTON));\r
-\r
-               if (!hToolBar)\r
-                       return -1;\r
-\r
-               CreateNewDoc();\r
-\r
-// The following can only be done because we use a private DC (using "CS_OWNDC")\r
-// (Is that true???)\r
-// Set the mapping to draw the character so it fits in the viewport...\r
-               hdc = GetDC(hWnd);\r
-               GetClientRect(hWnd, &rc1);\r
-               GetClientRect(hStatusBar, &rc2);\r
-               rc1.bottom -= rc2.bottom;\r
-               SetMapMode(hdc, MM_ISOTROPIC);\r
-               SetWindowExtEx(hdc, rc1.right, rc1.bottom, NULL);\r
-               SetViewportExtEx(hdc, rc1.right, -rc1.bottom, NULL);\r
-               SetViewportOrgEx(hdc, 0, rc1.bottom, NULL);\r
-               ReleaseDC(hWnd, hdc);\r
-               break;\r
-\r
-       case WM_CLOSE:\r
-\r
-               if (SaveChanges())\r
-               {\r
-                       wpM.length = wpC.length = sizeof(WINDOWPLACEMENT);\r
-                       GetWindowPlacement(hMainWnd, &wpM);\r
-                       GetWindowPlacement(hCharWnd, &wpC);\r
-\r
-                       if (!IsWindowVisible(hCharWnd))         // Needed because Windows lies about visibility\r
-                               wpC.showCmd = SW_HIDE;\r
-\r
-                       hdc = GetDC(hWnd);\r
-                       GetViewportOrgEx(hdc, &ptVPM);\r
-                       ReleaseDC(hWnd, hdc);\r
-\r
-                       DestroyWindow(hWnd);\r
-               }\r
-\r
-               break;\r
-\r
-       case WM_DESTROY:\r
-\r
-               PostQuitMessage(0);\r
-               break;\r
-\r
-       case WM_NCLBUTTONDOWN:\r
-\r
-               if (wParam == HTCAPTION)\r
-               {\r
-                       NCMouseDown = true;\r
-                       GetWindowRect(hMainWnd, &rc1);\r
-                       GetWindowRect(hCharWnd, &rc2);\r
-                       ptWinOffset.x = rc2.left - rc1.left;\r
-                       ptWinOffset.y = rc2.top - rc1.top;\r
-               }\r
-                   \r
-               // Let Windows do its thing with this msg, or weird things will happen...\r
-\r
-               DefWindowProc(hWnd, msgID, wParam, lParam);\r
-               NCMouseDown = false;\r
-               break;\r
-\r
-       case WM_WINDOWPOSCHANGING:\r
-\r
-               if (NCMouseDown)\r
-               {\r
-                       WINDOWPOS * wp = (WINDOWPOS *)lParam;\r
-\r
-                       if (wp->hwnd == hMainWnd && !(wp->flags & SWP_NOMOVE))\r
-                               SetWindowPos(hCharWnd, 0, wp->x + ptWinOffset.x, wp->y + ptWinOffset.y,\r
-                                               0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);\r
-               }\r
-\r
-               return DefWindowProc(hWnd, msgID, wParam, lParam);      // Seems this is needed... Bleah!\r
-\r
-       case WM_PAINT:\r
-       {\r
-               hdc = BeginPaint(hWnd, &ps);\r
-\r
-// Scrolling can be done by using OffsetViewportOrgEx\r
-// Scaling can be done by adjusting SetWindowExtEx (it's denominator of txform)\r
-// you'd use: % = ViewportExt / WindowExt\r
-// But it makes the window look like crap: fuggetuboutit.\r
-// Instead, we have to scale EVERYTHING by hand. Crap!\r
-\r
-               // Apparently, you *must* save the individual object types (pen, brush, etc.)\r
-\r
-               HGDIOBJ oldPen = SelectObject(hdc, hBluePen1),\r
-                       oldBrush = SelectObject(hdc, hNullBrush);\r
-\r
-           // Draw coordinate axes\r
-\r
-               MoveToEx(hdc, 0, -32000, NULL);\r
-               LineTo(hdc, 0, 32000);\r
-               MoveToEx(hdc, -32000, 0, NULL);\r
-               LineTo(hdc, 32000, 0);\r
-\r
-           // Draw points\r
-\r
-               for(int i=0; i<pts.GetNumPoints(); i++)\r
-               {\r
-                       if (i == ptHighlight)\r
-                       {\r
-                               SelectObject(hdc, hRedPen1);\r
-\r
-                               if (pts.GetOnCurve(i))\r
-                               {\r
-                                       DrawSquareDotN(hdc, pts.GetX(i), pts.GetY(i), 7);\r
-                                       DrawSquareDotN(hdc, pts.GetX(i), pts.GetY(i), 9);\r
-                               }\r
-                               else\r
-                               {\r
-                                       DrawRoundDotN(hdc, pts.GetX(i), pts.GetY(i), 7);\r
-                                       DrawRoundDotN(hdc, pts.GetX(i), pts.GetY(i), 9);\r
-                               }\r
-                       }\r
-                       else if ((i == ptHighlight || i == ptNextHighlight) && currentTool == TOOLAddPt)\r
-                       {\r
-                               SelectObject(hdc, hGreenPen1);\r
-\r
-                               if (pts.GetOnCurve(i))\r
-                               {\r
-                                       DrawSquareDotN(hdc, pts.GetX(i), pts.GetY(i), 7);\r
-                                       DrawSquareDotN(hdc, pts.GetX(i), pts.GetY(i), 9);\r
-                               }\r
-                               else\r
-                               {\r
-                                       DrawRoundDotN(hdc, pts.GetX(i), pts.GetY(i), 7);\r
-                                       DrawRoundDotN(hdc, pts.GetX(i), pts.GetY(i), 9);\r
-                               }\r
-                       }\r
-                       else\r
-                       {\r
-                               SelectObject(hdc, hBlackPen1);\r
-\r
-                               if (pts.GetOnCurve(i))\r
-                                       DrawSquareDot(hdc, pts.GetX(i), pts.GetY(i));\r
-                               else\r
-                                       DrawRoundDot(hdc, pts.GetX(i), pts.GetY(i));\r
-                       }\r
-\r
-                       if (currentTool == TOOLDelPt && i == ptHighlight)\r
-                       {\r
-                               SelectObject(hdc, hRedPen1);\r
-                               MoveToEx(hdc, pts.GetX(i) - 5, pts.GetY(i) - 5, NULL);\r
-                               LineTo(hdc, pts.GetX(i) + 5, pts.GetY(i) + 5);\r
-                               LineTo(hdc, pts.GetX(i) - 5, pts.GetY(i) - 5);//Lameness!\r
-                               MoveToEx(hdc, pts.GetX(i) - 5, pts.GetY(i) + 5, NULL);\r
-                               LineTo(hdc, pts.GetX(i) + 5, pts.GetY(i) - 5);\r
-                               LineTo(hdc, pts.GetX(i) - 5, pts.GetY(i) + 5);//More lameness!!\r
-                       }\r
-               }\r
-\r
-               SelectObject(hdc, hBlackPen1);\r
-\r
-               // Draw curve formed by points\r
-\r
-               for(int poly=0; poly<pts.GetNumPolys(); poly++)\r
-               {\r
-                       if (pts.GetNumPoints(poly) > 2)\r
-                       {\r
-                               // Initial move...\r
-                               // If it's not on curve, then move to it, otherwise move to last point...\r
-       \r
-                               if (pts.GetOnCurve(poly, pts.GetNumPoints(poly) - 1))\r
-                                       MoveToEx(hdc, pts.GetX(poly, pts.GetNumPoints(poly) - 1), pts.GetY(poly, pts.GetNumPoints(poly) - 1), NULL);\r
-                               else\r
-                                       MoveToEx(hdc, pts.GetX(poly, 0), pts.GetY(poly, 0), NULL);\r
-       \r
-                               for(int i=0; i<pts.GetNumPoints(poly); i++)\r
-                               {\r
-                                       if (pts.GetOnCurve(poly, i))\r
-                                               LineTo(hdc, pts.GetX(poly, i), pts.GetY(poly, i));\r
-                                       else\r
-                                       {\r
-                                               uint32 prev = pts.GetPrev(poly, i), next = pts.GetNext(poly, i);\r
-                                               float px = pts.GetX(poly, prev), py = pts.GetY(poly, prev),\r
-                                                       nx = pts.GetX(poly, next), ny = pts.GetY(poly, next);\r
-       \r
-                                               if (!pts.GetOnCurve(poly, prev))\r
-                                                       px = (px + pts.GetX(poly, i)) / 2.0f,\r
-                                                       py = (py + pts.GetY(poly, i)) / 2.0f;\r
-       \r
-                                               if (!pts.GetOnCurve(poly, next))\r
-                                                       nx = (nx + pts.GetX(poly, i)) / 2.0f,\r
-                                                       ny = (ny + pts.GetY(poly, i)) / 2.0f;\r
-       \r
-                                               Bezier(hdc, point(px, py), point(pts.GetX(poly, i), pts.GetY(poly, i)), point(nx, ny));\r
-       \r
-                                               if (pts.GetOnCurve(poly, next))\r
-                                                       i++;                                    // Following point is on curve, so move past it\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-\r
-               SelectObject(hdc, oldPen);                              // Restore the stuff we disrupted...\r
-               SelectObject(hdc, oldBrush);\r
-               EndPaint(hWnd, &ps);\r
-               break;\r
-       }\r
-       case WM_SIZE:\r
-\r
-               // Apparently this is needed since these windows don't update themselves.\r
-               SendMessage(hStatusBar, msgID, wParam, lParam);\r
-               SendMessage(hToolBar, msgID, wParam, lParam);\r
-\r
-               // This is needed to make the 2nd status pane visible\r
-               GetClientRect(hWnd, &rc1);\r
-               pt.x = rc1.right - zoomWndWidth, pt.y = -1;\r
-               SendMessage(hStatusBar, SB_SETPARTS, 2, (LPARAM)&pt);\r
-               break;\r
-\r
-       case WM_RBUTTONDOWN:\r
-\r
-               GetCursorPos(&pt);\r
-               SetWindowPos(hToolPalWnd, 0, pt.x, pt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);\r
-               SetFocus(hToolPalWnd);\r
-               SetCapture(hToolPalWnd);                                // Ensure tool palette gets RButtonUp\r
-               SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));        // Tool pallete has "regular" cursor\r
-               break;\r
-\r
-       case WM_LBUTTONDOWN:\r
-\r
-               mouseDown = true;\r
-\r
-               if (currentTool == TOOLScroll || currentTool == TOOLZoom)\r
-                       SetCapture(hWnd);                                       // Make sure we capture the mouse when in scroll/zoom mode\r
-               else if (currentTool == TOOLAddPt)              // "Add Point" tool\r
-               {\r
-                       if (pts.GetNumPoints() > 0)\r
-                       {\r
-//Do we really need to put a cap on this???\r
-//Maybe...\r
-//                             if (pts.GetNumPoints() < 16)\r
-//                             {\r
-                               pt.x = lParam & 0xFFFF, pt.y = lParam >> 16;\r
-                               hdc = GetDC(hWnd);\r
-                               DPtoLP(hdc, &pt, 1);\r
-                               pts.InsertPoint(pts.GetNext(ptHighlight), pt.x, pt.y, (wParam & (MK_SHIFT | MK_CONTROL) ? false : true));\r
-                               ptHighlight = ptNextHighlight;\r
-                               ReleaseDC(hWnd, hdc);\r
-                               InvalidateRect(hWnd, NULL, TRUE);\r
-//                             }\r
-                       }\r
-               }\r
-               else if (currentTool == TOOLAddPoly)    // "Add Poly" tool\r
-               {\r
-#ifdef DEBUGFOO\r
-wsprintf(strBuf, "Adding point... # polys: %u, # points: %u", pts.GetNumPolys(), pts.GetNumPoints());\r
-WriteLogMsg(strBuf);\r
-#endif\r
-                       if (polyFirstPoint)\r
-                       {\r
-                               polyFirstPoint = false;\r
-                               pts.AddNewPolyAtEnd();\r
-                       }\r
-\r
-//Do we really need to put a cap on this???\r
-//Maybe...\r
-//                     if (pts.GetNumPoints() < 16)\r
-//                     {\r
-                       pt.x = lParam & 0xFFFF, pt.y = lParam >> 16;\r
-                       hdc = GetDC(hWnd);\r
-                       DPtoLP(hdc, &pt, 1);\r
-                       ReleaseDC(hWnd, hdc);\r
-                       // Append a point to the end of the structure\r
-                       pts += IPoint(pt.x, pt.y, (wParam & (MK_SHIFT | MK_CONTROL) ? false : true));\r
-ptHighlight = pts.GetNumPoints() - 1;\r
-                       InvalidateRect(hWnd, NULL, TRUE);\r
-//                     }\r
-#ifdef DEBUGFOO\r
-wsprintf(strBuf, " --> [# polys: %u, # points: %u]\xD\xA", pts.GetNumPolys(), pts.GetNumPoints());\r
-WriteLogMsg(strBuf);\r
-#endif\r
-               }\r
-               else if (currentTool == TOOLSelect || currentTool == TOOLPolySelect)\r
-               {\r
-                       if (pts.GetNumPoints() > 0)\r
-                       {\r
-                               pt.x = pts.GetX(ptHighlight), pt.y = pts.GetY(ptHighlight);\r
-                               hdc = GetDC(hWnd);\r
-                               LPtoDP(hdc, &pt, 1);\r
-                               ClientToScreen(hWnd, &pt);\r
-                               SetCursorPos(pt.x, pt.y);\r
-                               ReleaseDC(hWnd, hdc);\r
-\r
-                               if (wParam & (MK_SHIFT | MK_CONTROL))\r
-                                       pts.SetOnCurve(ptHighlight, !pts.GetOnCurve(ptHighlight));\r
-                       }\r
-               }\r
-               else if (currentTool == TOOLDelPt)\r
-               {\r
-                       if (pts.GetNumPoints() > 0)\r
-//Or could use:\r
-//                     if (ptHighlight != -1)\r
-                       {\r
-//This assumes that WM_MOUSEMOVE happens before this!\r
-//The above commented out line should take care of this contingency... !!! FIX !!!\r
-                               pts.DeletePoint(ptHighlight);\r
-                               InvalidateRect(hWnd, NULL, TRUE);\r
-                       }\r
-               }\r
-\r
-               break;\r
-\r
-       case WM_LBUTTONUP:\r
-\r
-               mouseDown = false;\r
-\r
-               if (currentTool == TOOLScroll || currentTool == TOOLZoom)\r
-                       ReleaseCapture();\r
-\r
-               break;\r
-\r
-       case WM_MOUSEMOVE:\r
-\r
-               SetCursor(hCur[currentTool]);\r
-\r
-           // Extract current point from lParam/calc offset from previous point\r
-\r
-               pt.x = lParam & 0xFFFF, pt.y = lParam >> 16;\r
-               ptOffset.x = pt.x - ptPrevious.x,\r
-               ptOffset.y = pt.y - ptPrevious.y;\r
-\r
-               if (mouseDown)\r
-               {\r
-                       if (currentTool == TOOLScroll)\r
-                       {\r
-                               // NOTE: OffsetViewportOrg operates in DEVICE UNITS...\r
-\r
-                               hdc = GetDC(hWnd);\r
-                               OffsetViewportOrgEx(hdc, ptOffset.x, ptOffset.y, NULL);\r
-                               ReleaseDC(hWnd, hdc);\r
-\r
-// this shows that it works, so the logic above must be faulty...\r
-// And it is. It should convert the coords first, then do the subtraction to figure the offset...\r
-// Above: DONE\r
-// Then multiply it by the scaling factor. Whee!\r
-\r
-                               InvalidateRect(hWnd, NULL, TRUE);\r
-//                             SendMessage(hWnd, WM_PAINT, NULL, NULL);\r
-                       }\r
-                       else if (currentTool == TOOLAddPt || currentTool == TOOLAddPoly || currentTool == TOOLSelect)\r
-                       {\r
-                               if (currentTool != TOOLAddPt || pts.GetNumPoints() > 0)//yecch.\r
-                               {\r
-                                       POINT pt2;\r
-                                       pt2.x = pt.x, pt2.y = pt.y;\r
-                                       // Should also set onCurve here as well, depending on keystate\r
-//Or should we?\r
-                                       hdc = GetDC(hWnd);\r
-                                       DPtoLP(hdc, &pt2, 1);\r
-                                       pts.SetXY(ptHighlight, pt2.x, pt2.y);\r
-                                       ReleaseDC(hWnd, hdc);\r
-                                       InvalidateRect(hWnd, NULL, TRUE);\r
-                               }\r
-                       }\r
-                       else if (currentTool == TOOLPolySelect)\r
-                       {\r
-                               if (pts.GetNumPoints() > 0)\r
-                               {\r
-                                       POINT pt2;\r
-                                       pt2.x = pt.x, pt2.y = pt.y;\r
-                                       // Should also set onCurve here as well, depending on keystate\r
-//Or should we?\r
-                                       hdc = GetDC(hWnd);\r
-                                       DPtoLP(hdc, &pt2, 1);\r
-                                       pts.OffsetPoly(pts.GetPoly(ptHighlight), pt2.x - pts.GetX(ptHighlight), pt2.y - pts.GetY(ptHighlight));\r
-                                       ReleaseDC(hWnd, hdc);\r
-                                       InvalidateRect(hWnd, NULL, TRUE);\r
-                               }\r
-                       }\r
-               }\r
-               else\r
-               {\r
-                       if (currentTool == TOOLSelect || currentTool == TOOLDelPt || currentTool == TOOLAddPt\r
-                               || currentTool == TOOLPolySelect)// || currentTool == TOOLAddPoly)\r
-                       {\r
-                               POINT pt2;\r
-                               pt2.x = pt.x, pt2.y = pt.y;\r
-                               hdc = GetDC(hWnd);\r
-                               DPtoLP(hdc, &pt2, 1);\r
-                               ReleaseDC(hWnd, hdc);\r
-\r
-                               double closest = 1.0e+99;\r
-\r
-                               for(int i=0; i<pts.GetNumPoints(); i++)\r
-                               {\r
-                                       double dist = ((pt2.x - pts.GetX(i)) * (pt2.x - pts.GetX(i)))\r
-                                               + ((pt2.y - pts.GetY(i)) * (pt2.y - pts.GetY(i)));\r
-\r
-                                       if (dist < closest)\r
-                                               closest = dist, ptHighlight = i;\r
-                               }\r
-\r
-                               if (ptHighlight != oldPtHighlight)\r
-                               {\r
-                                       oldPtHighlight = ptHighlight;\r
-                                       InvalidateRect(hWnd, NULL, TRUE);\r
-                               }\r
-\r
-                               // What follows here looks like voodoo, but is really simple. What we do is\r
-                               // check to see if the mouse point has a perpendicular intersection with any of\r
-                               // the line segments. If it does, calculate the length of the perpendicular\r
-                               // and choose the smallest length. If there is no perpendicular, then choose the\r
-                               // length of line connecting the closer of either the first endpoint or the\r
-                               // second and choose the smallest of those.\r
-\r
-                               // There is one bit of math that looks like voodoo to me ATM--will explain once\r
-                               // I understand it better (the calculation of the length of the perpendicular).\r
-\r
-                               if (pts.GetNumPoints() > 1 && currentTool == TOOLAddPt)\r
-                               {\r
-                                       double smallest = 1.0e+99;\r
-\r
-                                       for(int i=0; i<pts.GetNumPoints(); i++)\r
-                                       {\r
-                                               int32 p1x = pts.GetX(i), p1y = pts.GetY(i),\r
-                                                       p2x = pts.GetX(pts.GetNext(i)), p2y = pts.GetY(pts.GetNext(i));\r
-\r
-                                               vector ls(p2x, p2y, 0, p1x, p1y, 0), v1(pt2.x, pt2.y, 0, p1x, p1y, 0),\r
-                                                       v2(pt2.x, pt2.y, 0, p2x, p2y, 0);\r
-                                               double pp = ls.dot(v1) / ls.length(), dist;\r
-// Geometric interpretation:\r
-// pp is the paremeterized point on the vector ls where the perpendicular intersects ls.\r
-// If pp < 0, then the perpendicular lies beyond the 1st endpoint. If pp > length of ls,\r
-// then the perpendicular lies beyond the 2nd endpoint.\r
-\r
-                                               if (pp < 0.0)\r
-                                                       dist = v1.length();\r
-                                               else if (pp > ls.length())\r
-                                                       dist = v2.length();\r
-                                               else                                    // distance = ?Det?(ls, v1) / |ls|\r
-                                                       dist = abs((ls.x * v1.y - v1.x * ls.y) / ls.length());\r
-\r
-//The answer to the above looks like it might be found here:\r
-//\r
-//If the segment endpoints are s and e, and the point is p, then the test for the perpendicular\r
-//intercepting the segment is equivalent to insisting that the two dot products {s-e}.{s-p} and\r
-//{e-s}.{e-p} are both non-negative.  Perpendicular distance from the point to the segment is\r
-//computed by first computing the area of the triangle the three points form, then dividing by the\r
-//length of the segment.  Distances are done just by the Pythagorean theorem.  Twice the area of the\r
-//triangle formed by three points is the determinant of the following matrix:\r
-//\r
-//sx sy 1\r
-//ex ey 1\r
-//px py 1\r
-//\r
-//(???) By translating the start point to the origin, this can be rewritten as:\r
-//By subtracting row 1 from all rows, you get the following:\r
-//\r
-//0         0         0\r
-//(ex - sx) (ey - sy) 0\r
-//(px - sx) (py - sy) 0\r
-//\r
-//which greatly simplifies the calculation of the determinant.\r
-\r
-                                               if (dist < smallest)\r
-                                                       smallest = dist, ptNextHighlight = pts.GetNext(i), ptHighlight = i;\r
-                                       }\r
-\r
-                                       if (ptNextHighlight != oldPtNextHighlight)\r
-                                       {\r
-                                               oldPtNextHighlight = ptNextHighlight;\r
-                                               InvalidateRect(hWnd, NULL, TRUE);\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-\r
-               ptPrevious.x = pt.x, ptPrevious.y = pt.y;\r
-\r
-               break;\r
-\r
-       case WM_NOTIFY:\r
-\r
-               if (((NMHDR *)lParam)->code == TTN_NEEDTEXT)\r
-               {\r
-                       LoadString(hInst, ((TOOLTIPTEXT *)lParam)->hdr.idFrom + 0x80, toolTipTxt, 16);\r
-                       ((TOOLTIPTEXT *)lParam)->lpszText = toolTipTxt;\r
-               }\r
-\r
-               break;\r
-\r
-       case WM_MENUSELECT:\r
-       {\r
-               statusBarTxt[0] = 0;                                    // Clear status bar text\r
-               uint16 flags = wParam >> 16;                    // Extract flags\r
-\r
-               if (!(flags & MFT_SEPARATOR))\r
-               {\r
-                       uint16 id = wParam & 0xFFFF;\r
-\r
-                       if (flags & MF_POPUP)\r
-                       {\r
-                               if (flags & MF_SYSMENU)\r
-                                       id = IDS_SYSMENU;\r
-                               else\r
-                                       id = IDM_FILEMENU + wParam;\r
-                       }\r
-\r
-                       LoadString(hInst, id, statusBarTxt, 64);\r
-               }\r
-\r
-               SendMessage(hStatusBar, SB_SETTEXT, 0 + SBT_NOBORDERS, (LPARAM)statusBarTxt);\r
-               break;\r
-       }\r
-       case WM_COMMAND:\r
-       {\r
-               uint16 cmd = wParam & 0xFFFF;\r
-\r
-               if (cmd == IDM_NEW)\r
-               {\r
-//                   call   CmdIDM_NEW\r
-               }\r
-               else if (cmd == IDM_OPEN)\r
-               {\r
-//                   call   SaveChanges\r
-//                   .IF (eax)\r
-//                     movmov ofn.hwndOwner, eax, hMainWnd\r
-//                     mov    ofn.Flags, OFN_PATHMUSTEXIST + OFN_FILEMUSTEXIST\r
-//                     invoke GetOpenFileName, ADDR ofn\r
-//                     .IF (eax)\r
-////////\r
-//jmp @F\r
-//szDMsg1a     BYTE    "Could not open the file (GetOpenFileName)...", 0\r
-//szDMsg1b     BYTE    "Open error!", 0\r
-//szDMsg1c     BYTE    "About to attempt to open file...", 0\r
-//@@:\r
-////invoke MessageBox, hWnd, ADDR szDMsg1a, ADDR szDMsg1b, MB_ICONERROR or MB_OK\r
-//invoke MessageBox, hMainWnd, ADDR szDMsg1c, ADDR szFile, MB_ICONERROR or MB_OK\r
-//                       invoke LoadTTF, ADDR szFile\r
-//\r
-//////\r
-//                       // <<< FILE OPEN CODE HERE >>>\r
-//                       or     fFileStatus, NAMEDbit\r
-//                       and    fFileStatus, NOT CHANGEDbit\r
-//                       call   NewWindowName\r
-//                       mov    eax, TRUE      // return TRUE\r
-//                       jmp    Return\r
-//                       //ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
-//OpenError:             invoke GetLastError\r
-//                       // <<< FILE OPEN ERROR CODE HERE >>>\r
-//                     .ENDIF\r
-//                     zero   eax      // return FALSE\r
-//                   .ENDIF\r
-               }\r
-               else if (cmd == IDM_SAVEAS)\r
-               {\r
-//                   and    fFileStatus, NOT NAMEDbit\r
-//                   call   CmdIDM_SAVE\r
-               }\r
-               else if (cmd == IDM_SAVE)\r
-               {\r
-//                   call   CmdIDM_SAVE\r
-               }\r
-               else if (cmd == IDM_ABOUT)\r
-                       DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_ABOUT), hMainWnd, AboutProc, NULL);\r
-               else if (cmd == IDM_EXIT)\r
-                       SendMessage(hWnd, WM_CLOSE, 0, 0);\r
-               else if (cmd == ID_TBCHARWIN)\r
-               {\r
-                       ShowWindow(hCharWnd, (IsWindowVisible(hCharWnd) ? SW_HIDE : SW_SHOWNOACTIVATE));\r
-\r
-#ifdef DEBUGFOO\r
-wpC.length = sizeof(WINDOWPLACEMENT);\r
-GetWindowPlacement(hCharWnd, &wpC);\r
-wsprintf(strBuf, "Char window showCmd = %08X...\n", wpC.showCmd);\r
-WriteLogMsg(strBuf);\r
-#endif\r
-               }\r
-               else\r
-                       return DefWindowProc(hWnd, msgID, wParam, lParam);\r
-\r
-               break;\r
-       }\r
-       default:\r
-               return DefWindowProc(hWnd, msgID, wParam, lParam);\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-//\r
-// Initialize TTF data\r
-//\r
-void CreateNewDoc(void)\r
-{\r
-}\r
-\r
-//\r
-// Save changes to document before quitting\r
-//\r
-bool SaveChanges(void)\r
-{\r
-       return true;\r
-}\r
-\r
-\r
-\r
-//\r
-// ABOUT Dialog WndProc\r
-//\r
-BOOL CALLBACK AboutProc(HWND hDlg, UINT msgID, WPARAM wParam, LPARAM lParam)\r
-{\r
-       switch (msgID)\r
-       {\r
-       case WM_INITDIALOG:\r
-\r
-               MiscCenterWnd(hDlg, hMainWnd);\r
-               break;\r
-\r
-       case WM_COMMAND:\r
-\r
-               if (wParam == IDOK || wParam == IDCANCEL)\r
-                       EndDialog(hDlg, TRUE);\r
-\r
-               break;\r
-\r
-       default:\r
-               return FALSE;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-//\r
-// Character Window WndProc\r
-//\r
-WndProcCW      PROC  STDCALL, hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM\r
-\r
-               mov    eax, uMsg                // pickup our message\r
-               .IF (eax == WM_PAINT)\r
-                 mov    eax, 0                 // Non-sense... (placeholder!)\r
-// Scan conversion etc. goes here...\r
-               .ELSEIF (eax == WM_LBUTTONDOWN)\r
-                 invoke SetCapture, hCharWnd\r
-               .ELSEIF (eax == WM_LBUTTONUP)\r
-                 invoke ReleaseCapture\r
-                 invoke SetFocus, hMainWnd     // Make sure the main wnd keeps focus!\r
-               .ELSEIF (eax == WM_NCLBUTTONDOWN)\r
-                 invoke DefWindowProc, hWnd, uMsg, wParam, lParam // Let it do its thing\r
-                 invoke SetFocus, hMainWnd     // Make sure the main wnd keeps focus!\r
-               .ELSE\r
-DefProc:         invoke DefWindowProc, hWnd, uMsg, wParam, lParam\r
-               .ENDIF\r
-               ret\r
-\r
-WndProcCW      ENDP\r
-\r
-//\r
-// Character Window WndProc\r
-//\r
-LRESULT CALLBACK WndProcCW(HWND hWnd, UINT msgID, WPARAM wParam, LPARAM lParam)\r
-{\r
-       switch (msgID)\r
-       {\r
-       default:\r
-               return DefWindowProc(hWnd, msgID, wParam, lParam);\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-\r
-// Function prototypes\r
-\r
-int32 FindSelectedTool(void);\r
-\r
-//\r
-// Tool Palette WndProc\r
-//\r
-LRESULT CALLBACK WndProcTP(HWND hWnd, UINT msgID, WPARAM wParam, LPARAM lParam)\r
-{\r
-       PAINTSTRUCT ps;\r
-       HDC hdc;\r
-       POINT pt;\r
-       static uint32 prevTool = -1;\r
-\r
-       switch (msgID)\r
-       {\r
-       case WM_PAINT:\r
-       {\r
-               hdc = BeginPaint(hWnd, &ps);\r
-               HDC newDC = CreateCompatibleDC(NULL);\r
-               SelectObject(newDC, hBMToolPal1);\r
-               BitBlt(hdc, 0, 0, sizeTPBM.x, sizeTPBM.y, newDC, 0, 0, SRCCOPY);\r
-               DeleteDC(newDC);\r
-\r
-// This is crappy. Find some way to tighten this up!\r
-               int32 tool = FindSelectedTool();\r
-\r
-               if (tool != -1)\r
-               {\r
-                       newDC = CreateCompatibleDC(NULL);\r
-                       SelectObject(newDC, hBMToolPal1);\r
-                   //need ul corner of bitmap, ul corner of dest, width/height\r
-                       pt.x = sizeStamp.x * (tool & 0x03), pt.y = sizeStamp.y * (tool >> 2);\r
-                       BitBlt(hdc, pt.x, pt.y, sizeStamp.x, sizeStamp.y, newDC, pt.x, pt.y, NOTSRCCOPY);\r
-                       DeleteDC(newDC);\r
-               }\r
-\r
-               EndPaint(hWnd, &ps);\r
-               break;\r
-       }\r
-       case WM_MOUSEMOVE:\r
-       {\r
-               int32 tool = FindSelectedTool();\r
-\r
-               if (tool != prevTool)\r
-               {\r
-                       prevTool = tool;\r
-                       InvalidateRect(hWnd, NULL, FALSE);\r
-               }\r
-\r
-               break;\r
-       }\r
-       case WM_RBUTTONUP:\r
-       {\r
-               int32 tool = FindSelectedTool(), oldTool = currentTool;\r
-\r
-               if (tool != -1)\r
-                       currentTool = tool;\r
-\r
-               if (currentTool != TOOLSelect && currentTool != TOOLDelPt && currentTool != TOOLAddPt\r
-                       && currentTool != TOOLPolySelect)\r
-                       ptHighlight = -1;\r
-\r
-               if (currentTool != oldTool)\r
-                       InvalidateRect(hMainWnd, NULL, TRUE);\r
-\r
-               if (currentTool == TOOLAddPoly)\r
-#ifdef DEBUGFOO\r
-{\r
-#endif\r
-                       polyFirstPoint = true;\r
-#ifdef DEBUGFOO\r
-wsprintf(strBuf, "--> Selected poly tool, polyFirstPoint is %s\n", polyFirstPoint ? "true" : "false");\r
-WriteLogMsg(strBuf);\r
-}\r
-#endif\r
-\r
-               ReleaseCapture();\r
-               ShowWindow(hToolPalWnd, SW_HIDE);\r
-               SetFocus(hMainWnd);                                             // Make sure the main wnd keeps focus!\r
-\r
-               break;\r
-       }\r
-       default:\r
-               return DefWindowProc(hWnd, msgID, wParam, lParam);\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-//\r
-// Find which tool we're pointing at\r
-// Use: xcoord = mouse.x / (bmsize.x/4), ycoord = mouse.y / (bmsize.y/2)\r
-//\r
-int32 FindSelectedTool(void)\r
-{\r
-       POINT pt;\r
-               \r
-       GetCursorPos(&pt);\r
-       ScreenToClient(hToolPalWnd, &pt);\r
-\r
-       uint32 x = (uint32)pt.x / sizeStamp.x, y = (uint32)pt.y / sizeStamp.y, tool = -1;\r
-\r
-       if (x < 4 && y < 2)\r
-//     {\r
-               tool = (y * 4) + x;\r
-\r
-//             if (tool == 7)\r
-//                     tool = -1;                                                      // 7 has no tool...\r
-//     }\r
-\r
-       return tool;\r
-}\r
-\r
-\r
-//\r
-// Misc center window\r
-//\r
-void MiscCenterWnd(HWND hChild, HWND hParent)\r
-{\r
-       RECT parent, child;\r
-\r
-       if (!GetWindowRect(hParent, &parent) || !GetWindowRect(hChild, &child))\r
-               return;\r
-\r
-       int32 x = parent.left + (((parent.right - parent.left) - (child.right - child.left)) / 2),\r
-               y = parent.top + (((parent.bottom - parent.top) - (child.bottom - child.top)) / 2);\r
-\r
-       if (x < 0)\r
-               x = 0;\r
-       else if (x > GetSystemMetrics(SM_CXFULLSCREEN) - (child.right - child.left))\r
-               x = GetSystemMetrics(SM_CXFULLSCREEN) - (child.right - child.left);\r
-\r
-       if (y < 0)\r
-               y = 0;\r
-       else if (y > GetSystemMetrics(SM_CYFULLSCREEN) - (child.bottom - child.top))\r
-               y = GetSystemMetrics(SM_CYFULLSCREEN) - (child.bottom - child.top);\r
-\r
-       SetWindowPos(hChild, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);\r
-}\r
-\r
-//\r
-// Allow only one instance\r
-//\r
-bool OnlyOneInstance(void)\r
-{\r
-       HWND window = FindWindow(className, NULL);\r
-\r
-       if (window == NULL)\r
-               return true;\r
-\r
-       ShowWindow(window, SW_SHOWNORMAL);\r
-       SetWindowPos(window, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);\r
-\r
-       return false;\r
-}\r
-\r
-//\r
-// Load/Allocate all resources\r
-//\r
-bool LoadResources(void)\r
-{\r
-       hCur[0] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR1));\r
-       hCur[1] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR2));\r
-       hCur[2] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR3));\r
-       hCur[3] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR4));\r
-       hCur[4] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR5));\r
-       hCur[5] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR6));\r
-       hCur[6] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR7));\r
-       hCur[7] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR8));\r
-\r
-       BITMAP bm;\r
-\r
-       hBMToolPal1 = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TOOLPAL1));\r
-       GetObject(hBMToolPal1, sizeof(bm), &bm);\r
-\r
-       // Set up sizes\r
-\r
-       sizeTPBM.x = bm.bmWidth, sizeTPBM.y = bm.bmHeight;\r
-       sizeStamp.x = bm.bmWidth / 4, sizeStamp.y = bm.bmHeight / 2;\r
-\r
-       hBluePen1 = CreatePen(PS_DOT, 1, 0x00FF0000);\r
-       hRedPen1 = CreatePen(PS_SOLID, 1, 0x000000FF);\r
-       hGreenPen1 = CreatePen(PS_SOLID, 1, 0x0000AF00);\r
-       hBlackPen1 = CreatePen(PS_SOLID, 1, 0x00000000);\r
-\r
-       LOGBRUSH lb = { BS_NULL, 0, 0 };\r
-\r
-       hNullBrush = CreateBrushIndirect(&lb);\r
-\r
-       return true;\r
-}\r
-\r
-//\r
-// Deallocate all resources\r
-//\r
-void DeallocateResources(void)\r
-{\r
-       DeleteObject(hBMToolPal1);\r
-       DeleteObject(hBluePen1);\r
-       DeleteObject(hRedPen1);\r
-       DeleteObject(hGreenPen1);\r
-       DeleteObject(hBlackPen1);\r
-       DeleteObject(hNullBrush);\r
-}\r
-\r
-//\r
-// Save all application specific data, so we can pick up where we last left off...\r
-//\r
-void SaveAppState(void)\r
-{\r
-       SetINIInt("Main", "flags", wpM.flags);\r
-       SetINIInt("Main", "showCmd", wpM.showCmd);\r
-       SetINIInt("Main", "x1", wpM.rcNormalPosition.left);\r
-       SetINIInt("Main", "y1", wpM.rcNormalPosition.top);\r
-       SetINIInt("Main", "x2", wpM.rcNormalPosition.right);\r
-       SetINIInt("Main", "y2", wpM.rcNormalPosition.bottom);\r
-\r
-       SetINIInt("Main", "vpx", ptVPM.x);\r
-       SetINIInt("Main", "vpy", ptVPM.y);\r
-\r
-       SetINIInt("Char", "flags", wpC.flags);\r
-       SetINIInt("Char", "showCmd", wpC.showCmd);\r
-       SetINIInt("Char", "x1", wpC.rcNormalPosition.left);\r
-       SetINIInt("Char", "y1", wpC.rcNormalPosition.top);\r
-       SetINIInt("Char", "x2", wpC.rcNormalPosition.right);\r
-       SetINIInt("Char", "y2", wpC.rcNormalPosition.bottom);\r
-\r
-       // Need to write out currently opened font, character looking at, other misc. crap\r
-//     SetINIString("Main", "currentFile", pDoc->GetPathName());\r
-//     SetINIInt("Main", "currentChar", pDoc->character_num);\r
-}\r
-\r
-//\r
-// Restore all application specific data previously saved\r
-//\r
-bool RestoreAppState(void)\r
-{\r
-       InitINIFile();\r
-\r
-       WINDOWPLACEMENT wp;\r
-       wp.length = sizeof(WINDOWPLACEMENT);\r
-       GetWindowPlacement(hMainWnd, &wp);\r
-\r
-       wp.flags = GetINIInt("Main", "flags", wp.flags);\r
-       wp.showCmd = GetINIInt("Main", "showCmd", wp.showCmd);\r
-       wp.rcNormalPosition.left = GetINIInt("Main", "x1", wp.rcNormalPosition.left);\r
-       wp.rcNormalPosition.top = GetINIInt("Main", "y1", wp.rcNormalPosition.top);\r
-       wp.rcNormalPosition.right = GetINIInt("Main", "x2", wp.rcNormalPosition.right);\r
-       wp.rcNormalPosition.bottom = GetINIInt("Main", "y2", wp.rcNormalPosition.bottom);\r
-\r
-       SetWindowPlacement(hMainWnd, &wp);\r
-\r
-       HDC hdc;\r
-       POINT pt;\r
-       hdc = GetDC(hMainWnd);\r
-       GetViewportOrgEx(hdc, &pt);\r
-\r
-       pt.x = GetINIInt("Main", "vpx", pt.x);\r
-       pt.y = GetINIInt("Main", "vpy", pt.y);\r
-\r
-       SetViewportOrgEx(hdc, pt.x, pt.y, NULL);\r
-       ReleaseDC(hMainWnd, hdc);\r
-\r
-       GetWindowPlacement(hCharWnd, &wp);\r
-\r
-       wp.flags = GetINIInt("Char", "flags", wp.flags);\r
-       wp.showCmd = GetINIInt("Char", "showCmd", wp.showCmd);\r
-       wp.rcNormalPosition.left = GetINIInt("Char", "x1", wp.rcNormalPosition.left);\r
-       wp.rcNormalPosition.top = GetINIInt("Char", "y1", wp.rcNormalPosition.top);\r
-       wp.rcNormalPosition.right = GetINIInt("Char", "x2", wp.rcNormalPosition.right);\r
-       wp.rcNormalPosition.bottom = GetINIInt("Char", "y2", wp.rcNormalPosition.bottom);\r
-\r
-       SetWindowPlacement(hCharWnd, &wp);\r
-\r
-       if (wp.showCmd == SW_HIDE)\r
-               SendMessage(hToolBar, TB_SETSTATE, ID_TBCHARWIN, MAKELONG(TBSTATE_ENABLED, 0));\r
-\r
-//  CString lastFile = theApplicationObject.GetProfileString(version, "currentFile", "");\r
-//  int lastChar = theApplicationObject.GetProfileInt(version, "currentChar", 0);\r
-//  if (lastFile.GetLength())\r
-//  {\r
-//    // Attempt to restore the last session by open the last file used, etc...\r
-//    if (!pDoc->m_myFont.Load(lastFile))\r
-//    {\r
-//      // Err, make sure you can support any allegations you make below, buddy!\r
-//      AfxMessageBox("The last file opened with TTF Edit\n\rseems to have been moved or deleted.");\r
-//    }\r
-//    else\r
-//    {\r
-//      pDoc->m_myFont.SetGlyph(lastChar);  // Set TTF object to last used char\r
-//      pDoc->character_num = lastChar;\r
-//      pDoc->SetPathName(lastFile);\r
-//\r
-//      BYTE name[512];\r
-//      pDoc->m_myFont.GetCharName(lastChar, name);\r
-//      m_wndOwned.SetWindowText((char *)name);\r
-//    }\r
-//  }\r
-\r
-       return true;\r
-}\r
-\r
-//\r
-// Initialization\r
-//\r
-bool Initialization(void)\r
-{\r
-       WNDCLASSEX wcex;\r
-\r
-       if (!LoadResources())\r
-               return false;\r
-\r
-       RtlFillMemory(&wcex, sizeof(WNDCLASSEX), 0);\r
-       wcex.cbSize = sizeof(WNDCLASSEX);\r
-       wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;\r
-       wcex.lpfnWndProc = WndProc;\r
-       wcex.hInstance = hInst;\r
-       wcex.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON));\r
-       wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);\r
-       wcex.lpszMenuName = MAKEINTRESOURCE(IDM_MENU);\r
-       wcex.lpszClassName = className;\r
-       wcex.hIconSm = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, NULL);\r
-\r
-       if (!RegisterClassEx(&wcex))\r
-               return false;\r
-\r
-       hMainWnd = CreateWindowEx(NULL, className, className, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,\r
-               0, 0, 0x1A0, 0x180, NULL, NULL, hInst, NULL);\r
-\r
-       if (!hMainWnd)\r
-               return false;\r
-\r
-       ShowWindow(hMainWnd, nCmdShow);\r
-       UpdateWindow(hMainWnd);\r
-\r
-       // Character window creation\r
-\r
-       wcex.lpfnWndProc = WndProcCW;\r
-       wcex.lpszMenuName = NULL;\r
-       wcex.lpszClassName = CNCharWin;\r
-       wcex.hCursor = LoadCursor(NULL, IDC_ARROW);     // Owned windows have "regular" cursors\r
-\r
-       if (!RegisterClassEx(&wcex))\r
-               return false;\r
-\r
-       hCharWnd = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW, CNCharWin,\r
-               curCharName, WS_POPUP | WS_CAPTION | WS_VISIBLE | WS_THICKFRAME,\r
-               100, 100, 120, 120, hMainWnd, NULL, hInst, NULL);\r
-\r
-       if (!hCharWnd)\r
-               return false;\r
-\r
-       ShowWindow(hCharWnd, SW_SHOWNORMAL);\r
-       UpdateWindow(hCharWnd);\r
-       SetFocus(hMainWnd);                                                     // Make sure main wnd has focus!\r
-\r
-       // Tool palette window creation\r
-\r
-       wcex.lpfnWndProc = WndProcTP;\r
-       wcex.lpszClassName = CNToolPal;\r
-\r
-       if (!RegisterClassEx(&wcex))\r
-               return false;\r
-\r
-       hToolPalWnd = CreateWindowEx(WS_EX_WINDOWEDGE, CNToolPal, NULL, WS_POPUP,\r
-               0, 0, sizeTPBM.x, sizeTPBM.y, hMainWnd, NULL, hInst, NULL);\r
-\r
-       if (!hToolPalWnd)\r
-               return false;\r
-\r
-// Note: A better way to handle this would be to have a sub that registers ALL\r
-//       classes beforehand and passes a TRUE/FALSE back depending on whether or not\r
-//       all the classes were able to be registered or not, THEN create the windows\r
-//       and controls...\r
-\r
-       RestoreAppState();                                                      // Restore app related stuff\r
-\r
-       return true;\r
-}\r
-\r
-*/\r
-\r
index de526f880b9280cfef86516ac075aa4a93f860df..7f1eba7da80992e2e1d76a1da95bde172d3cdce5 100755 (executable)
@@ -2,7 +2,7 @@
 // TTEDIT.H: Header file\r
 //\r
 // by James L. Hammons\r
-// (C) 2005 Underground Software\r
+// (C) 2008 Underground Software\r
 //\r
 \r
 #ifndef __TTEDIT_H__\r
@@ -29,9 +29,11 @@ class TTEditApp: public wxApp
                CharWindow * charWin;\r
                ToolWindow * toolPalette;\r
                TTF font;\r
+               wxCursor * cur[8];\r
 \r
                bool OnInit();\r
                int OnExit();\r
+               void CreateResources(void);\r
 };\r
 \r
 DECLARE_APP(TTEditApp)\r
@@ -51,131 +53,11 @@ class TTEditFrame: public wxFrame
                ~TTEditFrame(void);\r
 \r
                void OnCloseWindow(wxCloseEvent &e);\r
-\r
                void OnOpen(wxCommandEvent &e);\r
                void OnExit(wxCommandEvent &e);\r
                void OnAbout(wxCommandEvent &e);\r
-//             void OnEasy(wxCommandEvent &event);\r
-///            void OnMedium(wxCommandEvent &event);\r
-//             void OnDifficult(wxCommandEvent &event);\r
-\r
-       DECLARE_EVENT_TABLE()\r
-};\r
-\r
-class TTEditWindow: public wxWindow\r
-{\r
-       private:\r
-               TTEditApp & app;                                                // Reference to the application object\r
-               double scale;                                                   // Window scaling factor\r
-               int32 offsetX, offsetY;                                 // Window offsets\r
-\r
-       protected:\r
-       public:\r
-//             int field_width, field_height;\r
-//             int x_cell, y_cell;\r
-               wxBitmap * bmp;\r
-               wxPoint pt, ptOffset, ptPrevious;\r
-\r
-               // Constructor and destructor\r
-               TTEditWindow(wxFrame * parent, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = 0);\r
-               ~TTEditWindow(void);\r
-\r
-               void OnPaint(wxPaintEvent &e);\r
-               void OnMouseEvent(wxMouseEvent &e);\r
-//             void DrawField(wxDC *, int xc1, int yc1, int xc2, int yc2);\r
-//             void Refresh(int xc1, int yc1, int xc2, int yc2);\r
-//             void Uncover(int x, int y);\r
-//             void UpdateFieldSize();\r
-\r
-       protected:\r
-               wxPoint GetAdjustedMousePosition(wxMouseEvent &e);\r
-               wxPoint GetAdjustedClientPosition(wxCoord x, wxCoord y);\r
-\r
-       DECLARE_EVENT_TABLE()\r
-};\r
-\r
-class CharWindow: public wxWindow\r
-{\r
-       private:\r
-       protected:\r
-       public:\r
-//             int field_width, field_height;\r
-//             int x_cell, y_cell;\r
-               wxBitmap * bmp;\r
-\r
-               // Constructor and destructor\r
-               CharWindow(wxFrame * parent, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = 0);\r
-               ~CharWindow(void);\r
-\r
-               void OnPaint(wxPaintEvent &e);\r
-               void OnMouseEvent(wxMouseEvent &e);\r
-//             void DrawField(wxDC *, int xc1, int yc1, int xc2, int yc2);\r
-//             void Refresh(int xc1, int yc1, int xc2, int yc2);\r
-//             void Uncover(int x, int y);\r
-//             void UpdateFieldSize();\r
 \r
        DECLARE_EVENT_TABLE()\r
 };\r
 \r
-class ToolWindow: public wxFrame\r
-//class ToolWindow: public wxWindow\r
-{\r
-       private:\r
-       protected:\r
-       public:\r
-               wxBitmap * bmp;\r
-               wxPoint sizeStamp, sizeTPBM;\r
-               int prevTool;\r
-\r
-               // Constructor and destructor\r
-               ToolWindow(wxFrame * parent, const wxString &title, const wxPoint &pos, const wxSize &size, long style);\r
-//             ToolFrame(wxFrame * parent, const wxString &title, const wxPoint &pos, const wxSize &size, long style);\r
-//             ToolWindow(wxFrame * parent, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = 0);\r
-               ~ToolWindow(void);\r
-\r
-               void OnPaint(wxPaintEvent &e);\r
-               void OnMouseEvent(wxMouseEvent &e);\r
-//             void DrawField(wxDC *, int xc1, int yc1, int xc2, int yc2);\r
-//             void Refresh(int xc1, int yc1, int xc2, int yc2);\r
-//             void Uncover(int x, int y);\r
-//             void UpdateFieldSize();\r
-               int32 FindSelectedTool(void);\r
-\r
-       DECLARE_EVENT_TABLE()\r
-};\r
-\r
-// Resource/control IDs\r
-/*\r
-#define        IDI_ICON                        0x01L           // IDs same as in ttedit.asm\r
-#define        IDM_MENU                        0x02L\r
-#define        IDA_ACCEL                       0x03L\r
-#define        IDD_ABOUT                       0x04L\r
-#define IDR_TOOLBAR1           0x05L\r
-#define IDB_TOOLBAR1           0x06L\r
-#define IDB_TOOLPAL1           0x07L\r
-#define IDC_CURSOR1                    0x08L\r
-#define IDC_CURSOR2                    0x09L\r
-#define IDC_CURSOR3                    0x0AL\r
-#define IDC_CURSOR4                    0x0BL\r
-#define IDC_CURSOR5                    0x0CL\r
-#define IDC_CURSOR6                    0x0DL\r
-#define IDC_CURSOR7                    0x0EL\r
-#define IDC_CURSOR8                    0x0FL\r
-\r
-#define        IDS_SYSMENU                     0x010L\r
-#define        IDM_FILEMENU            0x011L\r
-#define        IDM_HELPMENU            0x012L\r
-\r
-#define        IDM_NEW                         0x020L\r
-#define        IDM_OPEN                        0x021L\r
-#define        IDM_SAVE                        0x022L\r
-#define        IDM_SAVEAS                      0x023L\r
-#define        IDM_EXIT                        0x024L\r
-#define        IDM_HELPTOPICS          0x025L\r
-#define        IDM_ABOUT                       0x026L\r
-\r
-#define        ID_TBLEFT                       0x030L\r
-#define        ID_TBRIGHT                      0x031L\r
-#define        ID_TBCHARWIN            0x032L */\r
-\r
 #endif // __TTEDIT_H__\r
index 7f589aa434847d901d05acb8407f463a97ce1cfa..cb107ebfab2e30935965ac0015200f8a9258aa3b 100755 (executable)
@@ -5,21 +5,18 @@
 #ifndef __TYPES_H__\r
 #define __TYPES_H__\r
 \r
-// This is only good on certain intel 32-bit platforms...\r
-// You may need to tweak to suit your specific platform.\r
+// This should be portable, since it's part of the C99 standard...!\r
 \r
-typedef unsigned char          uint8;\r
-typedef signed char                    int8;\r
-typedef unsigned short         uint16;\r
-typedef signed short           int16;\r
-typedef unsigned                       uint32;\r
-typedef signed                         int32;\r
-//typedef unsigned long long   uint64;\r
-//typedef signed long long     int64;\r
+#include <stdint.h>\r
 \r
-//typedef signed char                  SBYTE;\r
-//typedef signed short int     SWORD;\r
-//typedef signed long int              SDWORD;\r
+typedef uint8_t                uint8;\r
+typedef int8_t         int8;\r
+typedef uint16_t       uint16;\r
+typedef int16_t                int16;\r
+typedef uint32_t       uint32;\r
+typedef int32_t                int32;\r
+typedef uint64_t       uint64;\r
+typedef int64_t                int64;\r
 \r
 /*#ifndef _WINDOWS_\r
 #define NULL   0\r