if (xml.name() == FORM_KEYWORD) {
form = parseMainForm(xml);
if (form != NULL) {
+ /* image validation */
if (form->skinImg[MainForm::normal].size() == QSize(0, 0)) {
qDebug("general purpose skin form");
SkinPainter painter("main-skin",
- form->displayType->region.width(), form->displayType->region.height());
+ uiInfo->resolution, form->displayType->getAngle());
form->skinImg[MainForm::normal] = painter.getSkinImage();
- form->displayType->region.translate(painter.getCenterRect().topLeft());
+ form->displayType->setRect(painter.getCenterRect());
form->setGeneralPurpose(true);
}
} else if (xml.name() == FORM_KEYWORD) {
form = parseControllerForm(xml);
if (form != NULL) {
+ /* image validation */
if (form->conImg[ControllerForm::normal].size() == QSize(0, 0)) {
qDebug("general purpose con form");
- SkinPainter painter("controller-skin",
+ SkinPainter painter("controller-skin", QSize(
GPC_KEYBUTTON_WIDTH + (GPC_SCROLLBAR_WIDTH + GPC_SCROLLBAR_HSPACING),
GPC_HEAD_SPACING + (GPC_KEYBUTTON_HEIGHT * GPC_KEYBUTTON_DEFAULT_CNT) +
- (GPC_KEYBUTTON_VSPACING * (GPC_KEYBUTTON_DEFAULT_CNT - 1)));
+ (GPC_KEYBUTTON_VSPACING * (GPC_KEYBUTTON_DEFAULT_CNT - 1))),
+ 0);
form->conImg[ControllerForm::normal] = painter.getSkinImage();
form->centerRect = painter.getCenterRect();
form->setGeneralPurpose(true);
const qreal sx = scaleFactor;
const qreal sy = scaleFactor;
- widget->setGeometry(form->displayType->region.x() * sx,
- form->displayType->region.y() * sy,
- form->displayType->region.width() * sx,
- form->displayType->region.height() * sy);
+ widget->setGeometry(form->displayType->getRect().x() * sx,
+ form->displayType->getRect().y() * sy,
+ form->displayType->getRect().width() * sx,
+ form->displayType->getRect().height() * sy);
qt5_window_width = widget->width();
qt5_window_height = widget->height();
#include "displaytype.h"
-DisplayType::DisplayType(QRect region, int angle)
+DisplayType::DisplayType(QRect rect, int angle)
{
- this->region = region;
+ this->rect = rect;
this->angle = angle;
}
+void DisplayType::setRect(QRect rect)
+{
+ this->rect = rect;
+}
+
+QRect DisplayType::getRect()
+{
+ return rect;
+}
+
int DisplayType::getAngle()
{
return angle % 360;
class DisplayType
{
public:
- DisplayType(QRect region, int angle);
+ DisplayType(QRect rect, int angle);
~DisplayType();
+ void setRect(QRect rect);
+ QRect getRect();
int getAngle();
- QRect region;
-
private:
+ QRect rect;
int angle;
};
/* windowing */
setWindowTitle("Emulator");
setWindowIcon(QIcon(QPixmap(":/icons/emulator_icon.ico")));
-
- //setStyleSheet("background:transparent;");
- //setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::FramelessWindowHint);
+ setMinimumSize(0, 0);
winLayout = new QHBoxLayout(this);
winLayout->setMargin(0);
void MainWindow::startSwapper()
{
- QMetaObject::invokeMethod(swapper, "display", Qt::QueuedConnection);
+ if (swapper != NULL) {
+ QMetaObject::invokeMethod(swapper, "display", Qt::QueuedConnection);
+ }
}
void MainWindow::terminateSwapper()
{
- swapper->setTerminating();
- qt5_graphic_hw_invalidate();
+ if (swapper != NULL) {
+ swapper->setTerminating();
+ qt5_graphic_hw_invalidate();
+ }
}
QLabel *MainWindow::getScreenWidget()
keyboardShortcut->removeControllerShortcut();
}
+/* override */
void MainWindow::resizeEvent(QResizeEvent *event)
{
qDebug("resize main window");
resize(uiInfo->getUiSize());
- setRegion();
+ setMask(uiInfo->getUiRegion());
}
-void MainWindow::setRegion()
+/* override */
+void MainWindow::setMask(const QRegion ®ion)
{
- if (uiInfo->getUiRegion().isEmpty() == false) {
- setMask(uiInfo->getUiRegion());
+ if (region.isEmpty() == false) {
+ QWidget::setMask(region);
}
}
protected:
void resizeEvent(QResizeEvent *event);
+ void setMask(const QRegion ®ion);
void closeEvent(QCloseEvent *);
- void setRegion();
-
QLabel *screenWidget;
private:
<formList>
<form name="Portrait">
<display>
- <region left="0" top="0" width="720" height="1280"/>
<angle>0</angle>
</display>
</form>
<form name="Landscape">
<display>
- <region left="0" top="0" width="1280" height="720"/>
<angle>270</angle>
</display>
</form>
<form name="Reverse Portrait">
<display>
- <region left="0" top="0" width="720" height="1280"/>
<angle>180</angle>
</display>
</form>
<form name="Reverse Landscape">
<display>
- <region left="0" top="0" width="1280" height="720"/>
<angle>90</angle>
</display>
</form>
#include "skinpainter.h"
-SkinPainter::SkinPainter(QString patchPath,
- unsigned int displayWidth, unsigned int displayHeight)
+SkinPainter::SkinPainter(QString patchPath, QSize center, int degree)
{
QString path = ":/images/" + patchPath + "/";
- drawSkinPatch(path, displayWidth, displayHeight);
+ drawSkin(path, center, degree);
}
-void SkinPainter::drawSkinPatch(QString patchPath,
- unsigned int displayWidth, unsigned int displayHeight)
+void SkinPainter::drawSkin(QString patchPath, QSize center, int degree)
{
qDebug() << "load skin patch from :" << patchPath;
QImage RC(patchPath + "RC.png");
QImage RB(patchPath + "RB.png");
- centerRect.setRect(LT.width(), LT.height(), displayWidth, displayHeight);
+ QRect centerRect0(LT.width(), LT.height(), center.width(), center.height());
- skin = new QPixmap(displayWidth + (LT.width() * 2), displayHeight + (LT.height() * 2));
- skin->fill(Qt::transparent);
+ QPixmap image(center.width() + (LT.width() * 2),
+ center.height() + (LT.height() * 2));
+ image.fill(Qt::transparent);
- QPainter painter(skin);
+ QPainter painter(&image);
/* top side */
painter.drawImage(0, 0, LT);
- painter.drawImage(QRect(LT.width(), 0, displayWidth, LT.height()), TC);
- painter.drawImage(displayWidth + LT.width(), 0, RT);
+ painter.drawImage(QRect(LT.width(), 0, center.width(), LT.height()), TC);
+ painter.drawImage(center.width() + LT.width(), 0, RT);
/* middle side */
- painter.drawImage(QRect(0, LT.height(), LT.width(), displayHeight), LC);
- painter.fillRect(centerRect, Qt::SolidPattern);
- painter.drawImage(QRect(displayWidth + LT.width(), LT.height(), RT.width(), displayHeight), RC);
+ painter.drawImage(QRect(0, LT.height(), LT.width(), center.height()), LC);
+ painter.fillRect(centerRect0, Qt::SolidPattern);
+ painter.drawImage(QRect(
+ center.width() + LT.width(), LT.height(), RT.width(), center.height()), RC);
/* bottom side */
- painter.drawImage(0, displayHeight + LT.height(), LB);
- painter.drawImage(QRect(LT.width(), displayHeight + LT.height(), displayWidth, LB.height()), BC);
- painter.drawImage(displayWidth + LT.width(), displayHeight + LT.height(), RB);
+ painter.drawImage(0, center.height() + LT.height(), LB);
+ painter.drawImage(QRect(
+ LT.width(), center.height() + LT.height(), center.width(), LB.height()), BC);
+ painter.drawImage(center.width() + LT.width(), center.height() + LT.height(), RB);
+
+ /* rotate */
+ QMatrix matrix;
+ matrix.rotate(degree);
+ skin = new QPixmap(image.transformed(matrix));
+
+ centerRect = QRect(centerRect0.topLeft(), matrix.mapRect(centerRect0).size());
}
QImage SkinPainter::getSkinImage()
class SkinPainter
{
public:
- SkinPainter(QString patchPath,
- unsigned int displayWidth, unsigned int displayHeight);
+ SkinPainter(QString patchPath, QSize center, int degree);
QImage getSkinImage();
QRect getCenterRect();
private:
- void drawSkinPatch(QString patchPath,
- unsigned int displayWidth, unsigned int displayHeight);
+ void drawSkin(QString patchPath, QSize center, int degree);
QPixmap *skin;
QRect centerRect;
{
MainForm *mainForm = getMainForm();
if (mainForm == NULL) {
- qWarning("main form is null");
- return QSize(100, 100);
- }
-
- if (mainForm->skinImg[MainForm::normal].size() == QSize(0, 0)) {
- qWarning("invalid normal image size");
-
- if (mainForm->displayType->region.size() == QSize(0, 0)) {
- return QSize(100, 100);
- } else {
- return mainForm->displayType->region.size() * uiState.getScaleFactor();
- }
+ qFatal("main form is null");
}
return mainForm->skinImg[MainForm::normal].size() * uiState.getScaleFactor();
if (uiState.conState.dockingCon != NULL) {
QSize conSize = getConSize();
uiSize.setWidth(uiSize.width() + conSize.width());
+ uiSize.setHeight(qMax(uiSize.height(), conSize.height()));
}
return uiSize;