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
|
|
|
|
2017-03-11 22:43:21 +08:00
|
|
|
using Platform::Narrow;
|
|
|
|
using Platform::Widen;
|
|
|
|
|
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
|
|
|
|
2017-01-11 10:44:29 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Utility routines
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::OpenWebsite(const char *url) {
|
2018-07-13 03:29:44 +08:00
|
|
|
ShellExecuteW((HWND)SS.GW.window->NativePtr(),
|
|
|
|
L"open", Widen(url).c_str(), NULL, NULL, SW_SHOWNORMAL);
|
2008-06-04 02:48:47 +08:00
|
|
|
}
|
|
|
|
|
2017-03-11 22:43:21 +08:00
|
|
|
std::vector<Platform::Path> SolveSpace::GetFontFiles() {
|
|
|
|
std::vector<Platform::Path> fonts;
|
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
|
|
|
|
2017-03-11 22:43:21 +08:00
|
|
|
std::wstring fontsDirW(MAX_PATH, '\0');
|
|
|
|
fontsDirW.resize(GetWindowsDirectoryW(&fontsDirW[0], fontsDirW.length()));
|
|
|
|
fontsDirW += L"\\fonts\\";
|
|
|
|
Platform::Path fontsDir = Platform::Path::From(Narrow(fontsDirW));
|
2008-06-30 17:09:17 +08:00
|
|
|
|
2015-12-27 09:03:24 +08:00
|
|
|
WIN32_FIND_DATA wfd;
|
2017-03-11 22:43:21 +08:00
|
|
|
HANDLE h = FindFirstFileW((fontsDirW + L"*").c_str(), &wfd);
|
2008-06-30 17:09:17 +08:00
|
|
|
while(h != INVALID_HANDLE_VALUE) {
|
2017-03-11 22:43:21 +08:00
|
|
|
fonts.push_back(fontsDir.Join(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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2018-07-13 03:29:44 +08:00
|
|
|
INITCOMMONCONTROLSEX icc;
|
|
|
|
icc.dwSize = sizeof(icc);
|
|
|
|
icc.dwICC = ICC_STANDARD_CLASSES|ICC_BAR_CLASSES;
|
|
|
|
InitCommonControlsEx(&icc);
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2016-12-05 08:25:31 +08:00
|
|
|
std::vector<std::string> args = InitPlatform(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();
|
2018-07-13 03:29:44 +08:00
|
|
|
SiOpenWinInit(&sod, (HWND)SS.GW.window->NativePtr());
|
|
|
|
SpaceNavigator = SiOpen("GraphicsWnd", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &sod);
|
2009-07-21 03:05:33 +08:00
|
|
|
SiSetUiMode(SpaceNavigator, SI_UI_NO_CONTROLS);
|
|
|
|
}
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2017-01-14 08:32:47 +08:00
|
|
|
// Use the user default locale, then fall back to English.
|
|
|
|
if(!SetLocale((uint16_t)GetUserDefaultLCID())) {
|
|
|
|
SetLocale("en_US");
|
|
|
|
}
|
2017-01-05 18:39:08 +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();
|
2016-12-05 08:25:31 +08:00
|
|
|
|
2018-07-13 03:29:44 +08:00
|
|
|
// A filename may have been specified on the command line.
|
2016-12-05 08:25:31 +08:00
|
|
|
if(args.size() >= 2) {
|
2017-03-11 22:43:21 +08:00
|
|
|
SS.Load(Platform::Path::From(args[1]).Expand(/*fromCurrentDirectory=*/true));
|
2016-12-05 08:25:31 +08:00
|
|
|
}
|
2008-03-26 17:18:12 +08:00
|
|
|
|
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?
|
2018-07-11 13:35:31 +08:00
|
|
|
if(ProcessSpaceNavigatorMsg(&msg)) continue;
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
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-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
|
|
|
|
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;
|
|
|
|
}
|