2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// The toolbar that appears at the top left of the graphics window, where the
|
|
|
|
// user can select icons with the mouse, to perform operations equivalent to
|
|
|
|
// selecting a menu item or using a keyboard shortcut.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
2009-01-02 10:38:36 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2016-05-25 08:22:59 +00:00
|
|
|
struct ToolIcon {
|
|
|
|
std::string name;
|
|
|
|
Command command;
|
2017-01-05 12:27:28 +00:00
|
|
|
const char *tooltip;
|
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 00:55:13 +00:00
|
|
|
std::shared_ptr<Pixmap> pixmap;
|
2016-05-25 08:22:59 +00:00
|
|
|
};
|
|
|
|
static ToolIcon Toolbar[] = {
|
2017-01-05 12:27:28 +00:00
|
|
|
{ "line", Command::LINE_SEGMENT,
|
|
|
|
N_("Sketch line segment"), {} },
|
|
|
|
{ "rectangle", Command::RECTANGLE,
|
|
|
|
N_("Sketch rectangle"), {} },
|
|
|
|
{ "circle", Command::CIRCLE,
|
|
|
|
N_("Sketch circle"), {} },
|
|
|
|
{ "arc", Command::ARC,
|
|
|
|
N_("Sketch arc of a circle"), {} },
|
|
|
|
{ "text", Command::TTF_TEXT,
|
|
|
|
N_("Sketch curves from text in a TrueType font"), {} },
|
2016-11-29 16:49:20 +00:00
|
|
|
{ "image", Command::IMAGE,
|
|
|
|
N_("Sketch image from a file"), {} },
|
2017-01-05 12:27:28 +00:00
|
|
|
{ "tangent-arc", Command::TANGENT_ARC,
|
|
|
|
N_("Create tangent arc at selected point"), {} },
|
|
|
|
{ "bezier", Command::CUBIC,
|
|
|
|
N_("Sketch cubic Bezier spline"), {} },
|
|
|
|
{ "point", Command::DATUM_POINT,
|
|
|
|
N_("Sketch datum point"), {} },
|
|
|
|
{ "construction", Command::CONSTRUCTION,
|
|
|
|
N_("Toggle construction"), {} },
|
|
|
|
{ "trim", Command::SPLIT_CURVES,
|
|
|
|
N_("Split lines / curves where they intersect"), {} },
|
|
|
|
{ "", Command::NONE, "", {} },
|
|
|
|
|
|
|
|
{ "length", Command::DISTANCE_DIA,
|
|
|
|
N_("Constrain distance / diameter / length"), {} },
|
|
|
|
{ "angle", Command::ANGLE,
|
|
|
|
N_("Constrain angle"), {} },
|
|
|
|
{ "horiz", Command::HORIZONTAL,
|
|
|
|
N_("Constrain to be horizontal"), {} },
|
|
|
|
{ "vert", Command::VERTICAL,
|
|
|
|
N_("Constrain to be vertical"), {} },
|
|
|
|
{ "parallel", Command::PARALLEL,
|
|
|
|
N_("Constrain to be parallel or tangent"), {} },
|
|
|
|
{ "perpendicular", Command::PERPENDICULAR,
|
|
|
|
N_("Constrain to be perpendicular"), {} },
|
|
|
|
{ "pointonx", Command::ON_ENTITY,
|
|
|
|
N_("Constrain point on line / curve / plane / point"), {} },
|
|
|
|
{ "symmetric", Command::SYMMETRIC,
|
|
|
|
N_("Constrain symmetric"), {} },
|
|
|
|
{ "equal", Command::EQUAL,
|
|
|
|
N_("Constrain equal length / radius / angle"), {} },
|
|
|
|
{ "same-orientation",Command::ORIENTED_SAME,
|
|
|
|
N_("Constrain normals in same orientation"), {} },
|
|
|
|
{ "other-supp", Command::OTHER_ANGLE,
|
|
|
|
N_("Other supplementary angle"), {} },
|
|
|
|
{ "ref", Command::REFERENCE,
|
|
|
|
N_("Toggle reference dimension"), {} },
|
|
|
|
{ "", Command::NONE, "", {} },
|
|
|
|
|
|
|
|
{ "extrude", Command::GROUP_EXTRUDE,
|
|
|
|
N_("New group extruding active sketch"), {} },
|
|
|
|
{ "lathe", Command::GROUP_LATHE,
|
|
|
|
N_("New group rotating active sketch"), {} },
|
|
|
|
{ "step-rotate", Command::GROUP_ROT,
|
|
|
|
N_("New group step and repeat rotating"), {} },
|
|
|
|
{ "step-translate", Command::GROUP_TRANS,
|
|
|
|
N_("New group step and repeat translating"), {} },
|
|
|
|
{ "sketch-in-plane", Command::GROUP_WRKPL,
|
|
|
|
N_("New group in new workplane (thru given entities)"), {} },
|
|
|
|
{ "sketch-in-3d", Command::GROUP_3D,
|
|
|
|
N_("New group in 3d"), {} },
|
|
|
|
{ "assemble", Command::GROUP_LINK,
|
|
|
|
N_("New group linking / assembling file"), {} },
|
|
|
|
{ "", Command::NONE, "", {} },
|
|
|
|
|
|
|
|
{ "in3d", Command::NEAREST_ISO,
|
|
|
|
N_("Nearest isometric view"), {} },
|
|
|
|
{ "ontoworkplane", Command::ONTO_WORKPLANE,
|
|
|
|
N_("Align view to active workplane"), {} },
|
2009-01-02 10:38:36 +00:00
|
|
|
};
|
|
|
|
|
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 00:55:13 +00:00
|
|
|
void GraphicsWindow::ToolbarDraw(UiCanvas *canvas) {
|
|
|
|
ToolbarDrawOrHitTest(0, 0, canvas, NULL);
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicsWindow::ToolbarMouseMoved(int x, int y) {
|
2018-07-12 19:29:44 +00:00
|
|
|
double width, height;
|
|
|
|
window->GetContentSize(&width, &height);
|
|
|
|
|
2009-01-02 10:38:36 +00:00
|
|
|
x += ((int)width/2);
|
|
|
|
y += ((int)height/2);
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
Command hit;
|
|
|
|
bool withinToolbar = ToolbarDrawOrHitTest(x, y, NULL, &hit);
|
2009-01-02 10:38:36 +00:00
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
if(hit != toolbarHovered) {
|
|
|
|
toolbarHovered = hit;
|
|
|
|
Invalidate();
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
2018-07-12 19:29:44 +00:00
|
|
|
|
|
|
|
if(toolbarHovered != Command::NONE) {
|
|
|
|
std::string tooltip;
|
|
|
|
for(ToolIcon &icon : Toolbar) {
|
|
|
|
if(toolbarHovered == icon.command) {
|
|
|
|
tooltip = Translate(icon.tooltip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Platform::KeyboardEvent accel = SS.GW.AcceleratorForCommand(toolbarHovered);
|
|
|
|
std::string accelDesc = Platform::AcceleratorDescription(accel);
|
|
|
|
if(!accelDesc.empty()) {
|
|
|
|
tooltip += ssprintf(" (%s)", accelDesc.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
window->SetTooltip(tooltip);
|
|
|
|
}
|
|
|
|
|
2009-01-02 10:38:36 +00:00
|
|
|
return withinToolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicsWindow::ToolbarMouseDown(int x, int y) {
|
2018-07-12 19:29:44 +00:00
|
|
|
double width, height;
|
|
|
|
window->GetContentSize(&width, &height);
|
|
|
|
|
2009-01-02 10:38:36 +00:00
|
|
|
x += ((int)width/2);
|
|
|
|
y += ((int)height/2);
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2018-07-11 10:48:38 +00:00
|
|
|
Command hit;
|
|
|
|
bool withinToolbar = ToolbarDrawOrHitTest(x, y, NULL, &hit);
|
2018-07-12 19:29:44 +00:00
|
|
|
if(hit != Command::NONE) {
|
|
|
|
SS.GW.ActivateCommand(hit);
|
|
|
|
}
|
2009-01-02 10:38:36 +00:00
|
|
|
return withinToolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicsWindow::ToolbarDrawOrHitTest(int mx, int my,
|
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 00:55:13 +00:00
|
|
|
UiCanvas *canvas, Command *menuHit)
|
2009-01-02 10:38:36 +00:00
|
|
|
{
|
2018-07-12 19:29:44 +00:00
|
|
|
double width, height;
|
|
|
|
window->GetContentSize(&width, &height);
|
|
|
|
|
2009-01-02 10:38:36 +00:00
|
|
|
int x = 17, y = (int)(height - 52);
|
|
|
|
|
|
|
|
int fudge = 8;
|
2017-03-13 01:14:59 +00:00
|
|
|
int h = 34*16 + 3*16 + fudge;
|
2009-01-02 10:38:36 +00:00
|
|
|
int aleft = 0, aright = 66, atop = y+16+fudge/2, abot = y+16-h;
|
|
|
|
|
|
|
|
bool withinToolbar =
|
|
|
|
(mx >= aleft && mx <= aright && my <= atop && my >= abot);
|
2019-02-19 11:35:56 +00:00
|
|
|
|
|
|
|
// Initialize/clear menuHit.
|
|
|
|
if(menuHit) *menuHit = Command::NONE;
|
2009-01-02 10:38:36 +00:00
|
|
|
|
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 00:55:13 +00:00
|
|
|
if(!canvas && !withinToolbar) {
|
2009-01-02 10:38:36 +00:00
|
|
|
// This gets called every MouseMove event, so return quickly.
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-29 00:30:52 +00:00
|
|
|
|
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 00:55:13 +00:00
|
|
|
if(canvas) {
|
|
|
|
canvas->DrawRect(aleft, aright, atop, abot,
|
|
|
|
/*fillColor=*/{ 30, 30, 30, 255 },
|
|
|
|
/*outlineColor=*/{});
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool leftpos = true;
|
2016-05-25 08:22:59 +00:00
|
|
|
for(ToolIcon &icon : Toolbar) {
|
|
|
|
if(icon.name == "") { // spacer
|
2009-01-02 10:38:36 +00:00
|
|
|
if(!leftpos) {
|
|
|
|
leftpos = true;
|
|
|
|
y -= 32;
|
|
|
|
x -= 32;
|
|
|
|
}
|
|
|
|
y -= 16;
|
|
|
|
|
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 00:55:13 +00:00
|
|
|
if(canvas) {
|
2009-01-02 10:38:36 +00:00
|
|
|
// Draw a separator bar in a slightly different color.
|
|
|
|
int divw = 30, divh = 2;
|
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 00:55:13 +00:00
|
|
|
canvas->DrawRect(x+16+divw, x+16-divw, y+24+divh, y+24-divh,
|
|
|
|
/*fillColor=*/{ 45, 45, 45, 255 },
|
|
|
|
/*outlineColor=*/{});
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
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 00:55:13 +00:00
|
|
|
if(icon.pixmap == nullptr) {
|
|
|
|
icon.pixmap = LoadPng("icons/graphics-window/" + icon.name + ".png");
|
2016-04-22 13:35:22 +00:00
|
|
|
}
|
|
|
|
|
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 00:55:13 +00:00
|
|
|
if(canvas) {
|
|
|
|
canvas->DrawPixmap(icon.pixmap,
|
2017-03-10 19:39:55 +00:00
|
|
|
x - (int)icon.pixmap->width / 2,
|
|
|
|
y - (int)icon.pixmap->height / 2);
|
2009-01-02 10:38:36 +00:00
|
|
|
|
2016-05-25 08:22:59 +00:00
|
|
|
if(toolbarHovered == icon.command ||
|
2016-05-23 10:15:38 +00:00
|
|
|
(pending.operation == Pending::COMMAND &&
|
2016-05-25 08:22:59 +00:00
|
|
|
pending.command == icon.command)) {
|
2009-01-02 10:38:36 +00:00
|
|
|
// Highlight the hovered or pending item.
|
|
|
|
int boxhw = 15;
|
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 00:55:13 +00:00
|
|
|
canvas->DrawRect(x+boxhw, x-boxhw, y+boxhw, y-boxhw,
|
|
|
|
/*fillColor=*/{ 255, 255, 0, 75 },
|
|
|
|
/*outlineColor=*/{});
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int boxhw = 16;
|
|
|
|
if(mx < (x+boxhw) && mx > (x - boxhw) &&
|
|
|
|
my < (y+boxhw) && my > (y - boxhw))
|
|
|
|
{
|
2016-05-25 08:22:59 +00:00
|
|
|
if(menuHit) *menuHit = icon.command;
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(leftpos) {
|
|
|
|
x += 32;
|
|
|
|
leftpos = false;
|
|
|
|
} else {
|
|
|
|
x -= 32;
|
|
|
|
y -= 32;
|
|
|
|
leftpos = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return withinToolbar;
|
|
|
|
}
|