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-04-22 13:35:22 +00:00
|
|
|
static const char *SPACER = "";
|
|
|
|
static struct {
|
|
|
|
const char *iconName;
|
2009-01-02 10:38:36 +00:00
|
|
|
int menu;
|
2013-08-26 18:58:35 +00:00
|
|
|
const char *tip;
|
2016-04-22 13:35:22 +00:00
|
|
|
Pixmap icon;
|
2009-01-02 10:38:36 +00:00
|
|
|
} Toolbar[] = {
|
2016-04-22 13:35:22 +00:00
|
|
|
{ "line", GraphicsWindow::MNU_LINE_SEGMENT, "Sketch line segment", {} },
|
|
|
|
{ "rectangle", GraphicsWindow::MNU_RECTANGLE, "Sketch rectangle", {} },
|
|
|
|
{ "circle", GraphicsWindow::MNU_CIRCLE, "Sketch circle", {} },
|
|
|
|
{ "arc", GraphicsWindow::MNU_ARC, "Sketch arc of a circle", {} },
|
|
|
|
{ "text", GraphicsWindow::MNU_TTF_TEXT, "Sketch curves from text in a TrueType font", {} },
|
|
|
|
{ "tangent-arc", GraphicsWindow::MNU_TANGENT_ARC, "Create tangent arc at selected point", {} },
|
|
|
|
{ "bezier", GraphicsWindow::MNU_CUBIC, "Sketch cubic Bezier spline", {} },
|
|
|
|
{ "point", GraphicsWindow::MNU_DATUM_POINT, "Sketch datum point", {} },
|
|
|
|
{ "construction", GraphicsWindow::MNU_CONSTRUCTION, "Toggle construction", {} },
|
|
|
|
{ "trim", GraphicsWindow::MNU_SPLIT_CURVES, "Split lines / curves where they intersect", {} },
|
|
|
|
{ SPACER, 0, 0, {} },
|
|
|
|
|
|
|
|
{ "length", GraphicsWindow::MNU_DISTANCE_DIA, "Constrain distance / diameter / length", {} },
|
|
|
|
{ "angle", GraphicsWindow::MNU_ANGLE, "Constrain angle", {} },
|
|
|
|
{ "horiz", GraphicsWindow::MNU_HORIZONTAL, "Constrain to be horizontal", {} },
|
|
|
|
{ "vert", GraphicsWindow::MNU_VERTICAL, "Constrain to be vertical", {} },
|
|
|
|
{ "parallel", GraphicsWindow::MNU_PARALLEL, "Constrain to be parallel or tangent", {} },
|
|
|
|
{ "perpendicular", GraphicsWindow::MNU_PERPENDICULAR, "Constrain to be perpendicular", {} },
|
|
|
|
{ "pointonx", GraphicsWindow::MNU_ON_ENTITY, "Constrain point on line / curve / plane / point", {} },
|
|
|
|
{ "symmetric", GraphicsWindow::MNU_SYMMETRIC, "Constrain symmetric", {} },
|
|
|
|
{ "equal", GraphicsWindow::MNU_EQUAL, "Constrain equal length / radius / angle", {} },
|
|
|
|
{ "same-orientation",GraphicsWindow::MNU_ORIENTED_SAME, "Constrain normals in same orientation", {} },
|
|
|
|
{ "other-supp", GraphicsWindow::MNU_OTHER_ANGLE, "Other supplementary angle", {} },
|
|
|
|
{ "ref", GraphicsWindow::MNU_REFERENCE, "Toggle reference dimension", {} },
|
|
|
|
{ SPACER, 0, 0, {} },
|
|
|
|
|
|
|
|
{ "extrude", GraphicsWindow::MNU_GROUP_EXTRUDE, "New group extruding active sketch", {} },
|
|
|
|
{ "lathe", GraphicsWindow::MNU_GROUP_LATHE, "New group rotating active sketch", {} },
|
|
|
|
{ "step-rotate", GraphicsWindow::MNU_GROUP_ROT, "New group step and repeat rotating", {} },
|
|
|
|
{ "step-translate", GraphicsWindow::MNU_GROUP_TRANS, "New group step and repeat translating", {} },
|
|
|
|
{ "sketch-in-plane", GraphicsWindow::MNU_GROUP_WRKPL, "New group in new workplane (thru given entities)", {} },
|
|
|
|
{ "sketch-in-3d", GraphicsWindow::MNU_GROUP_3D, "New group in 3d", {} },
|
|
|
|
{ "assemble", GraphicsWindow::MNU_GROUP_LINK, "New group linking / assembling file", {} },
|
|
|
|
{ SPACER, 0, 0, {} },
|
|
|
|
|
|
|
|
{ "in3d", GraphicsWindow::MNU_NEAREST_ISO, "Nearest isometric view", {} },
|
|
|
|
{ "ontoworkplane", GraphicsWindow::MNU_ONTO_WORKPLANE, "Align view to active workplane", {} },
|
|
|
|
{ NULL, 0, 0, {} }
|
2009-01-02 10:38:36 +00:00
|
|
|
};
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::ToolbarDraw() {
|
2009-01-02 10:38:36 +00:00
|
|
|
ToolbarDrawOrHitTest(0, 0, true, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicsWindow::ToolbarMouseMoved(int x, int y) {
|
|
|
|
x += ((int)width/2);
|
|
|
|
y += ((int)height/2);
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2013-09-16 20:22:14 +00:00
|
|
|
int nh = 0;
|
2009-01-02 10:38:36 +00:00
|
|
|
bool withinToolbar = ToolbarDrawOrHitTest(x, y, false, &nh);
|
|
|
|
if(!withinToolbar) nh = 0;
|
|
|
|
|
|
|
|
if(nh != toolbarTooltipped) {
|
|
|
|
// Don't let the tool tip move around if the mouse moves within the
|
|
|
|
// same item.
|
|
|
|
toolbarMouseX = x;
|
|
|
|
toolbarMouseY = y;
|
|
|
|
toolbarTooltipped = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nh != toolbarHovered) {
|
|
|
|
toolbarHovered = nh;
|
|
|
|
SetTimerFor(1000);
|
|
|
|
PaintGraphics();
|
|
|
|
}
|
|
|
|
// So if we moved off the toolbar, then toolbarHovered is now equal to
|
|
|
|
// zero, so it doesn't matter if the tool tip timer expires. And if
|
|
|
|
// we moved from one item to another, we reset the timer, so also okay.
|
|
|
|
return withinToolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicsWindow::ToolbarMouseDown(int x, int y) {
|
|
|
|
x += ((int)width/2);
|
|
|
|
y += ((int)height/2);
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2009-09-22 06:47:11 +00:00
|
|
|
int nh = -1;
|
2009-01-02 10:38:36 +00:00
|
|
|
bool withinToolbar = ToolbarDrawOrHitTest(x, y, false, &nh);
|
2009-09-22 06:47:11 +00:00
|
|
|
// They might have clicked within the toolbar, but not on a button.
|
|
|
|
if(withinToolbar && nh >= 0) {
|
2009-01-02 10:38:36 +00:00
|
|
|
for(int i = 0; SS.GW.menu[i].level >= 0; i++) {
|
|
|
|
if(nh == SS.GW.menu[i].id) {
|
|
|
|
(SS.GW.menu[i].fn)((GraphicsWindow::MenuId)SS.GW.menu[i].id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return withinToolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicsWindow::ToolbarDrawOrHitTest(int mx, int my,
|
2013-10-19 05:36:45 +00:00
|
|
|
bool paint, int *menuHit)
|
2009-01-02 10:38:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int x = 17, y = (int)(height - 52);
|
|
|
|
|
|
|
|
int fudge = 8;
|
2016-01-18 05:31:31 +00:00
|
|
|
int h = 32*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);
|
|
|
|
|
|
|
|
if(!paint && !withinToolbar) {
|
|
|
|
// This gets called every MouseMove event, so return quickly.
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2009-01-02 10:38:36 +00:00
|
|
|
if(paint) {
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glTranslated(-1, -1, 0);
|
|
|
|
glScaled(2.0/width, 2.0/height, 0);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
|
|
|
|
double c = 30.0/255;
|
|
|
|
glColor4d(c, c, c, 1.0);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglAxisAlignedQuad(aleft, aright, atop, abot);
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct {
|
|
|
|
bool show;
|
2013-08-26 18:58:35 +00:00
|
|
|
const char *str;
|
2009-01-02 10:38:36 +00:00
|
|
|
} toolTip = { false, NULL };
|
|
|
|
|
|
|
|
bool leftpos = true;
|
2016-04-22 13:35:22 +00:00
|
|
|
for(i = 0; Toolbar[i].iconName; i++) {
|
|
|
|
if(Toolbar[i].iconName == SPACER) {
|
2009-01-02 10:38:36 +00:00
|
|
|
if(!leftpos) {
|
|
|
|
leftpos = true;
|
|
|
|
y -= 32;
|
|
|
|
x -= 32;
|
|
|
|
}
|
|
|
|
y -= 16;
|
|
|
|
|
|
|
|
if(paint) {
|
|
|
|
// Draw a separator bar in a slightly different color.
|
|
|
|
int divw = 30, divh = 2;
|
|
|
|
glColor4d(0.17, 0.17, 0.17, 1);
|
|
|
|
x += 16;
|
|
|
|
y += 24;
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglAxisAlignedQuad(x+divw, x-divw, y+divh, y-divh);
|
2009-01-02 10:38:36 +00:00
|
|
|
x -= 16;
|
|
|
|
y -= 24;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-04-22 13:35:22 +00:00
|
|
|
if(Toolbar[i].icon.IsEmpty()) {
|
|
|
|
std::string name = ssprintf("icons/graphics-window/%s.png", Toolbar[i].iconName);
|
|
|
|
Toolbar[i].icon = LoadPNG(name);
|
|
|
|
}
|
|
|
|
|
2009-01-02 10:38:36 +00:00
|
|
|
if(paint) {
|
2016-04-22 13:35:22 +00:00
|
|
|
glPushMatrix();
|
|
|
|
glTranslated(x - Toolbar[i].icon.width / 2, y - Toolbar[i].icon.height / 2, 0);
|
|
|
|
glColor4d(0, 0, 0, 1.0);
|
|
|
|
ssglDrawPixmap(Toolbar[i].icon, /*flip=*/true);
|
|
|
|
glPopMatrix();
|
2009-01-02 10:38:36 +00:00
|
|
|
|
2015-03-29 21:37:21 +00:00
|
|
|
if(toolbarHovered == Toolbar[i].menu ||
|
|
|
|
pending.operation == Toolbar[i].menu) {
|
2009-01-02 10:38:36 +00:00
|
|
|
// Highlight the hovered or pending item.
|
|
|
|
glColor4d(1, 1, 0, 0.3);
|
|
|
|
int boxhw = 15;
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglAxisAlignedQuad(x+boxhw, x-boxhw, y+boxhw, y-boxhw);
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(toolbarTooltipped == Toolbar[i].menu) {
|
|
|
|
// Display the tool tip for this item; postpone till later
|
|
|
|
// so that no one draws over us. Don't need position since
|
|
|
|
// that's just wherever the mouse is.
|
|
|
|
toolTip.show = true;
|
|
|
|
toolTip.str = Toolbar[i].tip;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int boxhw = 16;
|
|
|
|
if(mx < (x+boxhw) && mx > (x - boxhw) &&
|
|
|
|
my < (y+boxhw) && my > (y - boxhw))
|
|
|
|
{
|
2013-10-19 05:36:45 +00:00
|
|
|
if(menuHit) *menuHit = Toolbar[i].menu;
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(leftpos) {
|
|
|
|
x += 32;
|
|
|
|
leftpos = false;
|
|
|
|
} else {
|
|
|
|
x -= 32;
|
|
|
|
y -= 32;
|
|
|
|
leftpos = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(paint) {
|
|
|
|
// Do this last so that nothing can draw over it.
|
|
|
|
if(toolTip.show) {
|
2015-11-05 19:39:27 +00:00
|
|
|
ssglInitializeBitmapFont();
|
2016-04-17 10:01:44 +00:00
|
|
|
std::string str = toolTip.str;
|
2009-01-02 10:38:36 +00:00
|
|
|
|
|
|
|
for(i = 0; SS.GW.menu[i].level >= 0; i++) {
|
|
|
|
if(toolbarTooltipped == SS.GW.menu[i].id) {
|
2016-04-17 10:01:44 +00:00
|
|
|
std::string accel = MakeAcceleratorLabel(SS.GW.menu[i].accel);
|
|
|
|
if(!accel.empty()) {
|
|
|
|
str += ssprintf(" (%s)", accel.c_str());
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-17 10:01:44 +00:00
|
|
|
int tw = str.length() * (SS.TW.CHAR_WIDTH - 1) + 10,
|
2010-04-26 07:52:49 +00:00
|
|
|
th = SS.TW.LINE_HEIGHT + 2;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2009-01-02 10:38:36 +00:00
|
|
|
double ox = toolbarMouseX + 3, oy = toolbarMouseY + 3;
|
2009-01-25 11:25:40 +00:00
|
|
|
glLineWidth(1);
|
2009-01-02 10:38:36 +00:00
|
|
|
glColor4d(1.0, 1.0, 0.6, 1.0);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglAxisAlignedQuad(ox, ox+tw, oy, oy+th);
|
2009-01-02 10:38:36 +00:00
|
|
|
glColor4d(0.0, 0.0, 0.0, 1.0);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglAxisAlignedLineLoop(ox, ox+tw, oy, oy+th);
|
2009-01-02 10:38:36 +00:00
|
|
|
|
|
|
|
glColor4d(0, 0, 0, 1);
|
|
|
|
glPushMatrix();
|
2010-04-26 07:52:49 +00:00
|
|
|
glTranslated(ox+5, oy+3, 0);
|
|
|
|
glScaled(1, -1, 1);
|
2016-02-14 20:13:40 +00:00
|
|
|
ssglBitmapText(str, Vector::From(0, 0, 0));
|
2009-01-02 10:38:36 +00:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglDepthRangeLockToFront(false);
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return withinToolbar;
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::TimerCallback() {
|
2009-01-02 10:38:36 +00:00
|
|
|
SS.GW.toolbarTooltipped = SS.GW.toolbarHovered;
|
|
|
|
PaintGraphics();
|
|
|
|
}
|
|
|
|
|