// This file is part of c-evo-evo. // // This software is governed by the CeCILL license under French law and // abiding by the rules of distribution of free software. You can use, // modify and/or redistribute the software under the terms of the CeCILL // license as circulated by CEA, CNRS and INRIA at the following URL // "http://www.cecill.info". // // As a counterpart to the access to the source code and rights to copy, // modify and redistribute granted by the license, users are provided only // with a limited warranty and the software's author, the holder of the // economic rights, and the successive licensors have only limited // liability. // // In this respect, the user's attention is drawn to the risks associated // with loading, using, modifying and/or developing or reproducing the // software by the user in light of its specific status of free software, // that may mean that it is complicated to manipulate, and that also // therefore means that it is reserved for developers and experienced // professionals having in-depth computer knowledge. Users are therefore // encouraged to load and test the software's suitability as regards their // requirements in conditions enabling the security of their systems and/or // data to be ensured and, more generally, to use and operate it in the // same conditions as regards security. // // The fact that you are presently reading this means that you have had // knowledge of the CeCILL license and that you accept its terms. #include "Cevo/CevoBaseWin.h" #include "Cevo/CevoArea.h" #include "Cevo/CevoButtonBase.h" #include "Cevo/CevoScreenTools.h" #include "Cevo/CevoTexture.h" #include #include #include #include namespace Cevo { std::function BufferedDrawDlg::showNewContentHook; WindowMode windowModeMakePersistent(WindowMode mode) { return mode == WindowMode::Modal ? WindowMode::Submodal : WindowMode::Persistent; } void createOffscreen(Dpi::Bitmap &offscreen, int width, int height) { if (offscreen.width() != width || offscreen.height() != height) { offscreen.setSize(width, height); clearOffscreen(offscreen); } } void clearOffscreen(Dpi::Bitmap &offscreen) { Dpi::Canvas &canvas = offscreen.canvas(); canvas.begin(); canvas.brush().setColor(Qt::black); canvas.fillRect(QRect(0, 0, offscreen.width(), offscreen.height())); canvas.end(); } BufferedDrawDlg::BufferedDrawDlg(QWidget *parent) : DrawDlg(parent) { createOffscreen(offscreen, width(), height()); const Dpi::Monitor monitor = Dpi::Screen::primaryMonitor(); userLeft = monitor.left() + (monitor.width() - width()) / 2; userTop = monitor.top() + (monitor.height() - height()) / 2; titleHeight = WideFrame; } void BufferedDrawDlg::markUsedOffscreen(int xMax, int yMax) { usedOffscreenWidth = std::max(usedOffscreenWidth, xMax); usedOffscreenHeight = std::max(usedOffscreenHeight, yMax); } void BufferedDrawDlg::offscreenPaint() { createOffscreen(offscreen, width(), height()); } void BufferedDrawDlg::vpaint(Dpi::Canvas &canvas) { canvas.draw(0, 0, offscreen.image()); } void BufferedDrawDlg::paintEvent(QPaintEvent *) { offscreenPaint(); QPainter painter(this); Dpi::Canvas canvas; canvas.bind(&painter); vpaint(canvas); canvas.unbind(); } void BufferedDrawDlg::resizeEvent(QResizeEvent *event) { DrawDlg::resizeEvent(event); smartUpdateContent(); } void BufferedDrawDlg::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_F1) { if (showNewContentHook) showNewContentHook(windowModeMakePersistent(m_windowMode), helpContext); } else { DrawDlg::keyPressEvent(event); } } void BufferedDrawDlg::showNewContent(WindowMode newMode, bool forceClose) { if (isVisible()) { if (newMode == WindowMode::Modal && (forceClose || m_windowMode != WindowMode::Modal)) { userLeft = x(); userTop = y(); setVisible(false); m_windowMode = newMode; showModal(); } else if (forceClose) { setVisible(false); m_windowMode = newMode; move(userLeft, userTop); show(); } else { m_windowMode = newMode; if (onShow) onShow(); update(); raise(); } } else { m_windowMode = newMode; move(userLeft, userTop); if (m_windowMode == WindowMode::Modal) showModal(); else show(); } } void BufferedDrawDlg::smartUpdateContent(bool immediateUpdate) { if (isVisible()) { offscreenPaint(); smartInvalidate(); if (immediateUpdate) repaint(); } } // ---- FramedDlg ---- FramedDlg::FramedDlg(QWidget *parent) : BufferedDrawDlg(parent) { innerWidth = width() - 2 * SideFrame; innerHeight = height() - titleHeight - NarrowFrame; } void FramedDlg::smartInvalidate() { const int bottomFrame = wideBottom ? WideFrame : NarrowFrame; QRegion region(QRect(SideFrame, titleHeight, width() - 2 * SideFrame, height() - titleHeight - bottomFrame)); const auto children = findChildren(QString(), Qt::FindDirectChildrenOnly); for (QWidget *child : children) { if (!qobject_cast(child) && child->isVisible()) region -= QRegion(child->geometry()); } update(region); } void FramedDlg::resizeEvent(QResizeEvent *event) { BufferedDrawDlg::resizeEvent(event); innerWidth = width() - 2 * SideFrame; innerHeight = height() - titleHeight - NarrowFrame; } void FramedDlg::fillOffscreen(int left, int top, int w, int h) { fill(offscreen.canvas(), left, top, w, h, SideFrame, titleHeight); } void FramedDlg::initWindowRegion() { if (fullCaption) return; QRegion region(rect()); region -= QRegion(QRect(0, 0, captionLeft, titleHeight - NarrowFrame)); region -= QRegion(QRect(width() - captionLeft, 0, captionLeft, titleHeight - NarrowFrame)); if (wideBottom) { region -= QRegion(QRect(0, height() - (WideFrame - NarrowFrame), captionLeft, WideFrame - NarrowFrame)); region -= QRegion(QRect(width() - captionLeft, height() - (WideFrame - NarrowFrame), captionLeft, WideFrame - NarrowFrame)); } setMask(region); } void FramedDlg::vpaint(Dpi::Canvas &canvas) { if (!MainTexture) return; auto cornerFrame = [&](int x0, int y0, int x1, int y1) { frame(canvas, x0 + 1, y0 + 1, x1 - 2, y1 - 2, MainTexture->colorBevelLight, MainTexture->colorBevelShade); frame(canvas, x0 + 2, y0 + 2, x1 - 3, y1 - 3, MainTexture->colorBevelLight, MainTexture->colorBevelShade); corner(canvas, x0 + 1, y0 + 1, 0, *MainTexture); corner(canvas, x1 - 9, y0 + 1, 1, *MainTexture); corner(canvas, x0 + 1, y1 - 9, 2, *MainTexture); corner(canvas, x1 - 9, y1 - 9, 3, *MainTexture); }; canvas.font().assign(UniFont[static_cast(FontType::Caption)]); const int l = biColorTextWidth(canvas, windowTitle()); const int cut = (width() - l) / 2; const int innerBottom = wideBottom ? height() - WideFrame : height() - NarrowFrame; int frameTop, frameBottom; if (fullCaption) { frameTop = 0; frameBottom = height(); } else { frameTop = titleHeight - NarrowFrame; frameBottom = wideBottom ? height() - (WideFrame - NarrowFrame) : height(); } fill(canvas, 3, innerBottom + 1, width() - 6, height() - innerBottom - 4, 0, 0); fill(canvas, 3, titleHeight - 2, SideFrame - 3, innerBottom - titleHeight + 4, 0, 0); fill(canvas, width() - SideFrame, titleHeight - 2, SideFrame - 3, innerBottom - titleHeight + 4, 0, 0); frame(canvas, 0, frameTop, width() - 1, frameBottom - 1, Qt::black, Qt::black); frame(canvas, SideFrame - 1, titleHeight - 1, width() - SideFrame, innerBottom, MainTexture->colorBevelShade, MainTexture->colorBevelLight); // The original also draws an inset divider around the centered caption // text when FWindowMode = wmModal and ModalIndication is set; omitted // here as a purely cosmetic simplification (same Frame()/moveTo/lineTo // pattern used elsewhere in this function could reproduce it). if (fullCaption) { fill(canvas, 3, 3 + frameTop, width() - 6, titleHeight - frameTop - 4, 0, 0); cornerFrame(0, frameTop, width(), frameBottom); } else { fill(canvas, 3, 3 + frameTop, width() - 6, titleHeight - frameTop - 4, 0, 0); cornerFrame(0, frameTop, width(), frameBottom); frame(canvas, captionLeft, 0, width() - captionLeft - 1, frameTop, Qt::black, Qt::black); fill(canvas, captionLeft + 3, 3, width() - 2 * captionLeft - 6, titleHeight - 4, 0, 0); frame(canvas, captionLeft + 1, 1, width() - captionLeft - 2, titleHeight - 1, MainTexture->colorBevelLight, MainTexture->colorBevelShade); frame(canvas, captionLeft + 2, 2, width() - captionLeft - 3, titleHeight - 1, MainTexture->colorBevelLight, MainTexture->colorBevelShade); corner(canvas, captionLeft + 1, 1, 0, *MainTexture); corner(canvas, width() - captionLeft - 9, 1, 1, *MainTexture); if (wideBottom) { frame(canvas, captionLeft, frameBottom, width() - captionLeft - 1, height() - 1, Qt::black, Qt::black); fill(canvas, captionLeft + 3, height() - 3 - (WideFrame - 5), width() - 2 * captionLeft - 6, WideFrame - 5, 0, 0); frame(canvas, captionLeft + 1, height() - WideFrame, width() - captionLeft - 2, height() - 2, MainTexture->colorBevelLight, MainTexture->colorBevelShade); corner(canvas, captionLeft + 1, height() - 9, 2, *MainTexture); corner(canvas, width() - captionLeft - 9, height() - 9, 3, *MainTexture); } } risedTextOut(canvas, cut - 1, 7, windowTitle()); const auto children = findChildren(QString(), Qt::FindDirectChildrenOnly); for (ButtonBase *button : children) { if (button->isVisible()) { const QRect r = button->geometry(); if (r.bottom() <= titleHeight || r.top() >= innerBottom) btnFrame(canvas, r, *MainTexture); } } canvas.copyRect(QRect(SideFrame, titleHeight, width() - 2 * SideFrame, innerBottom - titleHeight), offscreen.canvas(), QRect(0, 0, width() - 2 * SideFrame, innerBottom - titleHeight)); } } // namespace Cevo