diff options
Diffstat (limited to 'wx+')
-rw-r--r-- | wx+/graph.cpp | 34 | ||||
-rw-r--r-- | wx+/grid.cpp | 22 | ||||
-rw-r--r-- | wx+/grid.h | 8 |
3 files changed, 35 insertions, 29 deletions
diff --git a/wx+/graph.cpp b/wx+/graph.cpp index 22358922..f4e758c1 100644 --- a/wx+/graph.cpp +++ b/wx+/graph.cpp @@ -19,7 +19,8 @@ using namespace zen; const wxEventType zen::wxEVT_GRAPH_SELECTION = wxNewEventType(); -const std::shared_ptr<LabelFormatter> Graph2D::MainAttributes::defaultFormat = std::make_shared<DecimalNumberFormatter>(); //for some buggy reason MSVC isn't able to use a temporary as a default argument +//for some buggy reason MSVC isn't able to use a temporary as a default argument +const std::shared_ptr<LabelFormatter> Graph2D::MainAttributes::defaultFormat = std::make_shared<DecimalNumberFormatter>(); double zen::nextNiceNumber(double blockSize) //round to next number which is a convenient to read block size @@ -82,7 +83,7 @@ public: outOfBoundsLow (-1 * scaleToReal + valMin), outOfBoundsHigh((screenSize + 1) * scaleToReal + valMin) { if (outOfBoundsLow > outOfBoundsHigh) std::swap(outOfBoundsLow, outOfBoundsHigh); } - double screenToReal(double screenPos) const //input value: [0, screenSize - 1] + double screenToReal(double screenPos) const //map [0, screenSize] -> [valMin, valMax] { return screenPos * scaleToReal + min_; } @@ -93,7 +94,7 @@ public: int realToScreenRound(double realPos) const //returns -1 and screenSize + 1 if out of bounds! { //catch large double values: if double is larger than what int can represent => undefined behavior! - numeric::confine(realPos , outOfBoundsLow, outOfBoundsHigh); + numeric::clamp(realPos , outOfBoundsLow, outOfBoundsHigh); return numeric::round(realToScreen(realPos)); } @@ -120,9 +121,14 @@ void widenRange(double& valMin, double& valMax, //in/out valRangePerBlock = labelFmt.getOptimalBlockSize(valRangePerBlock); if (!numeric::isNull(valRangePerBlock)) { - valMin = std::floor(valMin / valRangePerBlock) * valRangePerBlock; - valMax = std::ceil (valMax / valRangePerBlock) * valRangePerBlock; - blockCount = numeric::round((valMax - valMin) / valRangePerBlock); //"round" to avoid IEEE 754 surprises + int blockMin = std::floor(valMin / valRangePerBlock); + int blockMax = std::ceil (valMax / valRangePerBlock); + if (blockMin == blockMax) //handle valMin == valMax == integer + ++blockMax; + + valMin = blockMin * valRangePerBlock; + valMax = blockMax * valRangePerBlock; + blockCount = blockMax - blockMin; return; } } @@ -670,10 +676,10 @@ void Graph2D::render(wxDC& dc) const const wxPoint screenCurrent = activeSel->refCurrentPos() - graphAreaOrigin; //normalize positions: a mouse selection is symmetric and *not* an half-open range! - double screenFromX = confineCpy(screenStart .x, 0, graphArea.width - 1); - double screenFromY = confineCpy(screenStart .y, 0, graphArea.height - 1); - double screenToX = confineCpy(screenCurrent.x, 0, graphArea.width - 1); - double screenToY = confineCpy(screenCurrent.y, 0, graphArea.height - 1); + double screenFromX = clampCpy(screenStart .x, 0, graphArea.width - 1); + double screenFromY = clampCpy(screenStart .y, 0, graphArea.height - 1); + double screenToX = clampCpy(screenCurrent.x, 0, graphArea.width - 1); + double screenToY = clampCpy(screenCurrent.y, 0, graphArea.height - 1); widen(&screenFromX, &screenToX); //use full pixel range for selection! widen(&screenFromY, &screenToY); @@ -731,10 +737,10 @@ void Graph2D::render(wxDC& dc) const shrink(&screenFromX, &screenToX); shrink(&screenFromY, &screenToY); - confine(screenFromX, 0.0, graphArea.width - 1.0); - confine(screenFromY, 0.0, graphArea.height - 1.0); - confine(screenToX, 0.0, graphArea.width - 1.0); - confine(screenToY, 0.0, graphArea.height - 1.0); + clamp(screenFromX, 0.0, graphArea.width - 1.0); + clamp(screenFromY, 0.0, graphArea.height - 1.0); + clamp(screenToX, 0.0, graphArea.width - 1.0); + clamp(screenToY, 0.0, graphArea.height - 1.0); const wxPoint pixelFrom = wxPoint(numeric::round(screenFromX), numeric::round(screenFromY)) + graphAreaOrigin; diff --git a/wx+/grid.cpp b/wx+/grid.cpp index 248a82ef..5bcac1a5 100644 --- a/wx+/grid.cpp +++ b/wx+/grid.cpp @@ -79,7 +79,7 @@ void GridData::renderRowBackgound(wxDC& dc, const wxRect& rect, size_t row, bool } -void GridData::renderCell(wxDC& dc, const wxRect& rect, size_t row, ColumnType colType, bool selected) +void GridData::renderCell(wxDC& dc, const wxRect& rect, size_t row, ColumnType colType, bool enabled, bool selected) { wxRect rectTmp = drawCellBorder(dc, rect); @@ -938,7 +938,7 @@ private: { const wxRect cellRect(cellAreaTL.x, cellAreaTL.y + row * rowHeight, cw.width_, rowHeight); RecursiveDcClipper dummy3(dc, cellRect); - prov->renderCell(dc, cellRect, row, cw.type_, drawAsSelected(row)); + prov->renderCell(dc, cellRect, row, cw.type_, refParent().IsThisEnabled(), drawAsSelected(row)); } cellAreaTL.x += cw.width_; } @@ -1161,7 +1161,7 @@ private: { //select current row *after* scrolling wxPoint clientPosTrimmed = clientPos; - numeric::confine(clientPosTrimmed.y, 0, clientSize.GetHeight() - 1); //do not select row outside client window! + numeric::clamp(clientPosTrimmed.y, 0, clientSize.GetHeight() - 1); //do not select row outside client window! const wxPoint absPos = wnd_.refParent().CalcUnscrolledPosition(clientPosTrimmed); const ptrdiff_t newRow = wnd_.rowLabelWin_.getRowAtPos(absPos.y); //return -1 for invalid position; >= rowCount if out of range @@ -1310,8 +1310,8 @@ void Grid::updateWindowSizes(bool updateScrollbar) { ptrdiff_t yFrom = CalcUnscrolledPosition(wxPoint(0, 0)).y; ptrdiff_t yTo = CalcUnscrolledPosition(wxPoint(0, mainWinHeightGross - 1)).y ; - numeric::confine<ptrdiff_t>(yFrom, 0, logicalHeight - 1); - numeric::confine<ptrdiff_t>(yTo, 0, logicalHeight - 1); + numeric::clamp<ptrdiff_t>(yFrom, 0, logicalHeight - 1); + numeric::clamp<ptrdiff_t>(yTo, 0, logicalHeight - 1); const ptrdiff_t rowFrom = rowLabelWin_->getRowAtPos(yFrom); const ptrdiff_t rowTo = rowLabelWin_->getRowAtPos(yTo); @@ -1416,8 +1416,8 @@ wxSize Grid::GetSizeAvailableForScrollTarget(const wxSize& size) { ptrdiff_t yFrom = CalcUnscrolledPosition(wxPoint(0, 0)).y; ptrdiff_t yTo = CalcUnscrolledPosition(wxPoint(0, mainWinHeightGross - 1)).y ; - numeric::confine<ptrdiff_t>(yFrom, 0, logicalHeight - 1); - numeric::confine<ptrdiff_t>(yTo, 0, logicalHeight - 1); + numeric::clamp<ptrdiff_t>(yFrom, 0, logicalHeight - 1); + numeric::clamp<ptrdiff_t>(yTo, 0, logicalHeight - 1); const ptrdiff_t rowFrom = rowLabelWin_->getRowAtPos(yFrom); const ptrdiff_t rowTo = rowLabelWin_->getRowAtPos(yTo); @@ -1454,7 +1454,7 @@ void Grid::onKeyDown(wxKeyEvent& event) { if (rowCount > 0) { - numeric::confine<ptrdiff_t>(row, 0, rowCount - 1); + numeric::clamp<ptrdiff_t>(row, 0, rowCount - 1); setGridCursor(row); } }; @@ -1463,7 +1463,7 @@ void Grid::onKeyDown(wxKeyEvent& event) { if (rowCount > 0) { - numeric::confine<ptrdiff_t>(row, 0, rowCount - 1); + numeric::clamp<ptrdiff_t>(row, 0, rowCount - 1); selectWithCursor(row); } }; @@ -2009,8 +2009,8 @@ void Grid::selectRangeAndNotify(ptrdiff_t rowFrom, ptrdiff_t rowTo, bool positiv auto rowLast = std::max(rowFrom, rowTo) + 1; const size_t rowCount = getRowCount(); - numeric::confine<ptrdiff_t>(rowFirst, 0, rowCount); - numeric::confine<ptrdiff_t>(rowLast, 0, rowCount); + numeric::clamp<ptrdiff_t>(rowFirst, 0, rowCount); + numeric::clamp<ptrdiff_t>(rowLast, 0, rowCount); selection.selectRange(rowFirst, rowLast, positive); @@ -92,8 +92,8 @@ public: //grid area virtual wxString getValue(size_t row, ColumnType colType) const = 0; - virtual void renderRowBackgound(wxDC& dc, const wxRect& rect, size_t row, bool enabled, bool selected); //default implementation - virtual void renderCell (wxDC& dc, const wxRect& rect, size_t row, ColumnType colType, bool selected); // + virtual void renderRowBackgound(wxDC& dc, const wxRect& rect, size_t row, bool enabled, bool selected); //default implementation + virtual void renderCell (wxDC& dc, const wxRect& rect, size_t row, ColumnType colType, bool enabled, bool selected); // virtual int getBestSize (wxDC& dc, size_t row, ColumnType colType); //must correspond to renderCell()! virtual wxString getToolTip(size_t row, ColumnType colType) const { return wxString(); } @@ -250,8 +250,8 @@ private: { if (rowFirst <= rowLast) { - numeric::confine<size_t>(rowFirst, 0, rowSelectionValue.size()); - numeric::confine<size_t>(rowLast, 0, rowSelectionValue.size()); + numeric::clamp<size_t>(rowFirst, 0, rowSelectionValue.size()); + numeric::clamp<size_t>(rowLast, 0, rowSelectionValue.size()); std::fill(rowSelectionValue.begin() + rowFirst, rowSelectionValue.begin() + rowLast, positive); } |