// 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. // Start.pas, the painting part: TStartDlg.OffscreenPaint and DrawAction. #include "Start.h" #include "ui_Start.h" #include "Cevo/CevoButtonA.h" #include "Cevo/CevoButtonB.h" #include "Cevo/CevoButtonC.h" #include "Cevo/CevoGraphicSet.h" #include "Cevo/CevoListBoxEx.h" #include "Cevo/CevoScreenTools.h" #include "Cevo/CevoTexture.h" #include "Cevo/Database.h" #include "GameServer.h" #include "Global.h" #include "StartLayout.h" #include "localplayer/Term.h" #include #include namespace Cevo { using namespace StartLayout; namespace { QString startControl(int index) { return phrases.lookup(QStringLiteral("STARTCONTROLS"), index); } bool isPlayableBrain(const Brain *brain) { return brain && (brain->kind == BrainType::Term || brain->kind == BrainType::Random || brain->kind == BrainType::AI); } // Rectangular copy between two canvases (Pascal's BitBltCanvas). void copyBlock(Dpi::Canvas &dst, int x, int y, int w, int h, Dpi::Canvas &src, int xSrc, int ySrc) { dst.copyRect(QRect(x, y, w, h), src, QRect(xSrc, ySrc, w, h)); } // TabSize (like several other layout constants here) is a fixed pixel // width inherited from the original Windows build, sized for English // text - longer translations (e.g. French "Nouveau livre") can overflow // it and overlap the neighboring tab. Shrink the font just for this one // label, rather than changing the fixed tab layout, so every language // still fits without touching unrelated pixel-perfect positioning. void risedTextOutFitted(Dpi::Canvas &canvas, int x, int y, int maxWidth, const QString &text) { constexpr int MinPixelSize = 8; const Dpi::Font original = canvas.font(); int pixelSize = original.toQFont().pixelSize(); while (pixelSize > MinPixelSize && biColorTextWidth(canvas, text) > maxWidth) { --pixelSize; canvas.font().setHeight(pixelSize); } risedTextOut(canvas, x + (maxWidth - biColorTextWidth(canvas, text)) / 2, y, text); canvas.font().assign(original); } } // namespace void StartDlg::drawAction(int y, int iconIndex, const QString &headerItem, const QString &textItem) { Dpi::Canvas &canvas = offscreen.canvas(); canvas.font().assign(UniFont[static_cast(FontType::Caption)]); canvas.font().setUnderline(true); risedTextOut(canvas, xAction, y - 3, phrases2.lookup(headerItem)); canvas.font().assign(UniFont[static_cast(FontType::Normal)]); biColorTextOut(canvas, Colors->image().pixelColor(clkAge0 - 1, cliDimmedText), Qt::black, xAction, y + 21, phrases2.lookup(textItem)); drawBufferEnsureSize(50, 50); drawBuffer.canvas().begin(); copyBlock(drawBuffer.canvas(), 0, 0, 50, 50, canvas, xActionIcon - 2, y - 2); drawBuffer.canvas().end(); glowFrame(drawBuffer, 8, 8, 34, 34, QColor(0x20, 0x20, 0x20)); copyBlock(canvas, xActionIcon - 2, y - 2, 50, 50, drawBuffer.canvas(), 0, 0); copyBlock(canvas, xActionIcon, y, 40, 40, bigImp->canvas(), (iconIndex % 7) * xSizeBig + 8, (iconIndex / 7) * ySizeBig); rframe(canvas, xActionIcon - 1, y - 1, xActionIcon + 40, y + 40, Qt::black, Qt::black); } void StartDlg::offscreenPaint() { static const int tabNames[4] = { 0, 11, 3, 4 }; BufferedDrawDlg::offscreenPaint(); clearOffscreen(offscreen); if (!MainTexture || !HGrSystem || !Templates || !bigImp || !Colors) return; Dpi::Canvas &canvas = offscreen.canvas(); canvas.begin(); const QColor shade = MainTexture->colorBevelShade; const QColor light = MainTexture->colorBevelLight; const int clientWidth = width(); const int clientHeight = height(); const int tabIndex = static_cast(m_tab); canvas.font().assign(UniFont[static_cast(FontType::Normal)]); canvas.brush().setStyle(Qt::NoBrush); paintBackground(canvas, 3, 3, TabOffset + 4 * TabSize - 4, TabHeight - 3, clientWidth, clientHeight); paintBackground(canvas, 3, TabHeight + 3, clientWidth - 6, clientHeight - TabHeight - 6, clientWidth, clientHeight); canvas.brush().setStyle(Qt::SolidPattern); canvas.brush().setColor(Qt::black); canvas.fillRect(QRect(0, 1, clientWidth, 2)); canvas.fillRect(QRect(TabOffset + 4 * TabSize + 2, 0, clientWidth - (TabOffset + 4 * TabSize + 2), TabHeight)); canvas.brush().setStyle(Qt::NoBrush); if (m_page == Page::StartRandom || m_page == Page::StartMap) { frame(canvas, 328, yMain + 112 - 15, clientWidth + 10, ui->up2Btn->y() + 38, shade, light); if (m_autoDiff > 0) frame(canvas, -1, yMain + 112 - 15, x0Brain + dxBrain + 64, ui->up2Btn->y() + 38, shade, light); } else if (m_page != Page::Main) { frame(canvas, 328, ui->up1Btn->y() - 15, clientWidth + 10, ui->up2Btn->y() + 38, shade, light); } frame(canvas, 0, 0, clientWidth - 1, clientHeight - 1, Qt::black, Qt::black); // draw tabs const int lift0 = 2 * (m_tab != Tab::Main ? 1 : 0); frame(canvas, 2, 2 + lift0, TabOffset + (0 + 1) * TabSize - 1, TabHeight, light, shade); frame(canvas, 1, 1 + lift0, TabOffset + (0 + 1) * TabSize, TabHeight, light, shade); canvas.setPixel(1, 1 + lift0, shade); for (int tab2 = static_cast(Tab::Map); tab2 <= static_cast(Tab::PreviousGame); ++tab2) { const int lift = 2 * (tabIndex != tab2 ? 1 : 0); frame(canvas, TabOffset + tab2 * TabSize + 2, 2 + lift, TabOffset + (tab2 + 1) * TabSize - 1, TabHeight, light, shade); frame(canvas, TabOffset + tab2 * TabSize + 1, 1 + lift, TabOffset + (tab2 + 1) * TabSize, TabHeight, light, shade); canvas.setPixel(TabOffset + tab2 * TabSize + 1, 1 + lift, shade); } canvas.font().assign(UniFont[static_cast(FontType::Normal)]); for (int tab2 = static_cast(Tab::Map); tab2 <= static_cast(Tab::PreviousGame); ++tab2) { const QString s = startControl(tabNames[tab2]); risedTextOutFitted(canvas, TabOffset + tab2 * TabSize + 1, 10 + 2 * (tabIndex != tab2 ? 1 : 0), TabSize, s); } frame(canvas, TabOffset + 4 * TabSize + 1, -1, clientWidth, TabHeight, Qt::black, Qt::black); frame(canvas, 1, TabHeight + 1, clientWidth - 2, clientHeight - 2, light, shade); frame(canvas, 2, TabHeight + 2, clientWidth - 3, clientHeight - 3, light, shade); if (m_tab == Tab::Main) { paintBackground(canvas, 3, TabHeight - 1, TabSize - 4 - 3 + TabOffset + 3, 4, clientWidth, clientHeight); canvas.setPixel(2, TabHeight, light); } else { paintBackground(canvas, TabOffset + 3 + tabIndex * TabSize, TabHeight - 1, TabSize - 4, 4, clientWidth, clientHeight); canvas.setPixel(TabOffset + tabIndex * TabSize + 2, TabHeight, light); } canvas.setPixel(TabOffset + (tabIndex + 1) * TabSize - 1, TabHeight + 1, shade); if (m_tab < Tab::PreviousGame) frame(canvas, TabOffset + (tabIndex + 1) * TabSize + 1, 3, TabOffset + (tabIndex + 1) * TabSize + 2, TabHeight, shade, shade); // tab shadow // Paint menu logo if (GraphicSetItem *menuLogo = Templates->searchByName(QStringLiteral("MenuLogo"))) { const int logoY = 3 + 2 * (m_tab != Tab::Main ? 1 : 0); drawBufferEnsureSize(menuLogo->width, menuLogo->height); drawBuffer.canvas().begin(); copyBlock(drawBuffer.canvas(), 0, 0, menuLogo->width, menuLogo->height, canvas, 6, logoY); drawBuffer.canvas().end(); imageOpBCC(drawBuffer, Templates->data, 0, 0, menuLogo->left, menuLogo->top, menuLogo->width, menuLogo->height - 9, 0xBFBF20, 0x4040DF); // logo part 1 imageOpBCC(drawBuffer, Templates->data, 10, 27, menuLogo->left + 10, menuLogo->top + 27, menuLogo->width - 10, 9, 0xBFBF20, 0x4040DF); // logo part 2 copyBlock(canvas, 6, logoY, menuLogo->width, menuLogo->height, drawBuffer.canvas(), 0, 0); } if (m_page == Page::Main) { if (m_selectedAction != MainAction::None) { // mark selected action const int row = static_cast(m_selectedAction); const int w = clientWidth - 2 * ActionSideBorder; int h = ActionPitch; const int top = yAction + row * ActionPitch - 8; if (top + h > clientHeight - ActionBottomBorder) h = clientHeight - ActionBottomBorder - top; drawBufferEnsureSize(w, h); drawBuffer.canvas().begin(); copyBlock(drawBuffer.canvas(), 0, 0, w, h, canvas, ActionSideBorder, top); drawBuffer.canvas().end(); makeBlue(drawBuffer, 0, 0, w, h); copyBlock(canvas, ActionSideBorder, top, w, h, drawBuffer.canvas(), 0, 0); } int y = yAction; for (int row = 0; row <= static_cast(MainAction::None); ++row, y += ActionPitch) { const auto action = static_cast(row); if (std::find(m_actionsOffered.begin(), m_actionsOffered.end(), action) == m_actionsOffered.end()) continue; switch (action) { case MainAction::Config: drawAction(y, 25, QStringLiteral("ACTIONHEADER_CONFIG"), QStringLiteral("ACTION_CONFIG")); break; case MainAction::Manual: drawAction(y, 19, QStringLiteral("ACTIONHEADER_MANUAL"), QStringLiteral("ACTION_MANUAL")); break; case MainAction::Credits: drawAction(y, 22, QStringLiteral("ACTIONHEADER_CREDITS"), QStringLiteral("ACTION_CREDITS")); break; case MainAction::AIDev: drawAction(y, 24, QStringLiteral("ACTIONHEADER_AIDEV"), QStringLiteral("ACTION_AIDEV")); break; case MainAction::Web: { canvas.font().assign(UniFont[static_cast(FontType::Caption)]); risedTextOut(canvas, xActionIcon + 99, y, phraseToQtFormat(phrases2.lookup(QStringLiteral("ACTIONHEADER_WEB"))) .arg(QString::fromLatin1(CevoHomepageShort))); canvas.font().assign(UniFont[static_cast(FontType::Normal)]); if (GraphicSetItem *arrows = Templates->searchByName(QStringLiteral("LinkArrows"))) { drawBufferEnsureSize(arrows->width, arrows->height); drawBuffer.canvas().begin(); copyBlock(drawBuffer.canvas(), 0, 0, arrows->width, arrows->height, canvas, xActionIcon, y + 2); drawBuffer.canvas().end(); imageOpBCC(drawBuffer, Templates->data, 0, 0, arrows->left, arrows->top, arrows->width, arrows->height, 0, colorToDelphi(Colors->image().pixelColor(clkAge0 - 1, cliDimmedText))); copyBlock(canvas, xActionIcon, y + 2, arrows->width, arrows->height, drawBuffer.canvas(), 0, 0); } break; } case MainAction::None: break; } } } else if (m_page == Page::StartRandom || m_page == Page::StartMap) { underlinedTitleValue(canvas, startControl(10), Term::turnToString(m_maxTurn), 344, y0Mini + 61, 170); QString s = startControl(7); loweredTextOut(canvas, -2, *MainTexture, x0Brain + 32 - canvas.textWidth(s) / 2, y0Brain + dyBrain + 69, s); initOrnament(); GraphicSetItem *ornament = HGrSystem2 ? HGrSystem2->searchByName(QStringLiteral("Ornament")) : nullptr; if (m_autoDiff < 0) { if (ornament) { for (int i = 12; i <= 19; ++i) { if (i < 13 || i > 17) sprite(canvas, 9 + i * 27, yLogo - 2, *ornament); } } paintLogo(canvas, 69 + 11 * 27, yLogo, light, shade); for (int i = 0; i < nPlOffered; ++i) { if (!((1 << i) & m_slotAvailable)) continue; Brain *brain = GameServer::playersBrain[static_cast(i)]; if (brain) frameImage(canvas, brain->picture, xBrain[i], yBrain[i], 64, 64, 0, 0, true); else frameImage(canvas, m_emptyPicture, xBrain[i], yBrain[i], 64, 64, 0, 0, true); if (isPlayableBrain(brain)) { const PlayerSlot &slot = m_playerSlots[static_cast(i)]; copyBlock(canvas, xBrain[i] - 18, yBrain[i] + 19, 12, 14, HGrSystem->data.canvas(), 134 + (Database::difficulty[static_cast(i)] - 1) * 13, 28); frame(canvas, xBrain[i] - 19, yBrain[i] + 18, xBrain[i] - 18 + 12, yBrain[i] + (19 + 14), Qt::black, Qt::black); rframe(canvas, slot.diffUpBtn->x() - 1, slot.diffUpBtn->y() - 1, slot.diffUpBtn->x() + 12, slot.diffUpBtn->y() + 24, shade, light); canvas.brush().setStyle(Qt::SolidPattern); canvas.brush().setColor(Qt::black); canvas.fillRect(QRect(xBrain[i] - 5, yBrain[i] + 25, 3, 2)); canvas.brush().setStyle(Qt::NoBrush); if (slot.offerMultiple) { rframe(canvas, slot.multiBtn->x() - 1, slot.multiBtn->y() - 1, slot.multiBtn->x() + 12, slot.multiBtn->y() + 12, shade, light); copyBlock(canvas, xBrain[i] - 31, yBrain[i], 13, 12, HGrSystem->data.canvas(), 88, 47); } } if (brain) { const PlayerSlot &slot = m_playerSlots[static_cast(i)]; const QString hint = phraseToQtFormat(startControl(9)).arg(brain->name()); slot.diffUpBtn->setToolTip(hint); slot.diffDownBtn->setToolTip(hint); } } } else { dLine(canvas, 24, 198, yMain + 140 + 19, light, shade); risedTextOut(canvas, 24, yMain + 140, startControl(15)); if (m_page == Page::StartRandom) s = QString::number(m_autoEnemies); else if (m_mapStartPositions == 0) s = QStringLiteral("0"); else s = QString::number(m_mapStartPositions - 1); risedTextOut(canvas, 198 - biColorTextWidth(canvas, s), yMain + 140, s); dLine(canvas, 24, xDefault - 6, yMain + 164 + 19, light, shade); risedTextOut(canvas, 24, yMain + 164, startControl(16)); if (m_autoDiff == 1) { if (Brain *beginner = GameServer::brains.beginner()) frameImage(canvas, beginner->picture, xDefault, yDefault, 64, 64, 0, 0, false); } else if (m_brainDefault) { frameImage(canvas, m_brainDefault->picture, xDefault, yDefault, 64, 64, 0, 0, true); } dLine(canvas, 56, 272, y0Mini + 61 + 19, light, shade); risedTextOut(canvas, 56, y0Mini + 61, startControl(14)); s = phrases.lookup(QStringLiteral("AUTODIFF"), m_autoDiff - 1); risedTextOut(canvas, 272 - biColorTextWidth(canvas, s), y0Mini + 61, s); if (ornament) { for (int i = 0; i < 20; ++i) { if (i < 2 || i > 6) sprite(canvas, 9 + i * 27, yLogo - 2, *ornament); } } paintLogo(canvas, 69, yLogo, light, shade); } } else if (m_page == Page::Load) { if (m_lastTurn > 0) { paintProgressBar(canvas, 6, xTurnSlider, yTurnSlider, 0, m_loadTurn * wTurnSlider / m_lastTurn, wTurnSlider, *MainTexture); frame(canvas, xTurnSlider - 2, yTurnSlider - 2, xTurnSlider + wTurnSlider + 1, yTurnSlider + 8, QColor(0xB0, 0xB0, 0xB0), Qt::white); rframe(canvas, xTurnSlider - 3, yTurnSlider - 3, xTurnSlider + wTurnSlider + 2, yTurnSlider + 9, Qt::white, QColor(0xB0, 0xB0, 0xB0)); } else { dLine(canvas, 344, 514, y0Mini + 61 + 19, light, shade); } risedTextOut(canvas, 344, y0Mini + 61, startControl(8)); const QString s = Term::turnToString(m_loadTurn); risedTextOut(canvas, 514 - biColorTextWidth(canvas, s), y0Mini + 61, s); } else if (m_page == Page::EditRandom) { const QPoint world = WorldSizes[m_worldSize]; underlinedTitleValue(canvas, startControl(5), QString::number((world.x() * world.y() * 20 + DefaultWorldTiles / 2) / DefaultWorldTiles * 5) + QLatin1Char('%'), 344, y0Mini - 77, 170); underlinedTitleValue(canvas, startControl(6), QString::number(m_startLandMass) + QLatin1Char('%'), 344, y0Mini + 61, 170); } else if (m_page == Page::EditMap) { const QString s = phraseToQtFormat(phrases2.lookup(QStringLiteral("MAPPROP"))) .arg((m_mapLandTiles * 100 + 556) / 1112) // 1112 is typical for a world with 100% size and default land mass .arg(m_mapStartPositions); risedTextOut(canvas, x0Mini - biColorTextWidth(canvas, s) / 2, y0Mini + 61, s); } const auto frameButtonUp = [&](const QWidget *button, int height) { if (button->isVisible()) rframe(canvas, button->x() - 1, button->y() - 1, button->x() + 12, button->y() + height, shade, light); }; if (ui->startBtn->isVisible()) btnFrame(canvas, ui->startBtn->geometry(), *MainTexture); frameButtonUp(ui->up2Btn, 24); frameButtonUp(ui->up1Btn, 24); frameButtonUp(ui->autoDiffUpBtn, 24); frameButtonUp(ui->autoEnemyUpBtn, 24); frameButtonUp(ui->customizeBtn, 12); if (ui->list->isVisible()) editFrame(canvas, ui->list->geometry(), *MainTexture); if (ui->renameBtn->isVisible()) btnFrame(canvas, ui->renameBtn->geometry(), *MainTexture); if (ui->deleteBtn->isVisible()) btnFrame(canvas, ui->deleteBtn->geometry(), *MainTexture); if (m_page == Page::Load) btnFrame(canvas, ui->replayBtn->geometry(), *MainTexture); if (m_page != Page::Main && m_page != Page::NoLoad) { const int xMini = x0Mini - m_miniMap.size.x(); const int yMini = y0Mini - m_miniMap.size.y() / 2; frame(canvas, xMini, yMini, xMini + 3 + m_miniMap.size.x() * 2, yMini + 3 + m_miniMap.size.y(), light, shade); frame(canvas, xMini + 1, yMini + 1, xMini + 2 + m_miniMap.size.x() * 2, yMini + 2 + m_miniMap.size.y(), shade, light); QString s; if (m_miniMap.mode == MiniMap::Mode::Picture) { canvas.draw(xMini + 2, yMini + 2, m_miniMap.bitmap.image()); if (m_page == Page::StartRandom) s = phrases.lookup(QStringLiteral("RANMAP")); } else if (m_miniMap.mode == MiniMap::Mode::MultiPlayer) { s = phrases.lookup(QStringLiteral("MPMAP")); } else if (m_page == Page::StartMap) { s = QFileInfo(m_mapFileName).completeBaseName(); } else if (m_page == Page::EditMap) { if (ui->list->currentItem()) s = ui->list->currentItem()->text(); } if (!s.isEmpty()) risedTextOut(canvas, x0Mini + 2 - biColorTextWidth(canvas, s) / 2, y0Mini - 8, s); } canvas.end(); } } // namespace Cevo