From a8e723381c6b74dfb1ec855ff079459f49de36a1 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 10 Oct 2016 12:34:10 +0000 Subject: [PATCH] Replace convenience #defines with const auto references. These are nicer as they are scoped, and so it's clear where they can be used. --- src/constraint.cpp | 2 +- src/describescreen.cpp | 3 ++- src/export.cpp | 2 +- src/group.cpp | 3 +-- src/groupmesh.cpp | 3 +-- src/solvespace.cpp | 2 +- src/textwin.cpp | 40 +++++++++++++++++++--------------------- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/constraint.cpp b/src/constraint.cpp index 23cee25..fb679df 100644 --- a/src/constraint.cpp +++ b/src/constraint.cpp @@ -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: diff --git a/src/describescreen.cpp b/src/describescreen.cpp index a1db11f..0aef091 100644 --- a/src/describescreen.cpp +++ b/src/describescreen.cpp @@ -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]); diff --git a/src/export.cpp b/src/export.cpp index e2f20b1..a604fec 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -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(); diff --git a/src/group.cpp b/src/group.cpp index f85d981..ae64acc 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -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: diff --git a/src/groupmesh.cpp b/src/groupmesh.cpp index d9d10ab..e01afa7 100644 --- a/src/groupmesh.cpp +++ b/src/groupmesh.cpp @@ -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 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); diff --git a/src/solvespace.cpp b/src/solvespace.cpp index 7115bc2..9ad65d4 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -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: diff --git a/src/textwin.cpp b/src/textwin.cpp index ffab474..c69679b 100644 --- a/src/textwin.cpp +++ b/src/textwin.cpp @@ -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)