From 5d7a5bf3a74a2778eb22ee73891db51cf7471d36 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 23 Mar 2015 20:49:04 +0300 Subject: [PATCH] Pack everything into `namespace SolveSpace`. This is required to avoid name conflicts with the Cocoa libraries on OS X. I renamed the `class SolveSpace` to `class SolveSpaceUI`, because that's what it does, and because otherwise the namespace would have to be called something else than `namespace SolveSpace`. --- src/clipboard.cpp | 6 +-- src/dsc.h | 2 - src/export.cpp | 16 +++---- src/file.cpp | 20 ++++----- src/generate.cpp | 30 ++++++------- src/glhelper.cpp | 3 ++ src/graphicswin.cpp | 22 +++++----- src/gtk/gtkmain.cpp | 90 +++++++++++++++++---------------------- src/lib.cpp | 8 ++-- src/solvespace.cpp | 54 ++++++++++++------------ src/solvespace.h | 13 +++++- src/srf/ratpoly.cpp | 4 +- src/undoredo.cpp | 16 +++---- src/unix/unixutil.cpp | 4 ++ src/util.cpp | 30 ++++++------- src/win32/w32main.cpp | 98 ++++++++++++++++++++++--------------------- src/win32/w32util.cpp | 3 +- 17 files changed, 212 insertions(+), 207 deletions(-) diff --git a/src/clipboard.cpp b/src/clipboard.cpp index 549d4a7e..ccbdef6d 100644 --- a/src/clipboard.cpp +++ b/src/clipboard.cpp @@ -6,12 +6,12 @@ //----------------------------------------------------------------------------- #include "solvespace.h" -void SolveSpace::Clipboard::Clear(void) { +void SolveSpaceUI::Clipboard::Clear(void) { c.Clear(); r.Clear(); } -hEntity SolveSpace::Clipboard::NewEntityFor(hEntity he) { +hEntity SolveSpaceUI::Clipboard::NewEntityFor(hEntity he) { ClipboardRequest *cr; for(cr = r.First(); cr; cr = r.NextAfter(cr)) { if(cr->oldEnt.v == he.v) { @@ -26,7 +26,7 @@ hEntity SolveSpace::Clipboard::NewEntityFor(hEntity he) { return Entity::NO_ENTITY; } -bool SolveSpace::Clipboard::ContainsEntity(hEntity he) { +bool SolveSpaceUI::Clipboard::ContainsEntity(hEntity he) { hEntity hen = NewEntityFor(he); if(hen.v) { return true; diff --git a/src/dsc.h b/src/dsc.h index 167191c8..278fc337 100644 --- a/src/dsc.h +++ b/src/dsc.h @@ -7,8 +7,6 @@ #ifndef __DSC_H #define __DSC_H -#include - #include "solvespace.h" class Vector; diff --git a/src/export.cpp b/src/export.cpp index 74a9b5b9..ea658d98 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -9,7 +9,7 @@ #include "solvespace.h" #include -void SolveSpace::ExportSectionTo(const char *filename) { +void SolveSpaceUI::ExportSectionTo(const char *filename) { Vector gn = (SS.GW.projRight).Cross(SS.GW.projUp); gn = gn.WithMagnitude(1); @@ -109,7 +109,7 @@ void SolveSpace::ExportSectionTo(const char *filename) { bl.Clear(); } -void SolveSpace::ExportViewOrWireframeTo(const char *filename, bool wireframe) { +void SolveSpaceUI::ExportViewOrWireframeTo(const char *filename, bool wireframe) { int i; SEdgeList edges; ZERO(&edges); @@ -194,7 +194,7 @@ void SolveSpace::ExportViewOrWireframeTo(const char *filename, bool wireframe) { beziers.Clear(); } -void SolveSpace::ExportWireframeCurves(SEdgeList *sel, SBezierList *sbl, +void SolveSpaceUI::ExportWireframeCurves(SEdgeList *sel, SBezierList *sbl, VectorFileWriter *out) { SBezierLoopSetSet sblss; @@ -217,7 +217,7 @@ void SolveSpace::ExportWireframeCurves(SEdgeList *sel, SBezierList *sbl, sblss.Clear(); } -void SolveSpace::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *sm, +void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *sm, Vector u, Vector v, Vector n, Vector origin, double cameraTan, VectorFileWriter *out) @@ -573,7 +573,7 @@ void VectorFileWriter::BezierAsNonrationalCubic(SBezier *sb, int depth) { //----------------------------------------------------------------------------- // Export a triangle mesh, in the requested format. //----------------------------------------------------------------------------- -void SolveSpace::ExportMeshTo(const char *filename) { +void SolveSpaceUI::ExportMeshTo(const char *filename) { SMesh *m = &(SK.GetGroup(SS.GW.activeGroup)->displayMesh); if(m->IsEmpty()) { Error("Active group mesh is empty; nothing to export."); @@ -602,7 +602,7 @@ void SolveSpace::ExportMeshTo(const char *filename) { // Export the mesh as an STL file; it should always be vertex-to-vertex and // not self-intersecting, so not much to do. //----------------------------------------------------------------------------- -void SolveSpace::ExportMeshAsStlTo(FILE *f, SMesh *sm) { +void SolveSpaceUI::ExportMeshAsStlTo(FILE *f, SMesh *sm) { char str[80]; memset(str, 0, sizeof(str)); strcpy(str, "STL exported mesh"); @@ -638,7 +638,7 @@ void SolveSpace::ExportMeshAsStlTo(FILE *f, SMesh *sm) { // Export the mesh as Wavefront OBJ format. This requires us to reduce all the // identical vertices to the same identifier, so do that first. //----------------------------------------------------------------------------- -void SolveSpace::ExportMeshAsObjTo(FILE *f, SMesh *sm) { +void SolveSpaceUI::ExportMeshAsObjTo(FILE *f, SMesh *sm) { SPointList spl; ZERO(&spl); STriangle *tr; @@ -673,7 +673,7 @@ void SolveSpace::ExportMeshAsObjTo(FILE *f, SMesh *sm) { // Export a view of the model as an image; we just take a screenshot, by // rendering the view in the usual way and then copying the pixels. //----------------------------------------------------------------------------- -void SolveSpace::ExportAsPngTo(const char *filename) { +void SolveSpaceUI::ExportAsPngTo(const char *filename) { int w = (int)SS.GW.width, h = (int)SS.GW.height; // No guarantee that the back buffer contains anything valid right now, // so repaint the scene. And hide the toolbar too. diff --git a/src/file.cpp b/src/file.cpp index e58f86e9..f5a9f5f9 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -16,7 +16,7 @@ static int StrStartsWith(const char *str, const char *start) { // sketch. This does not leave the program in an acceptable state (with the // references created, and so on), so anyone calling this must fix that later. //----------------------------------------------------------------------------- -void SolveSpace::ClearExisting(void) { +void SolveSpaceUI::ClearExisting(void) { UndoClearStack(&redo); UndoClearStack(&undo); @@ -34,7 +34,7 @@ void SolveSpace::ClearExisting(void) { SK.param.Clear(); } -hGroup SolveSpace::CreateDefaultDrawingGroup(void) { +hGroup SolveSpaceUI::CreateDefaultDrawingGroup(void) { Group g; ZERO(&g); @@ -51,7 +51,7 @@ hGroup SolveSpace::CreateDefaultDrawingGroup(void) { return g.h; } -void SolveSpace::NewFile(void) { +void SolveSpaceUI::NewFile(void) { ClearExisting(); // Our initial group, that contains the references. @@ -83,7 +83,7 @@ void SolveSpace::NewFile(void) { CreateDefaultDrawingGroup(); } -const SolveSpace::SaveTable SolveSpace::SAVED[] = { +const SolveSpaceUI::SaveTable SolveSpaceUI::SAVED[] = { { 'g', "Group.h.v", 'x', &(SS.sv.g.h.v) }, { 'g', "Group.type", 'd', &(SS.sv.g.type) }, { 'g', "Group.order", 'd', &(SS.sv.g.order) }, @@ -212,7 +212,7 @@ union SAVEDptr { uint32_t x; }; -void SolveSpace::SaveUsingTable(int type) { +void SolveSpaceUI::SaveUsingTable(int type) { int i; for(i = 0; SAVED[i].type != 0; i++) { if(SAVED[i].type != type) continue; @@ -253,7 +253,7 @@ void SolveSpace::SaveUsingTable(int type) { } } -bool SolveSpace::SaveToFile(const char *filename) { +bool SolveSpaceUI::SaveToFile(const char *filename) { // Make sure all the entities are regenerated up to date, since they // will be exported. We reload the imported files because that rewrites // the impFileRel for our possibly-new filename. @@ -369,7 +369,7 @@ bool SolveSpace::SaveToFile(const char *filename) { return true; } -void SolveSpace::LoadUsingTable(char *key, char *val) { +void SolveSpaceUI::LoadUsingTable(char *key, char *val) { int i; for(i = 0; SAVED[i].type != 0; i++) { if(strcmp(SAVED[i].desc, key)==0) { @@ -423,7 +423,7 @@ void SolveSpace::LoadUsingTable(char *key, char *val) { } } -bool SolveSpace::LoadFromFile(const char *filename) { +bool SolveSpaceUI::LoadFromFile(const char *filename) { allConsistent = false; fileLoadError = false; @@ -506,7 +506,7 @@ bool SolveSpace::LoadFromFile(const char *filename) { return true; } -bool SolveSpace::LoadEntitiesFromFile(const char *file, EntityList *le, +bool SolveSpaceUI::LoadEntitiesFromFile(const char *file, EntityList *le, SMesh *m, SShell *sh) { SSurface srf; @@ -648,7 +648,7 @@ bool SolveSpace::LoadEntitiesFromFile(const char *file, EntityList *le, return true; } -void SolveSpace::ReloadAllImported(void) { +void SolveSpaceUI::ReloadAllImported(void) { allConsistent = false; int i; diff --git a/src/generate.cpp b/src/generate.cpp index 37bb3b5a..b7b04c5c 100644 --- a/src/generate.cpp +++ b/src/generate.cpp @@ -8,12 +8,12 @@ //----------------------------------------------------------------------------- #include "solvespace.h" -void SolveSpace::MarkGroupDirtyByEntity(hEntity he) { +void SolveSpaceUI::MarkGroupDirtyByEntity(hEntity he) { Entity *e = SK.GetEntity(he); MarkGroupDirty(e->group); } -void SolveSpace::MarkGroupDirty(hGroup hg) { +void SolveSpaceUI::MarkGroupDirty(hGroup hg) { int i; bool go = false; for(i = 0; i < SK.group.n; i++) { @@ -28,7 +28,7 @@ void SolveSpace::MarkGroupDirty(hGroup hg) { unsaved = true; } -bool SolveSpace::PruneOrphans(void) { +bool SolveSpaceUI::PruneOrphans(void) { int i; for(i = 0; i < SK.request.n; i++) { Request *r = &(SK.request.elem[i]); @@ -52,7 +52,7 @@ bool SolveSpace::PruneOrphans(void) { return false; } -bool SolveSpace::GroupsInOrder(hGroup before, hGroup after) { +bool SolveSpaceUI::GroupsInOrder(hGroup before, hGroup after) { if(before.v == 0) return true; if(after.v == 0) return true; @@ -68,18 +68,18 @@ bool SolveSpace::GroupsInOrder(hGroup before, hGroup after) { return true; } -bool SolveSpace::GroupExists(hGroup hg) { +bool SolveSpaceUI::GroupExists(hGroup hg) { // A nonexistent group is not acceptable return SK.group.FindByIdNoOops(hg) ? true : false; } -bool SolveSpace::EntityExists(hEntity he) { +bool SolveSpaceUI::EntityExists(hEntity he) { // A nonexstient entity is acceptable, though, usually just means it // doesn't apply. if(he.v == Entity::NO_ENTITY.v) return true; return SK.entity.FindByIdNoOops(he) ? true : false; } -bool SolveSpace::PruneGroups(hGroup hg) { +bool SolveSpaceUI::PruneGroups(hGroup hg) { Group *g = SK.GetGroup(hg); if(GroupsInOrder(g->opA, hg) && EntityExists(g->predef.origin) && @@ -93,7 +93,7 @@ bool SolveSpace::PruneGroups(hGroup hg) { return true; } -bool SolveSpace::PruneRequests(hGroup hg) { +bool SolveSpaceUI::PruneRequests(hGroup hg) { int i; for(i = 0; i < SK.entity.n; i++) { Entity *e = &(SK.entity.elem[i]); @@ -110,7 +110,7 @@ bool SolveSpace::PruneRequests(hGroup hg) { return false; } -bool SolveSpace::PruneConstraints(hGroup hg) { +bool SolveSpaceUI::PruneConstraints(hGroup hg) { int i; for(i = 0; i < SK.constraint.n; i++) { Constraint *c = &(SK.constraint.elem[i]); @@ -141,7 +141,7 @@ bool SolveSpace::PruneConstraints(hGroup hg) { return false; } -void SolveSpace::GenerateAll(void) { +void SolveSpaceUI::GenerateAll(void) { int i; int firstDirty = INT_MAX, lastVisible = 0; // Start from the first dirty group, and solve until the active group, @@ -165,7 +165,7 @@ void SolveSpace::GenerateAll(void) { } } -void SolveSpace::GenerateAll(int first, int last, bool andFindFree) { +void SolveSpaceUI::GenerateAll(int first, int last, bool andFindFree) { int i, j; // Remove any requests or constraints that refer to a nonexistent @@ -351,7 +351,7 @@ pruned: GenerateAll(first, last); } -void SolveSpace::ForceReferences(void) { +void SolveSpaceUI::ForceReferences(void) { // Force the values of the parameters that define the three reference // coordinate systems. static const struct { @@ -381,7 +381,7 @@ void SolveSpace::ForceReferences(void) { } } -void SolveSpace::MarkDraggedParams(void) { +void SolveSpaceUI::MarkDraggedParams(void) { sys.dragged.Clear(); for(int i = -1; i < SS.GW.pending.points.n; i++) { @@ -440,7 +440,7 @@ void SolveSpace::MarkDraggedParams(void) { } } -void SolveSpace::SolveGroup(hGroup hg, bool andFindFree) { +void SolveSpaceUI::SolveGroup(hGroup hg, bool andFindFree) { int i; // Clear out the system to be solved. sys.entity.Clear(); @@ -476,7 +476,7 @@ void SolveSpace::SolveGroup(hGroup hg, bool andFindFree) { FreeAllTemporary(); } -bool SolveSpace::AllGroupsOkay(void) { +bool SolveSpaceUI::AllGroupsOkay(void) { int i; bool allOk = true; for(i = 0; i < SK.group.n; i++) { diff --git a/src/glhelper.cpp b/src/glhelper.cpp index 18ed3b00..adf6e487 100644 --- a/src/glhelper.cpp +++ b/src/glhelper.cpp @@ -5,6 +5,8 @@ //----------------------------------------------------------------------------- #include "solvespace.h" +namespace SolveSpace { + // A public-domain Hershey vector font ("Simplex"). #include "font.table.h" @@ -623,3 +625,4 @@ void ssglDrawPixelsWithTexture(uint8_t *data, int w, int h) glDisable(GL_TEXTURE_2D); } +}; diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index 113f5c5c..2b9f065f 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -11,10 +11,10 @@ #define mClip (&GraphicsWindow::MenuClipboard) #define mReq (&GraphicsWindow::MenuRequest) #define mCon (&Constraint::MenuConstrain) -#define mFile (&SolveSpace::MenuFile) +#define mFile (&SolveSpaceUI::MenuFile) #define mGrp (&Group::MenuGroup) -#define mAna (&SolveSpace::MenuAnalyze) -#define mHelp (&SolveSpace::MenuHelp) +#define mAna (&SolveSpaceUI::MenuAnalyze) +#define mHelp (&SolveSpaceUI::MenuHelp) #define DEL DELETE_KEY #define ESC ESCAPE_KEY #define S SHIFT_MASK @@ -171,7 +171,7 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = { #undef IC #undef IR -bool MakeAcceleratorLabel(int accel, char *out) { +bool SolveSpace::MakeAcceleratorLabel(int accel, char *out) { if(!accel) { out[0] = '\0'; return false; @@ -539,13 +539,13 @@ void GraphicsWindow::MenuView(int id) { break; case MNU_UNITS_INCHES: - SS.viewUnits = SolveSpace::UNIT_INCHES; + SS.viewUnits = SolveSpaceUI::UNIT_INCHES; SS.ScheduleShowTW(); SS.GW.EnsureValidActives(); break; case MNU_UNITS_MM: - SS.viewUnits = SolveSpace::UNIT_MM; + SS.viewUnits = SolveSpaceUI::UNIT_MM; SS.ScheduleShowTW(); SS.GW.EnsureValidActives(); break; @@ -611,15 +611,15 @@ void GraphicsWindow::EnsureValidActives(void) { SS.UndoEnableMenus(); switch(SS.viewUnits) { - case SolveSpace::UNIT_MM: - case SolveSpace::UNIT_INCHES: + case SolveSpaceUI::UNIT_MM: + case SolveSpaceUI::UNIT_INCHES: break; default: - SS.viewUnits = SolveSpace::UNIT_MM; + SS.viewUnits = SolveSpaceUI::UNIT_MM; break; } - RadioMenuById(MNU_UNITS_MM, SS.viewUnits == SolveSpace::UNIT_MM); - RadioMenuById(MNU_UNITS_INCHES, SS.viewUnits == SolveSpace::UNIT_INCHES); + RadioMenuById(MNU_UNITS_MM, SS.viewUnits == SolveSpaceUI::UNIT_MM); + RadioMenuById(MNU_UNITS_INCHES, SS.viewUnits == SolveSpaceUI::UNIT_INCHES); ShowTextWindow(SS.GW.showTextWindow); CheckMenuById(MNU_SHOW_TEXT_WND, SS.GW.showTextWindow); diff --git a/src/gtk/gtkmain.cpp b/src/gtk/gtkmain.cpp index 5681430d..5f546ba6 100644 --- a/src/gtk/gtkmain.cpp +++ b/src/gtk/gtkmain.cpp @@ -62,6 +62,7 @@ # endif #endif +namespace SolveSpace { char RecentFile[MAX_RECENT][MAX_PATH]; #define GL_CHECK() \ @@ -252,7 +253,6 @@ void ScheduleLater() { /* GL wrapper */ -namespace SolveSpacePlatf { class GlWidget : public Gtk::DrawingArea { public: GlWidget() : _offscreen(NULL) { @@ -378,11 +378,9 @@ private: GLOffscreen *_offscreen; ::Window _xwindow; }; -}; /* Editor overlay */ -namespace SolveSpacePlatf { class EditorOverlay : public Gtk::Fixed { public: EditorOverlay(Gtk::Widget &underlay) : _underlay(underlay) { @@ -457,11 +455,9 @@ private: Gtk::Entry _entry; sigc::signal _signal_editing_done; }; -}; /* Graphics window */ -namespace SolveSpacePlatf { int DeltaYOfScrollEvent(GdkEventScroll *event) { #ifdef HAVE_GTK3 int delta_y = event->delta_y; @@ -629,9 +625,9 @@ private: } }; -class GraphicsWindow : public Gtk::Window { +class GraphicsWindowGtk : public Gtk::Window { public: - GraphicsWindow() : _overlay(_widget) { + GraphicsWindowGtk() : _overlay(_widget) { set_default_size(900, 600); _box.pack_start(_menubar, false, true); @@ -640,7 +636,7 @@ public: add(_box); _overlay.signal_editing_done(). - connect(sigc::mem_fun(this, &GraphicsWindow::on_editing_done)); + connect(sigc::mem_fun(this, &GraphicsWindowGtk::on_editing_done)); } GraphicsWidget &get_widget() { @@ -701,9 +697,8 @@ private: bool _is_fullscreen; }; -}; -SolveSpacePlatf::GraphicsWindow *GW = NULL; +GraphicsWindowGtk *GW = NULL; void GetGraphicsWindowSize(int *w, int *h) { Gdk::Rectangle allocation = GW->get_widget().get_allocation(); @@ -767,7 +762,6 @@ bool MenuBarIsVisible(void) { /* Context menus */ -namespace SolveSpacePlatf { class ContextMenuItem : public Gtk::MenuItem { public: static int choice; @@ -806,14 +800,13 @@ private: }; int ContextMenuItem::choice = 0; -}; static Gtk::Menu *context_menu = NULL, *context_submenu = NULL; void AddContextMenuItem(const char *label, int id) { Gtk::MenuItem *menu_item; if(label) - menu_item = new SolveSpacePlatf::ContextMenuItem(label, id); + menu_item = new ContextMenuItem(label, id); else menu_item = new Gtk::SeparatorMenuItem(); @@ -846,7 +839,7 @@ int ShowContextMenu(void) { context_menu->signal_deactivate(). connect(sigc::mem_fun(loop.operator->(), &Glib::MainLoop::quit)); - SolveSpacePlatf::ContextMenuItem::choice = -1; + ContextMenuItem::choice = -1; context_menu->show_all(); context_menu->popup(3, GDK_CURRENT_TIME); @@ -856,15 +849,14 @@ int ShowContextMenu(void) { delete context_menu; context_menu = NULL; - return SolveSpacePlatf::ContextMenuItem::choice; + return ContextMenuItem::choice; } /* Main menu */ -namespace SolveSpacePlatf { template class MainMenuItem : public MenuItem { public: - MainMenuItem(const ::GraphicsWindow::MenuEntry &entry) : + MainMenuItem(const GraphicsWindow::MenuEntry &entry) : MenuItem(), _entry(entry), _synthetic(false) { Glib::ustring label(_entry.label); for(int i = 0; i < label.length(); i++) { @@ -875,25 +867,25 @@ public: guint accel_key = 0; Gdk::ModifierType accel_mods = Gdk::ModifierType(); switch(_entry.accel) { - case ::GraphicsWindow::DELETE_KEY: + case GraphicsWindow::DELETE_KEY: accel_key = GDK_KEY_Delete; break; - case ::GraphicsWindow::ESCAPE_KEY: + case GraphicsWindow::ESCAPE_KEY: accel_key = GDK_KEY_Escape; break; default: - accel_key = _entry.accel & ~(::GraphicsWindow::SHIFT_MASK | ::GraphicsWindow::CTRL_MASK); - if(accel_key > ::GraphicsWindow::FUNCTION_KEY_BASE && - accel_key <= ::GraphicsWindow::FUNCTION_KEY_BASE + 12) - accel_key = GDK_KEY_F1 + (accel_key - ::GraphicsWindow::FUNCTION_KEY_BASE - 1); + accel_key = _entry.accel & ~(GraphicsWindow::SHIFT_MASK | GraphicsWindow::CTRL_MASK); + if(accel_key > GraphicsWindow::FUNCTION_KEY_BASE && + accel_key <= GraphicsWindow::FUNCTION_KEY_BASE + 12) + accel_key = GDK_KEY_F1 + (accel_key - GraphicsWindow::FUNCTION_KEY_BASE - 1); else accel_key = gdk_unicode_to_keyval(accel_key); - if(_entry.accel & ::GraphicsWindow::SHIFT_MASK) + if(_entry.accel & GraphicsWindow::SHIFT_MASK) accel_mods |= Gdk::SHIFT_MASK; - if(_entry.accel & ::GraphicsWindow::CTRL_MASK) + if(_entry.accel & GraphicsWindow::CTRL_MASK) accel_mods |= Gdk::CONTROL_MASK; } @@ -922,10 +914,9 @@ protected: } private: - const ::GraphicsWindow::MenuEntry &_entry; + const GraphicsWindow::MenuEntry &_entry; bool _synthetic; }; -}; static std::map main_menu_items; @@ -951,16 +942,16 @@ static void InitMainMenu(Gtk::MenuShell *menu_shell) { if(entry->label) { switch(entry->kind) { case GraphicsWindow::MENU_ITEM_NORMAL: - menu_item = new SolveSpacePlatf::MainMenuItem(*entry); + menu_item = new MainMenuItem(*entry); break; case GraphicsWindow::MENU_ITEM_CHECK: - menu_item = new SolveSpacePlatf::MainMenuItem(*entry); + menu_item = new MainMenuItem(*entry); break; case GraphicsWindow::MENU_ITEM_RADIO: - SolveSpacePlatf::MainMenuItem *radio_item = - new SolveSpacePlatf::MainMenuItem(*entry); + MainMenuItem *radio_item = + new MainMenuItem(*entry); radio_item->set_draw_as_radio(true); menu_item = radio_item; break; @@ -986,15 +977,13 @@ static void ActivateMenuById(int id) { } void CheckMenuById(int id, bool checked) { - ((SolveSpacePlatf::MainMenuItem*)main_menu_items[id])-> - set_active(checked); + ((MainMenuItem*)main_menu_items[id])->set_active(checked); } void RadioMenuById(int id, bool selected) { - CheckMenuById(id, selected); + SolveSpace::CheckMenuById(id, selected); } -namespace SolveSpacePlatf { class RecentMenuItem : public Gtk::MenuItem { public: RecentMenuItem(const Glib::ustring& label, int id) : @@ -1004,7 +993,7 @@ public: protected: virtual void on_activate() { if(_id >= RECENT_OPEN && _id < (RECENT_OPEN + MAX_RECENT)) - SolveSpace::MenuFile(_id); + SolveSpaceUI::MenuFile(_id); else if(_id >= RECENT_IMPORT && _id < (RECENT_IMPORT + MAX_RECENT)) Group::MenuGroup(_id); } @@ -1012,7 +1001,6 @@ protected: private: int _id; }; -}; static void RefreshRecentMenu(int id, int base) { Gtk::MenuItem *recent = static_cast(main_menu_items[id]); @@ -1030,8 +1018,7 @@ static void RefreshRecentMenu(int id, int base) { if(std::string(RecentFile[i]).empty()) break; - SolveSpacePlatf::RecentMenuItem *item = - new SolveSpacePlatf::RecentMenuItem(RecentFile[i], base + i); + RecentMenuItem *item = new RecentMenuItem(RecentFile[i], base + i); menu->append(*item); } } @@ -1213,7 +1200,6 @@ int SaveFileYesNoCancel(void) { /* Text window */ -namespace SolveSpacePlatf { class TextWidget : public GlWidget { public: #ifdef HAVE_GTK3 @@ -1279,10 +1265,10 @@ private: #endif }; -class TextWindow : public Gtk::Window { +class TextWindowGtk : public Gtk::Window { public: - TextWindow() : _scrollbar(), _widget(_scrollbar.get_adjustment()), - _box(), _overlay(_widget) { + TextWindowGtk() : _scrollbar(), _widget(_scrollbar.get_adjustment()), + _box(), _overlay(_widget) { set_keep_above(true); set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY); set_skip_taskbar_hint(true); @@ -1295,15 +1281,15 @@ public: add(_box); _scrollbar.get_adjustment()->signal_value_changed(). - connect(sigc::mem_fun(this, &TextWindow::on_scrollbar_value_changed)); + connect(sigc::mem_fun(this, &TextWindowGtk::on_scrollbar_value_changed)); _overlay.signal_editing_done(). - connect(sigc::mem_fun(this, &TextWindow::on_editing_done)); + connect(sigc::mem_fun(this, &TextWindowGtk::on_editing_done)); _overlay.get_entry().signal_motion_notify_event(). - connect(sigc::mem_fun(this, &TextWindow::on_editor_motion_notify_event)); + connect(sigc::mem_fun(this, &TextWindowGtk::on_editor_motion_notify_event)); _overlay.get_entry().signal_button_press_event(). - connect(sigc::mem_fun(this, &TextWindow::on_editor_button_press_event)); + connect(sigc::mem_fun(this, &TextWindowGtk::on_editor_button_press_event)); } Gtk::VScrollbar &get_scrollbar() { @@ -1333,7 +1319,7 @@ protected: virtual bool on_delete_event(GdkEventAny *event) { /* trigger the action and ignore the request */ - ::GraphicsWindow::MenuView(::GraphicsWindow::MNU_SHOW_TEXT_WND); + GraphicsWindow::MenuView(GraphicsWindow::MNU_SHOW_TEXT_WND); return false; } @@ -1360,9 +1346,8 @@ private: EditorOverlay _overlay; Gtk::HBox _box; }; -}; -SolveSpacePlatf::TextWindow *TW = NULL; +TextWindowGtk *TW = NULL; void ShowTextWindow(bool visible) { if(visible) @@ -1480,6 +1465,7 @@ void ExitNow(void) { GW->hide(); TW->hide(); } +}; int main(int argc, char** argv) { /* If we don't call this, gtk_init will set the C standard library @@ -1496,8 +1482,8 @@ int main(int argc, char** argv) { CnfLoad(); - TW = new SolveSpacePlatf::TextWindow; - GW = new SolveSpacePlatf::GraphicsWindow; + TW = new TextWindowGtk; + GW = new GraphicsWindowGtk; InitMainMenu(&GW->get_menubar()); GW->get_menubar().accelerate(*TW); diff --git a/src/lib.cpp b/src/lib.cpp index a7468394..67fcb09c 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -8,7 +8,7 @@ #define EXPORT_DLL #include -Sketch SK; +Sketch SolveSpace::SK; static System SYS; static int IsInit = 0; @@ -17,18 +17,18 @@ void Group::GenerateEquations(IdList *l) { // Nothing to do for now. } -void CnfFreezeInt(uint32_t v, const char *name) +void SolveSpace::CnfFreezeInt(uint32_t v, const char *name) { abort(); } -uint32_t CnfThawInt(uint32_t v, const char *name) +uint32_t SolveSpace::CnfThawInt(uint32_t v, const char *name) { abort(); return 0; } -void DoMessageBox(const char *str, int rows, int cols, bool error) +void SolveSpace::DoMessageBox(const char *str, int rows, int cols, bool error) { abort(); } diff --git a/src/solvespace.cpp b/src/solvespace.cpp index ad24c565..7059b724 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -6,10 +6,10 @@ //----------------------------------------------------------------------------- #include "solvespace.h" -SolveSpace SS; -Sketch SK; +SolveSpaceUI SolveSpace::SS; +Sketch SolveSpace::SK; -void SolveSpace::Init(const char *cmdLine) { +void SolveSpaceUI::Init(const char *cmdLine) { SS.tangentArcRadius = 10.0; // Then, load the registry settings. @@ -109,7 +109,7 @@ void SolveSpace::Init(const char *cmdLine) { AfterNewFile(); } -void SolveSpace::Exit(void) { +void SolveSpaceUI::Exit(void) { int i; char name[100]; // Recent files @@ -187,39 +187,39 @@ void SolveSpace::Exit(void) { ExitNow(); } -void SolveSpace::ScheduleGenerateAll() { +void SolveSpaceUI::ScheduleGenerateAll() { if(!later.scheduled) ScheduleLater(); later.scheduled = true; later.generateAll = true; } -void SolveSpace::ScheduleShowTW() { +void SolveSpaceUI::ScheduleShowTW() { if(!later.scheduled) ScheduleLater(); later.scheduled = true; later.showTW = true; } -void SolveSpace::DoLater(void) { +void SolveSpaceUI::DoLater(void) { if(later.generateAll) GenerateAll(); if(later.showTW) TW.Show(); ZERO(&later); } -double SolveSpace::MmPerUnit(void) { +double SolveSpaceUI::MmPerUnit(void) { if(viewUnits == UNIT_INCHES) { return 25.4; } else { return 1.0; } } -const char *SolveSpace::UnitName(void) { +const char *SolveSpaceUI::UnitName(void) { if(viewUnits == UNIT_INCHES) { return "inch"; } else { return "mm"; } } -char *SolveSpace::MmToString(double v) { +char *SolveSpaceUI::MmToString(double v) { static int WhichBuf; static char Bufs[8][128]; @@ -234,19 +234,19 @@ char *SolveSpace::MmToString(double v) { } return s; } -double SolveSpace::ExprToMm(Expr *e) { +double SolveSpaceUI::ExprToMm(Expr *e) { return (e->Eval()) * MmPerUnit(); } -double SolveSpace::StringToMm(const char *str) { +double SolveSpaceUI::StringToMm(const char *str) { return atof(str) * MmPerUnit(); } -double SolveSpace::ChordTolMm(void) { +double SolveSpaceUI::ChordTolMm(void) { return SS.chordTol / SS.GW.scale; } -int SolveSpace::UnitDigitsAfterDecimal(void) { +int SolveSpaceUI::UnitDigitsAfterDecimal(void) { return (viewUnits == UNIT_INCHES) ? afterDecimalInch : afterDecimalMm; } -void SolveSpace::SetUnitDigitsAfterDecimal(int v) { +void SolveSpaceUI::SetUnitDigitsAfterDecimal(int v) { if(viewUnits == UNIT_INCHES) { afterDecimalInch = v; } else { @@ -254,7 +254,7 @@ void SolveSpace::SetUnitDigitsAfterDecimal(int v) { } } -double SolveSpace::CameraTangent(void) { +double SolveSpaceUI::CameraTangent(void) { if(!usePerspectiveProj) { return 0; } else { @@ -262,7 +262,7 @@ double SolveSpace::CameraTangent(void) { } } -void SolveSpace::AfterNewFile(void) { +void SolveSpaceUI::AfterNewFile(void) { // Clear out the traced point, which is no longer valid traced.point = Entity::NO_ENTITY; traced.path.l.Clear(); @@ -307,7 +307,7 @@ void SolveSpace::AfterNewFile(void) { UpdateWindowTitle(); } -void SolveSpace::RemoveFromRecentList(const char *file) { +void SolveSpaceUI::RemoveFromRecentList(const char *file) { int src, dest; dest = 0; for(src = 0; src < MAX_RECENT; src++) { @@ -319,7 +319,7 @@ void SolveSpace::RemoveFromRecentList(const char *file) { while(dest < MAX_RECENT) strcpy(RecentFile[dest++], ""); RefreshRecentMenus(); } -void SolveSpace::AddToRecentList(const char *file) { +void SolveSpaceUI::AddToRecentList(const char *file) { RemoveFromRecentList(file); int src; @@ -330,7 +330,7 @@ void SolveSpace::AddToRecentList(const char *file) { RefreshRecentMenus(); } -bool SolveSpace::GetFilenameAndSave(bool saveAs) { +bool SolveSpaceUI::GetFilenameAndSave(bool saveAs) { char prevSaveFile[MAX_PATH]; strcpy(prevSaveFile, saveFile); @@ -351,7 +351,7 @@ bool SolveSpace::GetFilenameAndSave(bool saveAs) { } } -bool SolveSpace::OkayToStartNewFile(void) { +bool SolveSpaceUI::OkayToStartNewFile(void) { if(!unsaved) return true; switch(SaveFileYesNoCancel()) { @@ -368,7 +368,7 @@ bool SolveSpace::OkayToStartNewFile(void) { } } -void SolveSpace::UpdateWindowTitle(void) { +void SolveSpaceUI::UpdateWindowTitle(void) { if(strlen(saveFile) == 0) { SetWindowTitle("SolveSpace - (not yet saved)"); } else { @@ -378,7 +378,7 @@ void SolveSpace::UpdateWindowTitle(void) { } } -void SolveSpace::MenuFile(int id) { +void SolveSpaceUI::MenuFile(int id) { if(id >= RECENT_OPEN && id < (RECENT_OPEN+MAX_RECENT)) { if(!SS.OkayToStartNewFile()) return; @@ -498,7 +498,7 @@ void SolveSpace::MenuFile(int id) { SS.UpdateWindowTitle(); } -void SolveSpace::MenuAnalyze(int id) { +void SolveSpaceUI::MenuAnalyze(int id) { SS.GW.GroupSelection(); #define gs (SS.GW.gs) @@ -646,7 +646,7 @@ void SolveSpace::MenuAnalyze(int id) { vol / pow(SS.MmPerUnit(), 3), SS.UnitName()); - if(SS.viewUnits == SolveSpace::UNIT_MM) { + if(SS.viewUnits == SolveSpaceUI::UNIT_MM) { sprintf(msg+strlen(msg), "\n %.2f mL", vol/(10*10*10)); } strcpy(msg+strlen(msg), @@ -729,7 +729,7 @@ void SolveSpace::MenuAnalyze(int id) { } } -void SolveSpace::MenuHelp(int id) { +void SolveSpaceUI::MenuHelp(int id) { switch(id) { case GraphicsWindow::MNU_WEBSITE: OpenWebsite("http://solvespace.com/helpmenu"); @@ -763,7 +763,7 @@ void SolveSpace::MenuHelp(int id) { } } -void SolveSpace::Clear(void) { +void SolveSpaceUI::Clear(void) { sys.Clear(); for(int i = 0; i < MAX_UNDO; i++) { if(i < undo.cnt) undo.d[i].Clear(); diff --git a/src/solvespace.h b/src/solvespace.h index bf452271..8c11552d 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,8 @@ # define isnan(x) (((x) != (x)) || (x > 1e11) || (x < -1e11)) #endif +namespace SolveSpace { + inline int WRAP(int v, int n) { // Clamp it to the range [0, n) while(v >= n) v -= n; @@ -680,7 +683,7 @@ public: #undef ENTITY #undef CONSTRAINT -class SolveSpace { +class SolveSpaceUI { public: TextWindow TW; GraphicsWindow GW; @@ -927,7 +930,13 @@ public: void Clear(void); }; -extern SolveSpace SS; +extern SolveSpaceUI SS; extern Sketch SK; +}; + +#ifndef __OBJC__ +using namespace SolveSpace; +#endif + #endif diff --git a/src/srf/ratpoly.cpp b/src/srf/ratpoly.cpp index 735f7208..db36d0e7 100644 --- a/src/srf/ratpoly.cpp +++ b/src/srf/ratpoly.cpp @@ -13,7 +13,7 @@ // and convergence should be fast by now. #define RATPOLY_EPS (LENGTH_EPS/(1e2)) -double Bernstein(int k, int deg, double t) +double SolveSpace::Bernstein(int k, int deg, double t) { if(k > deg || k < 0) return 0; @@ -54,7 +54,7 @@ double Bernstein(int k, int deg, double t) oops(); } -double BernsteinDerivative(int k, int deg, double t) +double SolveSpace::BernsteinDerivative(int k, int deg, double t) { switch(deg) { case 0: diff --git a/src/undoredo.cpp b/src/undoredo.cpp index 126dc5d9..ab214c72 100644 --- a/src/undoredo.cpp +++ b/src/undoredo.cpp @@ -7,14 +7,14 @@ //----------------------------------------------------------------------------- #include "solvespace.h" -void SolveSpace::UndoRemember(void) { +void SolveSpaceUI::UndoRemember(void) { unsaved = true; PushFromCurrentOnto(&undo); UndoClearStack(&redo); UndoEnableMenus(); } -void SolveSpace::UndoUndo(void) { +void SolveSpaceUI::UndoUndo(void) { if(undo.cnt <= 0) return; PushFromCurrentOnto(&redo); @@ -22,7 +22,7 @@ void SolveSpace::UndoUndo(void) { UndoEnableMenus(); } -void SolveSpace::UndoRedo(void) { +void SolveSpaceUI::UndoRedo(void) { if(redo.cnt <= 0) return; PushFromCurrentOnto(&undo); @@ -30,12 +30,12 @@ void SolveSpace::UndoRedo(void) { UndoEnableMenus(); } -void SolveSpace::UndoEnableMenus(void) { +void SolveSpaceUI::UndoEnableMenus(void) { EnableMenuById(GraphicsWindow::MNU_UNDO, undo.cnt > 0); EnableMenuById(GraphicsWindow::MNU_REDO, redo.cnt > 0); } -void SolveSpace::PushFromCurrentOnto(UndoStack *uk) { +void SolveSpaceUI::PushFromCurrentOnto(UndoStack *uk) { int i; if(uk->cnt == MAX_UNDO) { @@ -93,7 +93,7 @@ void SolveSpace::PushFromCurrentOnto(UndoStack *uk) { uk->write = WRAP(uk->write + 1, MAX_UNDO); } -void SolveSpace::PopOntoCurrentFrom(UndoStack *uk) { +void SolveSpaceUI::PopOntoCurrentFrom(UndoStack *uk) { if(uk->cnt <= 0) oops(); (uk->cnt)--; uk->write = WRAP(uk->write - 1, MAX_UNDO); @@ -131,7 +131,7 @@ void SolveSpace::PopOntoCurrentFrom(UndoStack *uk) { SS.ScheduleShowTW(); } -void SolveSpace::UndoClearStack(UndoStack *uk) { +void SolveSpaceUI::UndoClearStack(UndoStack *uk) { while(uk->cnt > 0) { uk->write = WRAP(uk->write - 1, MAX_UNDO); (uk->cnt)--; @@ -140,7 +140,7 @@ void SolveSpace::UndoClearStack(UndoStack *uk) { ZERO(uk); // for good measure } -void SolveSpace::UndoClearState(UndoState *ut) { +void SolveSpaceUI::UndoClearState(UndoState *ut) { int i; for(i = 0; i < ut->group.n; i++) { Group *g = &(ut->group.elem[i]); diff --git a/src/unix/unixutil.cpp b/src/unix/unixutil.cpp index 90665627..598d2b89 100644 --- a/src/unix/unixutil.cpp +++ b/src/unix/unixutil.cpp @@ -16,6 +16,8 @@ #include "solvespace.h" +namespace SolveSpace { + void dbp(const char *str, ...) { va_list f; @@ -115,3 +117,5 @@ void MemFree(void *p) { void InitHeaps(void) { /* nothing to do */ } + +}; diff --git a/src/util.cpp b/src/util.cpp index fd48b932..1f551f13 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -6,7 +6,7 @@ //----------------------------------------------------------------------------- #include "solvespace.h" -void MakePathRelative(const char *basep, char *pathp) +void SolveSpace::MakePathRelative(const char *basep, char *pathp) { int i; const char *p; @@ -66,7 +66,7 @@ void MakePathRelative(const char *basep, char *pathp) strcpy(pathp, out); } -void MakePathAbsolute(const char *basep, char *pathp) { +void SolveSpace::MakePathAbsolute(const char *basep, char *pathp) { char out[MAX_PATH]; strcpy(out, basep); @@ -84,7 +84,7 @@ void MakePathAbsolute(const char *basep, char *pathp) { strcpy(pathp, out); } -bool StringAllPrintable(const char *str) +bool SolveSpace::StringAllPrintable(const char *str) { const char *t; for(t = str; *t; t++) { @@ -95,7 +95,7 @@ bool StringAllPrintable(const char *str) return true; } -bool StringEndsIn(const char *str, const char *ending) +bool SolveSpace::StringEndsIn(const char *str, const char *ending) { int i, ls = (int)strlen(str), le = (int)strlen(ending); @@ -109,10 +109,11 @@ bool StringEndsIn(const char *str, const char *ending) return true; } -void MakeMatrix(double *mat, double a11, double a12, double a13, double a14, - double a21, double a22, double a23, double a24, - double a31, double a32, double a33, double a34, - double a41, double a42, double a43, double a44) +void SolveSpace::MakeMatrix(double *mat, + double a11, double a12, double a13, double a14, + double a21, double a22, double a23, double a24, + double a31, double a32, double a33, double a34, + double a41, double a42, double a43, double a44) { mat[ 0] = a11; mat[ 1] = a21; @@ -191,14 +192,14 @@ static void DoStringForMessageBox(const char *str, va_list f, bool error) // And then display the text with our actual longest line length. DoMessageBox(outBuf, rows, cols, error); } -void Error(const char *str, ...) +void SolveSpace::Error(const char *str, ...) { va_list f; va_start(f, str); DoStringForMessageBox(str, f, true); va_end(f); } -void Message(const char *str, ...) +void SolveSpace::Message(const char *str, ...) { va_list f; va_start(f, str); @@ -206,19 +207,18 @@ void Message(const char *str, ...) va_end(f); } -void CnfFreezeBool(bool v, const char *name) +void SolveSpace::CnfFreezeBool(bool v, const char *name) { CnfFreezeInt(v ? 1 : 0, name); } -void CnfFreezeColor(RgbColor v, const char *name) +void SolveSpace::CnfFreezeColor(RgbColor v, const char *name) { CnfFreezeInt(v.ToPackedInt(), name); } -bool CnfThawBool(bool v, const char *name) +bool SolveSpace::CnfThawBool(bool v, const char *name) { return CnfThawInt(v ? 1 : 0, name) != 0; } -RgbColor CnfThawColor(RgbColor v, const char *name) +RgbColor SolveSpace::CnfThawColor(RgbColor v, const char *name) { return RgbColor::FromPackedInt(CnfThawInt(v.ToPackedInt(), name)); } - //----------------------------------------------------------------------------- // Solve a mostly banded matrix. In a given row, there are LEFT_OF_DIAG // elements to the left of the diagonal element, and RIGHT_OF_DIAG elements to diff --git a/src/win32/w32main.cpp b/src/win32/w32main.cpp index d21f6f42..e3e5bf26 100644 --- a/src/win32/w32main.cpp +++ b/src/win32/w32main.cpp @@ -5,12 +5,16 @@ // // Copyright 2008-2013 Jonathan Westhues. //----------------------------------------------------------------------------- -#include "solvespace.h" #include +#include #include #include #include +#include + +#include "solvespace.h" + #ifdef HAVE_SPACEWARE # include # include @@ -38,7 +42,7 @@ static struct { int x, y; } LastMousePos; -char RecentFile[MAX_RECENT][MAX_PATH]; +char SolveSpace::RecentFile[MAX_RECENT][MAX_PATH]; HMENU SubMenus[100]; HMENU RecentOpenMenu, RecentImportMenu; @@ -124,7 +128,7 @@ HWND CreateWindowClient(DWORD exStyle, const char *className, const char *window return h; } -void DoMessageBox(const char *str, int rows, int cols, bool error) +void SolveSpace::DoMessageBox(const char *str, int rows, int cols, bool error) { EnableWindow(GraphicsWnd, false); EnableWindow(TextWnd, false); @@ -192,7 +196,7 @@ void DoMessageBox(const char *str, int rows, int cols, bool error) DestroyWindow(MessageWnd); } -void AddContextMenuItem(const char *label, int id) +void SolveSpace::AddContextMenuItem(const char *label, int id) { if(!ContextMenu) ContextMenu = CreatePopupMenu(); @@ -210,12 +214,12 @@ void AddContextMenuItem(const char *label, int id) } } -void CreateContextSubmenu(void) +void SolveSpace::CreateContextSubmenu(void) { ContextSubmenu = CreatePopupMenu(); } -int ShowContextMenu(void) +int SolveSpace::ShowContextMenu(void) { POINT p; GetCursorPos(&p); @@ -235,12 +239,12 @@ void CALLBACK TimerCallback(HWND hwnd, UINT msg, UINT_PTR id, DWORD time) SS.GW.TimerCallback(); SS.TW.TimerCallback(); } -void SetTimerFor(int milliseconds) +void SolveSpace::SetTimerFor(int milliseconds) { SetTimer(GraphicsWnd, 1, milliseconds, TimerCallback); } -void ScheduleLater() +void SolveSpace::ScheduleLater() { } @@ -251,20 +255,20 @@ static void GetWindowSize(HWND hwnd, int *w, int *h) *w = r.right - r.left; *h = r.bottom - r.top; } -void GetGraphicsWindowSize(int *w, int *h) +void SolveSpace::GetGraphicsWindowSize(int *w, int *h) { GetWindowSize(GraphicsWnd, w, h); } -void GetTextWindowSize(int *w, int *h) +void SolveSpace::GetTextWindowSize(int *w, int *h) { GetWindowSize(TextWnd, w, h); } -void OpenWebsite(const char *url) { +void SolveSpace::OpenWebsite(const char *url) { ShellExecute(GraphicsWnd, "open", url, NULL, NULL, SW_SHOWNORMAL); } -void ExitNow(void) { +void SolveSpace::ExitNow(void) { PostQuitMessage(0); } @@ -272,10 +276,10 @@ void ExitNow(void) { // Helpers so that we can read/write registry keys from the platform- // independent code. //----------------------------------------------------------------------------- -void CnfFreezeString(const char *str, const char *name) +void SolveSpace::CnfFreezeString(const char *str, const char *name) { FreezeStringF(str, FREEZE_SUBKEY, name); } -void CnfFreezeInt(uint32_t v, const char *name) +void SolveSpace::CnfFreezeInt(uint32_t v, const char *name) { FreezeDWORDF((DWORD)v, FREEZE_SUBKEY, name); } union floatDWORD { @@ -283,20 +287,20 @@ union floatDWORD { DWORD d; }; -void CnfFreezeFloat(float v, const char *name) { +void SolveSpace::CnfFreezeFloat(float v, const char *name) { if(sizeof(float) != sizeof(DWORD)) oops(); floatDWORD u; u.f = v; FreezeDWORDF(u.d, FREEZE_SUBKEY, name); } -void CnfThawString(char *str, int maxLen, const char *name) +void SolveSpace::CnfThawString(char *str, int maxLen, const char *name) { ThawStringF(str, maxLen, FREEZE_SUBKEY, name); } -uint32_t CnfThawInt(uint32_t v, const char *name) +uint32_t SolveSpace::CnfThawInt(uint32_t v, const char *name) { return (uint32_t)ThawDWORDF((DWORD)v, FREEZE_SUBKEY, name); } -float CnfThawFloat(float v, const char *name) { +float SolveSpace::CnfThawFloat(float v, const char *name) { floatDWORD u; u.f = v; u.d = ThawDWORDF(u.d, FREEZE_SUBKEY, name); @@ -307,7 +311,7 @@ void SetWindowTitle(const char *str) { SetWindowText(GraphicsWnd, str); } -void SetMousePointerToHand(bool yes) { +void SolveSpace::SetMousePointerToHand(bool yes) { SetCursor(LoadCursor(NULL, yes ? IDC_HAND : IDC_ARROW)); } @@ -323,7 +327,7 @@ static void PaintTextWnd(HDC hdc) wglMakeCurrent(GetDC(GraphicsWnd), GraphicsGl); } -void MoveTextScrollbarTo(int pos, int maxPos, int page) +void SolveSpace::MoveTextScrollbarTo(int pos, int maxPos, int page) { SCROLLINFO si; memset(&si, 0, sizeof(si)); @@ -411,7 +415,7 @@ LRESULT CALLBACK TextWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_CLOSE: case WM_DESTROY: - SolveSpace::MenuFile(GraphicsWindow::MNU_EXIT); + SolveSpaceUI::MenuFile(GraphicsWindow::MNU_EXIT); break; case WM_PAINT: { @@ -599,17 +603,17 @@ static bool ProcessKeyDown(WPARAM wParam) return false; } -void ToggleMenuBar(void) +void SolveSpace::ToggleMenuBar(void) { // Implement me } -bool MenuBarIsVisible(void) +bool SolveSpace::MenuBarIsVisible(void) { // Implement me return true; } -void ShowTextWindow(bool visible) +void SolveSpace::ShowTextWindow(bool visible) { ShowWindow(TextWnd, visible ? SW_SHOWNOACTIVATE : SW_HIDE); } @@ -642,27 +646,27 @@ static void CreateGlContext(HWND hwnd, HGLRC *glrc) wglMakeCurrent(hdc, *glrc); } -void PaintGraphics(void) +void SolveSpace::PaintGraphics(void) { SS.GW.Paint(); SwapBuffers(GetDC(GraphicsWnd)); } -void InvalidateGraphics(void) +void SolveSpace::InvalidateGraphics(void) { InvalidateRect(GraphicsWnd, NULL, false); } -void ToggleFullScreen(void) +void SolveSpace::ToggleFullScreen(void) { // Implement me } -bool FullScreenIsActive(void) +bool SolveSpace::FullScreenIsActive(void) { // Implement me return false; } -int64_t GetMilliseconds(void) +int64_t SolveSpace::GetMilliseconds(void) { LARGE_INTEGER t, f; QueryPerformanceCounter(&t); @@ -671,14 +675,14 @@ int64_t GetMilliseconds(void) return (int64_t)d; } -int64_t GetUnixTime(void) +int64_t SolveSpace::GetUnixTime(void) { __time64_t ret; _time64(&ret); return (int64_t)ret; } -void InvalidateText(void) +void SolveSpace::InvalidateText(void) { InvalidateRect(TextWnd, NULL, false); } @@ -692,21 +696,21 @@ static void ShowEditControl(HWND h, int x, int y, char *s) { SetFocus(h); } } -void ShowTextEditControl(int x, int y, char *s) +void SolveSpace::ShowTextEditControl(int x, int y, char *s) { if(GraphicsEditControlIsVisible()) return; ShowEditControl(TextEditControl, x, y, s); } -void HideTextEditControl(void) +void SolveSpace::HideTextEditControl(void) { ShowWindow(TextEditControl, SW_HIDE); } -bool TextEditControlIsVisible(void) +bool SolveSpace::TextEditControlIsVisible(void) { return IsWindowVisible(TextEditControl) ? true : false; } -void ShowGraphicsEditControl(int x, int y, char *s) +void SolveSpace::ShowGraphicsEditControl(int x, int y, char *s) { if(GraphicsEditControlIsVisible()) return; @@ -721,11 +725,11 @@ void ShowGraphicsEditControl(int x, int y, char *s) ShowEditControl(GraphicsEditControl, x, y, s); } -void HideGraphicsEditControl(void) +void SolveSpace::HideGraphicsEditControl(void) { ShowWindow(GraphicsEditControl, SW_HIDE); } -bool GraphicsEditControlIsVisible(void) +bool SolveSpace::GraphicsEditControlIsVisible(void) { return IsWindowVisible(GraphicsEditControl) ? true : false; } @@ -812,7 +816,7 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam, if(HIWORD(wParam) == 0) { int id = LOWORD(wParam); if((id >= RECENT_OPEN && id < (RECENT_OPEN + MAX_RECENT))) { - SolveSpace::MenuFile(id); + SolveSpaceUI::MenuFile(id); break; } if((id >= RECENT_IMPORT && id < (RECENT_IMPORT + MAX_RECENT))) { @@ -833,7 +837,7 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam, case WM_CLOSE: case WM_DESTROY: - SolveSpace::MenuFile(GraphicsWindow::MNU_EXIT); + SolveSpaceUI::MenuFile(GraphicsWindow::MNU_EXIT); return 1; default: @@ -846,7 +850,7 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam, //----------------------------------------------------------------------------- // Common dialog routines, to open or save a file. //----------------------------------------------------------------------------- -bool GetOpenFile(char *file, const char *defExtension, const char *selPattern) +bool SolveSpace::GetOpenFile(char *file, const char *defExtension, const char *selPattern) { OPENFILENAME ofn; @@ -871,7 +875,7 @@ bool GetOpenFile(char *file, const char *defExtension, const char *selPattern) return r ? true : false; } -bool GetSaveFile(char *file, const char *defExtension, const char *selPattern) +bool SolveSpace::GetSaveFile(char *file, const char *defExtension, const char *selPattern) { OPENFILENAME ofn; @@ -896,7 +900,7 @@ bool GetSaveFile(char *file, const char *defExtension, const char *selPattern) return r ? true : false; } -int SaveFileYesNoCancel(void) +int SolveSpace::SaveFileYesNoCancel(void) { EnableWindow(GraphicsWnd, false); EnableWindow(TextWnd, false); @@ -920,7 +924,7 @@ int SaveFileYesNoCancel(void) return SAVE_CANCEL; } -void LoadAllFontFiles(void) +void SolveSpace::LoadAllFontFiles(void) { WIN32_FIND_DATA wfd; char dir[MAX_PATH]; @@ -969,16 +973,16 @@ static void MenuById(int id, bool yes, bool check) } oops(); } -void CheckMenuById(int id, bool checked) +void SolveSpace::CheckMenuById(int id, bool checked) { MenuById(id, checked, true); } -void RadioMenuById(int id, bool selected) +void SolveSpace::RadioMenuById(int id, bool selected) { // Windows does not natively support radio-button menu items MenuById(id, selected, true); } -void EnableMenuById(int id, bool enabled) +void SolveSpace::EnableMenuById(int id, bool enabled) { MenuById(id, enabled, false); } @@ -996,7 +1000,7 @@ static void DoRecent(HMENU m, int base) } if(c == 0) AppendMenu(m, MF_STRING | MF_GRAYED, 0, "(no recent files)"); } -void RefreshRecentMenus(void) +void SolveSpace::RefreshRecentMenus(void) { DoRecent(RecentOpenMenu, RECENT_OPEN); DoRecent(RecentImportMenu, RECENT_IMPORT); diff --git a/src/win32/w32util.cpp b/src/win32/w32util.cpp index 4a83ba50..d23345d8 100644 --- a/src/win32/w32util.cpp +++ b/src/win32/w32util.cpp @@ -8,6 +8,7 @@ //----------------------------------------------------------------------------- #include "solvespace.h" +namespace SolveSpace { static HANDLE PermHeap, TempHeap; void dbp(const char *str, ...) @@ -81,4 +82,4 @@ void InitHeaps(void) { // Create the heap that we use to store Exprs and other temp stuff. FreeAllTemporary(); } - +} \ No newline at end of file