]> Shamusworld >> Repos - ttedit/blobdiff - src/ttedit.cpp
Set the eol style on the project to native, to avoid line ending chaos.
[ttedit] / src / ttedit.cpp
index 3c31541a8934d42c68804eac35c8e504ddb97afd..116bd4abfcea9b1daa9dd7dfb0446e3ad3546bdc 100755 (executable)
-//\r
-// TTEDIT.CPP - The TrueType Editor\r
-// by James L. Hammons\r
-// (C) 2004 Underground Software\r
-//\r
-// JLH = James L. Hammons <jlhamm@acm.org>\r
-//\r
-// Who  When        What\r
-// ---  ----------  -------------------------------------------------------------\r
-// JLH  04/10/2002  Created this file\r
-// 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
-// - Fix scrolling, zooming, settings (ini)\r
-// - Finish conversion to wxWidgets for cross-platform portability\r
-// - Fix problem with owned window causing main window refresh problems\r
-//   (ironically enough, it doesn't seem to be a problem anymore...)\r
-//\r
-\r
-// Uncomment this for debugging...\r
-#define DEBUG\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
-\r
-// Pixmap resouces\r
-\r
-#include "res/cur1.xpm"\r
-#include "res/cur2.xpm"\r
-#include "res/cur3.xpm"\r
-#include "res/cur4.xpm"\r
-#include "res/cur5.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
-IMPLEMENT_APP(TTEditApp)                                               // Run the main application loop\r
-\r
-bool TTEditApp::OnInit()\r
-{\r
-       wxLog * logTarget = new wxLogStderr();//fopen("!ttedit_log.txt", "wb"));\r
-       wxLog::SetActiveTarget(logTarget);\r
-#ifdef DEBUG\r
-       OpenDebugLog();\r
-#endif\r
-\r
-       // Initialize all the top-level window members to NULL.\r
-       mainFrame = NULL;\r
-       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(mainFrame, _("Own3d W1nd0w"), wxDefaultPosition, wxDefaultSize,\r
-               wxCAPTION | wxRESIZE_BORDER);\r
-\r
-       toolPalette = new ToolWindow(mainFrame, _(""), wxDefaultPosition, wxDefaultSize,\r
-               wxBORDER_NONE | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT);\r
-\r
-       return true;\r
-}\r
-\r
-int TTEditApp::OnExit()\r
-{\r
-#ifdef DEBUG\r
-       CloseDebugLog();\r
-#endif\r
-\r
-       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
-       EVT_MENU(IDM_ABOUT, TTEditFrame::OnAbout)\r
-       EVT_CLOSE(TTEditFrame::OnCloseWindow)\r
-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()), mainWindow(NULL)\r
-{\r
-       // Initialize child subwindow members (and hopefully avoid subtle bugs)\r
-//     mainWindow = NULL;\r
-\r
-       SetIcon(wxICON(ttedit));\r
-//     CreateStatusBar(2);                                                     // Create 2 panes\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
-\r
-       if (tb != NULL)\r
-       {\r
-               // Create buttons\r
-\r
-               wxBitmap tool1(tool1_xpm);\r
-               wxBitmap tool2(tool2_xpm);\r
-               wxBitmap tool3(tool3_xpm);\r
-\r
-               tb->AddTool(ID_TBLEFT, _("Prev char"), tool1, _("Go to prev char"), wxITEM_NORMAL);\r
-               tb->AddTool(ID_TBRIGHT, _("Next char"), tool2, _("Go to next char"), wxITEM_NORMAL);\r
-               tb->AddTool(ID_TBCHARWIN, _("Char Wnd"), tool3, _("Toggle char window"), wxITEM_NORMAL);\r
-               tb->Realize();\r
-       }\r
-\r
-       // Create a menu bar for the frame\r
-       menuBar = new wxMenuBar;\r
-       wxMenu * menu1 = new wxMenu;\r
-       menu1->Append(IDM_NEW, _("&New\tCtrl+N"), _("Create a new font."));\r
-       menu1->Append(IDM_OPEN, _("&Open...\tCtrl+O"), _("Opens an existing font."));\r
-       menu1->Append(IDM_SAVE, _("&Save\tCtrl+S"), _("Save the current font."));\r
-       menu1->Append(IDM_SAVEAS, _("Save &As..."), _("Save the current font under a different name."));\r
-       menu1->AppendSeparator();\r
-       menu1->Append(IDM_EXIT, _("E&xit\tAlt+X"), _("Quits the TTEdit program."));\r
-       menuBar->Append(menu1, _("&File"));\r
-       wxMenu * menu2 = new wxMenu;\r
-       menu2->Append(IDM_HELPTOPICS, _("&Help Topics"), _("Displays the Help contents and index."));\r
-       menu2->AppendSeparator();\r
-       menu2->Append(IDM_ABOUT, _("&About TTEdit"), _("Displays information about TTEdit."));\r
-       menuBar->Append(menu2, _("&Help"));\r
-       SetMenuBar(menuBar);\r
-\r
-       // Create child subwindows\r
-       mainWindow = new TTEditWindow(this);\r
-\r
-       Centre(wxBOTH);                                                         // Centre frame on the screen\r
-       Show(true);                                                                     // Show the frame\r
-}\r
-\r
-TTEditFrame::~TTEditFrame()\r
-{\r
-}\r
-\r
-void TTEditFrame::OnOpen(wxCommandEvent &e)\r
-{\r
-       wxFileDialog fd(this, _("Choose a font to load"), _(""), _(""), _("TTF files (*.ttf)|*.ttf|All files (*.*)|*.*"), wxOPEN);\r
-\r
-       if (fd.ShowModal() != wxID_OK)\r
-           return;\r
-\r
-// Hmm. The font object is causing a massive crash... (gdb says it's in "Load")\r
-       if (app.font.Load((char *)fd.GetPath().c_str()) != true)\r
-       {\r
-               wxMessageDialog dlg(NULL, _("Load font failed!"), _("Houston, we have a problem..."), wxOK | wxICON_ERROR);\r
-               dlg.ShowModal();\r
-       }\r
-\r
-//Huzzah! It works! Now just need scaling, scrolling, etc...\r
-//     pts = app.font.GetGlyphPoints(45);\r
-}\r
-\r
-void TTEditFrame::OnAbout(wxCommandEvent &e)\r
-{\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
-       app.toolPalette->Destroy();\r
-       this->Destroy();\r
-}\r
-\r
-void TTEditFrame::OnCloseWindow(wxCloseEvent &e)\r
-{\r
-       app.toolPalette->Destroy();\r
-       this->Destroy();\r
-}\r
+//
+// TTEDIT.CPP - The TrueType Editor
+// by James L. Hammons
+// (C) 2004 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -------------------------------------------------------------
+// JLH  04/10/2002  Created this file
+// 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
+// - Fix scrolling, zooming, settings (ini)
+// - Finish conversion to wxWidgets for cross-platform portability
+// - Fix problem with owned window causing main window refresh problems
+//   (ironically enough, it doesn't seem to be a problem anymore...)
+//
+
+// Uncomment this for debugging...
+#define DEBUG
+#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
+
+// Pixmap resouces
+
+#include "res/cur1.xpm"
+#include "res/cur2.xpm"
+#include "res/cur3.xpm"
+#include "res/cur4.xpm"
+#include "res/cur5.xpm"
+#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"
+
+
+IMPLEMENT_APP(TTEditApp)                                               // Run the main application loop
+
+bool TTEditApp::OnInit()
+{
+       wxLog * logTarget = new wxLogStderr();//fopen("!ttedit_log.txt", "wb"));
+       wxLog::SetActiveTarget(logTarget);
+#ifdef DEBUG
+       OpenDebugLog();
+#endif
+
+       // Initialize all the top-level window members to NULL.
+       mainFrame = NULL;
+       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(mainFrame, _("Own3d W1nd0w"), wxDefaultPosition, wxDefaultSize,
+               wxCAPTION | wxRESIZE_BORDER);
+
+       toolPalette = new ToolWindow(mainFrame, _(""), wxDefaultPosition, wxDefaultSize,
+               wxBORDER_NONE | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT);
+
+       return true;
+}
+
+int TTEditApp::OnExit()
+{
+#ifdef DEBUG
+       CloseDebugLog();
+#endif
+
+       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)
+       EVT_MENU(IDM_ABOUT, TTEditFrame::OnAbout)
+       EVT_CLOSE(TTEditFrame::OnCloseWindow)
+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()), mainWindow(NULL)
+{
+       // Initialize child subwindow members (and hopefully avoid subtle bugs)
+//     mainWindow = NULL;
+
+       SetIcon(wxICON(ttedit));
+//     CreateStatusBar(2);                                                     // Create 2 panes
+       int widths[2] = { -1, 120 };
+       wxStatusBar * sb = CreateStatusBar(2, 0);       // Create 2 panes
+       sb->SetStatusWidths(2, widths);
+       wxToolBar * tb = CreateToolBar();
+
+       if (tb != NULL)
+       {
+               // Create buttons
+
+               wxBitmap tool1(tool1_xpm);
+               wxBitmap tool2(tool2_xpm);
+               wxBitmap tool3(tool3_xpm);
+
+               tb->AddTool(ID_TBLEFT, _("Prev char"), tool1, _("Go to prev char"), wxITEM_NORMAL);
+               tb->AddTool(ID_TBRIGHT, _("Next char"), tool2, _("Go to next char"), wxITEM_NORMAL);
+               tb->AddTool(ID_TBCHARWIN, _("Char Wnd"), tool3, _("Toggle char window"), wxITEM_NORMAL);
+               tb->Realize();
+       }
+
+       // Create a menu bar for the frame
+       menuBar = new wxMenuBar;
+       wxMenu * menu1 = new wxMenu;
+       menu1->Append(IDM_NEW, _("&New\tCtrl+N"), _("Create a new font."));
+       menu1->Append(IDM_OPEN, _("&Open...\tCtrl+O"), _("Opens an existing font."));
+       menu1->Append(IDM_SAVE, _("&Save\tCtrl+S"), _("Save the current font."));
+       menu1->Append(IDM_SAVEAS, _("Save &As..."), _("Save the current font under a different name."));
+       menu1->AppendSeparator();
+       menu1->Append(IDM_EXIT, _("E&xit\tAlt+X"), _("Quits the TTEdit program."));
+       menuBar->Append(menu1, _("&File"));
+       wxMenu * menu2 = new wxMenu;
+       menu2->Append(IDM_HELPTOPICS, _("&Help Topics"), _("Displays the Help contents and index."));
+       menu2->AppendSeparator();
+       menu2->Append(IDM_ABOUT, _("&About TTEdit"), _("Displays information about TTEdit."));
+       menuBar->Append(menu2, _("&Help"));
+       SetMenuBar(menuBar);
+
+       // Create child subwindows
+       mainWindow = new TTEditWindow(this);
+
+       Centre(wxBOTH);                                                         // Centre frame on the screen
+       Show(true);                                                                     // Show the frame
+}
+
+TTEditFrame::~TTEditFrame()
+{
+}
+
+void TTEditFrame::OnOpen(wxCommandEvent &e)
+{
+       wxFileDialog fd(this, _("Choose a font to load"), _(""), _(""), _("TTF files (*.ttf)|*.ttf|All files (*.*)|*.*"), wxOPEN);
+
+       if (fd.ShowModal() != wxID_OK)
+           return;
+
+// Hmm. The font object is causing a massive crash... (gdb says it's in "Load")
+       if (app.font.Load((char *)fd.GetPath().c_str()) != true)
+       {
+               wxMessageDialog dlg(NULL, _("Load font failed!"), _("Houston, we have a problem..."), wxOK | wxICON_ERROR);
+               dlg.ShowModal();
+       }
+
+//Huzzah! It works! Now just need scaling, scrolling, etc...
+//     pts = app.font.GetGlyphPoints(45);
+}
+
+void TTEditFrame::OnAbout(wxCommandEvent &e)
+{
+       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)
+{
+       app.toolPalette->Destroy();
+       this->Destroy();
+}
+
+void TTEditFrame::OnCloseWindow(wxCloseEvent &e)
+{
+       app.toolPalette->Destroy();
+       this->Destroy();
+}