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