2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Helper functions for the text-based browser window.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-03-25 10:02:13 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2016-08-13 06:46:54 +00:00
|
|
|
namespace SolveSpace {
|
|
|
|
|
|
|
|
class Button {
|
|
|
|
public:
|
|
|
|
virtual std::string Tooltip() = 0;
|
|
|
|
virtual void Draw(UiCanvas *uiCanvas, int x, int y, bool asHovered) = 0;
|
|
|
|
virtual int AdvanceWidth() = 0;
|
|
|
|
virtual void Click() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SpacerButton : public Button {
|
|
|
|
public:
|
|
|
|
std::string Tooltip() override { return ""; }
|
|
|
|
|
|
|
|
void Draw(UiCanvas *uiCanvas, int x, int y, bool asHovered) override {
|
|
|
|
// Draw a darker-grey spacer in between the groups of icons.
|
|
|
|
uiCanvas->DrawRect(x, x + 4, y, y - 24,
|
|
|
|
/*fillColor=*/{ 45, 45, 45, 255 },
|
|
|
|
/*outlineColor=*/{});
|
|
|
|
}
|
|
|
|
|
|
|
|
int AdvanceWidth() override { return 12; }
|
|
|
|
|
|
|
|
void Click() override {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShowHideButton : public Button {
|
|
|
|
public:
|
|
|
|
bool *variable;
|
|
|
|
std::string tooltip;
|
|
|
|
std::string iconName;
|
|
|
|
std::shared_ptr<Pixmap> icon;
|
|
|
|
|
|
|
|
ShowHideButton(bool *variable, std::string iconName, std::string tooltip)
|
|
|
|
: variable(variable), tooltip(tooltip), iconName(iconName) {}
|
|
|
|
|
|
|
|
std::string Tooltip() override {
|
|
|
|
return ((*variable) ? "Hide " : "Show ") + tooltip;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Draw(UiCanvas *uiCanvas, int x, int y, bool asHovered) override {
|
|
|
|
if(icon == NULL) {
|
|
|
|
icon = LoadPng("icons/text-window/" + iconName + ".png");
|
|
|
|
}
|
|
|
|
|
|
|
|
uiCanvas->DrawPixmap(icon, x, y - 24);
|
|
|
|
if(asHovered) {
|
|
|
|
uiCanvas->DrawRect(x - 2, x + 26, y + 2, y - 26,
|
|
|
|
/*fillColor=*/{ 255, 255, 0, 75 },
|
|
|
|
/*outlineColor=*/{});
|
|
|
|
}
|
|
|
|
if(!*(variable)) {
|
|
|
|
int s = 0, f = 24;
|
|
|
|
RgbaColor color = { 255, 0, 0, 150 };
|
|
|
|
uiCanvas->DrawLine(x+s, y-s, x+f, y-f, color, 2);
|
|
|
|
uiCanvas->DrawLine(x+s, y-f, x+f, y-s, color, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int AdvanceWidth() override { return 32; }
|
|
|
|
|
|
|
|
void Click() override { SS.GW.ToggleBool(variable); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class FacesButton : public ShowHideButton {
|
|
|
|
public:
|
|
|
|
FacesButton()
|
|
|
|
: ShowHideButton(&(SS.GW.showFaces), "faces", "") {}
|
|
|
|
|
|
|
|
std::string Tooltip() override {
|
|
|
|
if(*variable) {
|
|
|
|
return "Don't make faces selectable with mouse";
|
|
|
|
} else {
|
|
|
|
return "Make faces selectable with mouse";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-13 09:02:12 +00:00
|
|
|
class OccludedLinesButton : public Button {
|
|
|
|
public:
|
|
|
|
std::shared_ptr<Pixmap> visibleIcon;
|
|
|
|
std::shared_ptr<Pixmap> stippledIcon;
|
|
|
|
std::shared_ptr<Pixmap> invisibleIcon;
|
|
|
|
|
|
|
|
std::string Tooltip() override {
|
|
|
|
switch(SS.GW.drawOccludedAs) {
|
|
|
|
case GraphicsWindow::DrawOccludedAs::INVISIBLE:
|
|
|
|
return "Stipple occluded lines";
|
|
|
|
|
|
|
|
case GraphicsWindow::DrawOccludedAs::STIPPLED:
|
|
|
|
return "Draw occluded lines";
|
|
|
|
|
|
|
|
case GraphicsWindow::DrawOccludedAs::VISIBLE:
|
|
|
|
return "Don't draw occluded lines";
|
|
|
|
|
|
|
|
default: ssassert(false, "Unexpected mode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Draw(UiCanvas *uiCanvas, int x, int y, bool asHovered) override {
|
|
|
|
if(visibleIcon == NULL) {
|
|
|
|
visibleIcon = LoadPng("icons/text-window/occluded-visible.png");
|
|
|
|
}
|
|
|
|
if(stippledIcon == NULL) {
|
|
|
|
stippledIcon = LoadPng("icons/text-window/occluded-stippled.png");
|
|
|
|
}
|
|
|
|
if(invisibleIcon == NULL) {
|
|
|
|
invisibleIcon = LoadPng("icons/text-window/occluded-invisible.png");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Pixmap> icon;
|
|
|
|
switch(SS.GW.drawOccludedAs) {
|
|
|
|
case GraphicsWindow::DrawOccludedAs::INVISIBLE: icon = invisibleIcon; break;
|
|
|
|
case GraphicsWindow::DrawOccludedAs::STIPPLED: icon = stippledIcon; break;
|
|
|
|
case GraphicsWindow::DrawOccludedAs::VISIBLE: icon = visibleIcon; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiCanvas->DrawPixmap(icon, x, y - 24);
|
|
|
|
if(asHovered) {
|
|
|
|
uiCanvas->DrawRect(x - 2, x + 26, y + 2, y - 26,
|
|
|
|
/*fillColor=*/{ 255, 255, 0, 75 },
|
|
|
|
/*outlineColor=*/{});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int AdvanceWidth() override { return 32; }
|
|
|
|
|
|
|
|
void Click() override {
|
|
|
|
switch(SS.GW.drawOccludedAs) {
|
|
|
|
case GraphicsWindow::DrawOccludedAs::INVISIBLE:
|
|
|
|
SS.GW.drawOccludedAs = GraphicsWindow::DrawOccludedAs::STIPPLED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GraphicsWindow::DrawOccludedAs::STIPPLED:
|
|
|
|
SS.GW.drawOccludedAs = GraphicsWindow::DrawOccludedAs::VISIBLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GraphicsWindow::DrawOccludedAs::VISIBLE:
|
|
|
|
SS.GW.drawOccludedAs = GraphicsWindow::DrawOccludedAs::INVISIBLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SS.GenerateAll();
|
|
|
|
InvalidateGraphics();
|
|
|
|
SS.ScheduleShowTW();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-13 06:46:54 +00:00
|
|
|
static SpacerButton spacerButton;
|
|
|
|
|
|
|
|
static ShowHideButton workplanesButton =
|
|
|
|
{ &(SS.GW.showWorkplanes), "workplane", "workplanes from inactive groups" };
|
|
|
|
static ShowHideButton normalsButton =
|
|
|
|
{ &(SS.GW.showNormals), "normal", "normals" };
|
|
|
|
static ShowHideButton pointsButton =
|
|
|
|
{ &(SS.GW.showPoints), "point", "points" };
|
|
|
|
static ShowHideButton constraintsButton =
|
|
|
|
{ &(SS.GW.showConstraints), "constraint", "constraints and dimensions" };
|
|
|
|
static FacesButton facesButton;
|
|
|
|
static ShowHideButton shadedButton =
|
|
|
|
{ &(SS.GW.showShaded), "shaded", "shaded view of solid model" };
|
|
|
|
static ShowHideButton edgesButton =
|
|
|
|
{ &(SS.GW.showEdges), "edges", "edges of solid model" };
|
|
|
|
static ShowHideButton outlinesButton =
|
|
|
|
{ &(SS.GW.showOutlines), "outlines", "outline of solid model" };
|
|
|
|
static ShowHideButton meshButton =
|
|
|
|
{ &(SS.GW.showMesh), "mesh", "triangle mesh of solid model" };
|
2016-08-13 09:02:12 +00:00
|
|
|
static OccludedLinesButton occludedLinesButton;
|
2016-08-13 06:46:54 +00:00
|
|
|
|
|
|
|
static Button *buttons[] = {
|
|
|
|
&workplanesButton,
|
|
|
|
&normalsButton,
|
|
|
|
&pointsButton,
|
|
|
|
&constraintsButton,
|
|
|
|
&facesButton,
|
|
|
|
&spacerButton,
|
|
|
|
&shadedButton,
|
|
|
|
&edgesButton,
|
|
|
|
&outlinesButton,
|
|
|
|
&meshButton,
|
|
|
|
&spacerButton,
|
2016-08-13 09:02:12 +00:00
|
|
|
&occludedLinesButton,
|
2016-08-13 06:46:54 +00:00
|
|
|
};
|
|
|
|
|
2008-04-28 07:18:39 +00:00
|
|
|
const TextWindow::Color TextWindow::fgColors[] = {
|
2013-12-02 06:25:09 +00:00
|
|
|
{ 'd', RGBi(255, 255, 255) },
|
|
|
|
{ 'l', RGBi(100, 100, 255) },
|
|
|
|
{ 't', RGBi(255, 200, 0) },
|
|
|
|
{ 'h', RGBi( 90, 90, 90) },
|
|
|
|
{ 's', RGBi( 40, 255, 40) },
|
|
|
|
{ 'm', RGBi(200, 200, 0) },
|
|
|
|
{ 'r', RGBi( 0, 0, 0) },
|
|
|
|
{ 'x', RGBi(255, 20, 20) },
|
|
|
|
{ 'i', RGBi( 0, 255, 255) },
|
|
|
|
{ 'g', RGBi(160, 160, 160) },
|
|
|
|
{ 'b', RGBi(200, 200, 200) },
|
2015-03-26 10:30:12 +00:00
|
|
|
{ 0, RGBi( 0, 0, 0) }
|
2008-04-28 07:18:39 +00:00
|
|
|
};
|
|
|
|
const TextWindow::Color TextWindow::bgColors[] = {
|
2013-12-02 06:25:09 +00:00
|
|
|
{ 'd', RGBi( 0, 0, 0) },
|
|
|
|
{ 't', RGBi( 34, 15, 15) },
|
|
|
|
{ 'a', RGBi( 25, 25, 25) },
|
|
|
|
{ 'r', RGBi(255, 255, 255) },
|
2015-03-26 10:30:12 +00:00
|
|
|
{ 0, RGBi( 0, 0, 0) }
|
2008-03-28 10:00:37 +00:00
|
|
|
};
|
|
|
|
|
2010-04-26 07:52:49 +00:00
|
|
|
void TextWindow::MakeColorTable(const Color *in, float *out) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; in[i].c != 0; i++) {
|
|
|
|
int c = in[i].c;
|
2016-05-18 22:51:36 +00:00
|
|
|
ssassert(c >= 0 && c <= 255, "Unexpected color index");
|
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-16 20:00:58 +00:00
|
|
|
out[c*3 + 0] = in[i].color.redF();
|
|
|
|
out[c*3 + 1] = in[i].color.greenF();
|
|
|
|
out[c*3 + 2] = in[i].color.blueF();
|
2010-04-26 07:52:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void TextWindow::Init() {
|
2008-06-01 00:26:41 +00:00
|
|
|
ClearSuper();
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void TextWindow::ClearSuper() {
|
2010-07-12 07:51:12 +00:00
|
|
|
HideEditControl();
|
2010-04-26 07:52:49 +00:00
|
|
|
|
2015-03-27 15:31:23 +00:00
|
|
|
// Cannot use *this = {} here because TextWindow instances
|
|
|
|
// are 2.4MB long; this causes stack overflows in prologue
|
|
|
|
// when built with MSVC, even with optimizations.
|
2008-04-12 14:12:26 +00:00
|
|
|
memset(this, 0, sizeof(*this));
|
2015-03-27 15:31:23 +00:00
|
|
|
|
2010-04-26 07:52:49 +00:00
|
|
|
MakeColorTable(fgColors, fgColorTable);
|
|
|
|
MakeColorTable(bgColors, bgColorTable);
|
|
|
|
|
2008-06-01 00:26:41 +00:00
|
|
|
ClearScreen();
|
|
|
|
Show();
|
2008-03-26 09:18:12 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void TextWindow::HideEditControl() {
|
2010-07-21 05:04:03 +00:00
|
|
|
editControl.colorPicker.show = false;
|
2010-07-12 07:51:12 +00:00
|
|
|
HideTextEditControl();
|
|
|
|
}
|
|
|
|
|
2016-01-26 11:19:52 +00:00
|
|
|
void TextWindow::ShowEditControl(int col, const std::string &str, int halfRow) {
|
|
|
|
if(halfRow < 0) halfRow = top[hoveredRow];
|
2010-07-12 07:51:12 +00:00
|
|
|
editControl.halfRow = halfRow;
|
|
|
|
editControl.col = col;
|
|
|
|
|
|
|
|
int x = LEFT_MARGIN + CHAR_WIDTH*col;
|
|
|
|
int y = (halfRow - SS.TW.scrollPos)*(LINE_HEIGHT/2);
|
|
|
|
|
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 14:24:09 +00:00
|
|
|
ShowTextEditControl(x, y + 18, str);
|
2010-07-12 07:51:12 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 11:19:52 +00:00
|
|
|
void TextWindow::ShowEditControlWithColorPicker(int col, RgbaColor rgb)
|
2010-07-21 05:04:03 +00:00
|
|
|
{
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2010-07-21 05:04:03 +00:00
|
|
|
|
|
|
|
editControl.colorPicker.show = true;
|
|
|
|
editControl.colorPicker.rgb = rgb;
|
|
|
|
editControl.colorPicker.h = 0;
|
|
|
|
editControl.colorPicker.s = 0;
|
|
|
|
editControl.colorPicker.v = 1;
|
2016-01-26 11:19:52 +00:00
|
|
|
ShowEditControl(col, ssprintf("%.2f, %.2f, %.2f", rgb.redF(), rgb.greenF(), rgb.blueF()));
|
2010-07-21 05:04:03 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void TextWindow::ClearScreen() {
|
2008-03-25 10:02:13 +00:00
|
|
|
int i, j;
|
|
|
|
for(i = 0; i < MAX_ROWS; i++) {
|
|
|
|
for(j = 0; j < MAX_COLS; j++) {
|
|
|
|
text[i][j] = ' ';
|
2008-04-28 07:18:39 +00:00
|
|
|
meta[i][j].fg = 'd';
|
|
|
|
meta[i][j].bg = 'd';
|
2008-03-25 10:02:13 +00:00
|
|
|
meta[i][j].link = NOT_A_LINK;
|
|
|
|
}
|
2008-04-28 07:18:39 +00:00
|
|
|
top[i] = i*2;
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
2008-03-26 09:18:12 +00:00
|
|
|
rows = 0;
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
|
|
|
|
2013-08-26 18:58:35 +00:00
|
|
|
void TextWindow::Printf(bool halfLine, const char *fmt, ...) {
|
2008-03-25 10:02:13 +00:00
|
|
|
va_list vl;
|
|
|
|
va_start(vl, fmt);
|
|
|
|
|
2008-04-09 09:35:09 +00:00
|
|
|
if(rows >= MAX_ROWS) return;
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
int r, c;
|
2008-04-09 09:35:09 +00:00
|
|
|
r = rows;
|
2008-04-28 07:18:39 +00:00
|
|
|
top[r] = (r == 0) ? 0 : (top[r-1] + (halfLine ? 3 : 2));
|
2008-04-09 09:35:09 +00:00
|
|
|
rows++;
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
for(c = 0; c < MAX_COLS; c++) {
|
|
|
|
text[r][c] = ' ';
|
|
|
|
meta[r][c].link = NOT_A_LINK;
|
|
|
|
}
|
|
|
|
|
2013-09-19 06:35:56 +00:00
|
|
|
char fg = 'd';
|
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-16 20:00:58 +00:00
|
|
|
char bg = 'd';
|
2015-07-10 11:54:39 +00:00
|
|
|
RgbaColor bgRgb = RGBi(0, 0, 0);
|
2008-03-28 10:00:37 +00:00
|
|
|
int link = NOT_A_LINK;
|
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 05:45:13 +00:00
|
|
|
uint32_t data = 0;
|
2008-05-26 09:56:50 +00:00
|
|
|
LinkFunction *f = NULL, *h = NULL;
|
2008-03-25 10:02:13 +00:00
|
|
|
|
|
|
|
c = 0;
|
|
|
|
while(*fmt) {
|
2008-03-28 10:00:37 +00:00
|
|
|
char buf[1024];
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
if(*fmt == '%') {
|
2008-03-26 09:18:12 +00:00
|
|
|
fmt++;
|
|
|
|
if(*fmt == '\0') goto done;
|
2008-03-28 10:00:37 +00:00
|
|
|
strcpy(buf, "");
|
2008-03-26 09:18:12 +00:00
|
|
|
switch(*fmt) {
|
2008-03-28 10:00:37 +00:00
|
|
|
case 'd': {
|
|
|
|
int v = va_arg(vl, int);
|
|
|
|
sprintf(buf, "%d", v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'x': {
|
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 05:45:13 +00:00
|
|
|
unsigned int v = va_arg(vl, unsigned int);
|
2008-03-28 10:00:37 +00:00
|
|
|
sprintf(buf, "%08x", v);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-11 04:22:52 +00:00
|
|
|
case '@': {
|
|
|
|
double v = va_arg(vl, double);
|
|
|
|
sprintf(buf, "%.2f", v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '2': {
|
|
|
|
double v = va_arg(vl, double);
|
|
|
|
sprintf(buf, "%s%.2f", v < 0 ? "" : " ", v);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-01 00:26:41 +00:00
|
|
|
case '3': {
|
|
|
|
double v = va_arg(vl, double);
|
|
|
|
sprintf(buf, "%s%.3f", v < 0 ? "" : " ", v);
|
|
|
|
break;
|
|
|
|
}
|
2009-09-30 10:02:15 +00:00
|
|
|
case '#': {
|
|
|
|
double v = va_arg(vl, double);
|
|
|
|
sprintf(buf, "%.3f", v);
|
|
|
|
break;
|
|
|
|
}
|
2008-03-26 09:18:12 +00:00
|
|
|
case 's': {
|
|
|
|
char *s = va_arg(vl, char *);
|
2008-03-28 10:00:37 +00:00
|
|
|
memcpy(buf, s, min(sizeof(buf), strlen(s)+1));
|
2008-03-26 09:18:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-01 00:26:41 +00:00
|
|
|
case 'c': {
|
2013-08-26 20:09:15 +00:00
|
|
|
// 'char' is promoted to 'int' when passed through '...'
|
|
|
|
int v = va_arg(vl, int);
|
2010-05-09 18:25:23 +00:00
|
|
|
if(v == 0) {
|
|
|
|
strcpy(buf, "");
|
|
|
|
} else {
|
|
|
|
sprintf(buf, "%c", v);
|
|
|
|
}
|
2008-06-01 00:26:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-28 10:00:37 +00:00
|
|
|
case 'E':
|
2008-04-28 07:18:39 +00:00
|
|
|
fg = 'd';
|
|
|
|
// leave the background, though
|
2008-03-28 10:00:37 +00:00
|
|
|
link = NOT_A_LINK;
|
|
|
|
data = 0;
|
|
|
|
f = NULL;
|
2008-05-26 09:56:50 +00:00
|
|
|
h = NULL;
|
2008-03-26 09:18:12 +00:00
|
|
|
break;
|
2008-03-28 10:00:37 +00:00
|
|
|
|
2008-04-28 07:18:39 +00:00
|
|
|
case 'F':
|
|
|
|
case 'B': {
|
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-16 20:00:58 +00:00
|
|
|
char cc = fmt[1]; // color code
|
2015-07-10 11:54:39 +00:00
|
|
|
RgbaColor *rgbPtr = NULL;
|
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-16 20:00:58 +00:00
|
|
|
switch(cc) {
|
|
|
|
case 0: goto done; // truncated directive
|
|
|
|
case 'p': cc = (char)va_arg(vl, int); break;
|
2015-07-10 11:54:39 +00:00
|
|
|
case 'z': rgbPtr = va_arg(vl, RgbaColor *); break;
|
2008-05-30 06:09:41 +00:00
|
|
|
}
|
2008-04-28 07:18:39 +00:00
|
|
|
if(*fmt == 'F') {
|
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-16 20:00:58 +00:00
|
|
|
fg = cc;
|
2008-04-28 07:18:39 +00:00
|
|
|
} else {
|
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-16 20:00:58 +00:00
|
|
|
bg = cc;
|
|
|
|
if(rgbPtr) bgRgb = *rgbPtr;
|
2008-04-28 07:18:39 +00:00
|
|
|
}
|
|
|
|
fmt++;
|
2008-03-28 10:00:37 +00:00
|
|
|
break;
|
2008-04-28 07:18:39 +00:00
|
|
|
}
|
2008-03-28 10:00:37 +00:00
|
|
|
case 'L':
|
|
|
|
if(fmt[1] == '\0') goto done;
|
|
|
|
fmt++;
|
2009-09-29 11:35:19 +00:00
|
|
|
if(*fmt == 'p') {
|
|
|
|
link = va_arg(vl, int);
|
|
|
|
} else {
|
|
|
|
link = *fmt;
|
|
|
|
}
|
2008-03-28 10:00:37 +00:00
|
|
|
break;
|
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
case 'f':
|
|
|
|
f = va_arg(vl, LinkFunction *);
|
|
|
|
break;
|
|
|
|
|
2008-05-26 09:56:50 +00:00
|
|
|
case 'h':
|
|
|
|
h = va_arg(vl, LinkFunction *);
|
|
|
|
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 05:45:13 +00:00
|
|
|
case 'D': {
|
|
|
|
unsigned int v = va_arg(vl, unsigned int);
|
|
|
|
data = (uint32_t)v;
|
2008-03-28 10:00:37 +00: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 05:45:13 +00:00
|
|
|
}
|
2008-03-26 09:18:12 +00:00
|
|
|
case '%':
|
2008-03-28 10:00:37 +00:00
|
|
|
strcpy(buf, "%");
|
2008-03-26 09:18:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-25 10:02:13 +00:00
|
|
|
} else {
|
2016-02-14 20:13:40 +00:00
|
|
|
utf8_iterator it2(fmt), it1 = it2++;
|
|
|
|
strncpy(buf, fmt, it2 - it1);
|
|
|
|
buf[it2 - it1] = '\0';
|
2008-03-28 10:00:37 +00:00
|
|
|
}
|
|
|
|
|
2016-02-14 20:13:40 +00:00
|
|
|
for(utf8_iterator it(buf); *it; ++it) {
|
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
|
|
|
for(size_t i = 0; i < BitmapFont::Builtin()->GetWidth(*it); i++) {
|
2015-11-05 19:39:27 +00:00
|
|
|
if(c >= MAX_COLS) goto done;
|
2016-02-14 20:13:40 +00:00
|
|
|
text[r][c] = (i == 0) ? *it : ' ';
|
2015-11-05 19:39:27 +00:00
|
|
|
meta[r][c].fg = fg;
|
|
|
|
meta[r][c].bg = bg;
|
|
|
|
meta[r][c].bgRgb = bgRgb;
|
|
|
|
meta[r][c].link = link;
|
|
|
|
meta[r][c].data = data;
|
|
|
|
meta[r][c].f = f;
|
|
|
|
meta[r][c].h = h;
|
|
|
|
c++;
|
|
|
|
}
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
2008-03-28 10:00:37 +00:00
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
fmt++;
|
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
while(c < MAX_COLS) {
|
2008-04-28 07:18:39 +00:00
|
|
|
meta[r][c].fg = fg;
|
|
|
|
meta[r][c].bg = bg;
|
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-16 20:00:58 +00:00
|
|
|
meta[r][c].bgRgb = bgRgb;
|
2008-04-12 14:12:26 +00:00
|
|
|
c++;
|
|
|
|
}
|
2008-03-25 10:02:13 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
va_end(vl);
|
|
|
|
}
|
|
|
|
|
2008-06-01 00:26:41 +00:00
|
|
|
#define gs (SS.GW.gs)
|
2016-05-05 05:54:05 +00:00
|
|
|
void TextWindow::Show() {
|
2016-05-23 10:15:38 +00:00
|
|
|
if(SS.GW.pending.operation == GraphicsWindow::Pending::NONE) SS.GW.ClearPending();
|
2008-04-13 10:57:41 +00:00
|
|
|
|
2008-05-26 09:56:50 +00:00
|
|
|
SS.GW.GroupSelection();
|
2008-04-12 14:12:26 +00:00
|
|
|
|
2010-05-09 18:25:23 +00:00
|
|
|
// Make sure these tests agree with test used to draw indicator line on
|
|
|
|
// main list of groups screen.
|
2008-05-05 06:18:01 +00:00
|
|
|
if(SS.GW.pending.description) {
|
2008-04-13 10:57:41 +00:00
|
|
|
// A pending operation (that must be completed with the mouse in
|
|
|
|
// the graphics window) will preempt our usual display.
|
2010-07-12 07:51:12 +00:00
|
|
|
HideEditControl();
|
2008-06-01 00:26:41 +00:00
|
|
|
ShowHeader(false);
|
2008-04-28 07:18:39 +00:00
|
|
|
Printf(false, "");
|
2008-05-05 06:18:01 +00:00
|
|
|
Printf(false, "%s", SS.GW.pending.description);
|
2008-07-14 04:29:43 +00:00
|
|
|
Printf(true, "%Fl%f%Ll(cancel operation)%E",
|
|
|
|
&TextWindow::ScreenUnselectAll);
|
2015-03-29 00:30:52 +00:00
|
|
|
} else if((gs.n > 0 || gs.constraints > 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 08:31:20 +00:00
|
|
|
shown.screen != Screen::PASTE_TRANSFORMED)
|
2009-12-15 12:26:22 +00: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 08:31:20 +00:00
|
|
|
if(edit.meaning != Edit::TTF_TEXT) HideEditControl();
|
2008-06-01 00:26:41 +00:00
|
|
|
ShowHeader(false);
|
|
|
|
DescribeSelection();
|
2008-04-13 10:57:41 +00: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 08:31:20 +00:00
|
|
|
if(edit.meaning == Edit::TTF_TEXT) HideEditControl();
|
2008-06-01 00:26:41 +00:00
|
|
|
ShowHeader(true);
|
2008-07-10 06:11:56 +00:00
|
|
|
switch(shown.screen) {
|
2008-04-13 10:57:41 +00:00
|
|
|
default:
|
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 08:31:20 +00:00
|
|
|
shown.screen = Screen::LIST_OF_GROUPS;
|
2008-04-13 10:57:41 +00:00
|
|
|
// fall through
|
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 08:31:20 +00:00
|
|
|
case Screen::LIST_OF_GROUPS: ShowListOfGroups(); break;
|
|
|
|
case Screen::GROUP_INFO: ShowGroupInfo(); break;
|
|
|
|
case Screen::GROUP_SOLVE_INFO: ShowGroupSolveInfo(); break;
|
|
|
|
case Screen::CONFIGURATION: ShowConfiguration(); break;
|
|
|
|
case Screen::STEP_DIMENSION: ShowStepDimension(); break;
|
|
|
|
case Screen::LIST_OF_STYLES: ShowListOfStyles(); break;
|
|
|
|
case Screen::STYLE_INFO: ShowStyleInfo(); break;
|
|
|
|
case Screen::PASTE_TRANSFORMED: ShowPasteTransformed(); break;
|
|
|
|
case Screen::EDIT_VIEW: ShowEditView(); break;
|
|
|
|
case Screen::TANGENT_ARC: ShowTangentArc(); break;
|
2008-04-13 10:57:41 +00:00
|
|
|
}
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
2008-06-13 04:41:27 +00:00
|
|
|
Printf(false, "");
|
2010-07-21 05:04:03 +00:00
|
|
|
|
|
|
|
// Make sure there's room for the color picker
|
|
|
|
if(editControl.colorPicker.show) {
|
|
|
|
int pickerHeight = 25;
|
|
|
|
int halfRow = editControl.halfRow;
|
|
|
|
if(top[rows-1] - halfRow < pickerHeight && rows < MAX_ROWS) {
|
|
|
|
rows++;
|
|
|
|
top[rows-1] = halfRow + pickerHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
InvalidateText();
|
2008-03-26 09:18:12 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void TextWindow::TimerCallback()
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
2016-08-13 06:46:54 +00:00
|
|
|
tooltippedButton = hoveredButton;
|
2010-05-03 05:04:42 +00:00
|
|
|
InvalidateText();
|
|
|
|
}
|
|
|
|
|
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 TextWindow::DrawOrHitTestIcons(UiCanvas *uiCanvas, TextWindow::DrawOrHitHow how,
|
|
|
|
double mx, double my)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
GetTextWindowSize(&width, &height);
|
|
|
|
|
|
|
|
int x = 20, y = 33 + LINE_HEIGHT;
|
|
|
|
y -= scrollPos*(LINE_HEIGHT/2);
|
|
|
|
|
2015-03-26 00:34:28 +00:00
|
|
|
if(how == PAINT) {
|
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
|
|
|
int top = y - 28, bot = y + 4;
|
|
|
|
uiCanvas->DrawRect(0, width, top, bot,
|
2016-08-13 06:46:54 +00:00
|
|
|
/*fillColor=*/{ 30, 30, 30, 255 }, /*outlineColor=*/{});
|
2015-03-26 00:34:28 +00:00
|
|
|
}
|
2010-05-03 05:04:42 +00:00
|
|
|
|
2016-08-13 06:46:54 +00:00
|
|
|
Button *oldHovered = hoveredButton;
|
2010-05-03 05:04:42 +00:00
|
|
|
if(how != PAINT) {
|
2016-08-13 06:46:54 +00:00
|
|
|
hoveredButton = NULL;
|
2010-05-03 05:04:42 +00:00
|
|
|
}
|
|
|
|
|
2016-08-13 06:46:54 +00:00
|
|
|
for(Button *button : buttons) {
|
2010-05-03 05:04:42 +00:00
|
|
|
if(how == PAINT) {
|
2016-08-13 06:46:54 +00:00
|
|
|
button->Draw(uiCanvas, x, y, (button == hoveredButton));
|
|
|
|
} else if(mx > x - 2 && mx < x + 26 &&
|
|
|
|
my < y + 2 && my > y - 26) {
|
|
|
|
// The mouse is hovered over this icon, so do the tooltip
|
|
|
|
// stuff.
|
|
|
|
if(button != tooltippedButton) {
|
|
|
|
oldMousePos = Point2d::From(mx, my);
|
2010-05-03 05:04:42 +00:00
|
|
|
}
|
2016-08-13 06:46:54 +00:00
|
|
|
if(button != oldHovered || how == CLICK) {
|
|
|
|
SetTimerFor(1000);
|
2010-05-03 05:04:42 +00:00
|
|
|
}
|
2016-08-13 06:46:54 +00:00
|
|
|
hoveredButton = button;
|
|
|
|
if(how == CLICK) {
|
|
|
|
button->Click();
|
2010-05-03 05:04:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-13 06:46:54 +00:00
|
|
|
x += button->AdvanceWidth();
|
2010-05-03 05:04:42 +00:00
|
|
|
}
|
|
|
|
|
2016-08-13 06:46:54 +00:00
|
|
|
if(how != PAINT && hoveredButton != oldHovered) {
|
2010-05-03 05:04:42 +00:00
|
|
|
InvalidateText();
|
|
|
|
}
|
|
|
|
|
2016-08-13 06:46:54 +00:00
|
|
|
if(tooltippedButton && !tooltippedButton->Tooltip().empty()) {
|
2010-05-03 05:04:42 +00:00
|
|
|
if(how == PAINT) {
|
2016-08-13 06:46:54 +00:00
|
|
|
std::string tooltip = tooltippedButton->Tooltip();
|
2010-05-03 05:04:42 +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
|
|
|
int ox = (int)oldMousePos.x, oy = (int)oldMousePos.y - LINE_HEIGHT;
|
2010-05-10 01:06:09 +00:00
|
|
|
ox += 3;
|
|
|
|
oy -= 3;
|
2016-08-13 06:46:54 +00:00
|
|
|
int tw = (tooltip.length() + 1) * (CHAR_WIDTH - 1);
|
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
|
|
|
ox = min(ox, (width - 25) - tw);
|
|
|
|
oy = max(oy, 5);
|
|
|
|
|
|
|
|
uiCanvas->DrawRect(ox, ox+tw, oy, oy+LINE_HEIGHT,
|
2016-08-13 06:46:54 +00:00
|
|
|
/*fillColor=*/{ 255, 255, 150, 255 },
|
|
|
|
/*outlineColor=*/{ 0, 0, 0, 255 });
|
|
|
|
uiCanvas->DrawBitmapText(tooltip, ox+5, oy-3+LINE_HEIGHT, { 0, 0, 0, 255 });
|
2010-05-03 05:04:42 +00:00
|
|
|
} else {
|
2016-08-13 06:46:54 +00:00
|
|
|
if(!hoveredButton || (hoveredButton != tooltippedButton)) {
|
|
|
|
tooltippedButton = NULL;
|
2010-05-03 05:04:42 +00:00
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
|
|
|
// And if we're hovered, then we've set a timer that will cause
|
|
|
|
// us to show the tool tip later.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-21 05:04:03 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Given (x, y, z) = (h, s, v) in [0,6), [0,1], [0,1], return (x, y, z) =
|
|
|
|
// (r, g, b) all in [0, 1].
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
Vector TextWindow::HsvToRgb(Vector hsv) {
|
|
|
|
if(hsv.x >= 6) hsv.x -= 6;
|
|
|
|
|
|
|
|
Vector rgb;
|
|
|
|
double hmod2 = hsv.x;
|
|
|
|
while(hmod2 >= 2) hmod2 -= 2;
|
|
|
|
double x = (1 - fabs(hmod2 - 1));
|
|
|
|
if(hsv.x < 1) {
|
2015-03-29 00:30:52 +00:00
|
|
|
rgb = Vector::From(1, x, 0);
|
2010-07-21 05:04:03 +00:00
|
|
|
} else if(hsv.x < 2) {
|
2015-03-29 00:30:52 +00:00
|
|
|
rgb = Vector::From(x, 1, 0);
|
2010-07-21 05:04:03 +00:00
|
|
|
} else if(hsv.x < 3) {
|
2015-03-29 00:30:52 +00:00
|
|
|
rgb = Vector::From(0, 1, x);
|
2010-07-21 05:04:03 +00:00
|
|
|
} else if(hsv.x < 4) {
|
2015-03-29 00:30:52 +00:00
|
|
|
rgb = Vector::From(0, x, 1);
|
2010-07-21 05:04:03 +00:00
|
|
|
} else if(hsv.x < 5) {
|
2015-03-29 00:30:52 +00:00
|
|
|
rgb = Vector::From(x, 0, 1);
|
2010-07-21 05:04:03 +00:00
|
|
|
} else {
|
2015-03-29 00:30:52 +00:00
|
|
|
rgb = Vector::From(1, 0, x);
|
2010-07-21 05:04:03 +00:00
|
|
|
}
|
|
|
|
double c = hsv.y*hsv.z;
|
|
|
|
double m = 1 - hsv.z;
|
|
|
|
rgb = rgb.ScaledBy(c);
|
|
|
|
rgb = rgb.Plus(Vector::From(m, m, m));
|
|
|
|
|
|
|
|
return rgb;
|
|
|
|
}
|
|
|
|
|
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> TextWindow::HsvPattern2d(int w, int h) {
|
|
|
|
std::shared_ptr<Pixmap> pixmap = Pixmap::Create(Pixmap::Format::RGB, w, h);
|
|
|
|
for(size_t j = 0; j < pixmap->height; j++) {
|
|
|
|
size_t p = pixmap->stride * j;
|
|
|
|
for(size_t i = 0; i < pixmap->width; i++) {
|
|
|
|
Vector hsv = Vector::From(6.0*i/(pixmap->width-1), 1.0*j/(pixmap->height-1), 1);
|
|
|
|
Vector rgb = HsvToRgb(hsv);
|
|
|
|
rgb = rgb.ScaledBy(255);
|
|
|
|
pixmap->data[p++] = (uint8_t)rgb.x;
|
|
|
|
pixmap->data[p++] = (uint8_t)rgb.y;
|
|
|
|
pixmap->data[p++] = (uint8_t)rgb.z;
|
2010-07-21 05:04:03 +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
|
|
|
return pixmap;
|
2010-07-21 05:04:03 +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
|
|
|
std::shared_ptr<Pixmap> TextWindow::HsvPattern1d(double hue, double sat, int w, int h) {
|
|
|
|
std::shared_ptr<Pixmap> pixmap = Pixmap::Create(Pixmap::Format::RGB, w, h);
|
|
|
|
for(size_t i = 0; i < pixmap->height; i++) {
|
|
|
|
size_t p = i * pixmap->stride;
|
|
|
|
for(size_t j = 0; j < pixmap->width; j++) {
|
|
|
|
Vector hsv = Vector::From(6*hue, sat, 1.0*(pixmap->width - 1 - j)/pixmap->width);
|
|
|
|
Vector rgb = HsvToRgb(hsv);
|
|
|
|
rgb = rgb.ScaledBy(255);
|
|
|
|
pixmap->data[p++] = (uint8_t)rgb.x;
|
|
|
|
pixmap->data[p++] = (uint8_t)rgb.y;
|
|
|
|
pixmap->data[p++] = (uint8_t)rgb.z;
|
|
|
|
}
|
2010-07-21 05:04:03 +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
|
|
|
return pixmap;
|
2010-07-21 05:04:03 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void TextWindow::ColorPickerDone() {
|
2015-07-10 11:54:39 +00:00
|
|
|
RgbaColor rgb = editControl.colorPicker.rgb;
|
2016-01-27 05:13:04 +00:00
|
|
|
EditControlDone(ssprintf("%.2f, %.2f, %.3f", rgb.redF(), rgb.greenF(), rgb.blueF()).c_str());
|
2010-07-21 05:04:03 +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
|
|
|
bool TextWindow::DrawOrHitTestColorPicker(UiCanvas *uiCanvas, DrawOrHitHow how, bool leftDown,
|
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 05:45:13 +00:00
|
|
|
double x, double y)
|
2010-07-21 05:04:03 +00:00
|
|
|
{
|
|
|
|
bool mousePointerAsHand = false;
|
|
|
|
|
|
|
|
if(how == HOVER && !leftDown) {
|
|
|
|
editControl.colorPicker.picker1dActive = false;
|
|
|
|
editControl.colorPicker.picker2dActive = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!editControl.colorPicker.show) return false;
|
|
|
|
if(how == CLICK || (how == HOVER && leftDown)) InvalidateText();
|
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
static const RgbaColor BaseColor[12] = {
|
2013-12-02 06:25:09 +00:00
|
|
|
RGBi(255, 0, 0),
|
|
|
|
RGBi( 0, 255, 0),
|
|
|
|
RGBi( 0, 0, 255),
|
|
|
|
|
|
|
|
RGBi( 0, 255, 255),
|
|
|
|
RGBi(255, 0, 255),
|
|
|
|
RGBi(255, 255, 0),
|
|
|
|
|
|
|
|
RGBi(255, 127, 0),
|
|
|
|
RGBi(255, 0, 127),
|
|
|
|
RGBi( 0, 255, 127),
|
|
|
|
RGBi(127, 255, 0),
|
|
|
|
RGBi(127, 0, 255),
|
|
|
|
RGBi( 0, 127, 255),
|
2010-07-21 05:04:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
GetTextWindowSize(&width, &height);
|
|
|
|
|
|
|
|
int px = LEFT_MARGIN + CHAR_WIDTH*editControl.col;
|
|
|
|
int py = (editControl.halfRow - SS.TW.scrollPos)*(LINE_HEIGHT/2);
|
|
|
|
|
|
|
|
py += LINE_HEIGHT + 5;
|
|
|
|
|
|
|
|
static const int WIDTH = 16, HEIGHT = 12;
|
|
|
|
static const int PITCH = 18, SIZE = 15;
|
|
|
|
|
|
|
|
px = min(px, width - (WIDTH*PITCH + 40));
|
|
|
|
|
|
|
|
int pxm = px + WIDTH*PITCH + 11,
|
|
|
|
pym = py + HEIGHT*PITCH + 7;
|
|
|
|
|
|
|
|
int bw = 6;
|
|
|
|
if(how == PAINT) {
|
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->DrawRect(px, pxm+bw, py, pym+bw,
|
|
|
|
/*fillColor=*/{ 50, 50, 50, 255 },
|
|
|
|
/*outlineColor=*/{});
|
|
|
|
uiCanvas->DrawRect(px+(bw/2), pxm+(bw/2), py+(bw/2), pym+(bw/2),
|
|
|
|
/*fillColor=*/{ 0, 0, 0, 255 },
|
|
|
|
/*outlineColor=*/{});
|
2010-07-21 05:04:03 +00:00
|
|
|
} else {
|
|
|
|
if(x < px || x > pxm+(bw/2) ||
|
|
|
|
y < py || y > pym+(bw/2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
px += (bw/2);
|
|
|
|
py += (bw/2);
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
for(i = 0; i < WIDTH/2; i++) {
|
|
|
|
for(j = 0; j < HEIGHT; j++) {
|
|
|
|
Vector rgb;
|
2015-07-10 11:54:39 +00:00
|
|
|
RgbaColor d;
|
2010-07-21 05:04:03 +00:00
|
|
|
if(i == 0 && j < 8) {
|
|
|
|
d = SS.modelColor[j];
|
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-16 20:00:58 +00:00
|
|
|
rgb = Vector::From(d.redF(), d.greenF(), d.blueF());
|
2010-07-21 05:04:03 +00:00
|
|
|
} else if(i == 0) {
|
|
|
|
double a = (j - 8.0)/3.0;
|
|
|
|
rgb = Vector::From(a, a, a);
|
|
|
|
} else {
|
|
|
|
d = BaseColor[j];
|
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-16 20:00:58 +00:00
|
|
|
rgb = Vector::From(d.redF(), d.greenF(), d.blueF());
|
2010-07-21 05:04:03 +00:00
|
|
|
if(i >= 2 && i <= 4) {
|
|
|
|
double a = (i == 2) ? 0.2 : (i == 3) ? 0.3 : 0.4;
|
|
|
|
rgb = rgb.Plus(Vector::From(a, a, a));
|
|
|
|
}
|
|
|
|
if(i >= 5 && i <= 7) {
|
|
|
|
double a = (i == 5) ? 0.7 : (i == 6) ? 0.4 : 0.18;
|
|
|
|
rgb = rgb.ScaledBy(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rgb = rgb.ClampWithin(0, 1);
|
|
|
|
int sx = px + 5 + PITCH*(i + 8) + 4, sy = py + 5 + PITCH*j;
|
|
|
|
|
|
|
|
if(how == PAINT) {
|
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->DrawRect(sx, sx+SIZE, sy, sy+SIZE,
|
|
|
|
/*fillColor=*/RGBf(rgb.x, rgb.y, rgb.z),
|
|
|
|
/*outlineColor=*/{});
|
2010-07-21 05:04:03 +00:00
|
|
|
} else if(how == CLICK) {
|
|
|
|
if(x >= sx && x <= sx+SIZE && y >= sy && y <= sy+SIZE) {
|
|
|
|
editControl.colorPicker.rgb = RGBf(rgb.x, rgb.y, rgb.z);
|
|
|
|
ColorPickerDone();
|
|
|
|
}
|
|
|
|
} else if(how == HOVER) {
|
|
|
|
if(x >= sx && x <= sx+SIZE && y >= sy && y <= sy+SIZE) {
|
|
|
|
mousePointerAsHand = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int hxm, hym;
|
|
|
|
int hx = px + 5, hy = py + 5;
|
|
|
|
hxm = hx + PITCH*7 + SIZE;
|
|
|
|
hym = hy + PITCH*2 + SIZE;
|
|
|
|
if(how == PAINT) {
|
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->DrawRect(hx, hxm, hy, hym,
|
|
|
|
/*fillColor=*/editControl.colorPicker.rgb,
|
|
|
|
/*outlineColor=*/{});
|
2010-07-21 05:04:03 +00:00
|
|
|
} else if(how == CLICK) {
|
|
|
|
if(x >= hx && x <= hxm && y >= hy && y <= hym) {
|
|
|
|
ColorPickerDone();
|
|
|
|
}
|
|
|
|
} else if(how == HOVER) {
|
|
|
|
if(x >= hx && x <= hxm && y >= hy && y <= hym) {
|
|
|
|
mousePointerAsHand = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hy += PITCH*3;
|
|
|
|
|
|
|
|
hxm = hx + PITCH*7 + SIZE;
|
|
|
|
hym = hy + PITCH*1 + SIZE;
|
|
|
|
// The one-dimensional thing to pick the color's value
|
|
|
|
if(how == PAINT) {
|
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->DrawPixmap(HsvPattern1d(editControl.colorPicker.h,
|
|
|
|
editControl.colorPicker.s,
|
|
|
|
hxm-hx, hym-hy),
|
|
|
|
hx, hy);
|
|
|
|
|
|
|
|
int cx = hx+(int)((hxm-hx)*(1.0 - editControl.colorPicker.v));
|
|
|
|
uiCanvas->DrawLine(cx, hy, cx, hym, { 0, 0, 0, 255 });
|
2015-03-29 00:30:52 +00:00
|
|
|
} else if(how == CLICK ||
|
2010-07-21 05:04:03 +00:00
|
|
|
(how == HOVER && leftDown && editControl.colorPicker.picker1dActive))
|
|
|
|
{
|
|
|
|
if(x >= hx && x <= hxm && y >= hy && y <= hym) {
|
|
|
|
editControl.colorPicker.v = 1 - (x - hx)/(hxm - hx);
|
|
|
|
|
|
|
|
Vector rgb = HsvToRgb(Vector::From(
|
|
|
|
6*editControl.colorPicker.h,
|
|
|
|
editControl.colorPicker.s,
|
|
|
|
editControl.colorPicker.v));
|
|
|
|
editControl.colorPicker.rgb = RGBf(rgb.x, rgb.y, rgb.z);
|
|
|
|
|
|
|
|
editControl.colorPicker.picker1dActive = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// and advance our vertical position
|
|
|
|
hy += PITCH*2;
|
|
|
|
|
|
|
|
hxm = hx + PITCH*7 + SIZE;
|
|
|
|
hym = hy + PITCH*6 + SIZE;
|
|
|
|
// Two-dimensional thing to pick a color by hue and saturation
|
|
|
|
if(how == PAINT) {
|
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->DrawPixmap(HsvPattern2d(hxm-hx, hym-hy), hx, hy);
|
|
|
|
|
|
|
|
int cx = hx+(int)((hxm-hx)*editControl.colorPicker.h),
|
|
|
|
cy = hy+(int)((hym-hy)*editControl.colorPicker.s);
|
|
|
|
uiCanvas->DrawLine(cx - 5, cy, cx + 4, cy, { 255, 255, 255, 255 });
|
|
|
|
uiCanvas->DrawLine(cx, cy - 5, cx, cy + 4, { 255, 255, 255, 255 });
|
2015-03-29 00:30:52 +00:00
|
|
|
} else if(how == CLICK ||
|
2010-07-21 05:04:03 +00:00
|
|
|
(how == HOVER && leftDown && editControl.colorPicker.picker2dActive))
|
|
|
|
{
|
|
|
|
if(x >= hx && x <= hxm && y >= hy && y <= hym) {
|
|
|
|
double h = (x - hx)/(hxm - hx),
|
|
|
|
s = (y - hy)/(hym - hy);
|
|
|
|
editControl.colorPicker.h = h;
|
|
|
|
editControl.colorPicker.s = s;
|
|
|
|
|
|
|
|
Vector rgb = HsvToRgb(Vector::From(
|
|
|
|
6*editControl.colorPicker.h,
|
|
|
|
editControl.colorPicker.s,
|
|
|
|
editControl.colorPicker.v));
|
|
|
|
editControl.colorPicker.rgb = RGBf(rgb.x, rgb.y, rgb.z);
|
|
|
|
|
|
|
|
editControl.colorPicker.picker2dActive = true;
|
|
|
|
}
|
|
|
|
}
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2010-07-21 05:04:03 +00:00
|
|
|
SetMousePointerToHand(mousePointerAsHand);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void TextWindow::Paint() {
|
2016-07-25 19:37:48 +00:00
|
|
|
#if !defined(HEADLESS)
|
2010-05-03 05:04:42 +00:00
|
|
|
int width, height;
|
|
|
|
GetTextWindowSize(&width, &height);
|
|
|
|
|
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
|
|
|
Camera camera = {};
|
|
|
|
camera.width = width;
|
|
|
|
camera.height = height;
|
|
|
|
camera.LoadIdentity();
|
|
|
|
camera.offset.x = -(double)camera.width / 2.0;
|
|
|
|
camera.offset.y = -(double)camera.height / 2.0;
|
|
|
|
|
|
|
|
OpenGl1Renderer canvas = {};
|
|
|
|
canvas.camera = camera;
|
|
|
|
canvas.BeginFrame();
|
|
|
|
canvas.UpdateProjection();
|
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
|
|
|
UiCanvas uiCanvas = {};
|
|
|
|
uiCanvas.canvas = &canvas;
|
|
|
|
uiCanvas.flip = true;
|
2010-04-26 07:52:49 +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
|
|
|
halfRows = camera.height / (LINE_HEIGHT/2);
|
2010-04-26 07:52:49 +00:00
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
int bottom = top[rows-1] + 2;
|
2010-04-26 07:52:49 +00:00
|
|
|
scrollPos = min(scrollPos, bottom - halfRows);
|
|
|
|
scrollPos = max(scrollPos, 0);
|
|
|
|
|
|
|
|
// Let's set up the scroll bar first
|
2010-05-03 05:04:42 +00:00
|
|
|
MoveTextScrollbarTo(scrollPos, top[rows - 1] + 1, halfRows);
|
2010-04-26 07:52:49 +00:00
|
|
|
|
|
|
|
// Now paint the window.
|
|
|
|
int r, c, a;
|
2010-05-03 05:04:42 +00:00
|
|
|
for(a = 0; a < 2; a++) {
|
|
|
|
for(r = 0; r < rows; r++) {
|
|
|
|
int ltop = top[r];
|
|
|
|
if(ltop < (scrollPos-1)) continue;
|
|
|
|
if(ltop > scrollPos+halfRows) break;
|
2010-04-26 07:52:49 +00:00
|
|
|
|
2015-03-27 15:43:28 +00:00
|
|
|
for(c = 0; c < min((width/CHAR_WIDTH)+1, (int) MAX_COLS); c++) {
|
2010-04-26 07:52:49 +00:00
|
|
|
int x = LEFT_MARGIN + c*CHAR_WIDTH;
|
2010-05-03 05:04:42 +00:00
|
|
|
int y = (ltop-scrollPos)*(LINE_HEIGHT/2) + 4;
|
2010-04-26 07:52:49 +00:00
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
int fg = meta[r][c].fg;
|
|
|
|
int bg = meta[r][c].bg;
|
2010-04-26 07:52:49 +00:00
|
|
|
|
|
|
|
// On the first pass, all the background quads; on the next
|
|
|
|
// pass, all the foreground (i.e., font) quads.
|
|
|
|
if(a == 0) {
|
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
|
|
|
RgbaColor bgRgb = meta[r][c].bgRgb;
|
|
|
|
int bh = LINE_HEIGHT, adj = 0;
|
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-16 20:00:58 +00:00
|
|
|
if(bg == 'z') {
|
2010-04-26 07:52:49 +00:00
|
|
|
bh = CHAR_HEIGHT;
|
2010-05-09 18:25:23 +00:00
|
|
|
adj += 2;
|
2010-04-26 07:52:49 +00:00
|
|
|
} else {
|
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
|
|
|
bgRgb = RgbaColor::FromFloat(bgColorTable[bg*3+0],
|
|
|
|
bgColorTable[bg*3+1],
|
|
|
|
bgColorTable[bg*3+2]);
|
2010-04-26 07:52:49 +00:00
|
|
|
}
|
|
|
|
|
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-16 20:00:58 +00:00
|
|
|
if(bg != 'd') {
|
2010-04-26 07:52:49 +00:00
|
|
|
// Move the quad down a bit, so that the descenders
|
|
|
|
// still have the correct background.
|
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.DrawRect(x, x + CHAR_WIDTH, y + adj, y + adj + bh,
|
|
|
|
/*fillColor=*/bgRgb, /*outlineColor=*/{});
|
2010-04-26 07:52:49 +00:00
|
|
|
}
|
|
|
|
} else if(a == 1) {
|
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
|
|
|
RgbaColor fgRgb = RgbaColor::FromFloat(fgColorTable[fg*3+0],
|
|
|
|
fgColorTable[fg*3+1],
|
|
|
|
fgColorTable[fg*3+2]);
|
2016-04-23 04:37:42 +00:00
|
|
|
if(text[r][c] != ' ') {
|
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.DrawBitmapChar(text[r][c], x, y + CHAR_HEIGHT, fgRgb);
|
2016-04-23 04:37:42 +00:00
|
|
|
}
|
2010-05-03 05:04:42 +00:00
|
|
|
|
|
|
|
// If this is a link and it's hovered, then draw the
|
2010-05-09 18:25:23 +00:00
|
|
|
// underline
|
2010-05-03 05:04:42 +00:00
|
|
|
if(meta[r][c].link && meta[r][c].link != 'n' &&
|
|
|
|
(r == hoveredRow && c == hoveredCol))
|
|
|
|
{
|
|
|
|
int cs = c, cf = c;
|
|
|
|
while(cs >= 0 && meta[r][cs].link &&
|
|
|
|
meta[r][cs].f == meta[r][c].f &&
|
|
|
|
meta[r][cs].data == meta[r][c].data)
|
|
|
|
{
|
|
|
|
cs--;
|
|
|
|
}
|
|
|
|
cs++;
|
|
|
|
|
|
|
|
while( meta[r][cf].link &&
|
|
|
|
meta[r][cf].f == meta[r][c].f &&
|
|
|
|
meta[r][cf].data == meta[r][c].data)
|
|
|
|
{
|
|
|
|
cf++;
|
|
|
|
}
|
2010-05-09 18:25:23 +00:00
|
|
|
|
|
|
|
// But don't underline checkboxes or radio buttons
|
2015-11-05 19:39:27 +00:00
|
|
|
while(((text[r][cs] >= 0xe000 && text[r][cs] <= 0xefff) ||
|
|
|
|
text[r][cs] == ' ') &&
|
|
|
|
cs < cf)
|
2010-05-09 18:25:23 +00:00
|
|
|
{
|
|
|
|
cs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always use the color of the rightmost character
|
|
|
|
// in the link, so that underline is consistent color
|
|
|
|
fg = meta[r][cf-1].fg;
|
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
|
|
|
fgRgb = RgbaColor::FromFloat(fgColorTable[fg*3+0],
|
|
|
|
fgColorTable[fg*3+1],
|
|
|
|
fgColorTable[fg*3+2]);
|
|
|
|
int yp = y + CHAR_HEIGHT;
|
|
|
|
uiCanvas.DrawLine(LEFT_MARGIN + cs*CHAR_WIDTH, yp,
|
|
|
|
LEFT_MARGIN + cf*CHAR_WIDTH, yp,
|
|
|
|
fgRgb);
|
2010-04-26 07:52:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-03 05:04:42 +00:00
|
|
|
|
2010-05-09 18:25:23 +00:00
|
|
|
// The line to indicate the column of radio buttons that indicates the
|
|
|
|
// active group.
|
|
|
|
SS.GW.GroupSelection();
|
|
|
|
// Make sure this test agrees with test to determine which screen is drawn
|
|
|
|
if(!SS.GW.pending.description && gs.n == 0 && gs.constraints == 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 08:31:20 +00:00
|
|
|
shown.screen == Screen::LIST_OF_GROUPS)
|
2010-05-09 18:25:23 +00:00
|
|
|
{
|
|
|
|
int x = 29, y = 70 + LINE_HEIGHT;
|
|
|
|
y -= scrollPos*(LINE_HEIGHT/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
|
|
|
RgbaColor color = RgbaColor::FromFloat(fgColorTable['t'*3+0],
|
|
|
|
fgColorTable['t'*3+1],
|
|
|
|
fgColorTable['t'*3+2]);
|
|
|
|
uiCanvas.DrawLine(x, y, x, y+40, color);
|
2010-05-09 18:25:23 +00:00
|
|
|
}
|
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
// The header has some icons that are drawn separately from the text
|
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
|
|
|
DrawOrHitTestIcons(&uiCanvas, PAINT, 0, 0);
|
2010-07-21 05:04:03 +00:00
|
|
|
|
|
|
|
// And we may show a color picker for certain editable fields
|
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
|
|
|
DrawOrHitTestColorPicker(&uiCanvas, PAINT, false, 0, 0);
|
|
|
|
|
|
|
|
canvas.EndFrame();
|
2016-08-07 19:33:42 +00:00
|
|
|
canvas.Clear();
|
2016-07-25 19:37:48 +00:00
|
|
|
#endif
|
2010-04-26 07:52:49 +00:00
|
|
|
}
|
|
|
|
|
2010-07-21 05:04:03 +00:00
|
|
|
void TextWindow::MouseEvent(bool leftClick, bool leftDown, double x, double y) {
|
2010-04-26 07:52:49 +00:00
|
|
|
if(TextEditControlIsVisible() || GraphicsEditControlIsVisible()) {
|
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(DrawOrHitTestColorPicker(NULL, leftClick ? CLICK : HOVER, leftDown, x, y))
|
2010-07-21 05:04:03 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-26 07:52:49 +00:00
|
|
|
if(leftClick) {
|
2010-07-12 07:51:12 +00:00
|
|
|
HideEditControl();
|
2010-04-26 07:52:49 +00:00
|
|
|
HideGraphicsEditControl();
|
|
|
|
} else {
|
|
|
|
SetMousePointerToHand(false);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
DrawOrHitTestIcons(NULL, leftClick ? CLICK : HOVER, x, y);
|
2010-05-03 05:04:42 +00:00
|
|
|
|
2010-04-26 07:52:49 +00:00
|
|
|
GraphicsWindow::Selection ps = SS.GW.hover;
|
|
|
|
SS.GW.hover.Clear();
|
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
int prevHoveredRow = hoveredRow,
|
|
|
|
prevHoveredCol = hoveredCol;
|
|
|
|
hoveredRow = 0;
|
|
|
|
hoveredCol = 0;
|
|
|
|
|
2010-04-26 07:52:49 +00:00
|
|
|
// Find the corresponding character in the text buffer
|
|
|
|
int c = (int)((x - LEFT_MARGIN) / CHAR_WIDTH);
|
|
|
|
int hh = (LINE_HEIGHT)/2;
|
|
|
|
y += scrollPos*hh;
|
|
|
|
int r;
|
2010-05-03 05:04:42 +00:00
|
|
|
for(r = 0; r < rows; r++) {
|
|
|
|
if(y >= top[r]*hh && y <= (top[r]+2)*hh) {
|
2010-04-26 07:52:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-10 12:25:10 +00:00
|
|
|
if(r >= rows || c >= MAX_COLS) {
|
2010-04-26 07:52:49 +00:00
|
|
|
SetMousePointerToHand(false);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
hoveredRow = r;
|
|
|
|
hoveredCol = c;
|
|
|
|
|
|
|
|
#define META (meta[r][c])
|
2010-04-26 07:52:49 +00:00
|
|
|
if(leftClick) {
|
|
|
|
if(META.link && META.f) {
|
|
|
|
(META.f)(META.link, META.data);
|
2010-05-03 05:04:42 +00:00
|
|
|
Show();
|
2010-04-26 07:52:49 +00:00
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(META.link) {
|
|
|
|
SetMousePointerToHand(true);
|
|
|
|
if(META.h) {
|
|
|
|
(META.h)(META.link, META.data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SetMousePointerToHand(false);
|
|
|
|
}
|
|
|
|
}
|
2013-09-19 06:35:56 +00:00
|
|
|
#undef META
|
2010-04-26 07:52:49 +00:00
|
|
|
|
|
|
|
done:
|
2010-05-03 05:04:42 +00:00
|
|
|
if((!ps.Equals(&(SS.GW.hover))) ||
|
|
|
|
prevHoveredRow != hoveredRow ||
|
|
|
|
prevHoveredCol != hoveredCol)
|
|
|
|
{
|
2010-04-26 07:52:49 +00:00
|
|
|
InvalidateGraphics();
|
2010-05-03 05:04:42 +00:00
|
|
|
InvalidateText();
|
2010-04-26 07:52:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void TextWindow::MouseLeave() {
|
2016-08-13 06:46:54 +00:00
|
|
|
tooltippedButton = NULL;
|
|
|
|
hoveredButton = NULL;
|
2010-05-03 05:04:42 +00:00
|
|
|
hoveredRow = 0;
|
|
|
|
hoveredCol = 0;
|
|
|
|
InvalidateText();
|
|
|
|
}
|
|
|
|
|
2010-04-26 07:52:49 +00:00
|
|
|
void TextWindow::ScrollbarEvent(int newPos) {
|
2016-01-13 11:55:45 +00:00
|
|
|
if(TextEditControlIsVisible())
|
|
|
|
return;
|
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
int bottom = top[rows-1] + 2;
|
2010-04-26 07:52:49 +00:00
|
|
|
newPos = min(newPos, bottom - halfRows);
|
|
|
|
newPos = max(newPos, 0);
|
|
|
|
|
|
|
|
if(newPos != scrollPos) {
|
|
|
|
scrollPos = newPos;
|
2010-05-03 05:04:42 +00:00
|
|
|
MoveTextScrollbarTo(scrollPos, top[rows - 1] + 1, halfRows);
|
2010-04-26 07:52:49 +00:00
|
|
|
InvalidateText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-13 06:46:54 +00:00
|
|
|
}
|