Refactor Toolbar to not special-case last row.
This commit is contained in:
parent
1249f8496e
commit
3cd9c28ebc
|
@ -7,13 +7,13 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
#include "solvespace.h"
|
#include "solvespace.h"
|
||||||
|
|
||||||
static const char *SPACER = "";
|
struct ToolIcon {
|
||||||
static struct {
|
std::string name;
|
||||||
const char *iconName;
|
Command command;
|
||||||
Command menu;
|
std::string tooltip;
|
||||||
const char *tip;
|
Pixmap pixmap;
|
||||||
Pixmap icon;
|
};
|
||||||
} Toolbar[] = {
|
static ToolIcon Toolbar[] = {
|
||||||
{ "line", Command::LINE_SEGMENT, "Sketch line segment", {} },
|
{ "line", Command::LINE_SEGMENT, "Sketch line segment", {} },
|
||||||
{ "rectangle", Command::RECTANGLE, "Sketch rectangle", {} },
|
{ "rectangle", Command::RECTANGLE, "Sketch rectangle", {} },
|
||||||
{ "circle", Command::CIRCLE, "Sketch circle", {} },
|
{ "circle", Command::CIRCLE, "Sketch circle", {} },
|
||||||
|
@ -24,7 +24,7 @@ static struct {
|
||||||
{ "point", Command::DATUM_POINT, "Sketch datum point", {} },
|
{ "point", Command::DATUM_POINT, "Sketch datum point", {} },
|
||||||
{ "construction", Command::CONSTRUCTION, "Toggle construction", {} },
|
{ "construction", Command::CONSTRUCTION, "Toggle construction", {} },
|
||||||
{ "trim", Command::SPLIT_CURVES, "Split lines / curves where they intersect", {} },
|
{ "trim", Command::SPLIT_CURVES, "Split lines / curves where they intersect", {} },
|
||||||
{ SPACER, Command::NONE, 0, {} },
|
{ "", Command::NONE, "", {} },
|
||||||
|
|
||||||
{ "length", Command::DISTANCE_DIA, "Constrain distance / diameter / length", {} },
|
{ "length", Command::DISTANCE_DIA, "Constrain distance / diameter / length", {} },
|
||||||
{ "angle", Command::ANGLE, "Constrain angle", {} },
|
{ "angle", Command::ANGLE, "Constrain angle", {} },
|
||||||
|
@ -38,7 +38,7 @@ static struct {
|
||||||
{ "same-orientation",Command::ORIENTED_SAME, "Constrain normals in same orientation", {} },
|
{ "same-orientation",Command::ORIENTED_SAME, "Constrain normals in same orientation", {} },
|
||||||
{ "other-supp", Command::OTHER_ANGLE, "Other supplementary angle", {} },
|
{ "other-supp", Command::OTHER_ANGLE, "Other supplementary angle", {} },
|
||||||
{ "ref", Command::REFERENCE, "Toggle reference dimension", {} },
|
{ "ref", Command::REFERENCE, "Toggle reference dimension", {} },
|
||||||
{ SPACER, Command::NONE, 0, {} },
|
{ "", Command::NONE, "", {} },
|
||||||
|
|
||||||
{ "extrude", Command::GROUP_EXTRUDE, "New group extruding active sketch", {} },
|
{ "extrude", Command::GROUP_EXTRUDE, "New group extruding active sketch", {} },
|
||||||
{ "lathe", Command::GROUP_LATHE, "New group rotating active sketch", {} },
|
{ "lathe", Command::GROUP_LATHE, "New group rotating active sketch", {} },
|
||||||
|
@ -47,11 +47,10 @@ static struct {
|
||||||
{ "sketch-in-plane", Command::GROUP_WRKPL, "New group in new workplane (thru given entities)", {} },
|
{ "sketch-in-plane", Command::GROUP_WRKPL, "New group in new workplane (thru given entities)", {} },
|
||||||
{ "sketch-in-3d", Command::GROUP_3D, "New group in 3d", {} },
|
{ "sketch-in-3d", Command::GROUP_3D, "New group in 3d", {} },
|
||||||
{ "assemble", Command::GROUP_LINK, "New group linking / assembling file", {} },
|
{ "assemble", Command::GROUP_LINK, "New group linking / assembling file", {} },
|
||||||
{ SPACER, Command::NONE, 0, {} },
|
{ "", Command::NONE, "", {} },
|
||||||
|
|
||||||
{ "in3d", Command::NEAREST_ISO, "Nearest isometric view", {} },
|
{ "in3d", Command::NEAREST_ISO, "Nearest isometric view", {} },
|
||||||
{ "ontoworkplane", Command::ONTO_WORKPLANE, "Align view to active workplane", {} },
|
{ "ontoworkplane", Command::ONTO_WORKPLANE, "Align view to active workplane", {} },
|
||||||
{ NULL, Command::NONE, 0, {} }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void GraphicsWindow::ToolbarDraw() {
|
void GraphicsWindow::ToolbarDraw() {
|
||||||
|
@ -141,8 +140,8 @@ bool GraphicsWindow::ToolbarDrawOrHitTest(int mx, int my,
|
||||||
} toolTip = { false, NULL };
|
} toolTip = { false, NULL };
|
||||||
|
|
||||||
bool leftpos = true;
|
bool leftpos = true;
|
||||||
for(i = 0; Toolbar[i].iconName; i++) {
|
for(ToolIcon &icon : Toolbar) {
|
||||||
if(Toolbar[i].iconName == SPACER) {
|
if(icon.name == "") { // spacer
|
||||||
if(!leftpos) {
|
if(!leftpos) {
|
||||||
leftpos = true;
|
leftpos = true;
|
||||||
y -= 32;
|
y -= 32;
|
||||||
|
@ -164,39 +163,38 @@ bool GraphicsWindow::ToolbarDrawOrHitTest(int mx, int my,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Toolbar[i].icon.IsEmpty()) {
|
if(icon.pixmap.IsEmpty()) {
|
||||||
std::string name = ssprintf("icons/graphics-window/%s.png", Toolbar[i].iconName);
|
icon.pixmap = LoadPNG("icons/graphics-window/" + icon.name + ".png");
|
||||||
Toolbar[i].icon = LoadPNG(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(paint) {
|
if(paint) {
|
||||||
glColor4d(0, 0, 0, 1.0);
|
glColor4d(0, 0, 0, 1.0);
|
||||||
Point2d o = { (double)(x - Toolbar[i].icon.width / 2),
|
Point2d o = { (double)(x - icon.pixmap.width / 2),
|
||||||
(double)(y - Toolbar[i].icon.height / 2) };
|
(double)(y - icon.pixmap.height / 2) };
|
||||||
ssglDrawPixmap(Toolbar[i].icon, o, /*flip=*/true);
|
ssglDrawPixmap(icon.pixmap, o, /*flip=*/true);
|
||||||
|
|
||||||
if(toolbarHovered == Toolbar[i].menu ||
|
if(toolbarHovered == icon.command ||
|
||||||
(pending.operation == Pending::COMMAND &&
|
(pending.operation == Pending::COMMAND &&
|
||||||
pending.command == Toolbar[i].menu)) {
|
pending.command == icon.command)) {
|
||||||
// Highlight the hovered or pending item.
|
// Highlight the hovered or pending item.
|
||||||
glColor4d(1, 1, 0, 0.3);
|
glColor4d(1, 1, 0, 0.3);
|
||||||
int boxhw = 15;
|
int boxhw = 15;
|
||||||
ssglAxisAlignedQuad(x+boxhw, x-boxhw, y+boxhw, y-boxhw);
|
ssglAxisAlignedQuad(x+boxhw, x-boxhw, y+boxhw, y-boxhw);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(toolbarTooltipped == Toolbar[i].menu) {
|
if(toolbarTooltipped == icon.command) {
|
||||||
// Display the tool tip for this item; postpone till later
|
// Display the tool tip for this item; postpone till later
|
||||||
// so that no one draws over us. Don't need position since
|
// so that no one draws over us. Don't need position since
|
||||||
// that's just wherever the mouse is.
|
// that's just wherever the mouse is.
|
||||||
toolTip.show = true;
|
toolTip.show = true;
|
||||||
toolTip.str = Toolbar[i].tip;
|
toolTip.str = icon.tooltip.c_str();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int boxhw = 16;
|
int boxhw = 16;
|
||||||
if(mx < (x+boxhw) && mx > (x - boxhw) &&
|
if(mx < (x+boxhw) && mx > (x - boxhw) &&
|
||||||
my < (y+boxhw) && my > (y - boxhw))
|
my < (y+boxhw) && my > (y - boxhw))
|
||||||
{
|
{
|
||||||
if(menuHit) *menuHit = Toolbar[i].menu;
|
if(menuHit) *menuHit = icon.command;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user