bool ResizableWindow::restoreWindowStateFromString (const String& s) { StringArray tokens; tokens.addTokens (s, false); tokens.removeEmptyStrings(); tokens.trim(); const bool fs = tokens[0].startsWithIgnoreCase ("fs"); const int firstCoord = fs ? 1 : 0; if (tokens.size() != firstCoord + 4) return false; Rectangle<int> newPos (tokens[firstCoord].getIntValue(), tokens[firstCoord + 1].getIntValue(), tokens[firstCoord + 2].getIntValue(), tokens[firstCoord + 3].getIntValue()); if (newPos.isEmpty()) return false; ComponentPeer* const peer = isOnDesktop() ? getPeer() : nullptr; if (peer != nullptr) peer->getFrameSize().addTo (newPos); { Desktop& desktop = Desktop::getInstance(); RectangleList allMonitors (desktop.getDisplays().getRectangleList (true)); allMonitors.clipTo (newPos); const Rectangle<int> onScreenArea (allMonitors.getBounds()); if (onScreenArea.getWidth() * onScreenArea.getHeight() < 32 * 32) { const Rectangle<int> screen (desktop.getDisplays().getDisplayContaining (newPos.getCentre()).userArea); newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()), jmin (newPos.getHeight(), screen.getHeight())); newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()), jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY())); } } if (peer != nullptr) { peer->getFrameSize().subtractFrom (newPos); peer->setNonFullScreenBounds (newPos); } lastNonFullScreenPos = newPos; setFullScreen (fs); if (! fs) setBoundsConstrained (newPos); return true; }
void Graphics::fillCheckerBoard (Rectangle<float> area, float checkWidth, float checkHeight, Colour colour1, Colour colour2) const { jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less! if (checkWidth > 0 && checkHeight > 0) { context.saveState(); if (colour1 == colour2) { context.setFill (colour1); context.fillRect (area); } else { auto clipped = context.getClipBounds().getIntersection (area.getSmallestIntegerContainer()); if (! clipped.isEmpty()) { const int checkNumX = (int) ((clipped.getX() - area.getX()) / checkWidth); const int checkNumY = (int) ((clipped.getY() - area.getY()) / checkHeight); const float startX = area.getX() + checkNumX * checkWidth; const float startY = area.getY() + checkNumY * checkHeight; const float right = (float) clipped.getRight(); const float bottom = (float) clipped.getBottom(); for (int i = 0; i < 2; ++i) { int cy = i; RectangleList<float> checks; for (float y = startY; y < bottom; y += checkHeight) for (float x = startX + (cy++ & 1) * checkWidth; x < right; x += checkWidth * 2.0f) checks.addWithoutMerging ({ x, y, checkWidth, checkHeight }); checks.clipTo (area); context.setFill (i == ((checkNumX ^ checkNumY) & 1) ? colour1 : colour2); context.fillRectList (checks); } } } context.restoreState(); } }