Replace convenience #defines with const auto references.

These are nicer as they are scoped, and so it's clear where they
can be used.
pull/66/head
whitequark 2016-10-10 12:34:10 +00:00
parent f5a37ae2fd
commit a8e723381c
7 changed files with 26 additions and 29 deletions

View File

@ -121,7 +121,7 @@ void Constraint::MenuConstrain(Command id) {
c.workplane = SS.GW.ActiveWorkplane();
SS.GW.GroupSelection();
#define gs (SS.GW.gs)
auto const &gs = SS.GW.gs;
switch(id) {
case Command::DISTANCE_DIA:

View File

@ -19,13 +19,13 @@ void TextWindow::ScreenEditTtfText(int link, uint32_t v) {
SS.TW.edit.request = hr;
}
#define gs (SS.GW.gs)
void TextWindow::ScreenSetTtfFont(int link, uint32_t v) {
int i = (int)v;
if(i < 0) return;
if(i >= SS.fonts.l.n) return;
SS.GW.GroupSelection();
auto const &gs = SS.GW.gs;
if(gs.entities != 1 || gs.n != 1) return;
Entity *e = SK.entity.FindByIdNoOops(gs.entity[0]);
@ -57,6 +57,7 @@ void TextWindow::DescribeSelection() {
int i;
Printf(false, "");
auto const &gs = SS.GW.gs;
if(gs.n == 1 && (gs.points == 1 || gs.entities == 1)) {
e = SK.GetEntity(gs.points == 1 ? gs.point[0] : gs.entity[0]);

View File

@ -26,7 +26,7 @@ void SolveSpaceUI::ExportSectionTo(const std::string &filename) {
double d;
SS.GW.GroupSelection();
#define gs (SS.GW.gs)
auto const &gs = SS.GW.gs;
if((gs.n == 0 && g->activeWorkplane.v != Entity::FREE_IN_3D.v)) {
Entity *wrkpl = SK.GetEntity(g->activeWorkplane);
origin = wrkpl->WorkplaneGetOffset();

View File

@ -13,8 +13,6 @@ const hParam Param::NO_PARAM = { 0 };
const hGroup Group::HGROUP_REFERENCES = { 1 };
#define gs (SS.GW.gs)
//-----------------------------------------------------------------------------
// The group structure includes pointers to other dynamically-allocated
// memory. This clears and frees them all.
@ -83,6 +81,7 @@ void Group::MenuGroup(Command id) {
}
SS.GW.GroupSelection();
auto const &gs = SS.GW.gs;
switch(id) {
case Command::GROUP_3D:

View File

@ -7,8 +7,6 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"
#define gs (SS.GW.gs)
void Group::AssembleLoops(bool *allClosed,
bool *allCoplanar,
bool *allNonZeroLen)
@ -513,6 +511,7 @@ void Group::DrawMesh(DrawMeshAs how, Canvas *canvas) {
std::vector<uint32_t> faces;
SS.GW.GroupSelection();
auto const &gs = SS.GW.gs;
if(gs.faces > 0) faces.push_back(gs.face[0].v);
if(gs.faces > 1) faces.push_back(gs.face[1].v);
canvas->DrawFaces(displayMesh, faces, hcf);

View File

@ -570,7 +570,7 @@ void SolveSpaceUI::MenuFile(Command id) {
void SolveSpaceUI::MenuAnalyze(Command id) {
SS.GW.GroupSelection();
#define gs (SS.GW.gs)
auto const &gs = SS.GW.gs;
switch(id) {
case Command::STEP_DIM:

View File

@ -448,11 +448,11 @@ done:
va_end(vl);
}
#define gs (SS.GW.gs)
void TextWindow::Show() {
if(SS.GW.pending.operation == GraphicsWindow::Pending::NONE) SS.GW.ClearPending();
SS.GW.GroupSelection();
auto const &gs = SS.GW.gs;
// Make sure these tests agree with test used to draw indicator line on
// main list of groups screen.
@ -963,6 +963,7 @@ void TextWindow::Paint() {
// The line to indicate the column of radio buttons that indicates the
// active group.
SS.GW.GroupSelection();
auto const &gs = SS.GW.gs;
// Make sure this test agrees with test to determine which screen is drawn
if(!SS.GW.pending.description && gs.n == 0 && gs.constraints == 0 &&
shown.screen == Screen::LIST_OF_GROUPS)
@ -1023,34 +1024,31 @@ void TextWindow::MouseEvent(bool leftClick, bool leftDown, double x, double y) {
break;
}
}
if(r >= rows || c >= MAX_COLS) {
if(r < rows && c < MAX_COLS) {
SetMousePointerToHand(false);
goto done;
}
hoveredRow = r;
hoveredCol = c;
hoveredRow = r;
hoveredCol = c;
#define META (meta[r][c])
if(leftClick) {
if(META.link && META.f) {
(META.f)(META.link, META.data);
Show();
InvalidateGraphics();
}
} else {
if(META.link) {
SetMousePointerToHand(true);
if(META.h) {
(META.h)(META.link, META.data);
const auto &item = meta[r][c];
if(leftClick) {
if(item.link && item.f) {
(item.f)(item.link, item.data);
Show();
InvalidateGraphics();
}
} else {
SetMousePointerToHand(false);
if(item.link) {
SetMousePointerToHand(true);
if(item.h) {
(item.h)(item.link, item.data);
}
} else {
SetMousePointerToHand(false);
}
}
}
#undef META
done:
if((!ps.Equals(&(SS.GW.hover))) ||
prevHoveredRow != hoveredRow ||
prevHoveredCol != hoveredCol)