Preliminary changes for FLTK support

* Added "Show Menu Bar" and "Full Screen" menu items, which will be
  implemented in the FLTK interface. These are currently prevented from
  appearing in the Win32 interface by the HAVE_FLTK and
  HAVE_FLTK_FULLSCREEN macros.

* Moved the "Show Text Window" down below the "Show Toolbar" item, so that
  "Show Menu Bar", "Show Toolbar" and "Show Text Window" are in the same
  vertical order as their corresponding UI elements typically take on

* Added new platform-dependent routines to back the new menu items:

    void ToggleMenuBar(void);
    bool MenuBarIsVisible(void);
    void ToggleFullScreen(void);
    bool FullScreenIsActive(void);

  These are stubs in the Win32 code.

* Fleshed out the system header #includes in solvespace.h, and moved them
  to the top of the file per convention

* Rewrote the file dialog selection patterns in terms of macros that allow
  them to expand to either the FLTK or Windows formats

* Don't use __stdcall in SSGL_CALLBACK, and make SSGL_CALLBACK 'extern "C"'
  as OpenGL usually expects function pointers to point to C functions
This commit is contained in:
Daniel Richard G 2013-10-25 01:04:16 -04:00
parent c6203678e1
commit 873811d865
4 changed files with 122 additions and 40 deletions

View File

@ -70,11 +70,18 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = {
{ 1, "Show Snap &Grid", MNU_SHOW_GRID, '>', mView }, { 1, "Show Snap &Grid", MNU_SHOW_GRID, '>', mView },
{ 1, "Use &Perspective Projection", MNU_PERSPECTIVE_PROJ,'`', mView }, { 1, "Use &Perspective Projection", MNU_PERSPECTIVE_PROJ,'`', mView },
{ 1, NULL, 0, 0, NULL }, { 1, NULL, 0, 0, NULL },
{ 1, "Show Text &Window", MNU_SHOW_TEXT_WND, '\t', mView }, #ifdef HAVE_FLTK
{ 1, "Show Menu &Bar", MNU_SHOW_MENU_BAR, F(12), mView },
#endif
{ 1, "Show &Toolbar", MNU_SHOW_TOOLBAR, 0, mView }, { 1, "Show &Toolbar", MNU_SHOW_TOOLBAR, 0, mView },
{ 1, "Show Text &Window", MNU_SHOW_TEXT_WND, '\t', mView },
{ 1, NULL, 0, 0, NULL }, { 1, NULL, 0, 0, NULL },
{ 1, "Dimensions in &Inches", MNU_UNITS_INCHES, 0, mView }, { 1, "Dimensions in &Inches", MNU_UNITS_INCHES, 0, mView },
{ 1, "Dimensions in &Millimeters", MNU_UNITS_MM, 0, mView }, { 1, "Dimensions in &Millimeters", MNU_UNITS_MM, 0, mView },
#ifdef HAVE_FLTK_FULLSCREEN
{ 1, NULL, 0, 0, NULL },
{ 1, "&Full Screen", MNU_FULL_SCREEN, F(11), mView },
#endif
{ 0, "&New Group", 0, 0, NULL }, { 0, "&New Group", 0, 0, NULL },
{ 1, "Sketch In &3d", MNU_GROUP_3D, S|'3', mGrp }, { 1, "Sketch In &3d", MNU_GROUP_3D, S|'3', mGrp },
@ -504,9 +511,10 @@ void GraphicsWindow::MenuView(int id) {
} }
break; break;
case MNU_SHOW_TEXT_WND: case MNU_SHOW_MENU_BAR:
SS.GW.showTextWindow = !SS.GW.showTextWindow; ToggleMenuBar();
SS.GW.EnsureValidActives(); SS.GW.EnsureValidActives();
InvalidateGraphics();
break; break;
case MNU_SHOW_TOOLBAR: case MNU_SHOW_TOOLBAR:
@ -515,9 +523,8 @@ void GraphicsWindow::MenuView(int id) {
InvalidateGraphics(); InvalidateGraphics();
break; break;
case MNU_UNITS_MM: case MNU_SHOW_TEXT_WND:
SS.viewUnits = SolveSpace::UNIT_MM; SS.GW.showTextWindow = !SS.GW.showTextWindow;
SS.later.showTW = true;
SS.GW.EnsureValidActives(); SS.GW.EnsureValidActives();
break; break;
@ -527,6 +534,17 @@ void GraphicsWindow::MenuView(int id) {
SS.GW.EnsureValidActives(); SS.GW.EnsureValidActives();
break; break;
case MNU_UNITS_MM:
SS.viewUnits = SolveSpace::UNIT_MM;
SS.later.showTW = true;
SS.GW.EnsureValidActives();
break;
case MNU_FULL_SCREEN:
ToggleFullScreen();
SS.GW.EnsureValidActives();
break;
default: oops(); default: oops();
} }
InvalidateGraphics(); InvalidateGraphics();
@ -596,9 +614,15 @@ void GraphicsWindow::EnsureValidActives(void) {
ShowTextWindow(SS.GW.showTextWindow); ShowTextWindow(SS.GW.showTextWindow);
CheckMenuById(MNU_SHOW_TEXT_WND, SS.GW.showTextWindow); CheckMenuById(MNU_SHOW_TEXT_WND, SS.GW.showTextWindow);
#ifdef HAVE_FLTK
CheckMenuById(MNU_SHOW_MENU_BAR, MenuBarIsVisible());
#endif
CheckMenuById(MNU_SHOW_TOOLBAR, SS.showToolbar); CheckMenuById(MNU_SHOW_TOOLBAR, SS.showToolbar);
CheckMenuById(MNU_PERSPECTIVE_PROJ, SS.usePerspectiveProj); CheckMenuById(MNU_PERSPECTIVE_PROJ, SS.usePerspectiveProj);
CheckMenuById(MNU_SHOW_GRID, SS.GW.showSnapGrid); CheckMenuById(MNU_SHOW_GRID, SS.GW.showSnapGrid);
#ifdef HAVE_FLTK_FULLSCREEN
CheckMenuById(MNU_FULL_SCREEN, FullScreenIsActive());
#endif
if(change) SS.later.showTW = true; if(change) SS.later.showTW = true;
} }

View File

@ -7,6 +7,25 @@
#ifndef __SOLVESPACE_H #ifndef __SOLVESPACE_H
#define __SOLVESPACE_H #define __SOLVESPACE_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <limits.h>
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef WIN32
# include <windows.h> // required by GL headers
#endif
#include <GL/gl.h>
#include <GL/glu.h>
// The few floating-point equality comparisons in SolveSpace have been // The few floating-point equality comparisons in SolveSpace have been
// carefully considered, so we disable the -Wfloat-equal warning for them // carefully considered, so we disable the -Wfloat-equal warning for them
#ifdef __clang__ #ifdef __clang__
@ -22,6 +41,7 @@
// Debugging functions // Debugging functions
#define oops() do { dbp("oops at line %d, file %s\n", __LINE__, __FILE__); \ #define oops() do { dbp("oops at line %d, file %s\n", __LINE__, __FILE__); \
if(0) *(char *)0 = 1; exit(-1); } while(0) if(0) *(char *)0 = 1; exit(-1); } while(0)
#ifndef min #ifndef min
# define min(x, y) ((x) < (y) ? (x) : (y)) # define min(x, y) ((x) < (y) ? (x) : (y))
#endif #endif
@ -65,18 +85,6 @@ inline double ffabs(double v) { return (v > 0) ? v : (-v); }
#define isforname(c) (isalnum(c) || (c) == '_' || (c) == '-' || (c) == '#') #define isforname(c) (isalnum(c) || (c) == '_' || (c) == '-' || (c) == '#')
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#ifdef WIN32
# include <windows.h> // required by GL headers
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#ifdef WIN32 #ifdef WIN32
// Define some useful C99 integer types. // Define some useful C99 integer types.
typedef UINT64 uint64_t; typedef UINT64 uint64_t;
@ -112,38 +120,58 @@ void RefreshRecentMenus(void);
#define SAVE_CANCEL (0) #define SAVE_CANCEL (0)
int SaveFileYesNoCancel(void); int SaveFileYesNoCancel(void);
#ifdef HAVE_FLTK
// Selection pattern format for FLTK's file chooser classes:
// "PNG File\t*.png\n"
// "JPEG File\t*.{jpg,jpeg}\n"
// "All Files\t*"
# define PAT1(desc,e1) desc "\t*." e1 "\n"
# define PAT2(desc,e1,e2) desc "\t*.{" e1 "," e2 "}\n"
# define ENDPAT "All Files\t*"
#else
// Selection pattern format for Win32's OPENFILENAME.lpstrFilter:
// "PNG File (*.png)\0*.png\0"
// "JPEG File (*.jpg;*.jpeg)\0*.jpg;*.jpeg\0"
// "All Files (*)\0*\0\0"
# define PAT1(desc,e1) desc " (*." e1 ")\0*." e1 "\0"
# define PAT2(desc,e1,e2) desc " (*." e1 ";*." e2 ")\0*." e1 ";*." e2 "\0"
# define ENDPAT "All Files (*)\0*\0\0"
#endif
// SolveSpace native file format // SolveSpace native file format
#define SLVS_PATTERN "SolveSpace Models (*.slvs)\0*.slvs\0All Files (*)\0*\0\0" #define SLVS_PATTERN PAT1("SolveSpace Models", "slvs") ENDPAT
#define SLVS_EXT "slvs" #define SLVS_EXT "slvs"
// PNG format bitmap // PNG format bitmap
#define PNG_PATTERN "PNG (*.png)\0*.png\0All Files (*)\0*\0\0" #define PNG_PATTERN PAT1("PNG", "png") ENDPAT
#define PNG_EXT "png" #define PNG_EXT "png"
// Triangle mesh // Triangle mesh
#define MESH_PATTERN "STL Mesh (*.stl)\0*.stl\0" \ #define MESH_PATTERN \
"Wavefront OBJ Mesh (*.obj)\0*.obj\0" \ PAT1("STL Mesh", "stl") \
"All Files (*)\0*\0\0" PAT1("Wavefront OBJ Mesh", "obj") \
ENDPAT
#define MESH_EXT "stl" #define MESH_EXT "stl"
// NURBS surfaces // NURBS surfaces
#define SRF_PATTERN "STEP File (*.step;*.stp)\0*.step;*.stp\0" \ #define SRF_PATTERN PAT2("STEP File", "step", "stp") ENDPAT
"All Files(*)\0*\0\0"
#define SRF_EXT "step" #define SRF_EXT "step"
// 2d vector (lines and curves) format // 2d vector (lines and curves) format
#define VEC_PATTERN "PDF File (*.pdf)\0*.pdf\0" \ #define VEC_PATTERN \
"Encapsulated PostScript (*.eps;*.ps)\0*.eps;*.ps\0" \ PAT1("PDF File", "pdf") \
"Scalable Vector Graphics (*.svg)\0*.svg\0" \ PAT2("Encapsulated PostScript", "eps", "ps") \
"STEP File (*.step;*.stp)\0*.step;*.stp\0" \ PAT1("Scalable Vector Graphics", "svg") \
"DXF File (*.dxf)\0*.dxf\0" \ PAT2("STEP File", "step", "stp") \
"HPGL File (*.plt;*.hpgl)\0*.plt;*.hpgl\0" \ PAT1("DXF File", "dxf") \
"G Code (*.txt)\0*.txt\0" \ PAT2("HPGL File", "plt", "hpgl") \
"All Files (*)\0*\0\0" PAT1("G Code", "txt") \
ENDPAT
#define VEC_EXT "pdf" #define VEC_EXT "pdf"
// 3d vector (wireframe lines and curves) format // 3d vector (wireframe lines and curves) format
#define V3D_PATTERN "STEP File (*.step;*.stp)\0*.step;*.stp\0" \ #define V3D_PATTERN \
"DXF File (*.dxf)\0*.dxf\0" \ PAT2("STEP File", "step", "stp") \
"All Files (*)\0*\0\0" PAT1("DXF File", "dxf") \
ENDPAT
#define V3D_EXT "step" #define V3D_EXT "step"
// Comma-separated value, like a spreadsheet would use // Comma-separated value, like a spreadsheet would use
#define CSV_PATTERN "CSV File (*.csv)\0*.csv\0All Files (*)\0*\0\0" #define CSV_PATTERN PAT1("CSV File", "csv") ENDPAT
#define CSV_EXT "csv" #define CSV_EXT "csv"
bool GetSaveFile(char *file, const char *defExtension, const char *selPattern); bool GetSaveFile(char *file, const char *defExtension, const char *selPattern);
bool GetOpenFile(char *file, const char *defExtension, const char *selPattern); bool GetOpenFile(char *file, const char *defExtension, const char *selPattern);
@ -170,10 +198,14 @@ void AddContextMenuItem(const char *legend, int id);
void CreateContextSubmenu(void); void CreateContextSubmenu(void);
int ShowContextMenu(void); int ShowContextMenu(void);
void ToggleMenuBar(void);
bool MenuBarIsVisible(void);
void ShowTextWindow(bool visible); void ShowTextWindow(bool visible);
void InvalidateText(void); void InvalidateText(void);
void InvalidateGraphics(void); void InvalidateGraphics(void);
void PaintGraphics(void); void PaintGraphics(void);
void ToggleFullScreen(void);
bool FullScreenIsActive(void);
void GetGraphicsWindowSize(int *w, int *h); void GetGraphicsWindowSize(int *w, int *h);
void GetTextWindowSize(int *w, int *h); void GetTextWindowSize(int *w, int *h);
int32_t GetMilliseconds(void); int32_t GetMilliseconds(void);
@ -232,8 +264,12 @@ void ssglVertex3v(Vector u);
void ssglAxisAlignedQuad(double l, double r, double t, double b, bool lone = true); void ssglAxisAlignedQuad(double l, double r, double t, double b, bool lone = true);
void ssglAxisAlignedLineLoop(double l, double r, double t, double b); void ssglAxisAlignedLineLoop(double l, double r, double t, double b);
#define DEFAULT_TEXT_HEIGHT (11.5) #define DEFAULT_TEXT_HEIGHT (11.5)
#define SSGL_CALLBACK __stdcall #ifdef WIN32
typedef void SSGL_CALLBACK ssglCallbackFptr(void); # define SSGL_CALLBACK __stdcall
#else
# define SSGL_CALLBACK
#endif
extern "C" { typedef void SSGL_CALLBACK ssglCallbackFptr(void); }
void ssglTesselatePolygon(GLUtesselator *gt, SPolygon *p); void ssglTesselatePolygon(GLUtesselator *gt, SPolygon *p);
void ssglFillPolygon(SPolygon *p); void ssglFillPolygon(SPolygon *p);
void ssglFillMesh(RgbColor color, SMesh *m, uint32_t h, uint32_t s1, uint32_t s2); void ssglFillMesh(RgbColor color, SMesh *m, uint32_t h, uint32_t s1, uint32_t s2);

4
ui.h
View File

@ -344,10 +344,12 @@ public:
MNU_NEAREST_ORTHO, MNU_NEAREST_ORTHO,
MNU_NEAREST_ISO, MNU_NEAREST_ISO,
MNU_CENTER_VIEW, MNU_CENTER_VIEW,
MNU_SHOW_TEXT_WND, MNU_SHOW_MENU_BAR,
MNU_SHOW_TOOLBAR, MNU_SHOW_TOOLBAR,
MNU_SHOW_TEXT_WND,
MNU_UNITS_INCHES, MNU_UNITS_INCHES,
MNU_UNITS_MM, MNU_UNITS_MM,
MNU_FULL_SCREEN,
// Edit // Edit
MNU_UNDO, MNU_UNDO,
MNU_REDO, MNU_REDO,

View File

@ -597,6 +597,16 @@ static bool ProcessKeyDown(WPARAM wParam)
return false; return false;
} }
void ToggleMenuBar(void)
{
// Implement me
}
bool MenuBarIsVisible(void)
{
// Implement me
return true;
}
void ShowTextWindow(bool visible) void ShowTextWindow(bool visible)
{ {
ShowWindow(TextWnd, visible ? SW_SHOWNOACTIVATE : SW_HIDE); ShowWindow(TextWnd, visible ? SW_SHOWNOACTIVATE : SW_HIDE);
@ -640,6 +650,16 @@ void InvalidateGraphics(void)
InvalidateRect(GraphicsWnd, NULL, false); InvalidateRect(GraphicsWnd, NULL, false);
} }
void ToggleFullScreen(void)
{
// Implement me
}
bool FullScreenIsActive(void)
{
// Implement me
return false;
}
int32_t GetMilliseconds(void) int32_t GetMilliseconds(void)
{ {
LARGE_INTEGER t, f; LARGE_INTEGER t, f;