From dde39638c285d18ff749269d1bb428f7379db775 Mon Sep 17 00:00:00 2001 From: "K.Ohta" Date: Wed, 15 Feb 2017 06:05:24 +0900 Subject: [PATCH] [UI][Qt][Draw] Update button api: Use *real* image, not texts. --- source/src/qt/common/menu_flags.cpp | 7 +++- source/src/qt/gui/menu_flags.h | 16 +++++--- source/src/qt/gui/menu_flags_tmpl.cpp | 4 +- source/src/qt/gui/qt_glutil_gl2_0.cpp | 64 ++++++++++++++--------------- source/src/qt/gui/qt_glutil_gl2_0.h | 3 ++ source/src/qt/machines/m5/MainWindow.cpp | 2 +- source/src/qt/machines/m5/menuclasses.h | 3 +- source/src/qt/machines/n5200/MainWindow.cpp | 2 +- source/src/qt/machines/n5200/menuclasses.h | 3 +- source/src/qt/osd_screen.cpp | 58 +++++++++++--------------- source/src/vm/event.h | 2 +- 11 files changed, 86 insertions(+), 78 deletions(-) diff --git a/source/src/qt/common/menu_flags.cpp b/source/src/qt/common/menu_flags.cpp index 6e4aec643..f8d639f63 100644 --- a/source/src/qt/common/menu_flags.cpp +++ b/source/src/qt/common/menu_flags.cpp @@ -485,9 +485,14 @@ USING_FLAGS_EXT::USING_FLAGS_EXT(config_t *cfg) : USING_FLAGS(cfg) use_vm_auto_key_table = true; #endif #if defined(MAX_BUTTONS) - max_button = MAX_BUTTONS; + max_button = sizeof(vm_buttons) / sizeof(button_desc_t); vm_buttons_d = (button_desc_t *)vm_buttons; #endif +#if defined(MAX_DRAW_RANGES) + max_ranges = sizeof(vm_ranges) / sizeof(vm_ranges_t); + vm_ranges_d = (vm_ranges_t *)vm_ranges; +#endif + #if defined(USE_VERTICAL_PIXEL_LINES) use_vertical_pixel_lines = true; #endif diff --git a/source/src/qt/gui/menu_flags.h b/source/src/qt/gui/menu_flags.h index e65c4aced..d13b0c880 100644 --- a/source/src/qt/gui/menu_flags.h +++ b/source/src/qt/gui/menu_flags.h @@ -13,14 +13,18 @@ class EMU; class OSD; + typedef struct { - const _TCHAR* caption; int x, y; int width, height; - int font_size; int code; } button_desc_t; +typedef struct { + int x, y; + int width, height; +} vm_ranges_t; + class DLL_PREFIX USING_FLAGS { protected: QString config_name; @@ -120,6 +124,7 @@ protected: bool use_vm_auto_key_table; int max_button; + int max_ranges; bool use_vertical_pixel_lines; int screen_width; @@ -154,7 +159,7 @@ protected: bool machine_z80tvgame; button_desc_t *vm_buttons_d; - + vm_ranges_t *vm_ranges_d; EMU *p_emu; OSD *p_osd; config_t *p_config; @@ -205,8 +210,6 @@ public: int get_max_drive() { return max_drive; } int get_max_d88_banks() { return max_d88_banks; } - int get_max_draw_ranges() { return max_draw_ranges; } - bool is_use_joystick() { return use_joystick; } bool is_use_joy_button_captions() { return use_joy_button_captions; } int get_num_joy_button_captions() { return num_joy_button_captions; } @@ -270,7 +273,10 @@ public: int get_screen_mode_num() { return screen_mode_num; } int get_max_button() { return max_button; } + int get_max_draw_ranges() { return max_ranges; } button_desc_t *get_vm_buttons() { return vm_buttons_d; } + vm_ranges_t *get_draw_ranges() { return vm_ranges_d; } + bool is_notify_key_down_lr_shift() { return notify_key_down_lr_shift; } bool is_datarec_sound() { return use_datarec_sound; } bool is_tape_binary_only() { return tape_binary_only; } diff --git a/source/src/qt/gui/menu_flags_tmpl.cpp b/source/src/qt/gui/menu_flags_tmpl.cpp index 9e459ac6d..2a8e21147 100644 --- a/source/src/qt/gui/menu_flags_tmpl.cpp +++ b/source/src/qt/gui/menu_flags_tmpl.cpp @@ -85,7 +85,9 @@ USING_FLAGS::USING_FLAGS(config_t *cfg) screen_height_aspect = WINDOW_HEIGHT_ASPECT; max_button = 0; vm_buttons_d = NULL; - + max_ranges = 0; + vm_ranges_d = NULL; + use_datarec_sound = false; use_vertical_pixel_lines = false; notify_key_down_lr_shift = false; diff --git a/source/src/qt/gui/qt_glutil_gl2_0.cpp b/source/src/qt/gui/qt_glutil_gl2_0.cpp index 10044e01f..565ed4d06 100644 --- a/source/src/qt/gui/qt_glutil_gl2_0.cpp +++ b/source/src/qt/gui/qt_glutil_gl2_0.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "qt_gldraw.h" //#include "csp_logger.h" @@ -92,6 +93,7 @@ GLDraw_2_0::GLDraw_2_0(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger, rec_count = 0; rec_width = using_flags->get_screen_width(); rec_height = using_flags->get_screen_height(); + ButtonImages.clear(); } GLDraw_2_0::~GLDraw_2_0() @@ -210,6 +212,7 @@ void GLDraw_2_0::initGLObjects() void GLDraw_2_0::initButtons(void) { button_desc_t *vm_buttons_d = using_flags->get_vm_buttons(); + if(vm_buttons_d != NULL) { button_shader = new QOpenGLShaderProgram(p_wid); if(button_shader != NULL) { @@ -217,10 +220,32 @@ void GLDraw_2_0::initButtons(void) button_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/normal_fragment_shader.glsl"); button_shader->link(); } - + + int ip = using_flags->get_max_button(); + if(ip > 0) { + for(int num = 0; num < ip; num++) { + QString tmps; + tmps = QString::asprintf(":/button%02d.png", num); + QImageReader *reader = new QImageReader(tmps); + QImage *result = new QImage(reader->read()); + QImage pic; + if(result != NULL) { + if(!result->isNull()) { + pic = result->convertToFormat(QImage::Format_ARGB32); + } else { + pic = QImage(10, 10, QImage::Format_RGBA8888); + pic.fill(QColor(0,0,0,0)); + } + delete result; + }else { + pic = QImage(10, 10, QImage::Format_RGBA8888); + pic.fill(QColor(0,0,0,0)); + } + ButtonImages.push_back(pic); + } + } vertexButtons = new QVector; - int i; - for(i = 0; i < using_flags->get_max_button(); i++) { + for(int i = 0; i < using_flags->get_max_button(); i++) { buffer_button_vertex[i] = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer); buffer_button_vertex[i]->create(); fButtonX[i] = -1.0 + (float)(vm_buttons_d[i].x * 2) / (float)using_flags->get_screen_width(); @@ -535,44 +560,17 @@ void GLDraw_2_0::drawGrids(void) void GLDraw_2_0::updateButtonTexture(void) { int i; - QImage *img; - QPainter *painter; - QColor col; - QRect rect; - QPen *pen; - QFont font = QFont(QString::fromUtf8("Sans")); - if(button_updated) return; - col.setRgb(0, 0, 0, 255); - pen = new QPen(col); button_desc_t *vm_buttons_d = using_flags->get_vm_buttons(); + if(button_updated) return; if(vm_buttons_d != NULL) { for(i = 0; i < using_flags->get_max_button(); i++) { - img = new QImage(vm_buttons_d[i].width * 4, vm_buttons_d[i].height * 4, QImage::Format_RGB32); - painter = new QPainter(img); - painter->setRenderHint(QPainter::Antialiasing, true); - col.setRgb(255, 255, 255, 255); - if(strlen(vm_buttons_d[i].caption) <= 3) { - font.setPixelSize((vm_buttons_d[i].width * 4) / 2); - } else { - font.setPixelSize((vm_buttons_d[i].width * 4) / 4); - } - painter->fillRect(0, 0, vm_buttons_d[i].width * 4, vm_buttons_d[i].height * 4, col); - painter->setFont(font); - //painter->setPen(pen); - rect.setWidth(vm_buttons_d[i].width * 4); - rect.setHeight(vm_buttons_d[i].height * 4); - rect.setX(0); - rect.setY(0); - painter->drawText(rect, Qt::AlignCenter, QString::fromUtf8(vm_buttons_d[i].caption)); + QImage img = ButtonImages.at(i); if(uButtonTextureID[i] != 0) { p_wid->deleteTexture(uButtonTextureID[i]); } - uButtonTextureID[i] = p_wid->bindTexture(*img); - delete painter; - delete img; + uButtonTextureID[i] = p_wid->bindTexture(img); } } - delete pen; button_updated = true; } diff --git a/source/src/qt/gui/qt_glutil_gl2_0.h b/source/src/qt/gui/qt_glutil_gl2_0.h index 587164e92..82ffb9cb3 100644 --- a/source/src/qt/gui/qt_glutil_gl2_0.h +++ b/source/src/qt/gui/qt_glutil_gl2_0.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "common.h" @@ -90,8 +91,10 @@ protected: GLfloat fButtonHeight[128]; QVector *vertexButtons; + QVector ButtonImages; bool button_updated; void updateButtonTexture(void); + GLfloat fBrightR; GLfloat fBrightG; diff --git a/source/src/qt/machines/m5/MainWindow.cpp b/source/src/qt/machines/m5/MainWindow.cpp index d94e73e0e..66fc02343 100644 --- a/source/src/qt/machines/m5/MainWindow.cpp +++ b/source/src/qt/machines/m5/MainWindow.cpp @@ -47,7 +47,7 @@ void META_MainWindow::retranslateUi(void) } // retranslateUi -META_MainWindow::META_MainWindow(USING_FLAGS *p, QWidget *parent) : Ui_MainWindow(p, parent) +META_MainWindow::META_MainWindow(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent) : Ui_MainWindow(p, logger, parent) { setupUI_Emu(); retranslateUi(); diff --git a/source/src/qt/machines/m5/menuclasses.h b/source/src/qt/machines/m5/menuclasses.h index 3b763f39d..64fcb3482 100644 --- a/source/src/qt/machines/m5/menuclasses.h +++ b/source/src/qt/machines/m5/menuclasses.h @@ -12,6 +12,7 @@ QT_BEGIN_NAMESPACE class Ui_MainWindow; class USING_FLAGS; +class CSP_Logger; class META_MainWindow : public Ui_MainWindow { Q_OBJECT protected: @@ -19,7 +20,7 @@ protected: void retranslateUi(void); public: - META_MainWindow(USING_FLAGS *p, QWidget *parent = 0); + META_MainWindow(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent = 0); ~META_MainWindow(); public slots: diff --git a/source/src/qt/machines/n5200/MainWindow.cpp b/source/src/qt/machines/n5200/MainWindow.cpp index 41d74d27b..fdedaffe4 100644 --- a/source/src/qt/machines/n5200/MainWindow.cpp +++ b/source/src/qt/machines/n5200/MainWindow.cpp @@ -43,7 +43,7 @@ void META_MainWindow::retranslateUi(void) -META_MainWindow::META_MainWindow(USING_FLAGS *p, QWidget *parent) : Ui_MainWindow(p, parent) +META_MainWindow::META_MainWindow(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent) : Ui_MainWindow(p, logger, parent) { setupUI_Emu(); retranslateUi(); diff --git a/source/src/qt/machines/n5200/menuclasses.h b/source/src/qt/machines/n5200/menuclasses.h index 17e0e432e..49e25d310 100644 --- a/source/src/qt/machines/n5200/menuclasses.h +++ b/source/src/qt/machines/n5200/menuclasses.h @@ -9,6 +9,7 @@ QT_BEGIN_NAMESPACE class Ui_MainWindow; class USING_FLAGS; +class CSP_Logger; // wrote of X1 Specific menu. class META_MainWindow : public Ui_MainWindow { Q_OBJECT @@ -16,7 +17,7 @@ protected: void setupUI_Emu(void); void retranslateUi(void); public: - META_MainWindow(USING_FLAGS *p, QWidget *parent = 0); + META_MainWindow(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent = 0); ~META_MainWindow(); public slots: }; diff --git a/source/src/qt/osd_screen.cpp b/source/src/qt/osd_screen.cpp index 033af825f..5871d5375 100644 --- a/source/src/qt/osd_screen.cpp +++ b/source/src/qt/osd_screen.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "qt_gldraw.h" #include "osd.h" @@ -253,47 +254,37 @@ void OSD_BASE::set_buttons() { if(!using_flags->is_use_one_board_computer()) return; - int i; - QImage *img; - QPainter *painter; - QColor col; - QRect rect; - QPen *pen; - QFont font = QFont(QString::fromUtf8("Sans")); - col.setRgb(0, 0, 0, 255); - pen = new QPen(col); - button_desc_t *vm_buttons_d = using_flags->get_vm_buttons(); if(vm_buttons_d != NULL) { - for(i = 0; i < using_flags->get_max_button(); i++) { - button_images[i] = QImage(vm_buttons_d[i].width, vm_buttons_d[i].height, QImage::Format_RGB32); - img = &(button_images[i]); - painter = new QPainter(img); - painter->setRenderHint(QPainter::Antialiasing, true); - col.setRgb(255, 255, 255, 255); - if(strlen(vm_buttons_d[i].caption) <= 3) { - font.setPixelSize(vm_buttons_d[i].width / 2); - } else { - font.setPixelSize(vm_buttons_d[i].width / 4); + for(int i = 0; i < using_flags->get_max_button(); i++) { + QString tmps; + tmps = QString::asprintf(":/button%02d.png", i); + QImageReader *reader = new QImageReader(tmps); + QImage *result = new QImage(reader->read()); + QImage pic; + if(result != NULL) { + if(!result->isNull()) { + pic = result->convertToFormat(QImage::Format_ARGB32); + } else { + pic = QImage(10, 10, QImage::Format_RGBA8888); + pic.fill(QColor(0,0,0,0)); + } + delete result; + }else { + pic = QImage(10, 10, QImage::Format_RGBA8888); + pic.fill(QColor(0,0,0,0)); } - painter->fillRect(0, 0, vm_buttons_d[i].width, vm_buttons_d[i].height, col); - painter->setFont(font); - //painter->setPen(pen); - rect.setWidth(vm_buttons_d[i].width); - rect.setHeight(vm_buttons_d[i].height); - rect.setX(0); - rect.setY(0); - painter->drawText(rect, Qt::AlignCenter, QString::fromUtf8(vm_buttons_d[i].caption)); - delete painter; + button_images[i] = pic; } } - delete pen; QRgb pixel; if(vm_buttons_d != NULL) { for(int ii = 0; ii < using_flags->get_max_button(); ii++) { - for(int yy = 0; yy < vm_buttons_d[ii].width; yy++) { - for(int xx = 0; xx < vm_buttons_d[ii].height; xx++) { + int ww = button_images[ii].width(); + int hh = button_images[ii].height(); + for(int yy = 0; yy < hh; yy++) { + for(int xx = 0; xx < ww; xx++) { pixel = button_images[ii].pixel(xx, yy); int xxx = vm_buttons_d[ii].x + xx; int yyy = vm_buttons_d[ii].y + yy; @@ -302,6 +293,7 @@ void OSD_BASE::set_buttons() } } } + } int OSD_BASE::add_video_frames() @@ -345,7 +337,7 @@ int OSD_BASE::add_video_frames() QRgb pixel; int ww = video_result->width(); int hh = video_result->height(); - printf("%d x %d\n", ww, hh); + //printf("%d x %d\n", ww, hh); for(int yy = 0; yy < hh; yy++) { for(int xx = 0; xx < ww; xx++) { pixel = video_result->pixel(xx, yy); diff --git a/source/src/vm/event.h b/source/src/vm/event.h index ee532eabc..c958e4f54 100644 --- a/source/src/vm/event.h +++ b/source/src/vm/event.h @@ -197,7 +197,7 @@ public: if(dcount_sound < MAX_SOUND) { d_sound[dcount_sound++] = device; } - printf("SOUND %d\n", dcount_sound); + //printf("SOUND %d\n", dcount_sound); } void touch_sound(void) { -- 2.11.0