OSDN Git Service

[OSD][Qt] Fix printer function: Now working to write to PNG file.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 12 Jan 2016 12:35:14 +0000 (21:35 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 12 Jan 2016 12:35:14 +0000 (21:35 +0900)
source/src/common.h
source/src/qt/osd_screen.cpp

index 1c2d81f..602128c 100644 (file)
@@ -480,10 +480,10 @@ typedef union {
        typedef uint32 scrntype;
        #define RGB_COLOR(r, g, b)      (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | (uint32)0xff << 24)
        #define RGBA_COLOR(r, g, b, a)  (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | ((uint32)(a) << 24))   
-       #define R_OF_COLOR(c)           (((c) >> 24) & 0xff)
-       #define G_OF_COLOR(c)           (((c) >> 16) & 0xff)
-       #define B_OF_COLOR(c)           (((c) >> 8 ) & 0xff)
-       #define A_OF_COLOR(c)           (((c) >> 0 ) & 0xff)
+       #define R_OF_COLOR(c)           (((c) >> 16) & 0xff)
+       #define G_OF_COLOR(c)           (((c) >> 8) & 0xff)
+       #define B_OF_COLOR(c)           (((c) >> 0 ) & 0xff)
+       #define A_OF_COLOR(c)           (((c) >> 24 ) & 0xff)
 # endif
 
 #endif  // ENDIAN
index d2d7a67..0a655c1 100644 (file)
@@ -404,18 +404,20 @@ void OSD::create_bitmap(bitmap_t *bitmap, int width, int height)
        initialize_screen_buffer(bitmap, width, height, 0); // HALFTONE
        bitmap->hPainter.begin(&(bitmap->pImage));
        bitmap->hPainter.fillRect(0, 0, width, height, col);
-       bitmap->hPainter.begin(&(bitmap->pImage));
        bitmap->hPainter.end();
+       AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Create bitmap: %08x %d x %d", bitmap, width, height);
 }
 
 void OSD::release_bitmap(bitmap_t *bitmap)
 {
        release_screen_buffer(bitmap);
+       AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Release bitmap: %08x", bitmap);
 }
 
 void OSD::create_font(font_t *font, const _TCHAR *family, int width, int height, int rotate, bool bold, bool italic)
 {
        QString fontName;
+       fontName = QString::fromUtf8(family);
        if(fontName == QString::fromUtf8("Gothic")) {
                fontName = QString::fromUtf8("Sans Serif");
        } else if(fontName == QString::fromUtf8("Mincho")) {
@@ -433,11 +435,13 @@ void OSD::create_font(font_t *font, const _TCHAR *family, int width, int height,
        font->hFont.setStretch((width * 10000) / (metric.width("F") * 100));
        font->rotate = rotate;
        font->init_flag = true;
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Create Font: Family=%s WIDTH=%d HEIGHT=%d",fontName.toUtf8().constData(), width, height);
        // Qt uses substitution font if not found.
 }
 
 void OSD::release_font(font_t *font)
 {
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Release Font");
 }
 
 void OSD::create_pen(pen_t *pen, int width, uint8 r, uint8 g, uint8 b)
@@ -450,15 +454,20 @@ void OSD::create_pen(pen_t *pen, int width, uint8 r, uint8 g, uint8 b)
        QColor color = QColor(r, g, b, 255);
        pen->hPen.setColor(color);
        pen->hPen.setWidth(width);
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Create PEN %08x to width=%d (RGB)=(%d,%d,%d)\n", pen, width, r, g, b);
 }
 
 void OSD::release_pen(pen_t *pen)
 {
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Release Pen %08x", pen);
 }
 
 void OSD::clear_bitmap(bitmap_t *bitmap, uint8 r, uint8 g, uint8 b)
 {
+       //lock_vm();
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Clear bitmap %08x", bitmap);
        draw_rectangle_to_bitmap(bitmap, 0, 0, bitmap->width, bitmap->height, r, g, b);
+       //unlock_vm();
 }
 
 int OSD::get_text_width(bitmap_t *bitmap, font_t *font, const char *text)
@@ -473,28 +482,29 @@ void OSD::draw_text_to_bitmap(bitmap_t *bitmap, font_t *font, int x, int y, cons
 {
        QColor col(r, g, b, 255);
        QPoint loc = QPoint(x, y);
-       //QString str = QString::fromUtf8(text);
        
        QTextCodec *codec = QTextCodec::codecForName("Shift-JIS");
        QString str = codec->toUnicode(text);
        bitmap->hPainter.begin(&(bitmap->pImage));
-       bitmap->hPainter.setBackgroundMode(Qt::TransparentMode);
+       //bitmap->hPainter.setBackgroundMode(Qt::OpaqueMode);
        bitmap->hPainter.setPen(col);
        bitmap->hPainter.rotate((qreal)font->rotate);
 
        bitmap->hPainter.setFont(font->hFont);
        bitmap->hPainter.drawText(loc, str);
        bitmap->hPainter.end();
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Draw Text to BITMAP %08x : (%d,%d) %s : Color(%d,%d,%d)", bitmap, x, y, str.toUtf8().constData(), r, g, b);
 }
 
 void OSD::draw_line_to_bitmap(bitmap_t *bitmap, pen_t *pen, int sx, int sy, int ex, int ey)
 {
        QLine line(sx, sy, ex, ey);
        bitmap->hPainter.begin(&(bitmap->pImage));
-       bitmap->hPainter.setBackgroundMode(Qt::TransparentMode);
+       //bitmap->hPainter.setBackgroundMode(Qt::TransparentMode);
        bitmap->hPainter.setPen(pen->hPen);
        bitmap->hPainter.drawLine(line);
        bitmap->hPainter.end();
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Draw Line from (%d,%d) to (%d,%d) to BITMAP %08x", sx, sy, ex, ey, bitmap);
 }
 
 void OSD::draw_point_to_bitmap(bitmap_t *bitmap, int x, int y, uint8 r, uint8 g, uint8 b)
@@ -503,20 +513,22 @@ void OSD::draw_point_to_bitmap(bitmap_t *bitmap, int x, int y, uint8 r, uint8 g,
        QColor d_col(r, g, b);
        QPen d_pen(d_col);
        bitmap->hPainter.begin(&(bitmap->pImage));
-       bitmap->hPainter.setBackgroundMode(Qt::TransparentMode);
+       //bitmap->hPainter.setBackgroundMode(Qt::OpaqueMode);
        bitmap->hPainter.setPen(d_pen);
        bitmap->hPainter.drawPoint(point);
        bitmap->hPainter.end();
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Draw Point to BITMAP %08x :(%d,%d) Color=(%d,%d,%d)", bitmap, x, y, r, g, b);
 }
 
 void OSD::draw_rectangle_to_bitmap(bitmap_t *bitmap, int x, int y, int width, int height, uint8 r, uint8 g, uint8 b)
 {
-       QColor d_col(r, g, b);
+       QColor d_col(r, g, b, 255);
        QBrush d_brush(d_col);
        bitmap->hPainter.begin(&(bitmap->pImage));
-       bitmap->hPainter.setBackgroundMode(Qt::TransparentMode);
+       //bitmap->hPainter.setBackgroundMode(Qt::OpaqueMode);
        bitmap->hPainter.fillRect(x, y, width, height, d_brush);
        bitmap->hPainter.end();
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Draw Rect BITMAP %08x :from (%d,%d) size=(%d,%d) Color=(%d,%d,%d)", bitmap, x, y, width, height, r, g, b);
 }
 
 void OSD::stretch_bitmap(bitmap_t *dest, int dest_x, int dest_y, int dest_width, int dest_height, bitmap_t *source, int source_x, int source_y, int source_width, int source_height)
@@ -524,9 +536,11 @@ void OSD::stretch_bitmap(bitmap_t *dest, int dest_x, int dest_y, int dest_width,
        QRect src_r(source_x, source_y, source_width, source_height);
        QRect dest_r(dest_x, dest_y, dest_width, dest_height);
        dest->hPainter.begin(&(dest->pImage));
-       dest->hPainter.setBackgroundMode(Qt::OpaqueMode);
+       //dest->hPainter.setBackgroundMode(Qt::OpaqueMode);
        dest->hPainter.drawImage(dest_r, source->pImage, src_r);
        dest->hPainter.end();
+       //AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Scale (%d,%d, %d, %d) to (%d,%d, %d, %d)", source_x, source_y, source_width, source_height,
+       //           dest_x, dest_y, dest_width, dest_height);
 }
 #endif
 
@@ -534,4 +548,5 @@ void OSD::stretch_bitmap(bitmap_t *dest, int dest_x, int dest_y, int dest_width,
 void OSD::write_bitmap_to_file(bitmap_t *bitmap, const _TCHAR *file_path)
 {
        bitmap->pImage.save(QString::fromUtf8(file_path));
+       AGAR_DebugLog(AGAR_LOG_DEBUG, "PRINTER: Save bitmap %08x to %s", bitmap, file_path);
 }