initial port for Cevo game in C++ (libs)
This commit is contained in:
commit
8436242032
375 files changed
+46282
No files matched your search
@@ -0,0 +1,10 @@
|
||||
#include "Cevo/CevoArea.h"
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
Area::Area(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,258 @@
|
||||
#include "Cevo/CevoBaseWin.h"
|
||||
#include "Cevo/CevoArea.h"
|
||||
#include "Cevo/CevoButtonBase.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
#include "Cevo/CevoTexture.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QPainter>
|
||||
#include <QRegion>
|
||||
#include <algorithm>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
std::function<void(WindowMode, const QString &)> 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<QWidget *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QWidget *child : children) {
|
||||
if (!qobject_cast<Area *>(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<size_t>(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<ButtonBase *>(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
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "Cevo/CevoButtonA.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
ButtonA::ButtonA(QWidget *parent) : ButtonBase(parent)
|
||||
{
|
||||
resize(100, 25);
|
||||
}
|
||||
|
||||
void ButtonA::paint(Dpi::Canvas &canvas)
|
||||
{
|
||||
if (m_graphic) {
|
||||
canvas.copyRect(QRect(0, 0, 100, 25), m_graphic->canvas(),
|
||||
QRect(195, 243 + 26 * (down() ? 1 : 0), 100, 25));
|
||||
canvas.font().assign(m_font);
|
||||
canvas.font().setColor(Qt::black);
|
||||
const QSize textSize = canvas.textExtent(m_caption);
|
||||
canvas.textOut(50 - (textSize.width() + 1) / 2, 12 - textSize.height() / 2, m_caption);
|
||||
} else {
|
||||
canvas.brush().setColor(colorFromDelphi(0x0000FF));
|
||||
canvas.frameRect(QRect(0, 0, 100, 25));
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonA::setCaption(const QString &text)
|
||||
{
|
||||
if (text != m_caption) {
|
||||
m_caption = text;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonA::setFont(const Dpi::Font &font)
|
||||
{
|
||||
m_font.assign(font);
|
||||
m_font.setColor(Qt::black);
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "Cevo/CevoButtonB.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
ButtonB::ButtonB(QWidget *parent) : ButtonBase(parent), m_buffer(25, 25)
|
||||
{
|
||||
resize(25, 25);
|
||||
}
|
||||
|
||||
void ButtonB::paint(Dpi::Canvas &canvas)
|
||||
{
|
||||
if (m_graphic) {
|
||||
unshareBitmap(m_buffer);
|
||||
bitBltBitmap(m_buffer, 0, 0, width(), height(), *m_graphic, 169, 243 + 26 * (down() ? 1 : 0));
|
||||
if (m_index >= 0 && m_mask) {
|
||||
bitBltBitmap(m_buffer, 0, 0, width(), height(), *m_mask,
|
||||
1 + m_index % 12 * 26, 337 + m_index / 12 * 26, RasterOp::And);
|
||||
bitBltBitmap(m_buffer, 0, 0, width(), height(), *m_graphic,
|
||||
1 + m_index % 12 * 26, 337 + m_index / 12 * 26, RasterOp::Paint);
|
||||
}
|
||||
canvas.draw(0, 0, m_buffer.image());
|
||||
} else {
|
||||
canvas.brush().setColor(colorFromDelphi(0x0000FF));
|
||||
canvas.frameRect(QRect(0, 0, width(), height()));
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonB::setButtonIndex(int value)
|
||||
{
|
||||
if (value != m_index) {
|
||||
m_index = value;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,76 @@
|
||||
#include "Cevo/CevoButtonBase.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
ButtonBase::ButtonBase(QWidget *parent) : QWidget(parent) {}
|
||||
|
||||
void ButtonBase::setDown(bool value)
|
||||
{
|
||||
m_down = value;
|
||||
update();
|
||||
}
|
||||
|
||||
void ButtonBase::setDownState(bool value)
|
||||
{
|
||||
if (m_down == value)
|
||||
return;
|
||||
m_down = value;
|
||||
update();
|
||||
if (onDownChanged)
|
||||
onDownChanged();
|
||||
}
|
||||
|
||||
void ButtonBase::trackMouse(const QPoint &pos, bool leftPressed)
|
||||
{
|
||||
if (!m_active)
|
||||
return;
|
||||
if (rect().contains(pos)) {
|
||||
if (leftPressed && !m_down)
|
||||
setDownState(true);
|
||||
} else if (m_down && !m_permanent) {
|
||||
setDownState(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonBase::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
m_active = true;
|
||||
trackMouse(event->pos(), event->buttons() & Qt::LeftButton);
|
||||
}
|
||||
|
||||
void ButtonBase::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
trackMouse(event->pos(), event->buttons() & Qt::LeftButton);
|
||||
}
|
||||
|
||||
void ButtonBase::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
return; // another button was released while left is still held
|
||||
trackMouse(event->pos(), false);
|
||||
if (m_active && m_down) {
|
||||
m_active = false;
|
||||
if (m_down != m_permanent)
|
||||
setDownState(m_permanent);
|
||||
if (event->button() == Qt::LeftButton && onClick)
|
||||
onClick();
|
||||
} else {
|
||||
m_active = false;
|
||||
if (m_down)
|
||||
setDownState(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonBase::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
Dpi::Canvas canvas;
|
||||
canvas.bind(&painter);
|
||||
paint(canvas);
|
||||
canvas.unbind();
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "Cevo/CevoButtonC.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
ButtonC::ButtonC(QWidget *parent) : ButtonBase(parent)
|
||||
{
|
||||
resize(12, 12);
|
||||
}
|
||||
|
||||
void ButtonC::paint(Dpi::Canvas &canvas)
|
||||
{
|
||||
if (m_graphic) {
|
||||
canvas.copyRect(QRect(0, 0, 12, 12), m_graphic->canvas(),
|
||||
QRect(169 + 13 * (down() ? 1 : 0), 159 + 13 * m_index, 12, 12));
|
||||
} else {
|
||||
canvas.brush().setColor(colorFromDelphi(0x0000FF));
|
||||
canvas.frameRect(QRect(0, 0, 12, 12));
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonC::setButtonIndex(int value)
|
||||
{
|
||||
if (value != m_index) {
|
||||
m_index = value;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,101 @@
|
||||
#include "Cevo/CevoButtonG.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
ButtonG::ButtonG(QWidget *parent) : ButtonBase(parent) {}
|
||||
|
||||
GraphicSetItem *ButtonG::resolveItem(int index, const QString &name) const
|
||||
{
|
||||
if (!m_graphicSet)
|
||||
return nullptr;
|
||||
if (index != -1 && index < m_graphicSet->items().count())
|
||||
return m_graphicSet->items().at(index);
|
||||
if (!name.isEmpty())
|
||||
return m_graphicSet->searchByName(name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ButtonG::paint(Dpi::Canvas &canvas)
|
||||
{
|
||||
bool drawn = false;
|
||||
Dpi::Bitmap buffer(width(), height());
|
||||
if (m_graphicSet) {
|
||||
GraphicSetItem *back = down() ? resolveItem(m_backgroundDownIndex, m_backgroundDownName)
|
||||
: resolveItem(m_backgroundUpIndex, m_backgroundUpName);
|
||||
if (back) {
|
||||
bitBltBitmap(buffer, 0, 0, back->width, back->height, m_graphicSet->data, back->left, back->top);
|
||||
drawn = true;
|
||||
}
|
||||
GraphicSetItem *glyph = resolveItem(m_glyphIndex, m_glyphName);
|
||||
if (glyph) {
|
||||
bitBltBitmap(buffer, 0, 0, glyph->width, glyph->height, m_graphicSet->mask,
|
||||
glyph->left, glyph->top, RasterOp::And);
|
||||
bitBltBitmap(buffer, 0, 0, glyph->width, glyph->height, m_graphicSet->data,
|
||||
glyph->left, glyph->top, RasterOp::Paint);
|
||||
drawn = true;
|
||||
}
|
||||
}
|
||||
if (drawn) {
|
||||
canvas.draw(0, 0, buffer.image());
|
||||
} else {
|
||||
canvas.brush().setColor(colorFromDelphi(0x0000FF));
|
||||
canvas.frameRect(QRect(0, 0, width() - 1, height() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonG::setBackgroundUpIndex(int value)
|
||||
{
|
||||
if (m_backgroundUpIndex == value)
|
||||
return;
|
||||
m_backgroundUpIndex = value;
|
||||
m_backgroundUpName.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
void ButtonG::setBackgroundUpName(const QString &value)
|
||||
{
|
||||
if (m_backgroundUpName == value)
|
||||
return;
|
||||
m_backgroundUpName = value;
|
||||
m_backgroundUpIndex = -1;
|
||||
update();
|
||||
}
|
||||
|
||||
void ButtonG::setBackgroundDownIndex(int value)
|
||||
{
|
||||
if (m_backgroundDownIndex == value)
|
||||
return;
|
||||
m_backgroundDownIndex = value;
|
||||
m_backgroundDownName.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
void ButtonG::setBackgroundDownName(const QString &value)
|
||||
{
|
||||
if (m_backgroundDownName == value)
|
||||
return;
|
||||
m_backgroundDownName = value;
|
||||
m_backgroundDownIndex = -1;
|
||||
update();
|
||||
}
|
||||
|
||||
void ButtonG::setGlyphIndex(int value)
|
||||
{
|
||||
if (m_glyphIndex == value)
|
||||
return;
|
||||
m_glyphIndex = value;
|
||||
m_glyphName.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
void ButtonG::setGlyphName(const QString &value)
|
||||
{
|
||||
if (m_glyphName == value)
|
||||
return;
|
||||
m_glyphName = value;
|
||||
m_glyphIndex = -1;
|
||||
update();
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "Cevo/CevoButtonN.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
ButtonN::ButtonN(QWidget *parent) : QWidget(parent), m_buffer(42, 42)
|
||||
{
|
||||
setToolTip(QString());
|
||||
resize(42, 42);
|
||||
}
|
||||
|
||||
void ButtonN::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
Dpi::Canvas canvas;
|
||||
canvas.bind(&painter);
|
||||
|
||||
if (m_graphic && m_backGraphic) {
|
||||
bitBltBitmap(m_buffer, 1, 1, 40, 40, *m_backGraphic,
|
||||
1 + 80 * m_backIndex + 40 * (m_possible && m_lit ? 1 : 0), 176);
|
||||
if (m_possible && m_mask) {
|
||||
bitBltBitmap(m_buffer, 3, 3, 36, 36, *m_mask,
|
||||
195 + 37 * (m_index % 3), 21 + 37 * (m_index / 3), RasterOp::And);
|
||||
bitBltBitmap(m_buffer, 3, 3, 36, 36, *m_graphic,
|
||||
195 + 37 * (m_index % 3), 21 + 37 * (m_index / 3), RasterOp::Paint);
|
||||
}
|
||||
canvas.draw(0, 0, m_buffer.image());
|
||||
}
|
||||
frame(canvas, 0, 0, 41, 41, colorFromDelphi(0xB0B0B0), colorFromDelphi(0xFFFFFF));
|
||||
|
||||
canvas.unbind();
|
||||
}
|
||||
|
||||
void ButtonN::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_possible && event->button() == Qt::LeftButton && onClick)
|
||||
onClick();
|
||||
}
|
||||
|
||||
void ButtonN::setPossible(bool value)
|
||||
{
|
||||
if (value == m_possible)
|
||||
return;
|
||||
m_possible = value;
|
||||
setToolTip(value ? m_smartHint : QString());
|
||||
update();
|
||||
}
|
||||
|
||||
void ButtonN::setLit(bool value)
|
||||
{
|
||||
if (value == m_lit)
|
||||
return;
|
||||
m_lit = value;
|
||||
update();
|
||||
}
|
||||
|
||||
void ButtonN::setButtonIndex(int value)
|
||||
{
|
||||
if (value == m_index)
|
||||
return;
|
||||
m_index = value;
|
||||
m_backIndex = value < 6 ? 1 : 0;
|
||||
update();
|
||||
}
|
||||
|
||||
void ButtonN::setSmartHint(const QString &value)
|
||||
{
|
||||
if (value == m_smartHint)
|
||||
return;
|
||||
m_smartHint = value;
|
||||
if (m_possible)
|
||||
setToolTip(value);
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,168 @@
|
||||
#include "Cevo/CevoDrawDlg.h"
|
||||
#include "Cevo/CevoArea.h"
|
||||
#include "Cevo/CevoButtonBase.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
#include "Cevo/CevoTexture.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QRegion>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
DrawDlg::DrawDlg(QWidget *parent) : Dpi::Form(parent)
|
||||
{
|
||||
QPalette pal = palette();
|
||||
pal.setColor(QPalette::Window, Qt::black);
|
||||
setPalette(pal);
|
||||
setAutoFillBackground(true);
|
||||
}
|
||||
|
||||
void DrawDlg::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
const QPoint pos = event->pos();
|
||||
if (rect().contains(pos) && pos.y() < titleHeight) {
|
||||
m_moveMousePos = mapToGlobal(event->pos());
|
||||
m_moveFormPos = QPoint(x(), y());
|
||||
m_moveActive = true;
|
||||
} else {
|
||||
m_moveActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawDlg::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_moveActive) {
|
||||
const QPoint delta = mapToGlobal(event->pos()) - m_moveMousePos;
|
||||
move(m_moveFormPos + delta);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawDlg::mouseReleaseEvent(QMouseEvent *)
|
||||
{
|
||||
m_moveActive = false;
|
||||
}
|
||||
|
||||
void DrawDlg::leaveEvent(QEvent *)
|
||||
{
|
||||
m_moveActive = false;
|
||||
}
|
||||
|
||||
void DrawDlg::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Escape)
|
||||
close();
|
||||
else
|
||||
QWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
void DrawDlg::smartInvalidate()
|
||||
{
|
||||
QRegion region(rect());
|
||||
const auto children = findChildren<QWidget *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QWidget *child : children) {
|
||||
if (!qobject_cast<Area *>(child) && child->isVisible())
|
||||
region -= QRegion(child->geometry());
|
||||
}
|
||||
update(region);
|
||||
}
|
||||
|
||||
void DrawDlg::centerToScreen()
|
||||
{
|
||||
centerToScreen(width(), height());
|
||||
}
|
||||
|
||||
void DrawDlg::centerToScreen(int w, int h)
|
||||
{
|
||||
const Dpi::Monitor monitor = Dpi::Screen::primaryMonitor();
|
||||
setGeometry(monitor.left() + (monitor.width() - w) / 2,
|
||||
monitor.top() + (monitor.height() - h) / 2, w, h);
|
||||
}
|
||||
|
||||
// ---- BaseMessgDlg ----
|
||||
|
||||
BaseMessgDlg::BaseMessgDlg(QWidget *parent) : DrawDlg(parent)
|
||||
{
|
||||
titleHeight = Dpi::Screen::height();
|
||||
}
|
||||
|
||||
void BaseMessgDlg::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
Dpi::Canvas canvas;
|
||||
canvas.bind(&painter);
|
||||
|
||||
paintBackground(canvas, 3 + Border, 3 + Border, width() - (6 + 2 * Border), height() - (6 + 2 * Border),
|
||||
width(), height());
|
||||
for (int i = 0; i <= Border; ++i)
|
||||
frame(canvas, i, i, width() - 1 - i, height() - 1 - i, Qt::black, Qt::black);
|
||||
if (MainTexture) {
|
||||
frame(canvas, Border + 1, Border + 1, width() - (2 + Border), height() - (2 + Border),
|
||||
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
|
||||
frame(canvas, 2 + Border, 2 + Border, width() - (3 + Border), height() - (3 + Border),
|
||||
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
|
||||
}
|
||||
splitText(false);
|
||||
|
||||
if (MainTexture) {
|
||||
const auto children = findChildren<ButtonBase *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (ButtonBase *button : children) {
|
||||
if (button->isVisible())
|
||||
btnFrame(canvas, button->geometry(), *MainTexture);
|
||||
}
|
||||
}
|
||||
canvas.unbind();
|
||||
}
|
||||
|
||||
void BaseMessgDlg::splitText(bool preview)
|
||||
{
|
||||
// Best-effort port of the 1-indexed Pascal word-wrap logic below; wraps
|
||||
// messageText at word boundaries (or '\' line breaks) to fit within
|
||||
// (width() - 56) px per line.
|
||||
if (!MainTexture)
|
||||
return;
|
||||
int start = 0;
|
||||
int linesCount = 0;
|
||||
QPixmap dummy(1, 1);
|
||||
QPainter painter(&dummy);
|
||||
Dpi::Canvas canvas;
|
||||
canvas.bind(&painter);
|
||||
while (start < messageText.length()) {
|
||||
int stop = start;
|
||||
while (stop < messageText.length() - 1 && messageText.at(stop) != QLatin1Char('\\') &&
|
||||
biColorTextWidth(canvas, messageText.mid(start, stop - start + 1)) < width() - 56)
|
||||
++stop;
|
||||
if (stop != messageText.length() - 1) {
|
||||
int ordinaryStop = stop;
|
||||
while (ordinaryStop > start && messageText.at(ordinaryStop) != QLatin1Char(' ') &&
|
||||
messageText.at(ordinaryStop) != QLatin1Char('\\'))
|
||||
--ordinaryStop;
|
||||
if ((ordinaryStop - start) * 2 >= stop - start)
|
||||
stop = ordinaryStop - 1;
|
||||
}
|
||||
if (!preview) {
|
||||
const QString s = messageText.mid(start, stop - start + 1);
|
||||
loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2,
|
||||
19 + Border + topSpace + linesCount * MessageLineSpacing, s);
|
||||
}
|
||||
start = stop + 2;
|
||||
++linesCount;
|
||||
}
|
||||
canvas.unbind();
|
||||
if (preview)
|
||||
lines = linesCount;
|
||||
}
|
||||
|
||||
void BaseMessgDlg::correctHeight()
|
||||
{
|
||||
const int newHeight = 72 + Border + topSpace + lines * MessageLineSpacing;
|
||||
const Dpi::Monitor monitor = Dpi::Screen::primaryMonitor();
|
||||
const int newTop = monitor.top() + (monitor.height() - newHeight) / 2;
|
||||
setGeometry(x(), newTop, width(), newHeight);
|
||||
const auto children = findChildren<QWidget *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QWidget *child : children)
|
||||
child->move(child->x(), newHeight - (34 + Border));
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "Cevo/CevoEOTButton.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
EOTButton::EOTButton(QWidget *parent) : ButtonBase(parent), m_buffer(48, 48), m_back(48, 48)
|
||||
{
|
||||
resize(48, 48);
|
||||
}
|
||||
|
||||
void EOTButton::paint(Dpi::Canvas &canvas)
|
||||
{
|
||||
if (m_graphic && m_template) {
|
||||
unshareBitmap(m_buffer);
|
||||
bitBltBitmap(m_buffer, 0, 0, 48, 48, m_back, 0, 0);
|
||||
imageOpCBC(m_buffer, *m_template, 0, 0, 133, 149 + 48 * (down() ? 1 : 0), 48, 48, 0x000000, 0xFFFFFF);
|
||||
if (m_index >= 0) {
|
||||
imageOpCBC(m_buffer, *m_template, 8, 8, 1 + 32 * m_index, 246, 32, 32, 0x000000, 0xFFFFFF);
|
||||
}
|
||||
canvas.draw(0, 0, m_buffer.image());
|
||||
} else {
|
||||
canvas.brush().setColor(colorFromDelphi(0x0000FF));
|
||||
canvas.frameRect(QRect(0, 0, 48, 48));
|
||||
}
|
||||
}
|
||||
|
||||
void EOTButton::setButtonIndex(int value)
|
||||
{
|
||||
if (value != m_index) {
|
||||
m_index = value;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void EOTButton::setButtonIndexFast(int value)
|
||||
{
|
||||
if (isVisible() && value != m_index) {
|
||||
m_index = value;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
void EOTButton::setBack(Dpi::Canvas &canvas, int x, int y)
|
||||
{
|
||||
m_back.canvas().copyRect(QRect(0, 0, 48, 48), canvas, QRect(x, y, 48, 48));
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "Cevo/CevoGraphicSet.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QtDebug>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
void GraphicSetItem::setBoundsRect(const QRect &rect)
|
||||
{
|
||||
left = rect.left();
|
||||
top = rect.top();
|
||||
width = rect.width();
|
||||
height = rect.height();
|
||||
}
|
||||
|
||||
GraphicSet::~GraphicSet()
|
||||
{
|
||||
qDeleteAll(m_items);
|
||||
}
|
||||
|
||||
GraphicSetItem *GraphicSet::searchByName(const QString &itemName) const
|
||||
{
|
||||
for (GraphicSetItem *item : m_items) {
|
||||
if (item->name == itemName)
|
||||
return item;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GraphicSetItem *GraphicSet::item(const QString &itemName) const
|
||||
{
|
||||
GraphicSetItem *found = searchByName(itemName);
|
||||
if (!found)
|
||||
qWarning("Graphic item %s not found in graphic set %s.", qUtf8Printable(itemName), qUtf8Printable(name));
|
||||
return found;
|
||||
}
|
||||
|
||||
GraphicSetItem *GraphicSet::addNew(const QString &itemName)
|
||||
{
|
||||
auto *newItem = new GraphicSetItem();
|
||||
newItem->name = itemName;
|
||||
newItem->graphicSet = this;
|
||||
m_items.append(newItem);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
void GraphicSet::loadFromFile(const QString &fileName)
|
||||
{
|
||||
qDeleteAll(m_items);
|
||||
m_items.clear();
|
||||
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return;
|
||||
|
||||
QXmlStreamReader xml(&file);
|
||||
while (!xml.atEnd()) {
|
||||
xml.readNext();
|
||||
if (xml.isStartElement() && xml.name() == QLatin1String("Item")) {
|
||||
const QXmlStreamAttributes attrs = xml.attributes();
|
||||
GraphicSetItem *newItem = addNew(attrs.value("Name").toString());
|
||||
newItem->left = attrs.value("Left").toInt();
|
||||
newItem->top = attrs.value("Top").toInt();
|
||||
newItem->width = attrs.value("Width").toInt();
|
||||
newItem->height = attrs.value("Height").toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicSet::saveToFile(const QString &fileName) const
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
return;
|
||||
|
||||
QXmlStreamWriter xml(&file);
|
||||
xml.setAutoFormatting(true);
|
||||
xml.writeStartDocument();
|
||||
xml.writeStartElement(QLatin1String(GraphicSetFileRootNode));
|
||||
xml.writeStartElement(QLatin1String("Items"));
|
||||
for (GraphicSetItem *item : m_items) {
|
||||
xml.writeStartElement(QLatin1String("Item"));
|
||||
xml.writeAttribute(QLatin1String("Name"), item->name);
|
||||
xml.writeAttribute(QLatin1String("Left"), QString::number(item->left));
|
||||
xml.writeAttribute(QLatin1String("Top"), QString::number(item->top));
|
||||
xml.writeAttribute(QLatin1String("Width"), QString::number(item->width));
|
||||
xml.writeAttribute(QLatin1String("Height"), QString::number(item->height));
|
||||
xml.writeEndElement();
|
||||
}
|
||||
xml.writeEndElement();
|
||||
xml.writeEndElement();
|
||||
xml.writeEndDocument();
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "Cevo/CevoListBoxEx.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
void ListBoxExDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
const QColor orange = colorFromDelphi(0x5F77CB);
|
||||
const QColor blue = colorFromDelphi(0xd77800);
|
||||
const bool selected = option.state & QStyle::State_Selected;
|
||||
const QColor background = selected ? blue : Qt::black;
|
||||
const QColor textColor = selected ? Qt::white : orange;
|
||||
|
||||
painter->fillRect(option.rect, Qt::black);
|
||||
const QRect inner = option.rect.adjusted(2, 1, -2, -2);
|
||||
painter->fillRect(inner, background);
|
||||
painter->setPen(textColor);
|
||||
painter->setFont(option.font);
|
||||
painter->drawText(inner, Qt::AlignVCenter | Qt::AlignLeft, index.data(Qt::DisplayRole).toString());
|
||||
if (selected) {
|
||||
painter->setPen(QPen(orange, 1, Qt::DotLine));
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawRect(inner);
|
||||
}
|
||||
}
|
||||
|
||||
ListBoxEx::ListBoxEx(QWidget *parent) : Dpi::ListBox(parent)
|
||||
{
|
||||
setItemDelegate(new ListBoxExDelegate(this));
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,330 @@
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
#include "Cevo/CevoGraphicSet.h"
|
||||
#include "Cevo/CevoTexture.h"
|
||||
#include "Dpi/DpiPixelPointer.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
std::array<Dpi::Font, static_cast<size_t>(FontType::Count)> UniFont;
|
||||
Texture *MainTexture = nullptr;
|
||||
GraphicSet *HGrSystem = nullptr;
|
||||
GraphicSet *HGrSystem2 = nullptr;
|
||||
GraphicSet *Templates = nullptr;
|
||||
Dpi::Bitmap *Colors = nullptr;
|
||||
|
||||
QColor colorFromDelphi(int value)
|
||||
{
|
||||
return QColor(value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
void bitBltBitmap(Dpi::Bitmap &dest, int x, int y, int width, int height,
|
||||
Dpi::Bitmap &src, int xSrc, int ySrc, RasterOp rop)
|
||||
{
|
||||
if (xSrc < 0) { x -= xSrc; width -= xSrc; xSrc = 0; }
|
||||
if (ySrc < 0) { y -= ySrc; height -= ySrc; ySrc = 0; }
|
||||
if (x < 0) { width += x; xSrc -= x; x = 0; }
|
||||
if (y < 0) { height += y; ySrc -= y; y = 0; }
|
||||
if (x + width > dest.width()) width = dest.width() - x;
|
||||
if (y + height > dest.height()) height = dest.height() - y;
|
||||
if (width < 0 || height < 0)
|
||||
return;
|
||||
|
||||
Dpi::PixelPointer srcPixel(&src.image(), xSrc, ySrc);
|
||||
Dpi::PixelPointer dstPixel(&dest.image(), x, y);
|
||||
for (int yy = 0; yy < height; ++yy) {
|
||||
for (int xx = 0; xx < width; ++xx) {
|
||||
switch (rop) {
|
||||
case RasterOp::Copy:
|
||||
dstPixel.setPixelRGB(srcPixel.pixelRGB());
|
||||
break;
|
||||
case RasterOp::And:
|
||||
dstPixel.setPixelRGB(dstPixel.pixelRGB() & srcPixel.pixelRGB());
|
||||
break;
|
||||
case RasterOp::Paint:
|
||||
dstPixel.setPixelRGB(dstPixel.pixelRGB() | srcPixel.pixelRGB());
|
||||
break;
|
||||
case RasterOp::Invert:
|
||||
dstPixel.setPixelRGB(~dstPixel.pixelRGB());
|
||||
break;
|
||||
}
|
||||
dstPixel.nextPixel();
|
||||
srcPixel.nextPixel();
|
||||
}
|
||||
dstPixel.nextLine();
|
||||
srcPixel.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
void unshareBitmap(Dpi::Bitmap &) {}
|
||||
|
||||
void sprite(Dpi::Canvas &canvas, GraphicSet &graphicSet, int xDst, int yDst,
|
||||
int width, int height, int xGr, int yGr)
|
||||
{
|
||||
Dpi::Bitmap scratch(width, height);
|
||||
bitBltBitmap(scratch, 0, 0, width, height, graphicSet.mask, xGr, yGr, RasterOp::And);
|
||||
bitBltBitmap(scratch, 0, 0, width, height, graphicSet.data, xGr, yGr, RasterOp::Paint);
|
||||
canvas.draw(xDst, yDst, scratch.image());
|
||||
}
|
||||
|
||||
void sprite(Dpi::Canvas &canvas, int xDst, int yDst, const GraphicSetItem &item)
|
||||
{
|
||||
if (!item.graphicSet)
|
||||
return;
|
||||
sprite(canvas, *item.graphicSet, xDst, yDst, item.width, item.height, item.left, item.top);
|
||||
}
|
||||
|
||||
void frame(Dpi::Canvas &canvas, int x0, int y0, int x1, int y1, QColor cl0, QColor cl1)
|
||||
{
|
||||
canvas.moveTo(x0, y1);
|
||||
canvas.pen().setColor(cl0);
|
||||
canvas.lineTo(x0, y0);
|
||||
canvas.lineTo(x1, y0);
|
||||
canvas.pen().setColor(cl1);
|
||||
canvas.lineTo(x1, y1);
|
||||
canvas.lineTo(x0, y1);
|
||||
}
|
||||
|
||||
void rframe(Dpi::Canvas &canvas, int x0, int y0, int x1, int y1, QColor cl0, QColor cl1)
|
||||
{
|
||||
canvas.pen().setColor(cl0);
|
||||
canvas.moveTo(x0, y0 + 1);
|
||||
canvas.lineTo(x0, y1);
|
||||
canvas.moveTo(x0 + 1, y0);
|
||||
canvas.lineTo(x1, y0);
|
||||
canvas.pen().setColor(cl1);
|
||||
canvas.moveTo(x1, y0 + 1);
|
||||
canvas.lineTo(x1, y1);
|
||||
canvas.moveTo(x0 + 1, y1);
|
||||
canvas.lineTo(x1, y1);
|
||||
}
|
||||
|
||||
void btnFrame(Dpi::Canvas &canvas, const QRect &rect, const Texture &texture)
|
||||
{
|
||||
rframe(canvas, rect.left() - 1, rect.top() - 1, rect.right(), rect.bottom(),
|
||||
texture.colorBevelShade, texture.colorBevelLight);
|
||||
}
|
||||
|
||||
void corner(Dpi::Canvas &, int, int, int, const Texture &)
|
||||
{
|
||||
// Unimplemented in the original ScreenTools.pas too (body is commented out there).
|
||||
}
|
||||
|
||||
void fill(Dpi::Canvas &canvas, int left, int top, int width, int height, int xOffset, int yOffset)
|
||||
{
|
||||
Q_UNUSED(xOffset);
|
||||
Q_UNUSED(yOffset);
|
||||
if (!MainTexture || MainTexture->width() <= 0 || MainTexture->height() <= 0)
|
||||
return;
|
||||
const int w = std::min(width, MainTexture->width());
|
||||
const int h = std::min(height, MainTexture->height());
|
||||
const int yy = height / MainTexture->height();
|
||||
const int xx = width / MainTexture->width();
|
||||
for (int y = 0; y <= yy; ++y) {
|
||||
for (int x = 0; x <= xx; ++x) {
|
||||
canvas.copyRect(QRect(left + x * MainTexture->width(), top + y * MainTexture->height(), w, h),
|
||||
MainTexture->canvas(), QRect(0, 0, w, h));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void fill(Dpi::Canvas &canvas, const QRect &rect, const QPoint &offset)
|
||||
{
|
||||
fill(canvas, rect.left(), rect.top(), rect.width(), rect.height(), offset.x(), offset.y());
|
||||
}
|
||||
|
||||
void paintBackground(Dpi::Canvas &canvas, int left, int top, int width, int height, int formWidth, int formHeight)
|
||||
{
|
||||
Q_UNUSED(formWidth);
|
||||
Q_UNUSED(formHeight);
|
||||
fill(canvas, left, top, width, height, 0, 0);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// %c=combat %f=food %l=luxury %m=manufacture %n=nation %o=output
|
||||
// %p=production %r=research %t=terrain %w=welfare, each a 10px-wide icon.
|
||||
const QString kIconChars = QStringLiteral("cflmnoprtw");
|
||||
const int kIconKinds[] = { 6, 0, 8, 17, 7, 16, 2, 12, 4, 13 };
|
||||
|
||||
void paintIcon(Dpi::Canvas &canvas, int x, int y, int kind)
|
||||
{
|
||||
if (!HGrSystem)
|
||||
return;
|
||||
sprite(canvas, *HGrSystem, x, y + 6, 10, 10, 66 + kind % 11 * 11, 115 + kind / 11 * 11);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void biColorTextOut(Dpi::Canvas &canvas, QColor mainColor, QColor backColor, int x, int y, const QString &text)
|
||||
{
|
||||
const bool skipShadow = backColor == QColor(0x7F, 0x00, 0x7F);
|
||||
for (int pass = 0; pass < 2; ++pass) {
|
||||
const bool shadow = pass == 0;
|
||||
if (shadow && skipShadow)
|
||||
continue;
|
||||
const int drawX = shadow ? x + 1 : x;
|
||||
const int drawY = shadow ? y + 1 : y;
|
||||
canvas.font().setColor(shadow ? backColor : mainColor);
|
||||
QString s = text;
|
||||
int xp = drawX;
|
||||
for (;;) {
|
||||
const int p = s.indexOf(QLatin1Char('%'));
|
||||
const bool hasIcon = p >= 0 && p + 1 < s.length() && kIconChars.contains(s.at(p + 1));
|
||||
if (!hasIcon) {
|
||||
canvas.textOut(xp, drawY, s);
|
||||
break;
|
||||
}
|
||||
const QString head = s.left(p);
|
||||
canvas.textOut(xp, drawY, head);
|
||||
xp += canvas.textWidth(head);
|
||||
if (!shadow)
|
||||
paintIcon(canvas, xp + 1, drawY, kIconKinds[kIconChars.indexOf(s.at(p + 1))]);
|
||||
xp += 10;
|
||||
s.remove(0, p + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int biColorTextWidth(Dpi::Canvas &canvas, const QString &text)
|
||||
{
|
||||
int result = 1;
|
||||
QString s = text;
|
||||
for (;;) {
|
||||
const int p = s.indexOf(QLatin1Char('%'));
|
||||
if (p < 0 || p == s.length() - 1) {
|
||||
result += canvas.textWidth(s);
|
||||
break;
|
||||
}
|
||||
if (!kIconChars.contains(s.at(p + 1)))
|
||||
result += canvas.textWidth(s.left(p + 2));
|
||||
else
|
||||
result += canvas.textWidth(s.left(p)) + 10;
|
||||
s.remove(0, p + 2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void risedTextOut(Dpi::Canvas &canvas, int x, int y, const QString &text)
|
||||
{
|
||||
biColorTextOut(canvas, Qt::white, Qt::black, x, y, text);
|
||||
}
|
||||
|
||||
void loweredTextOut(Dpi::Canvas &canvas, int cl, const Texture &texture, int x, int y, const QString &text)
|
||||
{
|
||||
if (cl == -2) {
|
||||
const QColor shade = texture.colorBevelShade;
|
||||
const QColor mixedShade(shade.red() / 2, shade.green() / 2, shade.blue() / 2);
|
||||
biColorTextOut(canvas, mixedShade, texture.colorBevelLight, x, y, text);
|
||||
} else if (cl < 0) {
|
||||
biColorTextOut(canvas, texture.colorTextShade, texture.colorTextLight, x, y, text);
|
||||
} else {
|
||||
biColorTextOut(canvas, colorFromDelphi(cl), texture.colorTextLight, x, y, text);
|
||||
}
|
||||
}
|
||||
|
||||
void imageOpB(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc, int width, int height)
|
||||
{
|
||||
if (xDst < 0) { width += xDst; xSrc -= xDst; xDst = 0; }
|
||||
if (yDst < 0) { height += yDst; ySrc -= yDst; yDst = 0; }
|
||||
if (xDst + width > dst.width()) width = dst.width() - xDst;
|
||||
if (yDst + height > dst.height()) height = dst.height() - yDst;
|
||||
if (width < 0 || height < 0)
|
||||
return;
|
||||
|
||||
Dpi::PixelPointer srcPixel(&src.image(), xSrc, ySrc);
|
||||
Dpi::PixelPointer dstPixel(&dst.image(), xDst, yDst);
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
const int brightness = qBlue(srcPixel.pixelARGB()); // greyscale template, one byte
|
||||
const QRgb d = dstPixel.pixelARGB();
|
||||
auto scale = [brightness](int c) { const int v = (c * brightness) >> 7; return v > 255 ? 255 : v; };
|
||||
dstPixel.setPixelARGB(qRgb(scale(qRed(d)), scale(qGreen(d)), scale(qBlue(d))));
|
||||
dstPixel.nextPixel();
|
||||
srcPixel.nextPixel();
|
||||
}
|
||||
dstPixel.nextLine();
|
||||
srcPixel.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Shared by ImageOp_BCC/ImageOp_CBC: Src is a template whose B channel is
|
||||
// the background blend amplitude and whose G/R channels are the amplitudes
|
||||
// for colorA/colorB respectively. colorA/colorB use the Delphi $BBGGRR byte
|
||||
// order (see colorFromDelphi).
|
||||
void blendTemplate(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc,
|
||||
int width, int height, int colorA, int colorB)
|
||||
{
|
||||
if (xDst < 0) { width += xDst; xSrc -= xDst; xDst = 0; }
|
||||
if (yDst < 0) { height += yDst; ySrc -= yDst; yDst = 0; }
|
||||
if (xDst + width > dst.width()) width = dst.width() - xDst;
|
||||
if (yDst + height > dst.height()) height = dst.height() - yDst;
|
||||
if (width < 0 || height < 0)
|
||||
return;
|
||||
|
||||
Dpi::PixelPointer srcPixel(&src.image(), xSrc, ySrc);
|
||||
Dpi::PixelPointer dstPixel(&dst.image(), xDst, yDst);
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
const QRgb s = srcPixel.pixelARGB();
|
||||
const int trans = qBlue(s) * 2;
|
||||
const int ampA = qGreen(s) * 2;
|
||||
const int ampB = qRed(s) * 2;
|
||||
if (trans != 0xFF) {
|
||||
const QRgb d = dstPixel.pixelARGB();
|
||||
auto mix = [&](int dstChannel, int shift) {
|
||||
const int value = (dstChannel * trans + ((colorB >> shift) & 0xFF) * ampB +
|
||||
((colorA >> shift) & 0xFF) * ampA) / 0xFF;
|
||||
return value > 255 ? 255 : value;
|
||||
};
|
||||
dstPixel.setPixelARGB(qRgb(mix(qRed(d), 0), mix(qGreen(d), 8), mix(qBlue(d), 16)));
|
||||
}
|
||||
dstPixel.nextPixel();
|
||||
srcPixel.nextPixel();
|
||||
}
|
||||
dstPixel.nextLine();
|
||||
srcPixel.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void imageOpBCC(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc,
|
||||
int width, int height, int color1, int color2)
|
||||
{
|
||||
blendTemplate(dst, src, xDst, yDst, xSrc, ySrc, width, height, color1, color2);
|
||||
}
|
||||
|
||||
void imageOpCBC(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc,
|
||||
int width, int height, int color0, int color2)
|
||||
{
|
||||
blendTemplate(dst, src, xDst, yDst, xSrc, ySrc, width, height, color0, color2);
|
||||
}
|
||||
|
||||
void imageOpCCC(Dpi::Bitmap &bmp, int x, int y, int width, int height, int color0, int color1, int color2)
|
||||
{
|
||||
if (x + width > bmp.width()) width = bmp.width() - x;
|
||||
if (y + height > bmp.height()) height = bmp.height() - y;
|
||||
if (width < 0 || height < 0)
|
||||
return;
|
||||
|
||||
Dpi::PixelPointer pixel(&bmp.image(), x, y);
|
||||
for (int yy = 0; yy < height; ++yy) {
|
||||
for (int xx = 0; xx < width; ++xx) {
|
||||
const QRgb p = pixel.pixelARGB();
|
||||
const int b = qBlue(p), g = qGreen(p), r = qRed(p);
|
||||
auto mix = [&](int shift) {
|
||||
return ((b * ((color0 >> shift) & 0xFF) + g * ((color1 >> shift) & 0xFF) +
|
||||
r * ((color2 >> shift) & 0xFF)) >> 8) & 0xFF;
|
||||
};
|
||||
pixel.setPixelARGB(qRgb(mix(0), mix(8), mix(16)));
|
||||
pixel.nextPixel();
|
||||
}
|
||||
pixel.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "Cevo/CevoTexture.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
Texture::Texture() : m_image(1, 1) {}
|
||||
|
||||
void Texture::setAge(int value)
|
||||
{
|
||||
if (m_age == value)
|
||||
return;
|
||||
m_age = value;
|
||||
if (!Colors)
|
||||
return;
|
||||
QImage &palette = Colors->image();
|
||||
colorBevelLight = palette.pixelColor(clkAge0 + m_age, cliBevelLight);
|
||||
colorBevelShade = palette.pixelColor(clkAge0 + m_age, cliBevelShade);
|
||||
colorTextLight = palette.pixelColor(clkAge0 + m_age, cliTextLight);
|
||||
colorTextShade = palette.pixelColor(clkAge0 + m_age, cliTextShade);
|
||||
colorLitText = palette.pixelColor(clkAge0 + m_age, cliLitText);
|
||||
colorMark = palette.pixelColor(clkAge0 + m_age, cliMark);
|
||||
colorPage = palette.pixelColor(clkAge0 + m_age, cliPage);
|
||||
colorCover = palette.pixelColor(clkAge0 + m_age, cliCover);
|
||||
}
|
||||
|
||||
void Texture::assign(const Texture &source)
|
||||
{
|
||||
m_age = source.m_age;
|
||||
m_image.assign(source.m_image);
|
||||
colorBevelLight = source.colorBevelLight;
|
||||
colorBevelShade = source.colorBevelShade;
|
||||
colorTextLight = source.colorTextLight;
|
||||
colorTextShade = source.colorTextShade;
|
||||
colorLitText = source.colorLitText;
|
||||
colorMark = source.colorMark;
|
||||
colorPage = source.colorPage;
|
||||
colorCover = source.colorCover;
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,65 @@
|
||||
#include "Dpi/DpiComCtrls.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
ListView::ListView(QWidget *parent) : QTreeWidget(parent)
|
||||
{
|
||||
setRootIsDecorated(false);
|
||||
connect(header(), &QHeaderView::sectionClicked, this, &ListView::columnClicked);
|
||||
connect(this, &QTreeWidget::itemSelectionChanged, this, &ListView::selectionChanged);
|
||||
}
|
||||
|
||||
void ListView::setViewStyle(ViewStyle value)
|
||||
{
|
||||
m_viewStyle = value;
|
||||
switch (value) {
|
||||
case ViewStyle::Report:
|
||||
setHeaderHidden(false);
|
||||
setIndentation(0);
|
||||
break;
|
||||
case ViewStyle::List:
|
||||
case ViewStyle::SmallIcon:
|
||||
case ViewStyle::Icon:
|
||||
setHeaderHidden(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ListView::setCheckboxes(bool value)
|
||||
{
|
||||
m_checkboxes = value;
|
||||
for (int i = 0; i < topLevelItemCount(); ++i) {
|
||||
QTreeWidgetItem *it = topLevelItem(i);
|
||||
it->setFlags(value ? (it->flags() | Qt::ItemIsUserCheckable)
|
||||
: (it->flags() & ~Qt::ItemIsUserCheckable));
|
||||
}
|
||||
}
|
||||
|
||||
ToolBar::ToolBar(QWidget *parent) : QToolBar(parent) {}
|
||||
|
||||
int ToolBar::buttonHeight() const { return iconSize().height(); }
|
||||
void ToolBar::setButtonHeight(int value) { setIconSize(QSize(iconSize().width(), value)); }
|
||||
int ToolBar::buttonWidth() const { return iconSize().width(); }
|
||||
void ToolBar::setButtonWidth(int value) { setIconSize(QSize(value, iconSize().height())); }
|
||||
|
||||
CoolBar::CoolBar(QWidget *parent) : QSplitter(Qt::Horizontal, parent)
|
||||
{
|
||||
setChildrenCollapsible(false);
|
||||
}
|
||||
|
||||
void CoolBar::addBand(const CoolBand &band)
|
||||
{
|
||||
if (!band.widget)
|
||||
return;
|
||||
band.widget->setMinimumSize(band.minWidth, band.minHeight);
|
||||
addWidget(band.widget);
|
||||
}
|
||||
|
||||
void CoolBar::beginUpdate() { setUpdatesEnabled(false); }
|
||||
void CoolBar::endUpdate() { setUpdatesEnabled(true); }
|
||||
|
||||
PageControl::PageControl(QWidget *parent) : QTabWidget(parent) {}
|
||||
|
||||
} // namespace Dpi
|
||||
@@ -0,0 +1,87 @@
|
||||
#include "Dpi/DpiCommon.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <QtMath>
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
int ScreenInfo::dpi()
|
||||
{
|
||||
return qRound(96.0 * toNative());
|
||||
}
|
||||
|
||||
double ScreenInfo::toNative()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
return screen ? screen->devicePixelRatio() : 1.0;
|
||||
}
|
||||
|
||||
double ScreenInfo::fromNative()
|
||||
{
|
||||
const double ratio = toNative();
|
||||
return ratio != 0.0 ? 1.0 / ratio : 1.0;
|
||||
}
|
||||
|
||||
int scaleToNative(int value)
|
||||
{
|
||||
return qRound(value * ScreenInfo::toNative());
|
||||
}
|
||||
|
||||
int scaleFromNative(int value)
|
||||
{
|
||||
return qRound(value * ScreenInfo::fromNative());
|
||||
}
|
||||
|
||||
int scaleToNativeDist(int base, int value)
|
||||
{
|
||||
return scaleToNative(base + value) - scaleToNative(base);
|
||||
}
|
||||
|
||||
QPoint scalePointToNative(const QPoint &value)
|
||||
{
|
||||
return QPoint(scaleToNative(value.x()), scaleToNative(value.y()));
|
||||
}
|
||||
|
||||
QPoint scalePointFromNative(const QPoint &value)
|
||||
{
|
||||
return QPoint(scaleFromNative(value.x()), scaleFromNative(value.y()));
|
||||
}
|
||||
|
||||
QSize scaleSizeToNative(const QSize &value)
|
||||
{
|
||||
return QSize(scaleToNative(value.width()), scaleToNative(value.height()));
|
||||
}
|
||||
|
||||
QSize scaleSizeFromNative(const QSize &value)
|
||||
{
|
||||
return QSize(scaleFromNative(value.width()), scaleFromNative(value.height()));
|
||||
}
|
||||
|
||||
QRect scaleRectToNative(const QRect &value)
|
||||
{
|
||||
return QRect(scalePointToNative(value.topLeft()), scaleSizeToNative(value.size()));
|
||||
}
|
||||
|
||||
QRect scaleRectFromNative(const QRect &value)
|
||||
{
|
||||
return QRect(scalePointFromNative(value.topLeft()), scaleSizeFromNative(value.size()));
|
||||
}
|
||||
|
||||
double scaleFloatToNative(double value)
|
||||
{
|
||||
return value * ScreenInfo::toNative();
|
||||
}
|
||||
|
||||
double scaleFloatFromNative(double value)
|
||||
{
|
||||
return value * ScreenInfo::fromNative();
|
||||
}
|
||||
|
||||
void writeLog(const QString &text)
|
||||
{
|
||||
qDebug().noquote() << text;
|
||||
}
|
||||
|
||||
} // namespace Dpi
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "Dpi/DpiControls.h"
|
||||
|
||||
#include <QCursor>
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
int ImageList::add(const QIcon &icon)
|
||||
{
|
||||
m_icons.append(icon);
|
||||
return m_icons.count() - 1;
|
||||
}
|
||||
|
||||
QIcon ImageList::icon(int index) const
|
||||
{
|
||||
return m_icons.value(index);
|
||||
}
|
||||
|
||||
QPoint Mouse::cursorPos() { return QCursor::pos(); }
|
||||
void Mouse::setCursorPos(const QPoint &value) { QCursor::setPos(value); }
|
||||
|
||||
} // namespace Dpi
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "Dpi/DpiExtCtrls.h"
|
||||
#include "Dpi/DpiGraphics.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
Panel::Panel(QWidget *parent) : QFrame(parent)
|
||||
{
|
||||
setFrameShape(QFrame::StyledPanel);
|
||||
}
|
||||
|
||||
PaintBox::PaintBox(QWidget *parent) : QWidget(parent) {}
|
||||
|
||||
void PaintBox::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
if (!onPaint)
|
||||
return;
|
||||
QPainter painter(this);
|
||||
Canvas canvas;
|
||||
canvas.bind(&painter);
|
||||
onPaint(canvas);
|
||||
canvas.unbind();
|
||||
}
|
||||
|
||||
Image::Image(QWidget *parent) : QLabel(parent)
|
||||
{
|
||||
setScaledContents(false);
|
||||
}
|
||||
|
||||
void Image::setStretch(bool value)
|
||||
{
|
||||
m_stretch = value;
|
||||
updatePixmap();
|
||||
}
|
||||
|
||||
void Image::setPicture(const QPixmap &pixmap)
|
||||
{
|
||||
m_source = pixmap;
|
||||
updatePixmap();
|
||||
}
|
||||
|
||||
void Image::updatePixmap()
|
||||
{
|
||||
setScaledContents(m_stretch);
|
||||
setPixmap(m_source);
|
||||
}
|
||||
|
||||
} // namespace Dpi
|
||||
@@ -0,0 +1,146 @@
|
||||
#include "Dpi/DpiForms.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCloseEvent>
|
||||
#include <QEventLoop>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <QtMath>
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
Form::Form(QWidget *parent) : QWidget(parent) {}
|
||||
|
||||
Form::~Form()
|
||||
{
|
||||
if (m_modalLoop)
|
||||
m_modalLoop->quit();
|
||||
}
|
||||
|
||||
ModalResult Form::showModal()
|
||||
{
|
||||
setWindowModality(Qt::ApplicationModal);
|
||||
m_modalResult = ModalResult::None;
|
||||
show();
|
||||
|
||||
QEventLoop loop;
|
||||
m_modalLoop = &loop;
|
||||
loop.exec();
|
||||
m_modalLoop = nullptr;
|
||||
|
||||
return m_modalResult;
|
||||
}
|
||||
|
||||
void Form::showEvent(QShowEvent *event)
|
||||
{
|
||||
QWidget::showEvent(event);
|
||||
if (onShow)
|
||||
onShow();
|
||||
}
|
||||
|
||||
void Form::hideEvent(QHideEvent *event)
|
||||
{
|
||||
QWidget::hideEvent(event);
|
||||
if (onHide)
|
||||
onHide();
|
||||
if (m_modalLoop)
|
||||
m_modalLoop->quit();
|
||||
}
|
||||
|
||||
void Form::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (onCloseQuery && !onCloseQuery()) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
if (onClose)
|
||||
onClose();
|
||||
QWidget::closeEvent(event);
|
||||
}
|
||||
|
||||
bool Form::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::WindowActivate && onActivate)
|
||||
onActivate();
|
||||
if (event->type() == QEvent::WindowDeactivate && onDeactivate)
|
||||
onDeactivate();
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
Form *Application::s_mainForm = nullptr;
|
||||
|
||||
void Application::run()
|
||||
{
|
||||
if (s_mainForm)
|
||||
s_mainForm->show();
|
||||
QApplication::exec();
|
||||
}
|
||||
|
||||
void Application::processMessages()
|
||||
{
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void Application::terminate()
|
||||
{
|
||||
QApplication::quit();
|
||||
}
|
||||
|
||||
QString Application::title() { return QApplication::applicationDisplayName(); }
|
||||
void Application::setTitle(const QString &value) { QApplication::setApplicationDisplayName(value); }
|
||||
QString Application::exeName() { return QApplication::applicationFilePath(); }
|
||||
|
||||
int Monitor::left() const { return m_screen ? m_screen->geometry().left() : 0; }
|
||||
int Monitor::top() const { return m_screen ? m_screen->geometry().top() : 0; }
|
||||
int Monitor::width() const { return m_screen ? m_screen->geometry().width() : 0; }
|
||||
int Monitor::height() const { return m_screen ? m_screen->geometry().height() : 0; }
|
||||
QRect Monitor::boundsRect() const { return m_screen ? m_screen->geometry() : QRect(); }
|
||||
|
||||
int Screen::formCount()
|
||||
{
|
||||
int count = 0;
|
||||
const auto widgets = QApplication::topLevelWidgets();
|
||||
for (QWidget *widget : widgets) {
|
||||
if (qobject_cast<Form *>(widget))
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
Form *Screen::activeForm()
|
||||
{
|
||||
return qobject_cast<Form *>(QApplication::activeWindow());
|
||||
}
|
||||
|
||||
int Screen::dpi()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
return screen ? qRound(screen->logicalDotsPerInch()) : 96;
|
||||
}
|
||||
|
||||
int Screen::pixelsPerInch() { return dpi(); }
|
||||
|
||||
int Screen::width()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
return screen ? screen->geometry().width() : 0;
|
||||
}
|
||||
|
||||
int Screen::height()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
return screen ? screen->geometry().height() : 0;
|
||||
}
|
||||
|
||||
QRect Screen::desktopRect()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
return screen ? screen->availableGeometry() : QRect();
|
||||
}
|
||||
|
||||
Monitor Screen::primaryMonitor()
|
||||
{
|
||||
return Monitor(QGuiApplication::primaryScreen());
|
||||
}
|
||||
|
||||
} // namespace Dpi
|
||||
@@ -0,0 +1,318 @@
|
||||
#include "Dpi/DpiGraphics.h"
|
||||
|
||||
#include <QFontMetrics>
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
// ---- Font ----
|
||||
|
||||
Font::Font() : m_color(Qt::black) {}
|
||||
|
||||
QString Font::name() const { return m_font.family(); }
|
||||
void Font::setName(const QString &value) { m_font.setFamily(value); changed(); }
|
||||
|
||||
bool Font::bold() const { return m_font.bold(); }
|
||||
void Font::setBold(bool value) { m_font.setBold(value); changed(); }
|
||||
bool Font::italic() const { return m_font.italic(); }
|
||||
void Font::setItalic(bool value) { m_font.setItalic(value); changed(); }
|
||||
bool Font::underline() const { return m_font.underline(); }
|
||||
void Font::setUnderline(bool value) { m_font.setUnderline(value); changed(); }
|
||||
|
||||
int Font::size() const { return m_font.pointSize(); }
|
||||
void Font::setSize(int value) { m_font.setPointSize(value); changed(); }
|
||||
int Font::height() const { return QFontMetrics(m_font).height(); }
|
||||
void Font::setHeight(int value) { m_font.setPixelSize(value); changed(); }
|
||||
|
||||
QColor Font::color() const { return m_color; }
|
||||
void Font::setColor(const QColor &value) { m_color = value; changed(); }
|
||||
|
||||
QSize Font::getTextSize(const QString &text) const
|
||||
{
|
||||
return QFontMetrics(m_font).size(Qt::TextSingleLine, text);
|
||||
}
|
||||
|
||||
int Font::getTextWidth(const QString &text) const
|
||||
{
|
||||
return QFontMetrics(m_font).horizontalAdvance(text);
|
||||
}
|
||||
|
||||
int Font::getTextHeight(const QString &text) const
|
||||
{
|
||||
Q_UNUSED(text);
|
||||
return QFontMetrics(m_font).height();
|
||||
}
|
||||
|
||||
void Font::assign(const Font &source)
|
||||
{
|
||||
m_font = source.m_font;
|
||||
m_color = source.m_color;
|
||||
changed();
|
||||
}
|
||||
|
||||
void Font::changed()
|
||||
{
|
||||
if (onChange)
|
||||
onChange();
|
||||
}
|
||||
|
||||
// ---- Pen ----
|
||||
|
||||
Pen::Pen() : m_color(Qt::black), m_style(Qt::SolidLine), m_width(1) {}
|
||||
|
||||
void Pen::assign(const Pen &source)
|
||||
{
|
||||
m_color = source.m_color;
|
||||
m_style = source.m_style;
|
||||
m_width = source.m_width;
|
||||
}
|
||||
|
||||
QPen Pen::toQPen() const
|
||||
{
|
||||
QPen pen(m_color);
|
||||
pen.setStyle(m_style);
|
||||
pen.setWidth(m_width);
|
||||
return pen;
|
||||
}
|
||||
|
||||
// ---- Brush ----
|
||||
|
||||
Brush::Brush() : m_color(Qt::white), m_style(Qt::SolidPattern) {}
|
||||
|
||||
void Brush::assign(const Brush &source)
|
||||
{
|
||||
m_color = source.m_color;
|
||||
m_style = source.m_style;
|
||||
}
|
||||
|
||||
QBrush Brush::toQBrush() const
|
||||
{
|
||||
return QBrush(m_color, m_style);
|
||||
}
|
||||
|
||||
// ---- Canvas ----
|
||||
|
||||
Canvas::Canvas() = default;
|
||||
|
||||
Canvas::Canvas(QPaintDevice *device)
|
||||
{
|
||||
setDevice(device);
|
||||
}
|
||||
|
||||
Canvas::~Canvas()
|
||||
{
|
||||
end();
|
||||
}
|
||||
|
||||
void Canvas::setDevice(QPaintDevice *device)
|
||||
{
|
||||
end();
|
||||
m_device = device;
|
||||
}
|
||||
|
||||
void Canvas::begin()
|
||||
{
|
||||
if (m_painter || !m_device)
|
||||
return;
|
||||
m_painter = new QPainter(m_device);
|
||||
m_ownsPainter = true;
|
||||
applyPenBrush();
|
||||
}
|
||||
|
||||
void Canvas::end()
|
||||
{
|
||||
if (m_painter && m_ownsPainter) {
|
||||
m_painter->end();
|
||||
delete m_painter;
|
||||
}
|
||||
m_painter = nullptr;
|
||||
m_ownsPainter = false;
|
||||
}
|
||||
|
||||
void Canvas::bind(QPainter *painter)
|
||||
{
|
||||
end();
|
||||
m_painter = painter;
|
||||
m_ownsPainter = false;
|
||||
m_device = painter ? painter->device() : nullptr;
|
||||
applyPenBrush();
|
||||
}
|
||||
|
||||
void Canvas::unbind()
|
||||
{
|
||||
if (!m_ownsPainter) {
|
||||
m_painter = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QPainter *Canvas::painter()
|
||||
{
|
||||
if (!m_painter)
|
||||
begin();
|
||||
return m_painter;
|
||||
}
|
||||
|
||||
void Canvas::applyPenBrush()
|
||||
{
|
||||
if (!m_painter)
|
||||
return;
|
||||
m_painter->setPen(m_pen.toQPen());
|
||||
m_painter->setBrush(m_brush.toQBrush());
|
||||
m_painter->setFont(m_font.toQFont());
|
||||
}
|
||||
|
||||
int Canvas::width() const { return m_device ? m_device->width() : 0; }
|
||||
int Canvas::height() const { return m_device ? m_device->height() : 0; }
|
||||
|
||||
QColor Canvas::pixel(int x, int y) const
|
||||
{
|
||||
auto *image = dynamic_cast<QImage *>(m_device);
|
||||
return image ? image->pixelColor(x, y) : QColor();
|
||||
}
|
||||
|
||||
void Canvas::setPixel(int x, int y, const QColor &color)
|
||||
{
|
||||
auto *image = dynamic_cast<QImage *>(m_device);
|
||||
if (image)
|
||||
image->setPixelColor(x, y, color);
|
||||
}
|
||||
|
||||
void Canvas::moveTo(int x, int y)
|
||||
{
|
||||
m_penPos = QPoint(x, y);
|
||||
}
|
||||
|
||||
void Canvas::lineTo(int x, int y)
|
||||
{
|
||||
painter()->setPen(m_pen.toQPen());
|
||||
painter()->drawLine(m_penPos, QPoint(x, y));
|
||||
m_penPos = QPoint(x, y);
|
||||
}
|
||||
|
||||
void Canvas::line(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
painter()->setPen(m_pen.toQPen());
|
||||
painter()->drawLine(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
void Canvas::rectangle(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
applyPenBrush();
|
||||
painter()->drawRect(QRect(QPoint(x1, y1), QPoint(x2 - 1, y2 - 1)));
|
||||
}
|
||||
|
||||
void Canvas::ellipse(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
applyPenBrush();
|
||||
painter()->drawEllipse(QRect(QPoint(x1, y1), QPoint(x2 - 1, y2 - 1)));
|
||||
}
|
||||
|
||||
void Canvas::roundRect(int x1, int y1, int x2, int y2, int rx, int ry)
|
||||
{
|
||||
applyPenBrush();
|
||||
painter()->drawRoundedRect(QRect(QPoint(x1, y1), QPoint(x2 - 1, y2 - 1)), rx, ry);
|
||||
}
|
||||
|
||||
void Canvas::polygon(const QPolygon &points)
|
||||
{
|
||||
applyPenBrush();
|
||||
painter()->drawPolygon(points);
|
||||
}
|
||||
|
||||
void Canvas::polyline(const QPolygon &points)
|
||||
{
|
||||
painter()->setPen(m_pen.toQPen());
|
||||
painter()->drawPolyline(points);
|
||||
}
|
||||
|
||||
void Canvas::textOut(int x, int y, const QString &text)
|
||||
{
|
||||
painter()->setFont(m_font.toQFont());
|
||||
painter()->setPen(QPen(m_font.color()));
|
||||
painter()->drawText(x, y + QFontMetrics(m_font.toQFont()).ascent(), text);
|
||||
}
|
||||
|
||||
int Canvas::textWidth(const QString &text) const { return m_font.getTextWidth(text); }
|
||||
int Canvas::textHeight(const QString &text) const { return m_font.getTextHeight(text); }
|
||||
QSize Canvas::textExtent(const QString &text) const { return m_font.getTextSize(text); }
|
||||
|
||||
void Canvas::fillRect(const QRect &rect)
|
||||
{
|
||||
painter()->fillRect(rect, m_brush.toQBrush());
|
||||
}
|
||||
|
||||
void Canvas::frameRect(const QRect &rect)
|
||||
{
|
||||
painter()->setPen(m_pen.toQPen());
|
||||
painter()->setBrush(Qt::NoBrush);
|
||||
painter()->drawRect(rect.adjusted(0, 0, -1, -1));
|
||||
}
|
||||
|
||||
void Canvas::draw(int x, int y, const QImage &image)
|
||||
{
|
||||
painter()->drawImage(QPoint(x, y), image);
|
||||
}
|
||||
|
||||
void Canvas::stretchDraw(const QRect &rect, const QImage &image)
|
||||
{
|
||||
painter()->drawImage(rect, image);
|
||||
}
|
||||
|
||||
void Canvas::copyRect(const QRect &dest, Canvas &source, const QRect &sourceRect)
|
||||
{
|
||||
auto *image = dynamic_cast<QImage *>(source.device());
|
||||
if (image)
|
||||
painter()->drawImage(dest, *image, sourceRect);
|
||||
}
|
||||
|
||||
// ---- Bitmap ----
|
||||
|
||||
Bitmap::Bitmap() : m_image(1, 1, QImage::Format_ARGB32), m_canvas(&m_image) {}
|
||||
|
||||
Bitmap::Bitmap(int width, int height)
|
||||
: m_image(width, height, QImage::Format_ARGB32), m_canvas(&m_image)
|
||||
{
|
||||
m_image.fill(Qt::transparent);
|
||||
}
|
||||
|
||||
void Bitmap::setSize(int width, int height)
|
||||
{
|
||||
QImage resized(width, height, QImage::Format_ARGB32);
|
||||
resized.fill(Qt::transparent);
|
||||
m_image = resized;
|
||||
m_canvas.setDevice(&m_image);
|
||||
}
|
||||
|
||||
void Bitmap::setTransparentColor(const QColor &value)
|
||||
{
|
||||
m_transparentColor = value;
|
||||
m_transparent = true;
|
||||
}
|
||||
|
||||
void Bitmap::loadFromFile(const QString &fileName)
|
||||
{
|
||||
m_image.load(fileName);
|
||||
m_image = m_image.convertToFormat(QImage::Format_ARGB32);
|
||||
m_canvas.setDevice(&m_image);
|
||||
}
|
||||
|
||||
void Bitmap::saveToFile(const QString &fileName) const
|
||||
{
|
||||
m_image.save(fileName);
|
||||
}
|
||||
|
||||
void Bitmap::assign(const Bitmap &source)
|
||||
{
|
||||
m_image = source.m_image;
|
||||
m_transparent = source.m_transparent;
|
||||
m_transparentColor = source.m_transparentColor;
|
||||
m_canvas.setDevice(&m_image);
|
||||
}
|
||||
|
||||
// ---- Picture ----
|
||||
|
||||
void Picture::loadFromFile(const QString &fileName)
|
||||
{
|
||||
m_bitmap.loadFromFile(fileName);
|
||||
}
|
||||
|
||||
} // namespace Dpi
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "Dpi/DpiGrids.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
StringGrid::StringGrid(QWidget *parent) : QTableWidget(parent) {}
|
||||
|
||||
QString StringGrid::cell(int col, int row) const
|
||||
{
|
||||
QTableWidgetItem *it = item(row, col);
|
||||
return it ? it->text() : QString();
|
||||
}
|
||||
|
||||
void StringGrid::setCell(int col, int row, const QString &value)
|
||||
{
|
||||
QTableWidgetItem *it = item(row, col);
|
||||
if (!it) {
|
||||
it = new QTableWidgetItem();
|
||||
setItem(row, col, it);
|
||||
}
|
||||
it->setText(value);
|
||||
}
|
||||
|
||||
void StringGrid::setFixedRows(int value)
|
||||
{
|
||||
m_fixedRows = value;
|
||||
for (int r = 0; r < value && r < rowCount(); ++r)
|
||||
verticalHeader()->resizeSection(r, verticalHeader()->defaultSectionSize());
|
||||
}
|
||||
|
||||
QRect StringGrid::cellRect(int col, int row) const
|
||||
{
|
||||
return visualItemRect(item(row, col));
|
||||
}
|
||||
|
||||
} // namespace Dpi
|
||||
@@ -0,0 +1,118 @@
|
||||
#include "Dpi/DpiMenus.h"
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
MenuItem::MenuItem(const QString &caption, QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_action = new QAction(caption, this);
|
||||
connect(m_action, &QAction::triggered, this, [this] {
|
||||
if (onClick)
|
||||
onClick();
|
||||
});
|
||||
}
|
||||
|
||||
MenuItem::MenuItem(QMenu *existingMenu, bool ownsMenu, QObject *parent)
|
||||
: QObject(parent), m_submenu(existingMenu), m_ownsSubmenu(ownsMenu)
|
||||
{
|
||||
m_action = existingMenu->menuAction();
|
||||
connect(m_action, &QAction::triggered, this, [this] {
|
||||
if (onClick)
|
||||
onClick();
|
||||
});
|
||||
}
|
||||
|
||||
MenuItem::MenuItem(QMenuBar *bar, QObject *parent) : QObject(parent), m_bar(bar) {}
|
||||
|
||||
MenuItem::~MenuItem()
|
||||
{
|
||||
qDeleteAll(m_items);
|
||||
if (m_ownsSubmenu)
|
||||
delete m_submenu;
|
||||
}
|
||||
|
||||
QMenu *MenuItem::submenu()
|
||||
{
|
||||
if (!m_submenu) {
|
||||
m_submenu = new QMenu();
|
||||
m_ownsSubmenu = true;
|
||||
if (m_action)
|
||||
m_action->setMenu(m_submenu);
|
||||
}
|
||||
return m_submenu;
|
||||
}
|
||||
|
||||
void MenuItem::setRadioItem(bool value)
|
||||
{
|
||||
m_radioItem = value;
|
||||
if (m_action)
|
||||
m_action->setCheckable(value);
|
||||
}
|
||||
|
||||
MenuItem *MenuItem::add(const QString &caption)
|
||||
{
|
||||
MenuItem *item;
|
||||
if (m_bar) {
|
||||
QMenu *menu = m_bar->addMenu(caption);
|
||||
item = new MenuItem(menu, false, this);
|
||||
} else {
|
||||
item = new MenuItem(caption, this);
|
||||
submenu()->addAction(item->action());
|
||||
}
|
||||
m_items.append(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
void MenuItem::insert(int index, MenuItem *item)
|
||||
{
|
||||
if (!m_bar) {
|
||||
QAction *before = (index >= 0 && index < m_items.count()) ? m_items[index]->action() : nullptr;
|
||||
submenu()->insertAction(before, item->action());
|
||||
}
|
||||
m_items.insert(index, item);
|
||||
}
|
||||
|
||||
void MenuItem::remove(MenuItem *item)
|
||||
{
|
||||
if (m_submenu)
|
||||
m_submenu->removeAction(item->action());
|
||||
m_items.removeOne(item);
|
||||
}
|
||||
|
||||
void MenuItem::deleteItem(int index)
|
||||
{
|
||||
MenuItem *item = m_items.value(index);
|
||||
if (!item)
|
||||
return;
|
||||
remove(item);
|
||||
delete item;
|
||||
}
|
||||
|
||||
void MenuItem::clear()
|
||||
{
|
||||
for (MenuItem *item : std::as_const(m_items)) {
|
||||
if (m_submenu)
|
||||
m_submenu->removeAction(item->action());
|
||||
delete item;
|
||||
}
|
||||
m_items.clear();
|
||||
}
|
||||
|
||||
void MenuItem::click()
|
||||
{
|
||||
if (m_action)
|
||||
m_action->trigger();
|
||||
}
|
||||
|
||||
PopupMenu::PopupMenu(QObject *parent) : MenuItem(new QMenu(), true, parent) {}
|
||||
|
||||
void PopupMenu::popup(const QPoint &pos)
|
||||
{
|
||||
submenu()->popup(pos);
|
||||
}
|
||||
|
||||
QKeySequence shortCut(int key, Qt::KeyboardModifiers modifiers)
|
||||
{
|
||||
return QKeySequence(static_cast<int>(modifiers) | key);
|
||||
}
|
||||
|
||||
} // namespace Dpi
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "Dpi/DpiPixelPointer.h"
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
PixelPointer::PixelPointer(QImage *image, int baseX, int baseY)
|
||||
: m_image(image)
|
||||
{
|
||||
if (m_image) {
|
||||
m_width = m_image->width();
|
||||
m_height = m_image->height();
|
||||
}
|
||||
setXY(baseX, baseY);
|
||||
}
|
||||
|
||||
void PixelPointer::setXY(int x, int y)
|
||||
{
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
}
|
||||
|
||||
void PixelPointer::setX(int x)
|
||||
{
|
||||
m_x = x;
|
||||
}
|
||||
|
||||
void PixelPointer::nextPixel()
|
||||
{
|
||||
++m_x;
|
||||
}
|
||||
|
||||
void PixelPointer::previousPixel()
|
||||
{
|
||||
--m_x;
|
||||
}
|
||||
|
||||
void PixelPointer::nextLine()
|
||||
{
|
||||
++m_y;
|
||||
}
|
||||
|
||||
void PixelPointer::previousLine()
|
||||
{
|
||||
--m_y;
|
||||
}
|
||||
|
||||
bool PixelPointer::posValid() const
|
||||
{
|
||||
return m_image && m_x >= 0 && m_x < m_width && m_y >= 0 && m_y < m_height;
|
||||
}
|
||||
|
||||
QRgb PixelPointer::pixelARGB() const
|
||||
{
|
||||
if (!posValid())
|
||||
return 0;
|
||||
return reinterpret_cast<const QRgb *>(m_image->constScanLine(m_y))[m_x];
|
||||
}
|
||||
|
||||
void PixelPointer::setPixelARGB(QRgb value)
|
||||
{
|
||||
if (!posValid())
|
||||
return;
|
||||
reinterpret_cast<QRgb *>(m_image->scanLine(m_y))[m_x] = value;
|
||||
}
|
||||
|
||||
QRgb PixelPointer::pixelRGB() const
|
||||
{
|
||||
return pixelARGB() | 0xFF000000;
|
||||
}
|
||||
|
||||
void PixelPointer::setPixelRGB(QRgb value)
|
||||
{
|
||||
setPixelARGB(value | 0xFF000000);
|
||||
}
|
||||
|
||||
} // namespace Dpi
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "Dpi/DpiSpin.h"
|
||||
|
||||
// No out-of-line members yet; this translation unit exists so AUTOMOC picks
|
||||
// up SpinEdit's Q_OBJECT macro consistently with the rest of the library.
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "Dpi/DpiStdCtrls.h"
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
QStringList Memo::lines() const
|
||||
{
|
||||
return toPlainText().split(QLatin1Char('\n'));
|
||||
}
|
||||
|
||||
void Memo::setLines(const QStringList &value)
|
||||
{
|
||||
setPlainText(value.join(QLatin1Char('\n')));
|
||||
}
|
||||
|
||||
QStringList ListBox::items() const
|
||||
{
|
||||
QStringList result;
|
||||
for (int i = 0; i < count(); ++i)
|
||||
result << item(i)->text();
|
||||
return result;
|
||||
}
|
||||
|
||||
void ListBox::setItems(const QStringList &value)
|
||||
{
|
||||
clear();
|
||||
addItems(value);
|
||||
}
|
||||
|
||||
} // namespace Dpi
|
||||
Reference in new issue
Block a user