2013-07-29 06:08:34 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Our WinMain() functions, and Win32-specific stuff to set up our windows
|
|
|
|
// and otherwise handle our interface to the operating system. Everything
|
2016-04-22 02:24:49 +08:00
|
|
|
// outside platform/... should be standard C++ and gl.
|
2013-07-29 06:08:34 +08:00
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
#include <time.h>
|
Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
* It is now possible to port SolveSpace to a later version of
OpenGL, such as OpenGLES 2, so that it runs on platforms that
only have that OpenGL version;
* The majority of geometry is now rendered without references to
the camera in C++ code, so a renderer can now submit it to
the video card once and re-rasterize with a different projection
matrix every time the projection is changed, avoiding expensive
reuploads;
* The DOGD (draw or get distance) interface is now
a straightforward Canvas implementation;
* There are no more direct references to SS.GW.(projection)
in sketch rendering code, which allows rendering to multiple
viewports;
* There are no more unnecessary framebuffer flips on CPU on Cocoa
and GTK;
* The platform-dependent GL code is now confined to rendergl1.cpp.
* The Microsoft and Apple headers required by it that are prone to
identifier conflicts are no longer included globally;
* The rendergl1.cpp implementation can now be omitted from
compilation to run SolveSpace headless or with a different
OpenGL version.
Note these implementation details of Canvas:
* GetCamera currently always returns a reference to the field
`Camera camera;`. This is so that a future renderer that caches
geometry in the video memory can define it as asserting, which
would provide assurance against code that could accidentally
put something projection-dependent in the cache;
* Line and triangle rendering is specified through a level of
indirection, hStroke and hFill. This is so that a future renderer
that batches geometry could cheaply group identical styles.
* DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
This is so that a future renderer into an output format that
uses 2d transforms (e.g. SVG) could easily derive those.
Some additional internal changes were required to enable this:
* Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
This is so that the renderer could cache uploaded textures
between API calls, which requires it to capture a (weak)
reference.
* The PlatformPathEqual function was properly extracted into
platform-specific code. This is so that the <windows.h> header
could be included only where needed (in platform/w32* as well
as rendergl1.cpp).
* The SBsp{2,3}::DebugDraw functions were removed. They can be
rewritten using the Canvas API if they are ever needed.
While no visual changes were originally intended, some minor fixes
happened anyway:
* The "emphasis" yellow line from top-left corner is now correctly
rendered much wider.
* The marquee rectangle is now pixel grid aligned.
* The hidden entities now do not clobber the depth buffer, removing
some minor artifacts.
* The workplane "tab" now scales with the font used to render
the workplane name.
* The workplane name font is now taken from the normals style.
* Workplane and constraint line stipple is insignificantly
different. This is so that it can reuse the existing stipple
codepaths; rendering of workplanes and constraints predates
those.
Some debug functionality was added:
* In graphics window, an fps counter that becomes red when
rendering under 60fps is drawn.
2016-05-31 08:55:13 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "solvespace.h"
|
|
|
|
|
|
|
|
// Include after solvespace.h to avoid identifier clashes.
|
2015-03-24 01:49:04 +08:00
|
|
|
#include <windows.h>
|
2008-02-09 21:52:01 +08:00
|
|
|
#include <shellapi.h>
|
2008-03-25 18:02:13 +08:00
|
|
|
#include <commctrl.h>
|
2008-04-18 19:11:48 +08:00
|
|
|
#include <commdlg.h>
|
2008-03-25 18:02:13 +08:00
|
|
|
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2013-11-13 13:33:23 +08:00
|
|
|
# include <si.h>
|
|
|
|
# include <siapp.h>
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
# undef uint32_t // thanks but no thanks
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2009-07-21 03:05:33 +08:00
|
|
|
|
2016-11-16 10:22:10 +08:00
|
|
|
#define EGLAPI /*static linkage*/
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
HINSTANCE Instance;
|
|
|
|
|
2008-04-01 18:48:44 +08:00
|
|
|
HWND TextWnd;
|
2008-03-25 18:02:13 +08:00
|
|
|
HWND TextWndScrollBar;
|
2008-05-27 14:36:59 +08:00
|
|
|
HWND TextEditControl;
|
2016-11-16 10:22:10 +08:00
|
|
|
EGLDisplay TextGlDisplay;
|
|
|
|
EGLSurface TextGlSurface;
|
|
|
|
EGLContext TextGlContext;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2008-04-01 18:48:44 +08:00
|
|
|
HWND GraphicsWnd;
|
2008-04-21 18:12:04 +08:00
|
|
|
HWND GraphicsEditControl;
|
2016-11-16 10:22:10 +08:00
|
|
|
EGLDisplay GraphicsGlDisplay;
|
|
|
|
EGLSurface GraphicsGlSurface;
|
|
|
|
EGLContext GraphicsGlContext;
|
2013-10-19 13:36:45 +08:00
|
|
|
static struct {
|
2008-04-01 18:48:44 +08:00
|
|
|
int x, y;
|
|
|
|
} LastMousePos;
|
2008-03-25 18:02:13 +08:00
|
|
|
|
2008-05-28 18:10:31 +08:00
|
|
|
HMENU SubMenus[100];
|
|
|
|
HMENU RecentOpenMenu, RecentImportMenu;
|
|
|
|
|
2009-09-23 18:59:59 +08:00
|
|
|
HMENU ContextMenu, ContextSubmenu;
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
int ClientIsSmallerBy;
|
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
HFONT FixedFont;
|
2008-03-25 18:02:13 +08:00
|
|
|
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
// The 6-DOF input device.
|
|
|
|
SiHdl SpaceNavigator = SI_NO_HANDLE;
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2009-07-21 03:05:33 +08:00
|
|
|
|
2010-01-16 17:22:44 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Routines to display message boxes on screen. Do our own, instead of using
|
2015-03-29 08:30:52 +08:00
|
|
|
// MessageBox, because that is not consistent from version to version and
|
2010-01-16 17:22:44 +08:00
|
|
|
// there's word wrap problems.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
HWND MessageWnd, OkButton;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
bool MessageDone;
|
2016-10-10 05:54:21 +08:00
|
|
|
int MessageWidth, MessageHeight;
|
2013-08-27 02:58:35 +08:00
|
|
|
const char *MessageString;
|
2010-01-16 17:22:44 +08:00
|
|
|
|
|
|
|
static LRESULT CALLBACK MessageProc(HWND hwnd, UINT msg, WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
2008-04-12 23:17:58 +08:00
|
|
|
{
|
2010-01-16 17:22:44 +08:00
|
|
|
switch (msg) {
|
|
|
|
case WM_COMMAND:
|
|
|
|
if((HWND)lParam == OkButton && wParam == BN_CLICKED) {
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MessageDone = true;
|
2010-01-16 17:22:44 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_DESTROY:
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MessageDone = true;
|
2010-01-16 17:22:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_PAINT: {
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc = BeginPaint(hwnd, &ps);
|
|
|
|
SelectObject(hdc, FixedFont);
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-17 04:00:58 +08:00
|
|
|
SetTextColor(hdc, 0x000000);
|
2010-01-16 17:22:44 +08:00
|
|
|
SetBkMode(hdc, TRANSPARENT);
|
2016-10-10 05:54:21 +08:00
|
|
|
RECT rc;
|
|
|
|
SetRect(&rc, 10, 10, MessageWidth, MessageHeight);
|
|
|
|
std::wstring text = Widen(MessageString);
|
|
|
|
DrawText(hdc, text.c_str(), text.length(), &rc, DT_LEFT | DT_WORDBREAK);
|
2010-01-16 17:22:44 +08:00
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
2008-02-09 21:52:01 +08:00
|
|
|
}
|
2008-06-25 13:14:49 +08:00
|
|
|
|
2010-01-16 17:22:44 +08:00
|
|
|
return 1;
|
2008-04-12 23:17:58 +08:00
|
|
|
}
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
HWND CreateWindowClient(DWORD exStyle, const wchar_t *className, const wchar_t *windowName,
|
2010-01-16 17:22:44 +08:00
|
|
|
DWORD style, int x, int y, int width, int height, HWND parent,
|
|
|
|
HMENU menu, HINSTANCE instance, void *param)
|
2008-02-09 21:52:01 +08:00
|
|
|
{
|
2015-12-27 15:51:28 +08:00
|
|
|
HWND h = CreateWindowExW(exStyle, className, windowName, style, x, y,
|
2010-01-16 17:22:44 +08:00
|
|
|
width, height, parent, menu, instance, param);
|
|
|
|
|
|
|
|
RECT r;
|
|
|
|
GetClientRect(h, &r);
|
|
|
|
width = width - (r.right - width);
|
|
|
|
height = height - (r.bottom - height);
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2010-01-16 17:22:44 +08:00
|
|
|
SetWindowPos(h, HWND_TOP, x, y, width, height, 0);
|
|
|
|
|
|
|
|
return h;
|
2008-02-09 21:52:01 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::DoMessageBox(const char *str, int rows, int cols, bool error)
|
2008-02-09 21:52:01 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(GraphicsWnd, false);
|
|
|
|
EnableWindow(TextWnd, false);
|
2010-01-16 17:22:44 +08:00
|
|
|
|
|
|
|
// Register the window class for our dialog.
|
2015-03-27 23:31:23 +08:00
|
|
|
WNDCLASSEX wc = {};
|
2015-12-27 15:51:28 +08:00
|
|
|
wc.cbSize = sizeof(wc);
|
2010-01-16 17:22:44 +08:00
|
|
|
wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC;
|
|
|
|
wc.lpfnWndProc = (WNDPROC)MessageProc;
|
|
|
|
wc.hInstance = Instance;
|
|
|
|
wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
|
2015-12-27 15:51:28 +08:00
|
|
|
wc.lpszClassName = L"MessageWnd";
|
2010-01-16 17:22:44 +08:00
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
|
|
|
|
IMAGE_ICON, 32, 32, 0);
|
|
|
|
wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
|
|
|
|
IMAGE_ICON, 16, 16, 0);
|
|
|
|
RegisterClassEx(&wc);
|
|
|
|
|
|
|
|
// Create the window.
|
|
|
|
MessageString = str;
|
|
|
|
RECT r;
|
|
|
|
GetWindowRect(GraphicsWnd, &r);
|
2013-10-19 13:36:45 +08:00
|
|
|
const char *title = error ? "SolveSpace - Error" : "SolveSpace - Message";
|
2010-04-26 15:52:49 +08:00
|
|
|
int width = cols*SS.TW.CHAR_WIDTH + 20,
|
|
|
|
height = rows*SS.TW.LINE_HEIGHT + 60;
|
2016-10-10 05:54:21 +08:00
|
|
|
MessageWidth = width;
|
|
|
|
MessageHeight = height;
|
2015-12-27 15:51:28 +08:00
|
|
|
MessageWnd = CreateWindowClient(0, L"MessageWnd", Widen(title).c_str(),
|
2010-01-16 17:22:44 +08:00
|
|
|
WS_OVERLAPPED | WS_SYSMENU,
|
|
|
|
r.left + 100, r.top + 100, width, height, NULL, NULL, Instance, NULL);
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
OkButton = CreateWindowExW(0, WC_BUTTON, L"OK",
|
2010-01-16 17:22:44 +08:00
|
|
|
WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON,
|
2010-04-26 15:52:49 +08:00
|
|
|
(width - 70)/2, rows*SS.TW.LINE_HEIGHT + 20,
|
2015-03-29 08:30:52 +08:00
|
|
|
70, 25, MessageWnd, NULL, Instance, NULL);
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
SendMessage(OkButton, WM_SETFONT, (WPARAM)FixedFont, true);
|
2010-01-16 17:22:44 +08:00
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
ShowWindow(MessageWnd, true);
|
2010-01-16 17:22:44 +08:00
|
|
|
SetFocus(OkButton);
|
|
|
|
|
|
|
|
MSG msg;
|
|
|
|
DWORD ret;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MessageDone = false;
|
2013-08-27 04:54:04 +08:00
|
|
|
while((ret = GetMessage(&msg, NULL, 0, 0)) != 0 && !MessageDone) {
|
2010-01-16 17:22:44 +08:00
|
|
|
if((msg.message == WM_KEYDOWN &&
|
|
|
|
(msg.wParam == VK_RETURN ||
|
|
|
|
msg.wParam == VK_ESCAPE)) ||
|
|
|
|
(msg.message == WM_KEYUP &&
|
|
|
|
(msg.wParam == VK_SPACE)))
|
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MessageDone = true;
|
2010-01-16 17:22:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2010-01-16 17:22:44 +08:00
|
|
|
MessageString = NULL;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(TextWnd, true);
|
|
|
|
EnableWindow(GraphicsWnd, true);
|
2010-01-16 17:22:44 +08:00
|
|
|
SetForegroundWindow(GraphicsWnd);
|
|
|
|
DestroyWindow(MessageWnd);
|
2008-02-09 21:52:01 +08:00
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
void SolveSpace::AddContextMenuItem(const char *label, ContextCommand cmd)
|
2009-09-23 18:59:59 +08:00
|
|
|
{
|
|
|
|
if(!ContextMenu) ContextMenu = CreatePopupMenu();
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
if(cmd == ContextCommand::SUBMENU) {
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(ContextMenu, MF_STRING | MF_POPUP,
|
|
|
|
(UINT_PTR)ContextSubmenu, Widen(label).c_str());
|
2009-09-23 18:59:59 +08:00
|
|
|
ContextSubmenu = NULL;
|
|
|
|
} else {
|
|
|
|
HMENU m = ContextSubmenu ? ContextSubmenu : ContextMenu;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
if(cmd == ContextCommand::SEPARATOR) {
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(m, MF_SEPARATOR, 0, L"");
|
2009-09-23 18:59:59 +08:00
|
|
|
} else {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
AppendMenuW(m, MF_STRING, (uint32_t)cmd, Widen(label).c_str());
|
2009-09-23 18:59:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 13:54:05 +08:00
|
|
|
void SolveSpace::CreateContextSubmenu()
|
2009-09-23 18:59:59 +08:00
|
|
|
{
|
|
|
|
ContextSubmenu = CreatePopupMenu();
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
ContextCommand SolveSpace::ShowContextMenu()
|
2009-09-23 18:59:59 +08:00
|
|
|
{
|
|
|
|
POINT p;
|
|
|
|
GetCursorPos(&p);
|
2015-03-29 08:30:52 +08:00
|
|
|
int r = TrackPopupMenu(ContextMenu,
|
2009-09-23 18:59:59 +08:00
|
|
|
TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_TOPALIGN,
|
|
|
|
p.x, p.y, 0, GraphicsWnd, NULL);
|
|
|
|
|
|
|
|
DestroyMenu(ContextMenu);
|
|
|
|
ContextMenu = NULL;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
return (ContextCommand)r;
|
2009-09-23 18:59:59 +08:00
|
|
|
}
|
|
|
|
|
2009-01-02 18:38:36 +08:00
|
|
|
void CALLBACK TimerCallback(HWND hwnd, UINT msg, UINT_PTR id, DWORD time)
|
|
|
|
{
|
2009-01-04 20:52:11 +08:00
|
|
|
// The timer is periodic, so needs to be killed explicitly.
|
|
|
|
KillTimer(GraphicsWnd, 1);
|
2009-01-02 18:38:36 +08:00
|
|
|
SS.GW.TimerCallback();
|
2010-05-03 13:04:42 +08:00
|
|
|
SS.TW.TimerCallback();
|
2009-01-02 18:38:36 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::SetTimerFor(int milliseconds)
|
2009-01-02 18:38:36 +08:00
|
|
|
{
|
|
|
|
SetTimer(GraphicsWnd, 1, milliseconds, TimerCallback);
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::ScheduleLater()
|
2015-03-19 01:02:11 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-29 12:46:57 +08:00
|
|
|
static void CALLBACK AutosaveCallback(HWND hwnd, UINT msg, UINT_PTR id, DWORD time)
|
|
|
|
{
|
|
|
|
KillTimer(GraphicsWnd, 1);
|
|
|
|
SS.Autosave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SolveSpace::SetAutosaveTimerFor(int minutes)
|
|
|
|
{
|
|
|
|
SetTimer(GraphicsWnd, 2, minutes * 60 * 1000, AutosaveCallback);
|
|
|
|
}
|
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
static void GetWindowSize(HWND hwnd, int *w, int *h)
|
2009-01-02 18:38:36 +08:00
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
RECT r;
|
|
|
|
GetClientRect(hwnd, &r);
|
|
|
|
*w = r.right - r.left;
|
|
|
|
*h = r.bottom - r.top;
|
2009-01-02 18:38:36 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::GetGraphicsWindowSize(int *w, int *h)
|
2009-01-02 18:38:36 +08:00
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
GetWindowSize(GraphicsWnd, w, h);
|
2009-01-02 18:38:36 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::GetTextWindowSize(int *w, int *h)
|
2010-05-03 13:04:42 +08:00
|
|
|
{
|
|
|
|
GetWindowSize(TextWnd, w, h);
|
|
|
|
}
|
2008-02-09 21:52:01 +08:00
|
|
|
|
2016-08-01 21:44:38 +08:00
|
|
|
double SolveSpace::GetScreenDpi() {
|
|
|
|
HDC hdc = GetDC(NULL);
|
|
|
|
double dpi = GetDeviceCaps(hdc, LOGPIXELSX);
|
|
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
return dpi;
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::OpenWebsite(const char *url) {
|
2015-12-27 15:51:28 +08:00
|
|
|
ShellExecuteW(GraphicsWnd, L"open", Widen(url).c_str(), NULL, NULL, SW_SHOWNORMAL);
|
2008-02-09 21:52:01 +08:00
|
|
|
}
|
|
|
|
|
2016-05-05 13:54:05 +08:00
|
|
|
void SolveSpace::ExitNow() {
|
2008-06-04 02:48:47 +08:00
|
|
|
PostQuitMessage(0);
|
|
|
|
}
|
|
|
|
|
2008-06-11 12:22:52 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Helpers so that we can read/write registry keys from the platform-
|
|
|
|
// independent code.
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-12-26 23:54:26 +08:00
|
|
|
inline int CLAMP(int v, int a, int b) {
|
|
|
|
// Clamp it to the range [a, b]
|
|
|
|
if(v <= a) return a;
|
|
|
|
if(v >= b) return b;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HKEY GetRegistryKey()
|
|
|
|
{
|
|
|
|
HKEY Software;
|
2015-12-27 15:51:28 +08:00
|
|
|
if(RegOpenKeyExW(HKEY_CURRENT_USER, L"Software", 0,
|
|
|
|
KEY_ALL_ACCESS, &Software) != ERROR_SUCCESS)
|
2015-12-26 23:54:26 +08:00
|
|
|
return NULL;
|
2008-06-11 12:22:52 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
HKEY SolveSpace;
|
2015-12-27 15:51:28 +08:00
|
|
|
if(RegCreateKeyExW(Software, L"SolveSpace", 0, NULL, 0,
|
|
|
|
KEY_ALL_ACCESS, NULL, &SolveSpace, NULL) != ERROR_SUCCESS)
|
2015-12-26 23:54:26 +08:00
|
|
|
return NULL;
|
2008-06-11 12:22:52 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(Software);
|
2013-10-19 13:36:45 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
return SolveSpace;
|
2013-10-19 13:36:45 +08:00
|
|
|
}
|
2008-07-08 15:41:29 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
void SolveSpace::CnfFreezeInt(uint32_t val, const std::string &name)
|
|
|
|
{
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
2015-12-27 15:51:28 +08:00
|
|
|
RegSetValueExW(SolveSpace, &Widen(name)[0], 0,
|
|
|
|
REG_DWORD, (const BYTE*) &val, sizeof(DWORD));
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
}
|
|
|
|
void SolveSpace::CnfFreezeFloat(float val, const std::string &name)
|
|
|
|
{
|
|
|
|
static_assert(sizeof(float) == sizeof(DWORD),
|
|
|
|
"sizes of float and DWORD must match");
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
2015-12-27 15:51:28 +08:00
|
|
|
RegSetValueExW(SolveSpace, &Widen(name)[0], 0,
|
|
|
|
REG_DWORD, (const BYTE*) &val, sizeof(DWORD));
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
}
|
|
|
|
void SolveSpace::CnfFreezeString(const std::string &str, const std::string &name)
|
|
|
|
{
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
2015-12-27 15:51:28 +08:00
|
|
|
std::wstring strW = Widen(str);
|
|
|
|
RegSetValueExW(SolveSpace, &Widen(name)[0], 0,
|
|
|
|
REG_SZ, (const BYTE*) &strW[0], (strW.length() + 1) * 2);
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
}
|
|
|
|
static void FreezeWindowPos(HWND hwnd, const std::string &name)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
GetWindowRect(hwnd, &r);
|
|
|
|
CnfFreezeInt(r.left, name + "_left");
|
|
|
|
CnfFreezeInt(r.right, name + "_right");
|
|
|
|
CnfFreezeInt(r.top, name + "_top");
|
|
|
|
CnfFreezeInt(r.bottom, name + "_bottom");
|
2008-06-11 12:22:52 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
CnfFreezeInt(IsZoomed(hwnd), name + "_maximized");
|
|
|
|
}
|
2008-06-11 12:22:52 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
uint32_t SolveSpace::CnfThawInt(uint32_t val, const std::string &name)
|
|
|
|
{
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
|
|
|
DWORD type, newval, len = sizeof(DWORD);
|
2015-12-27 15:51:28 +08:00
|
|
|
LONG result = RegQueryValueEx(SolveSpace, &Widen(name)[0], NULL,
|
|
|
|
&type, (BYTE*) &newval, &len);
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
|
|
|
|
if(result == ERROR_SUCCESS && type == REG_DWORD)
|
|
|
|
return newval;
|
|
|
|
else
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
float SolveSpace::CnfThawFloat(float val, const std::string &name)
|
|
|
|
{
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
|
|
|
DWORD type, len = sizeof(DWORD);
|
|
|
|
float newval;
|
2015-12-27 15:51:28 +08:00
|
|
|
LONG result = RegQueryValueExW(SolveSpace, &Widen(name)[0], NULL,
|
|
|
|
&type, (BYTE*) &newval, &len);
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
|
|
|
|
if(result == ERROR_SUCCESS && type == REG_DWORD)
|
|
|
|
return newval;
|
|
|
|
else
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
std::string SolveSpace::CnfThawString(const std::string &val, const std::string &name)
|
|
|
|
{
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
|
|
|
DWORD type, len;
|
2015-12-27 15:51:28 +08:00
|
|
|
if(RegQueryValueExW(SolveSpace, &Widen(name)[0], NULL,
|
|
|
|
&type, NULL, &len) != ERROR_SUCCESS || type != REG_SZ) {
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
std::wstring newval;
|
|
|
|
newval.resize(len / 2 - 1);
|
|
|
|
if(RegQueryValueExW(SolveSpace, &Widen(name)[0], NULL,
|
|
|
|
NULL, (BYTE*) &newval[0], &len) != ERROR_SUCCESS) {
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(SolveSpace);
|
2015-12-27 15:51:28 +08:00
|
|
|
return Narrow(newval);
|
2015-12-26 23:54:26 +08:00
|
|
|
}
|
|
|
|
static void ThawWindowPos(HWND hwnd, const std::string &name)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
GetWindowRect(hwnd, &r);
|
|
|
|
r.left = CnfThawInt(r.left, name + "_left");
|
|
|
|
r.right = CnfThawInt(r.right, name + "_right");
|
|
|
|
r.top = CnfThawInt(r.top, name + "_top");
|
|
|
|
r.bottom = CnfThawInt(r.bottom, name + "_bottom");
|
|
|
|
|
|
|
|
HMONITOR hMonitor = MonitorFromRect(&r, MONITOR_DEFAULTTONEAREST);;
|
|
|
|
MONITORINFO mi;
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
GetMonitorInfo(hMonitor, &mi);
|
|
|
|
|
|
|
|
// If it somehow ended up off-screen, then put it back.
|
|
|
|
RECT dr = mi.rcMonitor;
|
|
|
|
r.left = CLAMP(r.left, dr.left, dr.right);
|
|
|
|
r.right = CLAMP(r.right, dr.left, dr.right);
|
|
|
|
r.top = CLAMP(r.top, dr.top, dr.bottom);
|
|
|
|
r.bottom = CLAMP(r.bottom, dr.top, dr.bottom);
|
|
|
|
MoveWindow(hwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE);
|
|
|
|
|
|
|
|
if(CnfThawInt(FALSE, name + "_maximized"))
|
|
|
|
ShowWindow(hwnd, SW_MAXIMIZE);
|
2008-07-08 15:41:29 +08:00
|
|
|
}
|
|
|
|
|
2015-12-27 09:03:24 +08:00
|
|
|
void SolveSpace::SetCurrentFilename(const std::string &filename) {
|
|
|
|
if(!filename.empty()) {
|
2015-12-27 15:51:28 +08:00
|
|
|
SetWindowTextW(GraphicsWnd, Widen("SolveSpace - " + filename).c_str());
|
2015-03-24 14:45:53 +08:00
|
|
|
} else {
|
2015-12-27 15:51:28 +08:00
|
|
|
SetWindowTextW(GraphicsWnd, L"SolveSpace - (not yet saved)");
|
2015-03-24 14:45:53 +08:00
|
|
|
}
|
2008-07-08 16:02:22 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::SetMousePointerToHand(bool yes) {
|
2010-04-26 15:52:49 +08:00
|
|
|
SetCursor(LoadCursor(NULL, yes ? IDC_HAND : IDC_ARROW));
|
|
|
|
}
|
|
|
|
|
2016-11-16 10:22:10 +08:00
|
|
|
static void PaintTextWnd()
|
2008-03-25 18:02:13 +08:00
|
|
|
{
|
2016-11-16 10:22:10 +08:00
|
|
|
eglMakeCurrent(TextGlDisplay, TextGlSurface, TextGlSurface, TextGlContext);
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2010-05-03 13:04:42 +08:00
|
|
|
SS.TW.Paint();
|
2016-11-16 10:22:10 +08:00
|
|
|
eglSwapBuffers(TextGlDisplay, TextGlSurface);
|
2008-03-25 18:02:13 +08:00
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
// Leave the graphics window context active, except when we're painting
|
|
|
|
// this text window.
|
2016-11-16 10:22:10 +08:00
|
|
|
eglMakeCurrent(GraphicsGlDisplay, GraphicsGlSurface, GraphicsGlSurface, GraphicsGlContext);
|
2010-04-26 15:52:49 +08:00
|
|
|
}
|
2008-04-09 17:35:09 +08:00
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::MoveTextScrollbarTo(int pos, int maxPos, int page)
|
2010-04-26 15:52:49 +08:00
|
|
|
{
|
2015-03-27 23:31:23 +08:00
|
|
|
SCROLLINFO si = {};
|
2008-03-25 18:02:13 +08:00
|
|
|
si.cbSize = sizeof(si);
|
|
|
|
si.fMask = SIF_DISABLENOSCROLL | SIF_ALL;
|
|
|
|
si.nMin = 0;
|
2010-04-26 15:52:49 +08:00
|
|
|
si.nMax = maxPos;
|
|
|
|
si.nPos = pos;
|
|
|
|
si.nPage = page;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
SetScrollInfo(TextWndScrollBar, SB_CTL, &si, true);
|
2008-03-26 17:18:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void HandleTextWindowScrollBar(WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
int maxPos, minPos, pos;
|
|
|
|
GetScrollRange(TextWndScrollBar, SB_CTL, &minPos, &maxPos);
|
|
|
|
pos = GetScrollPos(TextWndScrollBar, SB_CTL);
|
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
switch(LOWORD(wParam)) {
|
2010-04-26 15:52:49 +08:00
|
|
|
case SB_LINEUP: pos--; break;
|
|
|
|
case SB_PAGEUP: pos -= 4; break;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
case SB_LINEDOWN: pos++; break;
|
|
|
|
case SB_PAGEDOWN: pos += 4; break;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
case SB_TOP: pos = 0; break;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
case SB_BOTTOM: pos = maxPos; break;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
|
|
|
case SB_THUMBTRACK:
|
2010-04-26 15:52:49 +08:00
|
|
|
case SB_THUMBPOSITION: pos = HIWORD(wParam); break;
|
2008-03-26 17:18:12 +08:00
|
|
|
}
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
SS.TW.ScrollbarEvent(pos);
|
2008-03-25 18:02:13 +08:00
|
|
|
}
|
|
|
|
|
2009-07-21 03:05:33 +08:00
|
|
|
static void MouseWheel(int thisDelta) {
|
|
|
|
static int DeltaAccum;
|
|
|
|
int delta = 0;
|
|
|
|
// Handle mouse deltas of less than 120 (like from an un-detented mouse
|
|
|
|
// wheel) correctly, even though no one ever uses those.
|
|
|
|
DeltaAccum += thisDelta;
|
|
|
|
while(DeltaAccum >= 120) {
|
|
|
|
DeltaAccum -= 120;
|
|
|
|
delta += 120;
|
|
|
|
}
|
|
|
|
while(DeltaAccum <= -120) {
|
|
|
|
DeltaAccum += 120;
|
|
|
|
delta -= 120;
|
|
|
|
}
|
|
|
|
if(delta == 0) return;
|
|
|
|
|
2008-08-15 12:55:03 +08:00
|
|
|
POINT pt;
|
|
|
|
GetCursorPos(&pt);
|
|
|
|
HWND hw = WindowFromPoint(pt);
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-08-15 12:55:03 +08:00
|
|
|
// Make the mousewheel work according to which window the mouse is
|
|
|
|
// over, not according to which window is active.
|
|
|
|
bool inTextWindow;
|
|
|
|
if(hw == TextWnd) {
|
|
|
|
inTextWindow = true;
|
|
|
|
} else if(hw == GraphicsWnd) {
|
|
|
|
inTextWindow = false;
|
|
|
|
} else if(GetForegroundWindow() == TextWnd) {
|
|
|
|
inTextWindow = true;
|
|
|
|
} else {
|
|
|
|
inTextWindow = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(inTextWindow) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < abs(delta/40); i++) {
|
|
|
|
HandleTextWindowScrollBar(delta > 0 ? SB_LINEUP : SB_LINEDOWN, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SS.GW.MouseScroll(LastMousePos.x, LastMousePos.y, delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
LRESULT CALLBACK TextWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (msg) {
|
2008-04-27 17:31:56 +08:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
break;
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_DESTROY:
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
SolveSpaceUI::MenuFile(Command::EXIT);
|
2008-03-25 18:02:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_PAINT: {
|
2010-04-26 15:52:49 +08:00
|
|
|
// Actually paint the text window, with gl.
|
2016-11-16 10:22:10 +08:00
|
|
|
PaintTextWnd();
|
2010-04-26 15:52:49 +08:00
|
|
|
// And then just make Windows happy.
|
2008-03-25 18:02:13 +08:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc = BeginPaint(hwnd, &ps);
|
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
break;
|
|
|
|
}
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
case WM_SIZING: {
|
|
|
|
RECT *r = (RECT *)lParam;
|
|
|
|
int hc = (r->bottom - r->top) - ClientIsSmallerBy;
|
2010-04-26 15:52:49 +08:00
|
|
|
int extra = hc % (SS.TW.LINE_HEIGHT/2);
|
2008-03-25 18:02:13 +08:00
|
|
|
switch(wParam) {
|
|
|
|
case WMSZ_BOTTOM:
|
|
|
|
case WMSZ_BOTTOMLEFT:
|
|
|
|
case WMSZ_BOTTOMRIGHT:
|
|
|
|
r->bottom -= extra;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WMSZ_TOP:
|
|
|
|
case WMSZ_TOPLEFT:
|
|
|
|
case WMSZ_TOPRIGHT:
|
|
|
|
r->top += extra;
|
|
|
|
break;
|
|
|
|
}
|
2010-04-26 15:52:49 +08:00
|
|
|
int tooNarrow = (SS.TW.MIN_COLS*SS.TW.CHAR_WIDTH) -
|
|
|
|
(r->right - r->left);
|
2008-04-11 20:47:14 +08:00
|
|
|
if(tooNarrow >= 0) {
|
|
|
|
switch(wParam) {
|
|
|
|
case WMSZ_RIGHT:
|
|
|
|
case WMSZ_BOTTOMRIGHT:
|
|
|
|
case WMSZ_TOPRIGHT:
|
|
|
|
r->right += tooNarrow;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WMSZ_LEFT:
|
|
|
|
case WMSZ_BOTTOMLEFT:
|
|
|
|
case WMSZ_TOPLEFT:
|
|
|
|
r->left -= tooNarrow;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-25 18:02:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-03 13:04:42 +08:00
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
SS.TW.MouseLeave();
|
|
|
|
break;
|
|
|
|
|
2008-03-28 18:00:37 +08:00
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_MOUSEMOVE: {
|
2010-05-03 13:04:42 +08:00
|
|
|
// We need this in order to get the WM_MOUSELEAVE
|
2015-03-27 23:31:23 +08:00
|
|
|
TRACKMOUSEEVENT tme = {};
|
2010-05-03 13:04:42 +08:00
|
|
|
tme.cbSize = sizeof(tme);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
|
|
|
tme.hwndTrack = TextWnd;
|
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
|
|
|
|
// And process the actual message
|
2008-03-28 18:00:37 +08:00
|
|
|
int x = LOWORD(lParam);
|
|
|
|
int y = HIWORD(lParam);
|
2010-07-21 13:04:03 +08:00
|
|
|
SS.TW.MouseEvent(msg == WM_LBUTTONDOWN, wParam & MK_LBUTTON, x, y);
|
2008-03-28 18:00:37 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
case WM_SIZE: {
|
|
|
|
RECT r;
|
|
|
|
GetWindowRect(TextWndScrollBar, &r);
|
|
|
|
int sw = r.right - r.left;
|
|
|
|
GetClientRect(hwnd, &r);
|
|
|
|
MoveWindow(TextWndScrollBar, r.right - sw, r.top, sw,
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
(r.bottom - r.top), true);
|
2008-05-27 14:36:59 +08:00
|
|
|
// If the window is growing, then the scrollbar position may
|
|
|
|
// be moving, so it's as if we're dragging the scrollbar.
|
2013-08-27 04:09:15 +08:00
|
|
|
HandleTextWindowScrollBar((WPARAM)-1, -1);
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
InvalidateRect(TextWnd, NULL, false);
|
2008-03-25 18:02:13 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2008-08-15 12:55:03 +08:00
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
MouseWheel(GET_WHEEL_DELTA_WPARAM(wParam));
|
2008-02-10 22:06:54 +08:00
|
|
|
break;
|
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
case WM_VSCROLL:
|
|
|
|
HandleTextWindowScrollBar(wParam, lParam);
|
|
|
|
break;
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
default:
|
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
static std::string EditControlText(HWND hwnd)
|
|
|
|
{
|
|
|
|
std::wstring result;
|
|
|
|
result.resize(GetWindowTextLength(hwnd));
|
|
|
|
GetWindowTextW(hwnd, &result[0], result.length() + 1);
|
|
|
|
return Narrow(result);
|
|
|
|
}
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
static bool ProcessKeyDown(WPARAM wParam)
|
2008-04-12 23:17:58 +08:00
|
|
|
{
|
2008-04-21 18:12:04 +08:00
|
|
|
if(GraphicsEditControlIsVisible() && wParam != VK_ESCAPE) {
|
|
|
|
if(wParam == VK_RETURN) {
|
2015-12-27 15:51:28 +08:00
|
|
|
SS.GW.EditControlDone(EditControlText(GraphicsEditControl).c_str());
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return true;
|
2008-04-21 18:12:04 +08:00
|
|
|
} else {
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return false;
|
2008-04-21 18:12:04 +08:00
|
|
|
}
|
|
|
|
}
|
2008-05-27 14:36:59 +08:00
|
|
|
if(TextEditControlIsVisible() && wParam != VK_ESCAPE) {
|
|
|
|
if(wParam == VK_RETURN) {
|
2015-12-27 15:51:28 +08:00
|
|
|
SS.TW.EditControlDone(EditControlText(TextEditControl).c_str());
|
2008-05-27 14:36:59 +08:00
|
|
|
} else {
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return false;
|
2008-05-27 14:36:59 +08:00
|
|
|
}
|
|
|
|
}
|
2008-04-21 18:12:04 +08:00
|
|
|
|
2008-04-12 23:17:58 +08:00
|
|
|
int c;
|
|
|
|
switch(wParam) {
|
2009-09-28 18:01:34 +08:00
|
|
|
case VK_OEM_PLUS: c = '+'; break;
|
|
|
|
case VK_OEM_MINUS: c = '-'; break;
|
|
|
|
case VK_ESCAPE: c = 27; break;
|
|
|
|
case VK_OEM_1: c = ';'; break;
|
2009-09-29 19:35:19 +08:00
|
|
|
case VK_OEM_3: c = '`'; break;
|
2009-09-28 18:01:34 +08:00
|
|
|
case VK_OEM_4: c = '['; break;
|
|
|
|
case VK_OEM_6: c = ']'; break;
|
|
|
|
case VK_OEM_5: c = '\\'; break;
|
2009-09-29 19:35:19 +08:00
|
|
|
case VK_OEM_PERIOD: c = '.'; break;
|
2009-09-28 18:01:34 +08:00
|
|
|
case VK_SPACE: c = ' '; break;
|
|
|
|
case VK_DELETE: c = 127; break;
|
|
|
|
case VK_TAB: c = '\t'; break;
|
|
|
|
|
|
|
|
case VK_BROWSER_BACK:
|
2013-09-19 04:41:23 +08:00
|
|
|
case VK_BACK: c = '\b'; break;
|
2008-04-12 23:17:58 +08:00
|
|
|
|
2009-01-02 12:06:47 +08:00
|
|
|
case VK_F1:
|
|
|
|
case VK_F2:
|
|
|
|
case VK_F3:
|
|
|
|
case VK_F4:
|
|
|
|
case VK_F5:
|
|
|
|
case VK_F6:
|
|
|
|
case VK_F7:
|
|
|
|
case VK_F8:
|
|
|
|
case VK_F9:
|
|
|
|
case VK_F10:
|
|
|
|
case VK_F11:
|
2013-08-27 04:09:15 +08:00
|
|
|
case VK_F12: c = ((int)wParam - VK_F1) + 0xf1; break;
|
2009-01-02 12:06:47 +08:00
|
|
|
|
2008-07-10 15:26:41 +08:00
|
|
|
// These overlap with some character codes that I'm using, so
|
|
|
|
// don't let them trigger by accident.
|
|
|
|
case VK_F16:
|
|
|
|
case VK_INSERT:
|
|
|
|
case VK_EXECUTE:
|
|
|
|
case VK_APPS:
|
|
|
|
case VK_LWIN:
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
case VK_RWIN: return false;
|
2008-07-10 15:26:41 +08:00
|
|
|
|
2008-04-12 23:17:58 +08:00
|
|
|
default:
|
2013-08-27 04:09:15 +08:00
|
|
|
c = (int)wParam;
|
2008-04-12 23:17:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-09-21 01:54:57 +08:00
|
|
|
if(GetAsyncKeyState(VK_SHIFT) & 0x8000) c |= GraphicsWindow::SHIFT_MASK;
|
|
|
|
if(GetAsyncKeyState(VK_CONTROL) & 0x8000) c |= GraphicsWindow::CTRL_MASK;
|
2008-04-12 23:17:58 +08:00
|
|
|
|
2013-09-21 02:01:31 +08:00
|
|
|
switch(c) {
|
|
|
|
case GraphicsWindow::SHIFT_MASK | '.': c = '>'; break;
|
|
|
|
}
|
|
|
|
|
2008-04-12 23:17:58 +08:00
|
|
|
for(int i = 0; SS.GW.menu[i].level >= 0; i++) {
|
|
|
|
if(c == SS.GW.menu[i].accel) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
(SS.GW.menu[i].fn)((Command)SS.GW.menu[i].id);
|
2008-04-12 23:17:58 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
if(SS.GW.KeyDown(c)) return true;
|
2009-09-28 18:01:34 +08:00
|
|
|
|
2008-04-12 23:17:58 +08:00
|
|
|
// No accelerator; process the key as normal.
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return false;
|
2008-04-12 23:17:58 +08:00
|
|
|
}
|
|
|
|
|
2016-05-05 13:54:05 +08:00
|
|
|
void SolveSpace::ToggleMenuBar()
|
2013-10-25 13:04:16 +08:00
|
|
|
{
|
|
|
|
// Implement me
|
|
|
|
}
|
2016-05-05 13:54:05 +08:00
|
|
|
bool SolveSpace::MenuBarIsVisible()
|
2013-10-25 13:04:16 +08:00
|
|
|
{
|
|
|
|
// Implement me
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::ShowTextWindow(bool visible)
|
2008-04-27 13:00:12 +08:00
|
|
|
{
|
|
|
|
ShowWindow(TextWnd, visible ? SW_SHOWNOACTIVATE : SW_HIDE);
|
|
|
|
}
|
|
|
|
|
Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
* It is now possible to port SolveSpace to a later version of
OpenGL, such as OpenGLES 2, so that it runs on platforms that
only have that OpenGL version;
* The majority of geometry is now rendered without references to
the camera in C++ code, so a renderer can now submit it to
the video card once and re-rasterize with a different projection
matrix every time the projection is changed, avoiding expensive
reuploads;
* The DOGD (draw or get distance) interface is now
a straightforward Canvas implementation;
* There are no more direct references to SS.GW.(projection)
in sketch rendering code, which allows rendering to multiple
viewports;
* There are no more unnecessary framebuffer flips on CPU on Cocoa
and GTK;
* The platform-dependent GL code is now confined to rendergl1.cpp.
* The Microsoft and Apple headers required by it that are prone to
identifier conflicts are no longer included globally;
* The rendergl1.cpp implementation can now be omitted from
compilation to run SolveSpace headless or with a different
OpenGL version.
Note these implementation details of Canvas:
* GetCamera currently always returns a reference to the field
`Camera camera;`. This is so that a future renderer that caches
geometry in the video memory can define it as asserting, which
would provide assurance against code that could accidentally
put something projection-dependent in the cache;
* Line and triangle rendering is specified through a level of
indirection, hStroke and hFill. This is so that a future renderer
that batches geometry could cheaply group identical styles.
* DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
This is so that a future renderer into an output format that
uses 2d transforms (e.g. SVG) could easily derive those.
Some additional internal changes were required to enable this:
* Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
This is so that the renderer could cache uploaded textures
between API calls, which requires it to capture a (weak)
reference.
* The PlatformPathEqual function was properly extracted into
platform-specific code. This is so that the <windows.h> header
could be included only where needed (in platform/w32* as well
as rendergl1.cpp).
* The SBsp{2,3}::DebugDraw functions were removed. They can be
rewritten using the Canvas API if they are ever needed.
While no visual changes were originally intended, some minor fixes
happened anyway:
* The "emphasis" yellow line from top-left corner is now correctly
rendered much wider.
* The marquee rectangle is now pixel grid aligned.
* The hidden entities now do not clobber the depth buffer, removing
some minor artifacts.
* The workplane "tab" now scales with the font used to render
the workplane name.
* The workplane name font is now taken from the normals style.
* Workplane and constraint line stipple is insignificantly
different. This is so that it can reuse the existing stipple
codepaths; rendering of workplanes and constraints predates
those.
Some debug functionality was added:
* In graphics window, an fps counter that becomes red when
rendering under 60fps is drawn.
2016-05-31 08:55:13 +08:00
|
|
|
const bool SolveSpace::FLIP_FRAMEBUFFER = false;
|
|
|
|
|
2016-11-16 10:22:10 +08:00
|
|
|
static void CreateGlContext(HWND hwnd, EGLDisplay *eglDisplay, EGLSurface *eglSurface,
|
|
|
|
EGLContext *eglContext) {
|
|
|
|
ssassert(eglBindAPI(EGL_OPENGL_ES_API), "Cannot bind EGL API");
|
|
|
|
|
|
|
|
*eglDisplay = eglGetDisplay(GetDC(hwnd));
|
|
|
|
ssassert(eglInitialize(*eglDisplay, NULL, NULL), "Cannot initialize EGL");
|
|
|
|
|
|
|
|
EGLint configAttributes[] = {
|
|
|
|
EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER,
|
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
|
|
|
EGL_DEPTH_SIZE, 24,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
EGLint numConfigs;
|
|
|
|
EGLConfig windowConfig;
|
|
|
|
ssassert(eglChooseConfig(*eglDisplay, configAttributes, &windowConfig, 1, &numConfigs),
|
|
|
|
"Cannot choose EGL configuration");
|
|
|
|
|
|
|
|
EGLint surfaceAttributes[] = {
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
*eglSurface = eglCreateWindowSurface(*eglDisplay, windowConfig, hwnd, surfaceAttributes);
|
|
|
|
ssassert(eglSurface != EGL_NO_SURFACE, "Cannot create EGL window surface");
|
|
|
|
|
|
|
|
EGLint contextAttributes[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
*eglContext = eglCreateContext(*eglDisplay, windowConfig, NULL, contextAttributes);
|
|
|
|
ssassert(eglContext != EGL_NO_CONTEXT, "Cannot create EGL context");
|
|
|
|
|
|
|
|
eglMakeCurrent(*eglDisplay, *eglSurface, *eglSurface, *eglContext);
|
2008-03-27 17:53:51 +08:00
|
|
|
}
|
|
|
|
|
2016-05-05 13:54:05 +08:00
|
|
|
void SolveSpace::PaintGraphics()
|
2008-06-12 15:31:41 +08:00
|
|
|
{
|
2010-05-03 13:04:42 +08:00
|
|
|
SS.GW.Paint();
|
2016-11-16 10:22:10 +08:00
|
|
|
eglSwapBuffers(GraphicsGlDisplay, GraphicsGlSurface);
|
2008-04-18 19:11:48 +08:00
|
|
|
}
|
2016-05-05 13:54:05 +08:00
|
|
|
void SolveSpace::InvalidateGraphics()
|
2010-04-26 15:52:49 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
InvalidateRect(GraphicsWnd, NULL, false);
|
2010-04-26 15:52:49 +08:00
|
|
|
}
|
2008-05-16 12:54:47 +08:00
|
|
|
|
2016-05-05 13:54:05 +08:00
|
|
|
void SolveSpace::ToggleFullScreen()
|
2013-10-25 13:04:16 +08:00
|
|
|
{
|
|
|
|
// Implement me
|
|
|
|
}
|
2016-05-05 13:54:05 +08:00
|
|
|
bool SolveSpace::FullScreenIsActive()
|
2013-10-25 13:04:16 +08:00
|
|
|
{
|
|
|
|
// Implement me
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-05 13:54:05 +08:00
|
|
|
void SolveSpace::InvalidateText()
|
2008-04-11 20:47:14 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
InvalidateRect(TextWnd, NULL, false);
|
2008-04-11 20:47:14 +08:00
|
|
|
}
|
2008-03-27 17:53:51 +08:00
|
|
|
|
2016-04-16 08:10:32 +08:00
|
|
|
static void ShowEditControl(HWND h, int x, int y, int fontHeight, int minWidthChars,
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
bool isMonospace, const std::wstring &s) {
|
|
|
|
static HFONT hf;
|
|
|
|
if(hf) DeleteObject(hf);
|
|
|
|
hf = CreateFontW(-fontHeight, 0, 0, 0,
|
|
|
|
FW_REGULAR, false, false, false, ANSI_CHARSET,
|
|
|
|
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
|
|
|
|
DEFAULT_QUALITY, FF_DONTCARE, isMonospace ? L"Lucida Console" : L"Arial");
|
|
|
|
if(hf) SendMessage(h, WM_SETFONT, (WPARAM)hf, false);
|
|
|
|
else SendMessage(h, WM_SETFONT, (WPARAM)(HFONT)GetStockObject(SYSTEM_FONT), false);
|
|
|
|
SendMessage(h, EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN, 0);
|
|
|
|
|
|
|
|
HDC hdc = GetDC(h);
|
2016-04-16 08:10:32 +08:00
|
|
|
TEXTMETRICW tm;
|
|
|
|
SIZE ts;
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
SelectObject(hdc, hf);
|
|
|
|
GetTextMetrics(hdc, &tm);
|
2016-04-16 08:10:32 +08:00
|
|
|
GetTextExtentPoint32W(hdc, s.c_str(), s.length(), &ts);
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
ReleaseDC(h, hdc);
|
|
|
|
|
2016-04-16 08:10:32 +08:00
|
|
|
RECT rc;
|
|
|
|
rc.left = x;
|
|
|
|
rc.top = y - tm.tmAscent;
|
|
|
|
// Add one extra char width to avoid scrolling.
|
|
|
|
rc.right = x + std::max(tm.tmAveCharWidth * minWidthChars,
|
|
|
|
ts.cx + tm.tmAveCharWidth);
|
|
|
|
rc.bottom = y + tm.tmDescent;
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
|
2016-04-16 08:10:32 +08:00
|
|
|
AdjustWindowRectEx(&rc, 0, false, WS_EX_CLIENTEDGE);
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
MoveWindow(h, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, true);
|
2008-05-27 14:36:59 +08:00
|
|
|
ShowWindow(h, SW_SHOW);
|
2015-12-27 15:51:28 +08:00
|
|
|
if(!s.empty()) {
|
|
|
|
SendMessage(h, WM_SETTEXT, 0, (LPARAM)s.c_str());
|
|
|
|
SendMessage(h, EM_SETSEL, 0, s.length());
|
2010-04-26 15:52:49 +08:00
|
|
|
SetFocus(h);
|
|
|
|
}
|
2008-05-27 14:36:59 +08:00
|
|
|
}
|
2015-11-06 16:40:12 +08:00
|
|
|
void SolveSpace::ShowTextEditControl(int x, int y, const std::string &str)
|
2008-05-27 14:36:59 +08:00
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
if(GraphicsEditControlIsVisible()) return;
|
2008-05-27 14:36:59 +08:00
|
|
|
|
2016-04-16 08:10:32 +08:00
|
|
|
ShowEditControl(TextEditControl, x, y, TextWindow::CHAR_HEIGHT, 30,
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
/*isMonospace=*/true, Widen(str));
|
2008-05-27 14:36:59 +08:00
|
|
|
}
|
2016-05-05 13:54:05 +08:00
|
|
|
void SolveSpace::HideTextEditControl()
|
2008-05-27 14:36:59 +08:00
|
|
|
{
|
|
|
|
ShowWindow(TextEditControl, SW_HIDE);
|
|
|
|
}
|
2016-05-05 13:54:05 +08:00
|
|
|
bool SolveSpace::TextEditControlIsVisible()
|
2008-05-27 14:36:59 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return IsWindowVisible(TextEditControl) ? true : false;
|
2008-05-27 14:36:59 +08:00
|
|
|
}
|
2016-04-16 08:10:32 +08:00
|
|
|
void SolveSpace::ShowGraphicsEditControl(int x, int y, int fontHeight, int minWidthChars,
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
const std::string &str)
|
2008-04-21 18:12:04 +08:00
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
if(GraphicsEditControlIsVisible()) return;
|
2008-05-27 14:36:59 +08:00
|
|
|
|
2008-04-21 18:12:04 +08:00
|
|
|
RECT r;
|
|
|
|
GetClientRect(GraphicsWnd, &r);
|
|
|
|
x = x + (r.right - r.left)/2;
|
|
|
|
y = (r.bottom - r.top)/2 - y;
|
|
|
|
|
2016-04-16 08:10:32 +08:00
|
|
|
ShowEditControl(GraphicsEditControl, x, y, fontHeight, minWidthChars,
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
/*isMonospace=*/false, Widen(str));
|
2008-04-21 18:12:04 +08:00
|
|
|
}
|
2016-05-05 13:54:05 +08:00
|
|
|
void SolveSpace::HideGraphicsEditControl()
|
2008-04-21 18:12:04 +08:00
|
|
|
{
|
|
|
|
ShowWindow(GraphicsEditControl, SW_HIDE);
|
|
|
|
}
|
2016-05-05 13:54:05 +08:00
|
|
|
bool SolveSpace::GraphicsEditControlIsVisible()
|
2008-04-21 18:12:04 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return IsWindowVisible(GraphicsEditControl) ? true : false;
|
2008-04-21 18:12:04 +08:00
|
|
|
}
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (msg) {
|
2008-03-27 17:53:51 +08:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SIZE:
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
InvalidateRect(GraphicsWnd, NULL, false);
|
2008-03-27 17:53:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_PAINT: {
|
2010-04-26 15:52:49 +08:00
|
|
|
// Actually paint the window, with gl.
|
2008-05-16 12:54:47 +08:00
|
|
|
PaintGraphics();
|
2010-04-26 15:52:49 +08:00
|
|
|
// And make Windows happy.
|
2008-03-27 17:53:51 +08:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc = BeginPaint(hwnd, &ps);
|
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-02 18:38:36 +08:00
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
SS.GW.MouseLeave();
|
|
|
|
break;
|
|
|
|
|
2008-03-27 17:53:51 +08:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
case WM_LBUTTONDOWN:
|
2008-04-22 18:53:42 +08:00
|
|
|
case WM_LBUTTONUP:
|
2008-04-21 18:12:04 +08:00
|
|
|
case WM_LBUTTONDBLCLK:
|
2008-07-06 15:56:24 +08:00
|
|
|
case WM_RBUTTONDOWN:
|
2009-09-23 18:59:59 +08:00
|
|
|
case WM_RBUTTONUP:
|
2008-03-27 17:53:51 +08:00
|
|
|
case WM_MBUTTONDOWN: {
|
|
|
|
int x = LOWORD(lParam);
|
|
|
|
int y = HIWORD(lParam);
|
|
|
|
|
2009-01-02 18:38:36 +08:00
|
|
|
// We need this in order to get the WM_MOUSELEAVE
|
2015-03-27 23:31:23 +08:00
|
|
|
TRACKMOUSEEVENT tme = {};
|
2009-01-02 18:38:36 +08:00
|
|
|
tme.cbSize = sizeof(tme);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
|
|
|
tme.hwndTrack = GraphicsWnd;
|
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
|
|
|
|
// Convert to xy (vs. ij) style coordinates, with (0, 0) at center
|
2008-03-27 17:53:51 +08:00
|
|
|
RECT r;
|
|
|
|
GetClientRect(GraphicsWnd, &r);
|
|
|
|
x = x - (r.right - r.left)/2;
|
|
|
|
y = (r.bottom - r.top)/2 - y;
|
|
|
|
|
2008-04-01 18:48:44 +08:00
|
|
|
LastMousePos.x = x;
|
|
|
|
LastMousePos.y = y;
|
|
|
|
|
2008-03-27 17:53:51 +08:00
|
|
|
if(msg == WM_LBUTTONDOWN) {
|
|
|
|
SS.GW.MouseLeftDown(x, y);
|
2008-04-22 18:53:42 +08:00
|
|
|
} else if(msg == WM_LBUTTONUP) {
|
|
|
|
SS.GW.MouseLeftUp(x, y);
|
2008-04-21 18:12:04 +08:00
|
|
|
} else if(msg == WM_LBUTTONDBLCLK) {
|
|
|
|
SS.GW.MouseLeftDoubleClick(x, y);
|
2008-07-06 15:56:24 +08:00
|
|
|
} else if(msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) {
|
|
|
|
SS.GW.MouseMiddleOrRightDown(x, y);
|
2009-09-23 18:59:59 +08:00
|
|
|
} else if(msg == WM_RBUTTONUP) {
|
|
|
|
SS.GW.MouseRightUp(x, y);
|
2008-03-27 17:53:51 +08:00
|
|
|
} else if(msg == WM_MOUSEMOVE) {
|
|
|
|
SS.GW.MouseMoved(x, y,
|
|
|
|
!!(wParam & MK_LBUTTON),
|
|
|
|
!!(wParam & MK_MBUTTON),
|
|
|
|
!!(wParam & MK_RBUTTON),
|
|
|
|
!!(wParam & MK_SHIFT),
|
|
|
|
!!(wParam & MK_CONTROL));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-08-15 12:55:03 +08:00
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
MouseWheel(GET_WHEEL_DELTA_WPARAM(wParam));
|
2008-04-01 18:48:44 +08:00
|
|
|
break;
|
2008-08-15 12:55:03 +08:00
|
|
|
|
2008-04-12 23:17:58 +08:00
|
|
|
case WM_COMMAND: {
|
2008-04-21 18:12:04 +08:00
|
|
|
if(HIWORD(wParam) == 0) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
Command id = (Command)LOWORD(wParam);
|
|
|
|
if(((uint32_t)id >= (uint32_t)Command::RECENT_OPEN &&
|
|
|
|
(uint32_t)id < ((uint32_t)Command::RECENT_OPEN + MAX_RECENT))) {
|
2015-03-24 01:49:04 +08:00
|
|
|
SolveSpaceUI::MenuFile(id);
|
2008-05-28 18:10:31 +08:00
|
|
|
break;
|
|
|
|
}
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
if(((uint32_t)id >= (uint32_t)Command::RECENT_LINK &&
|
|
|
|
(uint32_t)id < ((uint32_t)Command::RECENT_LINK + MAX_RECENT))) {
|
2008-05-28 18:10:31 +08:00
|
|
|
Group::MenuGroup(id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
int i;
|
|
|
|
for(i = 0; SS.GW.menu[i].level >= 0; i++) {
|
2008-04-21 18:12:04 +08:00
|
|
|
if(id == SS.GW.menu[i].id) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
(SS.GW.menu[i].fn)((Command)id);
|
2008-04-21 18:12:04 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-04-12 23:17:58 +08:00
|
|
|
}
|
2016-05-19 06:51:36 +08:00
|
|
|
ssassert(SS.GW.menu[i].level >= 0, "Cannot find command in the menu");
|
2008-04-12 23:17:58 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-03-27 17:53:51 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_DESTROY:
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
SolveSpaceUI::MenuFile(Command::EXIT);
|
2008-03-25 18:02:13 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-04-18 19:11:48 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Common dialog routines, to open or save a file.
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-05-04 11:12:06 +08:00
|
|
|
static std::string ConvertFilters(const FileFilter ssFilters[]) {
|
|
|
|
std::string filter;
|
|
|
|
for(const FileFilter *ssFilter = ssFilters; ssFilter->name; ssFilter++) {
|
|
|
|
std::string desc, patterns;
|
|
|
|
for(const char *const *ssPattern = ssFilter->patterns; *ssPattern; ssPattern++) {
|
|
|
|
std::string pattern = "*." + std::string(*ssPattern);
|
|
|
|
if(desc == "")
|
|
|
|
desc = pattern;
|
|
|
|
else
|
|
|
|
desc += ", " + pattern;
|
|
|
|
if(patterns == "")
|
|
|
|
patterns = pattern;
|
|
|
|
else
|
|
|
|
patterns += ";" + pattern;
|
|
|
|
}
|
|
|
|
filter += std::string(ssFilter->name) + " (" + desc + ")" + '\0';
|
|
|
|
filter += patterns + '\0';
|
|
|
|
}
|
|
|
|
filter += '\0';
|
|
|
|
return filter;
|
2015-12-27 15:51:28 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 11:12:06 +08:00
|
|
|
static bool OpenSaveFile(bool isOpen, std::string *filename, const std::string &defExtension,
|
|
|
|
const FileFilter filters[]) {
|
2016-11-17 20:21:41 +08:00
|
|
|
std::string activeExtension = defExtension;
|
|
|
|
if(activeExtension == "") {
|
|
|
|
activeExtension = filters[0].patterns[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring initialFilenameW;
|
|
|
|
if(filename->empty()) {
|
|
|
|
initialFilenameW = Widen("untitled");
|
|
|
|
} else {
|
|
|
|
initialFilenameW = Widen(Dirname(*filename) + PATH_SEP +
|
|
|
|
Basename(*filename, /*stripExtension=*/true));
|
|
|
|
}
|
|
|
|
std::wstring selPatternW = Widen(ConvertFilters(filters));
|
|
|
|
std::wstring defExtensionW = Widen(defExtension);
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
// UNC paths may be as long as 32767 characters.
|
2015-12-27 09:03:24 +08:00
|
|
|
// Unfortunately, the Get*FileName API does not provide any way to use it
|
|
|
|
// except with a preallocated buffer of fixed size, so we use something
|
|
|
|
// reasonably large.
|
2015-12-27 15:51:28 +08:00
|
|
|
const int len = 32768;
|
|
|
|
wchar_t filenameC[len] = {};
|
2016-11-17 20:21:41 +08:00
|
|
|
wcsncpy(filenameC, initialFilenameW.c_str(), len - 1);
|
2008-04-18 19:11:48 +08:00
|
|
|
|
2015-12-27 09:03:24 +08:00
|
|
|
OPENFILENAME ofn = {};
|
2008-04-18 19:11:48 +08:00
|
|
|
ofn.lStructSize = sizeof(ofn);
|
|
|
|
ofn.hInstance = Instance;
|
|
|
|
ofn.hwndOwner = GraphicsWnd;
|
2015-12-27 15:51:28 +08:00
|
|
|
ofn.lpstrFilter = selPatternW.c_str();
|
|
|
|
ofn.lpstrDefExt = defExtensionW.c_str();
|
2015-12-27 09:03:24 +08:00
|
|
|
ofn.lpstrFile = filenameC;
|
2015-12-27 15:51:28 +08:00
|
|
|
ofn.nMaxFile = len;
|
2008-04-18 19:11:48 +08:00
|
|
|
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(GraphicsWnd, false);
|
|
|
|
EnableWindow(TextWnd, false);
|
2008-06-25 13:14:49 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
BOOL r;
|
|
|
|
if(isOpen) {
|
|
|
|
r = GetOpenFileNameW(&ofn);
|
|
|
|
} else {
|
|
|
|
r = GetSaveFileNameW(&ofn);
|
|
|
|
}
|
2008-06-25 13:14:49 +08:00
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(TextWnd, true);
|
|
|
|
EnableWindow(GraphicsWnd, true);
|
2008-04-18 19:11:48 +08:00
|
|
|
SetForegroundWindow(GraphicsWnd);
|
2008-06-25 13:14:49 +08:00
|
|
|
|
2016-05-04 11:12:06 +08:00
|
|
|
if(r) *filename = Narrow(filenameC);
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return r ? true : false;
|
2008-04-18 19:11:48 +08:00
|
|
|
}
|
2015-03-29 12:46:57 +08:00
|
|
|
|
2016-05-04 11:12:06 +08:00
|
|
|
bool SolveSpace::GetOpenFile(std::string *filename, const std::string &defExtension,
|
|
|
|
const FileFilter filters[])
|
2008-04-18 19:11:48 +08:00
|
|
|
{
|
2016-05-25 20:08:19 +08:00
|
|
|
return OpenSaveFile(/*isOpen=*/true, filename, defExtension, filters);
|
2015-12-27 15:51:28 +08:00
|
|
|
}
|
2008-06-25 13:14:49 +08:00
|
|
|
|
2016-05-04 11:12:06 +08:00
|
|
|
bool SolveSpace::GetSaveFile(std::string *filename, const std::string &defExtension,
|
|
|
|
const FileFilter filters[])
|
2015-12-27 15:51:28 +08:00
|
|
|
{
|
2016-05-25 20:08:19 +08:00
|
|
|
return OpenSaveFile(/*isOpen=*/false, filename, defExtension, filters);
|
2008-04-18 19:11:48 +08:00
|
|
|
}
|
2015-03-29 12:46:57 +08:00
|
|
|
|
2016-05-05 13:54:05 +08:00
|
|
|
DialogChoice SolveSpace::SaveFileYesNoCancel()
|
2008-04-18 19:11:48 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(GraphicsWnd, false);
|
|
|
|
EnableWindow(TextWnd, false);
|
2008-06-25 13:14:49 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
int r = MessageBoxW(GraphicsWnd,
|
2016-01-11 20:18:18 +08:00
|
|
|
L"The file has changed since it was last saved.\n\n"
|
2015-12-27 15:51:28 +08:00
|
|
|
L"Do you want to save the changes?", L"SolveSpace",
|
2008-04-18 19:11:48 +08:00
|
|
|
MB_YESNOCANCEL | MB_ICONWARNING);
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(TextWnd, true);
|
|
|
|
EnableWindow(GraphicsWnd, true);
|
2008-06-25 13:14:49 +08:00
|
|
|
SetForegroundWindow(GraphicsWnd);
|
|
|
|
|
2013-09-19 04:49:32 +08:00
|
|
|
switch(r) {
|
2016-01-11 20:18:18 +08:00
|
|
|
case IDYES:
|
|
|
|
return DIALOG_YES;
|
|
|
|
case IDNO:
|
|
|
|
return DIALOG_NO;
|
|
|
|
case IDCANCEL:
|
|
|
|
default:
|
|
|
|
return DIALOG_CANCEL;
|
2013-09-19 04:49:32 +08:00
|
|
|
}
|
2008-06-25 13:14:49 +08:00
|
|
|
}
|
2008-06-30 17:09:17 +08:00
|
|
|
|
2016-05-05 13:54:05 +08:00
|
|
|
DialogChoice SolveSpace::LoadAutosaveYesNo()
|
2015-03-29 12:46:57 +08:00
|
|
|
{
|
|
|
|
EnableWindow(GraphicsWnd, false);
|
|
|
|
EnableWindow(TextWnd, false);
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
int r = MessageBoxW(GraphicsWnd,
|
2016-01-11 20:18:18 +08:00
|
|
|
L"An autosave file is availible for this project.\n\n"
|
2015-12-27 15:51:28 +08:00
|
|
|
L"Do you want to load the autosave file instead?", L"SolveSpace",
|
2015-03-29 12:46:57 +08:00
|
|
|
MB_YESNO | MB_ICONWARNING);
|
|
|
|
|
|
|
|
EnableWindow(TextWnd, true);
|
|
|
|
EnableWindow(GraphicsWnd, true);
|
|
|
|
SetForegroundWindow(GraphicsWnd);
|
|
|
|
|
|
|
|
switch (r) {
|
2016-01-11 20:18:18 +08:00
|
|
|
case IDYES:
|
|
|
|
return DIALOG_YES;
|
|
|
|
case IDNO:
|
|
|
|
default:
|
|
|
|
return DIALOG_NO;
|
2015-03-29 12:46:57 +08:00
|
|
|
}
|
2016-01-11 20:18:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DialogChoice SolveSpace::LocateImportedFileYesNoCancel(const std::string &filename,
|
|
|
|
bool canCancel) {
|
|
|
|
EnableWindow(GraphicsWnd, false);
|
|
|
|
EnableWindow(TextWnd, false);
|
|
|
|
|
|
|
|
std::string message =
|
2016-05-07 13:27:54 +08:00
|
|
|
"The linked file " + filename + " is not present.\n\n"
|
2016-01-11 20:18:18 +08:00
|
|
|
"Do you want to locate it manually?\n\n"
|
|
|
|
"If you select \"No\", any geometry that depends on "
|
|
|
|
"the missing file will be removed.";
|
2015-03-29 12:46:57 +08:00
|
|
|
|
2016-01-11 20:18:18 +08:00
|
|
|
int r = MessageBoxW(GraphicsWnd, Widen(message).c_str(), L"SolveSpace",
|
|
|
|
(canCancel ? MB_YESNOCANCEL : MB_YESNO) | MB_ICONWARNING);
|
|
|
|
|
|
|
|
EnableWindow(TextWnd, true);
|
|
|
|
EnableWindow(GraphicsWnd, true);
|
|
|
|
SetForegroundWindow(GraphicsWnd);
|
|
|
|
|
|
|
|
switch(r) {
|
|
|
|
case IDYES:
|
|
|
|
return DIALOG_YES;
|
|
|
|
case IDNO:
|
|
|
|
return DIALOG_NO;
|
|
|
|
case IDCANCEL:
|
|
|
|
default:
|
|
|
|
return DIALOG_CANCEL;
|
|
|
|
}
|
2015-03-29 12:46:57 +08:00
|
|
|
}
|
|
|
|
|
Rewrite TTF to Bezier conversion using Freetype.
Benefits:
* Much simpler code.
* Handles the entire TTF spec, not just a small subset that
only really worked well on Windows fonts.
* Handles all character sets as well as accented characters.
* Much faster parsing, since Freetype lazily loads and
caches glyphs.
* Support for basically every kind of font that was invented,
not just TTF.
Note that OpenType features, e.g. ligatures, are not yet supported.
This means that Arabic and Devanagari scripts, among others, will
not be rendered in their proper form.
RTL scripts are not supported either, neither in TTF nor in
the text window. Adding RTL support is comparatively easy, but
given that Arabic would not be legibly rendered anyway, this is not
done so far.
2016-01-30 09:42:44 +08:00
|
|
|
std::vector<std::string> SolveSpace::GetFontFiles() {
|
|
|
|
std::vector<std::string> fonts;
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
std::wstring fontsDir(MAX_PATH, '\0');
|
|
|
|
fontsDir.resize(GetWindowsDirectoryW(&fontsDir[0], fontsDir.length()));
|
|
|
|
fontsDir += L"\\fonts\\";
|
2008-06-30 17:09:17 +08:00
|
|
|
|
2015-12-27 09:03:24 +08:00
|
|
|
WIN32_FIND_DATA wfd;
|
Rewrite TTF to Bezier conversion using Freetype.
Benefits:
* Much simpler code.
* Handles the entire TTF spec, not just a small subset that
only really worked well on Windows fonts.
* Handles all character sets as well as accented characters.
* Much faster parsing, since Freetype lazily loads and
caches glyphs.
* Support for basically every kind of font that was invented,
not just TTF.
Note that OpenType features, e.g. ligatures, are not yet supported.
This means that Arabic and Devanagari scripts, among others, will
not be rendered in their proper form.
RTL scripts are not supported either, neither in TTF nor in
the text window. Adding RTL support is comparatively easy, but
given that Arabic would not be legibly rendered anyway, this is not
done so far.
2016-01-30 09:42:44 +08:00
|
|
|
HANDLE h = FindFirstFileW((fontsDir + L"*").c_str(), &wfd);
|
2008-06-30 17:09:17 +08:00
|
|
|
while(h != INVALID_HANDLE_VALUE) {
|
Rewrite TTF to Bezier conversion using Freetype.
Benefits:
* Much simpler code.
* Handles the entire TTF spec, not just a small subset that
only really worked well on Windows fonts.
* Handles all character sets as well as accented characters.
* Much faster parsing, since Freetype lazily loads and
caches glyphs.
* Support for basically every kind of font that was invented,
not just TTF.
Note that OpenType features, e.g. ligatures, are not yet supported.
This means that Arabic and Devanagari scripts, among others, will
not be rendered in their proper form.
RTL scripts are not supported either, neither in TTF nor in
the text window. Adding RTL support is comparatively easy, but
given that Arabic would not be legibly rendered anyway, this is not
done so far.
2016-01-30 09:42:44 +08:00
|
|
|
fonts.push_back(Narrow(fontsDir) + Narrow(wfd.cFileName));
|
2015-12-27 15:51:28 +08:00
|
|
|
if(!FindNextFileW(h, &wfd)) break;
|
2008-06-30 17:09:17 +08:00
|
|
|
}
|
Rewrite TTF to Bezier conversion using Freetype.
Benefits:
* Much simpler code.
* Handles the entire TTF spec, not just a small subset that
only really worked well on Windows fonts.
* Handles all character sets as well as accented characters.
* Much faster parsing, since Freetype lazily loads and
caches glyphs.
* Support for basically every kind of font that was invented,
not just TTF.
Note that OpenType features, e.g. ligatures, are not yet supported.
This means that Arabic and Devanagari scripts, among others, will
not be rendered in their proper form.
RTL scripts are not supported either, neither in TTF nor in
the text window. Adding RTL support is comparatively easy, but
given that Arabic would not be legibly rendered anyway, this is not
done so far.
2016-01-30 09:42:44 +08:00
|
|
|
|
|
|
|
return fonts;
|
2008-06-30 17:09:17 +08:00
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
static void MenuByCmd(Command id, bool yes, bool check)
|
2008-04-14 18:28:32 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int subMenu = -1;
|
|
|
|
|
|
|
|
for(i = 0; SS.GW.menu[i].level >= 0; i++) {
|
|
|
|
if(SS.GW.menu[i].level == 0) subMenu++;
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-04-14 18:28:32 +08:00
|
|
|
if(SS.GW.menu[i].id == id) {
|
2016-05-19 06:51:36 +08:00
|
|
|
ssassert(subMenu >= 0 && subMenu < (int)arraylen(SubMenus),
|
|
|
|
"Submenu out of range");
|
2008-04-14 18:28:32 +08:00
|
|
|
|
2008-04-18 15:06:37 +08:00
|
|
|
if(check) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
CheckMenuItem(SubMenus[subMenu], (uint32_t)id,
|
2008-04-18 15:06:37 +08:00
|
|
|
yes ? MF_CHECKED : MF_UNCHECKED);
|
|
|
|
} else {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
EnableMenuItem(SubMenus[subMenu], (uint32_t)id,
|
2008-04-18 15:06:37 +08:00
|
|
|
yes ? MF_ENABLED : MF_GRAYED);
|
|
|
|
}
|
2008-04-14 18:28:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-05-19 06:51:36 +08:00
|
|
|
ssassert(false, "Cannot find submenu");
|
2008-04-14 18:28:32 +08:00
|
|
|
}
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
void SolveSpace::CheckMenuByCmd(Command cmd, bool checked)
|
2008-04-18 15:06:37 +08:00
|
|
|
{
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
MenuByCmd(cmd, checked, true);
|
2008-04-18 15:06:37 +08:00
|
|
|
}
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
void SolveSpace::RadioMenuByCmd(Command cmd, bool selected)
|
2013-09-19 12:59:18 +08:00
|
|
|
{
|
|
|
|
// Windows does not natively support radio-button menu items
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
MenuByCmd(cmd, selected, true);
|
2013-09-19 12:59:18 +08:00
|
|
|
}
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
void SolveSpace::EnableMenuByCmd(Command cmd, bool enabled)
|
2008-04-18 15:06:37 +08:00
|
|
|
{
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
MenuByCmd(cmd, enabled, false);
|
2008-04-18 15:06:37 +08:00
|
|
|
}
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
static void DoRecent(HMENU m, Command base)
|
2008-05-28 18:10:31 +08:00
|
|
|
{
|
|
|
|
while(DeleteMenu(m, 0, MF_BYPOSITION))
|
|
|
|
;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
int c = 0;
|
|
|
|
for(size_t i = 0; i < MAX_RECENT; i++) {
|
2015-12-27 09:03:24 +08:00
|
|
|
if(!RecentFile[i].empty()) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
AppendMenuW(m, MF_STRING, (uint32_t)base + i, Widen(RecentFile[i]).c_str());
|
2008-05-28 18:10:31 +08:00
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
2015-12-27 15:51:28 +08:00
|
|
|
if(c == 0) AppendMenuW(m, MF_STRING | MF_GRAYED, 0, L"(no recent files)");
|
2008-05-28 18:10:31 +08:00
|
|
|
}
|
2016-05-05 13:54:05 +08:00
|
|
|
void SolveSpace::RefreshRecentMenus()
|
2008-05-28 18:10:31 +08:00
|
|
|
{
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
DoRecent(RecentOpenMenu, Command::RECENT_OPEN);
|
|
|
|
DoRecent(RecentImportMenu, Command::RECENT_LINK);
|
2008-05-28 18:10:31 +08:00
|
|
|
}
|
2008-04-14 18:28:32 +08:00
|
|
|
|
2016-05-05 13:54:05 +08:00
|
|
|
HMENU CreateGraphicsWindowMenus()
|
2008-03-26 17:18:12 +08:00
|
|
|
{
|
|
|
|
HMENU top = CreateMenu();
|
2013-08-27 03:36:00 +08:00
|
|
|
HMENU m = 0;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
|
|
|
int i;
|
|
|
|
int subMenu = 0;
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
for(i = 0; SS.GW.menu[i].level >= 0; i++) {
|
2016-01-27 13:13:04 +08:00
|
|
|
std::string label;
|
2013-09-21 03:01:00 +08:00
|
|
|
if(SS.GW.menu[i].label) {
|
2016-04-17 18:01:44 +08:00
|
|
|
std::string accel = MakeAcceleratorLabel(SS.GW.menu[i].accel);
|
|
|
|
const char *sep = accel.empty() ? "" : "\t";
|
|
|
|
label = ssprintf("%s%s%s", SS.GW.menu[i].label, sep, accel.c_str());
|
2013-09-21 03:01:00 +08:00
|
|
|
}
|
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
if(SS.GW.menu[i].level == 0) {
|
|
|
|
m = CreateMenu();
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(top, MF_STRING | MF_POPUP, (UINT_PTR)m, Widen(label).c_str());
|
2016-05-19 06:51:36 +08:00
|
|
|
ssassert(subMenu < (int)arraylen(SubMenus), "Too many submenus");
|
2008-03-26 17:18:12 +08:00
|
|
|
SubMenus[subMenu] = m;
|
|
|
|
subMenu++;
|
2008-05-28 18:10:31 +08:00
|
|
|
} else if(SS.GW.menu[i].level == 1) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
if(SS.GW.menu[i].id == Command::OPEN_RECENT) {
|
2013-09-21 01:40:17 +08:00
|
|
|
RecentOpenMenu = CreateMenu();
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(m, MF_STRING | MF_POPUP,
|
|
|
|
(UINT_PTR)RecentOpenMenu, Widen(label).c_str());
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
} else if(SS.GW.menu[i].id == Command::GROUP_RECENT) {
|
2013-09-21 01:40:17 +08:00
|
|
|
RecentImportMenu = CreateMenu();
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(m, MF_STRING | MF_POPUP,
|
|
|
|
(UINT_PTR)RecentImportMenu, Widen(label).c_str());
|
2013-09-21 01:40:17 +08:00
|
|
|
} else if(SS.GW.menu[i].label) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
AppendMenuW(m, MF_STRING, (uint32_t)SS.GW.menu[i].id, Widen(label).c_str());
|
2008-03-26 17:18:12 +08:00
|
|
|
} else {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 16:31:20 +08:00
|
|
|
AppendMenuW(m, MF_SEPARATOR, (uint32_t)SS.GW.menu[i].id, L"");
|
2008-03-26 17:18:12 +08:00
|
|
|
}
|
2016-05-19 06:51:36 +08:00
|
|
|
} else ssassert(false, "Submenus nested too deeply");
|
2008-03-26 17:18:12 +08:00
|
|
|
}
|
2008-05-28 18:10:31 +08:00
|
|
|
RefreshRecentMenus();
|
2008-03-26 17:18:12 +08:00
|
|
|
|
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
2016-05-05 13:54:05 +08:00
|
|
|
static void CreateMainWindows()
|
2008-03-25 18:02:13 +08:00
|
|
|
{
|
2015-03-27 23:31:23 +08:00
|
|
|
WNDCLASSEX wc = {};
|
2008-03-25 18:02:13 +08:00
|
|
|
|
|
|
|
wc.cbSize = sizeof(wc);
|
2008-03-26 17:18:12 +08:00
|
|
|
|
|
|
|
// The graphics window, where the sketch is drawn and shown.
|
2008-03-25 18:02:13 +08:00
|
|
|
wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC |
|
|
|
|
CS_DBLCLKS;
|
2008-03-26 17:18:12 +08:00
|
|
|
wc.lpfnWndProc = (WNDPROC)GraphicsWndProc;
|
2015-03-29 08:30:52 +08:00
|
|
|
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
2015-12-27 15:51:28 +08:00
|
|
|
wc.lpszClassName = L"GraphicsWnd";
|
2008-03-25 18:02:13 +08:00
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
2008-07-18 17:50:52 +08:00
|
|
|
wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
|
|
|
|
IMAGE_ICON, 32, 32, 0);
|
|
|
|
wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
|
|
|
|
IMAGE_ICON, 16, 16, 0);
|
2016-05-19 06:51:36 +08:00
|
|
|
ssassert(RegisterClassEx(&wc), "Cannot register window class");
|
2008-03-25 18:02:13 +08:00
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
HMENU top = CreateGraphicsWindowMenus();
|
2015-12-27 15:51:28 +08:00
|
|
|
GraphicsWnd = CreateWindowExW(0, L"GraphicsWnd",
|
|
|
|
L"SolveSpace (not yet saved)",
|
2008-03-25 18:02:13 +08:00
|
|
|
WS_OVERLAPPED | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX |
|
2008-03-27 17:53:51 +08:00
|
|
|
WS_MINIMIZEBOX | WS_SYSMENU | WS_SIZEBOX | WS_CLIPSIBLINGS,
|
2008-05-27 17:59:19 +08:00
|
|
|
50, 50, 900, 600, NULL, top, Instance, NULL);
|
2016-05-19 06:51:36 +08:00
|
|
|
ssassert(GraphicsWnd != NULL, "Cannot create window");
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
GraphicsEditControl = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDIT, L"",
|
2008-04-21 18:12:04 +08:00
|
|
|
WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
|
|
|
|
50, 50, 100, 21, GraphicsWnd, NULL, Instance, NULL);
|
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
// The text window, with a comand line and some textual information
|
|
|
|
// about the sketch.
|
2008-04-11 20:47:14 +08:00
|
|
|
wc.style &= ~CS_DBLCLKS;
|
2008-03-26 17:18:12 +08:00
|
|
|
wc.lpfnWndProc = (WNDPROC)TextWndProc;
|
|
|
|
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
2015-12-27 15:51:28 +08:00
|
|
|
wc.lpszClassName = L"TextWnd";
|
2008-03-28 18:00:37 +08:00
|
|
|
wc.hCursor = NULL;
|
2016-05-19 06:51:36 +08:00
|
|
|
ssassert(RegisterClassEx(&wc), "Cannot register window class");
|
2008-03-26 17:18:12 +08:00
|
|
|
|
|
|
|
// We get the desired Alt+Tab behaviour by specifying that the text
|
|
|
|
// window is a child of the graphics window.
|
2015-12-27 15:51:28 +08:00
|
|
|
TextWnd = CreateWindowExW(0,
|
2016-05-18 20:13:59 +08:00
|
|
|
L"TextWnd", L"SolveSpace - Property Browser", WS_THICKFRAME | WS_CLIPCHILDREN,
|
2008-05-27 17:59:19 +08:00
|
|
|
650, 500, 420, 300, GraphicsWnd, (HMENU)NULL, Instance, NULL);
|
2016-05-19 06:51:36 +08:00
|
|
|
ssassert(TextWnd != NULL, "Cannot create window");
|
2008-03-25 18:02:13 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
TextWndScrollBar = CreateWindowExW(0, WC_SCROLLBAR, L"", WS_CHILD |
|
2015-03-29 08:30:52 +08:00
|
|
|
SBS_VERT | SBS_LEFTALIGN | WS_VISIBLE | WS_CLIPSIBLINGS,
|
2008-03-25 18:02:13 +08:00
|
|
|
200, 100, 100, 100, TextWnd, NULL, Instance, NULL);
|
|
|
|
// Force the scrollbar to get resized to the window,
|
|
|
|
TextWndProc(TextWnd, WM_SIZE, 0, 0);
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
TextEditControl = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDIT, L"",
|
2008-05-27 14:36:59 +08:00
|
|
|
WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
|
|
|
|
50, 50, 100, 21, TextWnd, NULL, Instance, NULL);
|
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
// Now that all our windows exist, set up gl contexts.
|
2016-11-16 10:22:10 +08:00
|
|
|
CreateGlContext(TextWnd, &TextGlDisplay, &TextGlSurface, &TextGlContext);
|
|
|
|
CreateGlContext(GraphicsWnd, &GraphicsGlDisplay, &GraphicsGlSurface, &GraphicsGlContext);
|
2008-03-25 18:02:13 +08:00
|
|
|
|
|
|
|
RECT r, rc;
|
|
|
|
GetWindowRect(TextWnd, &r);
|
|
|
|
GetClientRect(TextWnd, &rc);
|
|
|
|
ClientIsSmallerBy = (r.bottom - r.top) - (rc.bottom - rc.top);
|
|
|
|
}
|
|
|
|
|
Implement a resource system.
Currently, icons, fonts, etc are converted to C structures at compile
time and are hardcoded to the binary. This presents several problems:
* Cross-compilation is complicated. Right now, it is necessary
to be able to run executables for the target platform; this
happens to work with wine-binfmt installed, but is rather ugly.
* Icons can only have one resolution. On OS X, modern software is
expected to take advantage of high-DPI ("Retina") screens and
use so-called @2x assets when ran in high-DPI mode.
* Localization is complicated. Win32 and OS X provide built-in
support for loading the resource appropriate for the user's
locale.
* Embedding strings can only be done as raw strings, using C++'s
R"(...)" literals. This precludes embedding sizable strings,
e.g. JavaScript libraries as used in Three.js export, and makes
git history less useful. Not embedding the libraries means we
have to rely on external CDNs, which requires an Internet
connection and adds a glaring point of failure.
* Linux distribution guidelines are violated. All architecture-
independent data, especially large data such as fonts, is
expected to be in /usr/share, not in the binary.
* Customization is impossible without recompilation. Minor
modifications like adding a few missing vector font characters
or adjusting localization require a complete development
environment, which is unreasonable to expect from users of
a mechanical CAD.
As such, this commit adds a resource system that bundles (and
sometimes builds) resources with the executable. Where they go is
platform-dependent:
* on Win32: into resources of the executable, which allows us to
keep distributing one file;
* on OS X: into the app bundle;
* on other *nix: into /usr/share/solvespace/ or ../res/ (relative
to the executable path), the latter allowing us to run freshly
built executables without installation.
It also subsides the platform-specific resources that are in src/.
The resource system is not yet used for anything; this will be added
in later commits.
2016-04-21 23:54:18 +08:00
|
|
|
const void *SolveSpace::LoadResource(const std::string &name, size_t *size) {
|
|
|
|
HRSRC hres = FindResourceW(NULL, Widen(name).c_str(), RT_RCDATA);
|
2016-05-19 06:51:36 +08:00
|
|
|
ssassert(hres != NULL, "Cannot find resource");
|
Implement a resource system.
Currently, icons, fonts, etc are converted to C structures at compile
time and are hardcoded to the binary. This presents several problems:
* Cross-compilation is complicated. Right now, it is necessary
to be able to run executables for the target platform; this
happens to work with wine-binfmt installed, but is rather ugly.
* Icons can only have one resolution. On OS X, modern software is
expected to take advantage of high-DPI ("Retina") screens and
use so-called @2x assets when ran in high-DPI mode.
* Localization is complicated. Win32 and OS X provide built-in
support for loading the resource appropriate for the user's
locale.
* Embedding strings can only be done as raw strings, using C++'s
R"(...)" literals. This precludes embedding sizable strings,
e.g. JavaScript libraries as used in Three.js export, and makes
git history less useful. Not embedding the libraries means we
have to rely on external CDNs, which requires an Internet
connection and adds a glaring point of failure.
* Linux distribution guidelines are violated. All architecture-
independent data, especially large data such as fonts, is
expected to be in /usr/share, not in the binary.
* Customization is impossible without recompilation. Minor
modifications like adding a few missing vector font characters
or adjusting localization require a complete development
environment, which is unreasonable to expect from users of
a mechanical CAD.
As such, this commit adds a resource system that bundles (and
sometimes builds) resources with the executable. Where they go is
platform-dependent:
* on Win32: into resources of the executable, which allows us to
keep distributing one file;
* on OS X: into the app bundle;
* on other *nix: into /usr/share/solvespace/ or ../res/ (relative
to the executable path), the latter allowing us to run freshly
built executables without installation.
It also subsides the platform-specific resources that are in src/.
The resource system is not yet used for anything; this will be added
in later commits.
2016-04-21 23:54:18 +08:00
|
|
|
HGLOBAL res = LoadResource(NULL, hres);
|
2016-05-19 06:51:36 +08:00
|
|
|
ssassert(res != NULL, "Cannot load resource");
|
Implement a resource system.
Currently, icons, fonts, etc are converted to C structures at compile
time and are hardcoded to the binary. This presents several problems:
* Cross-compilation is complicated. Right now, it is necessary
to be able to run executables for the target platform; this
happens to work with wine-binfmt installed, but is rather ugly.
* Icons can only have one resolution. On OS X, modern software is
expected to take advantage of high-DPI ("Retina") screens and
use so-called @2x assets when ran in high-DPI mode.
* Localization is complicated. Win32 and OS X provide built-in
support for loading the resource appropriate for the user's
locale.
* Embedding strings can only be done as raw strings, using C++'s
R"(...)" literals. This precludes embedding sizable strings,
e.g. JavaScript libraries as used in Three.js export, and makes
git history less useful. Not embedding the libraries means we
have to rely on external CDNs, which requires an Internet
connection and adds a glaring point of failure.
* Linux distribution guidelines are violated. All architecture-
independent data, especially large data such as fonts, is
expected to be in /usr/share, not in the binary.
* Customization is impossible without recompilation. Minor
modifications like adding a few missing vector font characters
or adjusting localization require a complete development
environment, which is unreasonable to expect from users of
a mechanical CAD.
As such, this commit adds a resource system that bundles (and
sometimes builds) resources with the executable. Where they go is
platform-dependent:
* on Win32: into resources of the executable, which allows us to
keep distributing one file;
* on OS X: into the app bundle;
* on other *nix: into /usr/share/solvespace/ or ../res/ (relative
to the executable path), the latter allowing us to run freshly
built executables without installation.
It also subsides the platform-specific resources that are in src/.
The resource system is not yet used for anything; this will be added
in later commits.
2016-04-21 23:54:18 +08:00
|
|
|
|
|
|
|
*size = SizeofResource(NULL, hres);
|
|
|
|
return LockResource(res);
|
|
|
|
}
|
|
|
|
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Test if a message comes from the SpaceNavigator device. If yes, dispatch
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
// it appropriately and return true. Otherwise, do nothing and return false.
|
2009-07-21 03:05:33 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
static bool ProcessSpaceNavigatorMsg(MSG *msg) {
|
|
|
|
if(SpaceNavigator == SI_NO_HANDLE) return false;
|
2009-07-21 03:05:33 +08:00
|
|
|
|
|
|
|
SiGetEventData sged;
|
|
|
|
SiSpwEvent sse;
|
|
|
|
|
|
|
|
SiGetEventWinInit(&sged, msg->message, msg->wParam, msg->lParam);
|
|
|
|
int ret = SiGetEvent(SpaceNavigator, 0, &sged, &sse);
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
if(ret == SI_NOT_EVENT) return false;
|
2009-07-21 03:05:33 +08:00
|
|
|
// So the device is a SpaceNavigator event, or a SpaceNavigator error.
|
|
|
|
|
|
|
|
if(ret == SI_IS_EVENT) {
|
|
|
|
if(sse.type == SI_MOTION_EVENT) {
|
|
|
|
// The Z axis translation and rotation are both
|
|
|
|
// backwards in the default mapping.
|
2009-07-26 09:29:56 +08:00
|
|
|
double tx = sse.u.spwData.mData[SI_TX]*1.0,
|
|
|
|
ty = sse.u.spwData.mData[SI_TY]*1.0,
|
|
|
|
tz = -sse.u.spwData.mData[SI_TZ]*1.0,
|
2009-07-21 03:05:33 +08:00
|
|
|
rx = sse.u.spwData.mData[SI_RX]*0.001,
|
|
|
|
ry = sse.u.spwData.mData[SI_RY]*0.001,
|
|
|
|
rz = -sse.u.spwData.mData[SI_RZ]*0.001;
|
|
|
|
SS.GW.SpaceNavigatorMoved(tx, ty, tz, rx, ry, rz,
|
|
|
|
!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
|
|
|
|
} else if(sse.type == SI_BUTTON_EVENT) {
|
|
|
|
int button;
|
|
|
|
button = SiButtonReleased(&sse);
|
|
|
|
if(button == SI_APP_FIT_BUTTON) SS.GW.SpaceNavigatorButtonUp();
|
|
|
|
}
|
|
|
|
}
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return true;
|
2009-07-21 03:05:33 +08:00
|
|
|
}
|
2015-03-29 08:33:46 +08:00
|
|
|
#endif // HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Entry point into the program.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|
|
|
LPSTR lpCmdLine, INT nCmdShow)
|
|
|
|
{
|
|
|
|
Instance = hInstance;
|
|
|
|
|
2008-04-21 18:12:04 +08:00
|
|
|
InitCommonControls();
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
// A monospaced font
|
2015-12-27 15:51:28 +08:00
|
|
|
FixedFont = CreateFontW(SS.TW.CHAR_HEIGHT, SS.TW.CHAR_WIDTH, 0, 0,
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
FW_REGULAR, false,
|
|
|
|
false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
|
2015-12-27 15:51:28 +08:00
|
|
|
DEFAULT_QUALITY, FF_DONTCARE, L"Lucida Console");
|
2008-03-25 18:02:13 +08:00
|
|
|
if(!FixedFont)
|
|
|
|
FixedFont = (HFONT)GetStockObject(SYSTEM_FONT);
|
|
|
|
|
2008-04-21 18:12:04 +08:00
|
|
|
// Create the root windows: one for control, with text, and one for
|
|
|
|
// the graphics
|
|
|
|
CreateMainWindows();
|
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
ThawWindowPos(TextWnd, "TextWnd");
|
|
|
|
ThawWindowPos(GraphicsWnd, "GraphicsWnd");
|
2008-04-21 18:12:04 +08:00
|
|
|
|
2009-06-14 12:36:38 +08:00
|
|
|
ShowWindow(TextWnd, SW_SHOWNOACTIVATE);
|
|
|
|
ShowWindow(GraphicsWnd, SW_SHOW);
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2009-04-20 15:30:09 +08:00
|
|
|
// Create the heaps for all dynamic memory (AllocTemporary, MemAlloc)
|
|
|
|
InitHeaps();
|
2008-04-13 22:28:35 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
// Pull out the Unicode command line.
|
|
|
|
int argc;
|
|
|
|
LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
|
|
|
|
2008-06-16 16:35:05 +08:00
|
|
|
// A filename may have been specified on the command line; if so, then
|
|
|
|
// strip any quotation marks, and make it absolute.
|
2015-12-27 15:51:28 +08:00
|
|
|
std::wstring filenameRel, filename;
|
|
|
|
if(argc >= 2) {
|
|
|
|
filenameRel = argv[1];
|
|
|
|
if(filenameRel[0] == L'\"' && filenameRel[filenameRel.length() - 1] == L'\"') {
|
|
|
|
filenameRel.erase(0, 1);
|
|
|
|
filenameRel.erase(filenameRel.length() - 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD len = GetFullPathNameW(&filenameRel[0], 0, NULL, NULL);
|
|
|
|
filename.resize(len - 1);
|
|
|
|
GetFullPathNameW(&filenameRel[0], len, &filename[0], NULL);
|
|
|
|
}
|
2009-07-21 03:05:33 +08:00
|
|
|
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
// Initialize the SpaceBall, if present. Test if the driver is running
|
|
|
|
// first, to avoid a long timeout if it's not.
|
2015-12-27 15:51:28 +08:00
|
|
|
HWND swdc = FindWindowW(L"SpaceWare Driver Class", NULL);
|
2009-07-21 03:05:33 +08:00
|
|
|
if(swdc != NULL) {
|
|
|
|
SiOpenData sod;
|
|
|
|
SiInitialize();
|
|
|
|
SiOpenWinInit(&sod, GraphicsWnd);
|
|
|
|
SpaceNavigator =
|
|
|
|
SiOpen("GraphicsWnd", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &sod);
|
|
|
|
SiSetUiMode(SpaceNavigator, SI_UI_NO_CONTROLS);
|
|
|
|
}
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
// Call in to the platform-independent code, and let them do their init
|
2015-03-24 14:45:53 +08:00
|
|
|
SS.Init();
|
2015-12-27 09:03:24 +08:00
|
|
|
if(!filename.empty())
|
2015-12-27 15:51:28 +08:00
|
|
|
SS.OpenFile(Narrow(filename));
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2016-11-16 10:22:10 +08:00
|
|
|
// Repaint one more time, after we've set everything up.
|
|
|
|
PaintGraphics();
|
|
|
|
PaintTextWnd();
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
// And now it's the message loop. All calls in to the rest of the code
|
|
|
|
// will be from the wndprocs.
|
|
|
|
MSG msg;
|
|
|
|
DWORD ret;
|
2013-08-27 04:54:04 +08:00
|
|
|
while((ret = GetMessage(&msg, NULL, 0, 0)) != 0) {
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
// Is it a message from the six degree of freedom input device?
|
|
|
|
if(ProcessSpaceNavigatorMsg(&msg)) goto done;
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2009-07-21 03:05:33 +08:00
|
|
|
|
|
|
|
// A message from the keyboard, which should be processed as a keyboard
|
|
|
|
// accelerator?
|
2008-04-12 23:17:58 +08:00
|
|
|
if(msg.message == WM_KEYDOWN) {
|
2008-06-04 02:28:41 +08:00
|
|
|
if(ProcessKeyDown(msg.wParam)) goto done;
|
|
|
|
}
|
|
|
|
if(msg.message == WM_SYSKEYDOWN && msg.hwnd == TextWnd) {
|
|
|
|
// If the user presses the Alt key when the text window has focus,
|
|
|
|
// then that should probably go to the graphics window instead.
|
|
|
|
SetForegroundWindow(GraphicsWnd);
|
2008-04-12 23:17:58 +08:00
|
|
|
}
|
2009-07-21 03:05:33 +08:00
|
|
|
|
|
|
|
// None of the above; so just a normal message to process.
|
2008-03-25 18:02:13 +08:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
2008-06-04 02:28:41 +08:00
|
|
|
done:
|
|
|
|
SS.DoLater();
|
2008-03-25 18:02:13 +08:00
|
|
|
}
|
2008-05-28 18:10:31 +08:00
|
|
|
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
if(swdc != NULL) {
|
|
|
|
if(SpaceNavigator != SI_NO_HANDLE) SiClose(SpaceNavigator);
|
|
|
|
SiTerminate();
|
|
|
|
}
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2009-07-21 03:05:33 +08:00
|
|
|
|
2008-05-28 18:10:31 +08:00
|
|
|
// Write everything back to the registry
|
2015-12-26 23:54:26 +08:00
|
|
|
FreezeWindowPos(TextWnd, "TextWnd");
|
|
|
|
FreezeWindowPos(GraphicsWnd, "GraphicsWnd");
|
2013-09-19 12:33:12 +08:00
|
|
|
|
|
|
|
// Free the memory we've used; anything that remains is a leak.
|
|
|
|
SK.Clear();
|
|
|
|
SS.Clear();
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|