2 // TTEDIT.CPP - The TrueType Editor
4 // (C) 2004 Underground Software
6 // JLH = James L. Hammons <jlhamm@acm.org>
9 // --- ---------- -------------------------------------------------------------
10 // JLH 04/10/2002 Created this file
11 // JLH 05/10/2004 Translated file from ASM to CPP
12 // JLH 05/14/2004 Added rudimentary editing capability to tool palette tools
13 // JLH 11/18/2006 Initial port to Linux
14 // JLH 08/27/2008 Fixed tool palette focus problems
15 // JLH 08/28/2008 Split out classes defined here into separate files
16 // JLH 03/05/2009 Initial conversion from wxWidgets to Qt
21 // - Fix problem with tool palette not getting focus 1st time it's called up [DONE]
22 // - Split out windows/classes defined here into their own files [DONE]
26 // - Fix bug in Glyphpoints when dragging on an empty canvas or loading a font
27 // - Fix scrolling, zooming, settings (ini)
28 // - Finish conversion to wxWidgets for cross-platform portability
29 // - Fix problem with owned window causing main window refresh problems
30 // (ironically enough, it doesn't seem to be a problem anymore...)
33 // Uncomment this for debugging...
35 #define DEBUGFOO // Various tool debugging...
36 #define DEBUGTP // Toolpalette debugging...
40 #include <QApplication>
41 #include "editwindow.h"
43 // Here's the main application loop--short and simple...
44 int main(int argc, char * argv[])
46 Q_INIT_RESOURCE(ttedit); // This must the same name as the exe filename
48 QApplication app(argc, argv);
55 TTEMainWindow::TTEMainWindow()
57 editWnd = new EditWindow(this);
58 setCentralWidget(editWnd);
59 setWindowIcon(QIcon(":/res/ttedit.png"));
60 setWindowTitle("TTEdit!");
64 newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
65 newAct->setShortcuts(QKeySequence::New);
66 newAct->setStatusTip(tr("Create a new file"));
67 connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
69 openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
70 openAct->setShortcuts(QKeySequence::Open);
71 openAct->setStatusTip(tr("Open an existing file"));
72 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
74 aboutQtAct = new QAction(tr("About &Qt"), this);
75 aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
76 connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
79 fileMenu = menuBar()->addMenu(tr("&File"));
80 fileMenu->addAction(newAct);
81 fileMenu->addAction(openAct);
82 fileMenu->addAction(saveAct);
83 fileMenu->addAction(saveAsAct);
84 fileMenu->addSeparator();
85 fileMenu->addAction(exitAct);
87 editMenu = menuBar()->addMenu(tr("&Edit"));
88 editMenu->addAction(cutAct);
89 editMenu->addAction(copyAct);
90 editMenu->addAction(pasteAct);
92 menuBar()->addSeparator();
94 helpMenu = menuBar()->addMenu(tr("&Help"));
95 helpMenu->addAction(aboutAct);
96 helpMenu->addAction(aboutQtAct);
99 fileToolBar = addToolBar(tr("File"));
100 fileToolBar->addAction(newAct);
101 fileToolBar->addAction(openAct);
102 fileToolBar->addAction(saveAct);
104 editToolBar = addToolBar(tr("Edit"));
105 editToolBar->addAction(cutAct);
106 editToolBar->addAction(copyAct);
107 editToolBar->addAction(pasteAct);
111 statusBar()->showMessage(tr("Ready"));
115 // connect(textEdit->document(), SIGNAL(contentsChanged()),
116 // this, SLOT(documentWasModified()));
118 // setCurrentFile("");
119 setUnifiedTitleAndToolBarOnMac(true);
122 void TTEMainWindow::closeEvent(QCloseEvent * event)
125 event->accept(); // ignore() if can't close for some reason
128 void TTEMainWindow::Open(void)
132 void TTEMainWindow::ReadSettings(void)
134 QSettings settings("Underground Software", "TTEdit");
135 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
136 QSize size = settings.value("size", QSize(400, 400)).toSize();
141 void TTEMainWindow::WriteSettings(void)
143 QSettings settings("Underground Software", "TTEdit");
144 settings.setValue("pos", pos());
145 settings.setValue("size", size());
151 #include "charwindow.h"
152 #include "toolwindow.h"
153 #include "editwindow.h"
154 #include "tte_res.h" // Resource IDs
161 #include "res/cur1.xpm"
162 #include "res/cur2.xpm"
163 #include "res/cur3.xpm"
164 #include "res/cur4.xpm"
165 #include "res/cur5.xpm"
166 #include "res/cur6.xpm"
167 #include "res/cur7.xpm"
168 #include "res/cur8.xpm"
169 #include "res/ttedit.xpm" // *nix only, but small enough to not matter
170 #include "res/tool1.xpm"
171 #include "res/tool2.xpm"
172 #include "res/tool3.xpm"
175 IMPLEMENT_APP(TTEditApp) // Run the main application loop
177 bool TTEditApp::OnInit()
179 wxLog * logTarget = new wxLogStderr();//fopen("!ttedit_log.txt", "wb"));
180 wxLog::SetActiveTarget(logTarget);
185 // Initialize all the top-level window members to NULL.
189 for(int i=0; i<8; i++)
192 //Shouldn't we check to see if it was successful? This just assumes
195 mainFrame = new TTEditFrame(NULL, _("TTEdit"), wxPoint(155, 165), wxSize(300, 300),
196 wxDEFAULT_FRAME_STYLE | wxFULL_REPAINT_ON_RESIZE);
197 // wxMINIMIZE_BOX | wxRESIZE_BOX | wxMAXIMIZE_BOX | | wxSYSTEM_MENU | wxCAPTION);
199 // charWin = new CharWindow(NULL);//, _T("Own3d W1nd0w"), wxDefaultPosition, wxDefaultSize);
200 charWin = new CharWindow(mainFrame, _("Own3d W1nd0w"), wxDefaultPosition, wxDefaultSize,
201 wxCAPTION | wxRESIZE_BORDER | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT);
203 toolPalette = new ToolWindow(mainFrame, _(""), wxDefaultPosition, wxDefaultSize,
204 wxBORDER_NONE | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT);
209 int TTEditApp::OnExit()
214 for(int i=0; i<8; i++)
222 // OS dependent method of creating cursor (works for Win32 and GTK+)
224 #define CREATE_CURSOR(storage, name, hsx, hsy) \
225 wxBitmap name##_bitmap(name##_xpm); \
226 wxImage name##_image = name##_bitmap.ConvertToImage(); \
227 name##_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hsx); \
228 name##_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hsy); \
229 storage = new wxCursor(name##_image);
231 void TTEditApp::CreateResources(void)
233 // This is a sucky way to create cursors, but at least it's cross-platform...
234 // NOTE: Need to fix hotspots on a few... !!! FIX !!! [DONE]
236 CREATE_CURSOR(cur[0], cur1, 1, 1);
237 CREATE_CURSOR(cur[1], cur2, 1, 1);
238 CREATE_CURSOR(cur[2], cur3, 11, 11); // Prolly won't need this soon (scroll)...
239 CREATE_CURSOR(cur[3], cur4, 15, 13); // Prolly won't need this soon (zoom)...
240 CREATE_CURSOR(cur[4], cur5, 1, 1);
241 CREATE_CURSOR(cur[5], cur6, 1, 1);
242 CREATE_CURSOR(cur[6], cur7, 1, 1);
243 CREATE_CURSOR(cur[7], cur8, 1, 1);
247 BEGIN_EVENT_TABLE(TTEditFrame, wxFrame)
248 EVT_MENU(IDM_OPEN, TTEditFrame::OnOpen)
249 EVT_MENU(IDM_EXIT, TTEditFrame::OnExit)
250 EVT_MENU(IDM_ABOUT, TTEditFrame::OnAbout)
251 EVT_MENU(ID_TBCHARWIN, TTEditFrame::OnCharWindow)
252 EVT_CLOSE(TTEditFrame::OnCloseWindow)
255 TTEditFrame::TTEditFrame(wxFrame * parent, const wxString &title, const wxPoint &pos,
256 const wxSize &size, long style): wxFrame(parent, -1, title, pos, size, style), app(wxGetApp()), mainWindow(NULL)
258 // Initialize child subwindow members (and hopefully avoid subtle bugs)
259 // mainWindow = NULL;
261 SetIcon(wxICON(ttedit));
262 // CreateStatusBar(2); // Create 2 panes
263 int widths[2] = { -1, 120 };
264 wxStatusBar * sb = CreateStatusBar(2, 0); // Create 2 panes
265 sb->SetStatusWidths(2, widths);
266 wxToolBar * tb = CreateToolBar();
272 wxBitmap tool1(tool1_xpm);
273 wxBitmap tool2(tool2_xpm);
274 wxBitmap tool3(tool3_xpm);
276 tb->AddTool(ID_TBLEFT, _("Prev char"), tool1, _("Go to prev char"), wxITEM_NORMAL);
277 tb->AddTool(ID_TBRIGHT, _("Next char"), tool2, _("Go to next char"), wxITEM_NORMAL);
278 tb->AddTool(ID_TBCHARWIN, _("Char Wnd"), tool3, _("Toggle char window"), wxITEM_CHECK);
282 // Create a menu bar for the frame
283 menuBar = new wxMenuBar;
284 wxMenu * menu1 = new wxMenu;
285 menu1->Append(IDM_NEW, _("&New\tCtrl+N"), _("Create a new font."));
286 menu1->Append(IDM_OPEN, _("&Open...\tCtrl+O"), _("Opens an existing font."));
287 menu1->Append(IDM_SAVE, _("&Save\tCtrl+S"), _("Save the current font."));
288 menu1->Append(IDM_SAVEAS, _("Save &As..."), _("Save the current font under a different name."));
289 menu1->AppendSeparator();
290 menu1->Append(IDM_EXIT, _("E&xit\tAlt+X"), _("Quits the TTEdit program."));
291 menuBar->Append(menu1, _("&File"));
292 wxMenu * menu2 = new wxMenu;
293 menu2->Append(IDM_HELPTOPICS, _("&Help Topics"), _("Displays the Help contents and index."));
294 menu2->AppendSeparator();
295 menu2->Append(IDM_ABOUT, _("&About TTEdit"), _("Displays information about TTEdit."));
296 menuBar->Append(menu2, _("&Help"));
299 // Create child subwindows
300 mainWindow = new TTEditWindow(this);
302 Centre(wxBOTH); // Centre frame on the screen
303 Show(true); // Show the frame
306 TTEditFrame::~TTEditFrame()
310 void TTEditFrame::OnOpen(wxCommandEvent &e)
312 wxFileDialog fd(this, _("Choose a font to load"), _(""), _(""), _("TTF files (*.ttf)|*.ttf|All files (*.*)|*.*"), wxOPEN);
314 if (fd.ShowModal() != wxID_OK)
317 // Hmm. The font object is causing a massive crash... (gdb says it's in "Load")
318 if (app.font.Load((char *)fd.GetPath().c_str()) != true)
320 wxMessageDialog dlg(NULL, _("Load font failed!"), _("Houston, we have a problem..."), wxOK | wxICON_ERROR);
324 //Huzzah! It works! Now just need scaling, scrolling, etc...
325 // pts = app.font.GetGlyphPoints(45);
328 void TTEditFrame::OnAbout(wxCommandEvent &e)
330 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);
334 void TTEditFrame::OnExit(wxCommandEvent &e)
336 app.toolPalette->Destroy();
340 void TTEditFrame::OnCharWindow(wxCommandEvent &e)
342 app.charWin->Show(e.IsChecked() ? true : false);
348 void TTEditFrame::OnCloseWindow(wxCloseEvent &e)
350 app.toolPalette->Destroy();