Commit 5e5c1376 authored by Christoffer Ackelman's avatar Christoffer Ackelman

QT: fix Glow custom colors.

parent 61d30c53
...@@ -232,7 +232,11 @@ static QColor glow_allocate_custom_color(GlowDrawQt* draw_ctx, ...@@ -232,7 +232,11 @@ static QColor glow_allocate_custom_color(GlowDrawQt* draw_ctx,
return QColor(); return QColor();
} }
return QColor(rgb_red, rgb_green, rgb_blue); QColor color(rgb_red, rgb_green, rgb_blue);
draw_ctx->get_customcolors()->color_vect[drawtype - glow_eDrawType_CustomColor1] = color;
return color;
} }
GlowDrawQt::~GlowDrawQt() GlowDrawQt::~GlowDrawQt()
...@@ -274,13 +278,15 @@ int GlowDrawQt::init_nav(QWidget* nav_widget) ...@@ -274,13 +278,15 @@ int GlowDrawQt::init_nav(QWidget* nav_widget)
GlowDrawQt::GlowDrawQt(QWidget* toplevel, void** glow_ctx, GlowDrawQt::GlowDrawQt(QWidget* toplevel, void** glow_ctx,
int (*init_proc)(QWidget* w, GlowCtx* ctx, void* client_data), int (*init_proc)(QWidget* w, GlowCtx* ctx, void* client_data),
void* client_data, glow_eCtxType type) void* client_data, glow_eCtxType type)
: click_sensitivity(0), closing_down(0) : click_sensitivity(0), closing_down(0), customcolors_cnt(0)
{ {
timer_id = new QTimer(this); timer_id = new QTimer(this);
m_wind = new DrawWindQt(); m_wind = new DrawWindQt();
nav_wind = new DrawWindQt(); nav_wind = new DrawWindQt();
nav_wind->is_nav = 1; nav_wind->is_nav = 1;
memset(customcolors, 0, sizeof(customcolors));
if (type == glow_eCtxType_Brow) { if (type == glow_eCtxType_Brow) {
ctx = (GlowCtx*)new BrowCtx("Claes context", 20); ctx = (GlowCtx*)new BrowCtx("Claes context", 20);
} else if (type == glow_eCtxType_Grow) { } else if (type == glow_eCtxType_Grow) {
...@@ -1211,8 +1217,7 @@ int GlowDrawQt::polyline_helper(GlowWind* wind, int painter_type, int size, ...@@ -1211,8 +1217,7 @@ int GlowDrawQt::polyline_helper(GlowWind* wind, int painter_type, int size,
if (!fill) { if (!fill) {
painter->setBrush(Qt::NoBrush); painter->setBrush(Qt::NoBrush);
} }
// debug_print("polyline painter_type=%d, fill=%d, point_cnt=%d\n", // debug_print("polyline painter_type=%d, fill=%d, point_cnt=%d\n", painter_type, fill, point_cnt);
// painter_type, fill, point_cnt);
painter->drawPolygon(qpoints, point_cnt); painter->drawPolygon(qpoints, point_cnt);
delete[] qpoints; delete[] qpoints;
...@@ -1285,6 +1290,7 @@ int GlowDrawQt::text(GlowWind* wind, int x, int y, char* text, int len, ...@@ -1285,6 +1290,7 @@ int GlowDrawQt::text(GlowWind* wind, int x, int y, char* text, int len,
QRect rect QRect rect
= painter->fontMetrics().boundingRect(QString::fromLocal8Bit(text, len)); = painter->fontMetrics().boundingRect(QString::fromLocal8Bit(text, len));
// debug_print("text %s on %d,%d\n", text, x, y);
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip, painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip,
QString::fromLocal8Bit(text, len)); QString::fromLocal8Bit(text, len));
...@@ -1318,6 +1324,7 @@ int GlowDrawQt::text_cursor(GlowWind* wind, int x, int y, char* text, int len, ...@@ -1318,6 +1324,7 @@ int GlowDrawQt::text_cursor(GlowWind* wind, int x, int y, char* text, int len,
set_clip(w, get_painter(this, painter_type, idx)); set_clip(w, get_painter(this, painter_type, idx));
} }
// debug_print("cursor %d,%d to %d,%d\n", x + width, y + descent, x + width, y - height + descent);
painter->drawLine(x + width, y + descent, x + width, y - height + descent); painter->drawLine(x + width, y + descent, x + width, y - height + descent);
delete painter; delete painter;
...@@ -1361,6 +1368,7 @@ int GlowDrawQt::text_erase(GlowWind* wind, int x, int y, char* text, int len, ...@@ -1361,6 +1368,7 @@ int GlowDrawQt::text_erase(GlowWind* wind, int x, int y, char* text, int len,
QRect rect QRect rect
= painter->fontMetrics().boundingRect(QString::fromLocal8Bit(text, len)); = painter->fontMetrics().boundingRect(QString::fromLocal8Bit(text, len));
// debug_print("textErase %s on %d,%d\n", text, x, y);
painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip, painter->drawText(x, y, rect.width(), rect.height(), Qt::TextDontClip,
QString::fromLocal8Bit(text, len)); QString::fromLocal8Bit(text, len));
...@@ -1977,40 +1985,12 @@ int GlowDrawQt::create_buffer(GlowWind* wind) ...@@ -1977,40 +1985,12 @@ int GlowDrawQt::create_buffer(GlowWind* wind)
window_height = ctx->navw.window_height; window_height = ctx->navw.window_height;
} }
/*
if (!w->double_buffer_on || !window_width) {
return 0;
}
if (window_width == w->buffer->width() &&
window_height == w->buffer->height()) {
return 0;
}
if (w->buffer) {
delete w->buffer;
}
w->buffer = new QImage(window_width, window_height, QImage::Format_RGB32);
w->buffer_width = window_width;
w->buffer_height = window_height;
*/
buffer_background(w, 0); buffer_background(w, 0);
return 1; return 1;
} }
void GlowDrawQt::delete_buffer(GlowWind* wind) void GlowDrawQt::delete_buffer(GlowWind* wind)
{ {
/*
DrawWindQt *w = (DrawWindQt *) wind->window;
if (w->buffer) {
delete w->buffer;
}
w->buffer_width = 0;
w->buffer_height = 0;
*/
} }
void GlowDrawQt::buffer_background(DrawWind* wind, GlowCtx* cctx) void GlowDrawQt::buffer_background(DrawWind* wind, GlowCtx* cctx)
...@@ -2904,6 +2884,7 @@ int GlowDrawQt::gradient_fill_rect(GlowWind* wind, int x, int y, int w, int h, ...@@ -2904,6 +2884,7 @@ int GlowDrawQt::gradient_fill_rect(GlowWind* wind, int x, int y, int w, int h,
if (!gradient_create_pattern(x, y, w, h, d0, d1, d2, gradient, &pat)) { if (!gradient_create_pattern(x, y, w, h, d0, d1, d2, gradient, &pat)) {
return 0; return 0;
} }
// debug_print("gradient fillRect [%d,%d,%d,%d]\n", x, y, w, h);
painter->fillRect(QRect(x, y, w, h), *pat); painter->fillRect(QRect(x, y, w, h), *pat);
delete pat; delete pat;
...@@ -2932,6 +2913,7 @@ int GlowDrawQt::gradient_fill_rectrounded(GlowWind* wind, int x, int y, int w, ...@@ -2932,6 +2913,7 @@ int GlowDrawQt::gradient_fill_rectrounded(GlowWind* wind, int x, int y, int w,
return 0; return 0;
} }
// debug_print("gradient fillRect rounded [%d,%d,%d,%d]\n", x, y, w, h);
if (roundamount >= 0) { if (roundamount >= 0) {
QPainterPath path; QPainterPath path;
path.addRoundedRect(QRect(x, y, w, h), roundamount, roundamount); path.addRoundedRect(QRect(x, y, w, h), roundamount, roundamount);
...@@ -3107,6 +3089,7 @@ int GlowDrawQt::text_qt(GlowWind* wind, int x, int y, char* text, int len, ...@@ -3107,6 +3089,7 @@ int GlowDrawQt::text_qt(GlowWind* wind, int x, int y, char* text, int len,
px = x; px = x;
py = (int)(y - (1.0 - FONT_DESCENT) * height); py = (int)(y - (1.0 - FONT_DESCENT) * height);
} }
// debug_print("textQt %s on %d,%d with color %s, painter_type=%d, color=%d\n", text, px, py, qPrintable(painter->pen().color().name()), painter_type, color);
painter->drawText(px, py, rect.width(), rect.height(), Qt::TextDontClip, str); painter->drawText(px, py, rect.width(), rect.height(), Qt::TextDontClip, str);
delete painter; delete painter;
...@@ -3179,6 +3162,7 @@ int GlowDrawQt::text_erase_qt(GlowWind* wind, int x, int y, char* text, int len, ...@@ -3179,6 +3162,7 @@ int GlowDrawQt::text_erase_qt(GlowWind* wind, int x, int y, char* text, int len,
set_clip(w, painter); set_clip(w, painter);
} }
// debug_print("textEraseQt %s on %d,%d\n", text, px, py);
painter->fillRect(px, py, pw, ph, painter->brush()); painter->fillRect(px, py, pw, ph, painter->brush());
delete painter; delete painter;
...@@ -3318,38 +3302,47 @@ void GlowDrawQt::update_color(glow_eDrawType color) ...@@ -3318,38 +3302,47 @@ void GlowDrawQt::update_color(glow_eDrawType color)
void GlowDrawQt::push_customcolors(GlowCustomColors* cc) void GlowDrawQt::push_customcolors(GlowCustomColors* cc)
{ {
customcolors.push(*cc); if (customcolors_cnt > 10) {
printf("** Max number custom colors exceede\n");
return;
}
for (int i = customcolors_cnt; i > 0; i--)
customcolors[i] = customcolors[i - 1];
customcolors[0] = (GlowCustomColorsQt*)cc;
customcolors_cnt++;
} }
void GlowDrawQt::set_customcolors(GlowCustomColors* cc) void GlowDrawQt::set_customcolors(GlowCustomColors* cc)
{ {
while (!customcolors.empty()) { customcolors[0] = (GlowCustomColorsQt*)cc;
customcolors.pop(); customcolors_cnt = 1;
}
customcolors.push(*cc);
} }
void GlowDrawQt::pop_customcolors() void GlowDrawQt::pop_customcolors()
{ {
if (customcolors.empty()) { if (customcolors_cnt <= 0) {
printf("** Customcolor stack disorder\n"); printf("** Customcolor stack disorder\n");
} }
customcolors.pop(); for (int i = 0; i < customcolors_cnt - 1; i++)
customcolors[i] = customcolors[i + 1];
customcolors_cnt--;
} }
GlowCustomColors* GlowDrawQt::get_customcolors() GlowCustomColorsQt* GlowDrawQt::get_customcolors()
{ {
if (customcolors.empty()) { if (customcolors_cnt == 0)
return 0; return 0;
} return customcolors[0];
return &customcolors.top();
} }
GlowCustomColors* GlowDrawQt::create_customcolors() GlowCustomColors* GlowDrawQt::create_customcolors()
{ {
return new GlowCustomColors(); return new GlowCustomColorsQt();
} }
void GlowDrawQt::reset_customcolors(GlowCustomColors* cc) void GlowDrawQt::reset_customcolors(GlowCustomColors* cc)
{ {
memset(((GlowCustomColorsQt*)cc)->color_vect, 0,
sizeof(((GlowCustomColorsQt*)cc)->color_vect));
} }
\ No newline at end of file
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <stack> #include <stack>
#include "glow_customcolors.h"
#include "glow_draw.h" #include "glow_draw.h"
#include <QColor> #include <QColor>
...@@ -72,8 +73,6 @@ public: ...@@ -72,8 +73,6 @@ public:
QPixmap* background_pixmap; QPixmap* background_pixmap;
int background_pixmap_width; int background_pixmap_width;
int background_pixmap_height; int background_pixmap_height;
/*int buffer_width;
int buffer_height;*/
}; };
typedef struct { typedef struct {
...@@ -82,6 +81,8 @@ typedef struct { ...@@ -82,6 +81,8 @@ typedef struct {
QTimer* timer_id; QTimer* timer_id;
} glow_draw_sTimerCb; } glow_draw_sTimerCb;
class GlowCustomColorsQt;
class GlowDrawQt : private QObject, public GlowDraw { class GlowDrawQt : private QObject, public GlowDraw {
Q_OBJECT Q_OBJECT
...@@ -99,7 +100,8 @@ public: ...@@ -99,7 +100,8 @@ public:
QTimer* timer_id; QTimer* timer_id;
int click_sensitivity; int click_sensitivity;
int closing_down; int closing_down;
std::stack<GlowCustomColors> customcolors; GlowCustomColorsQt* customcolors[10];
int customcolors_cnt;
int event_handler(QEvent* event, QWidget *target); int event_handler(QEvent* event, QWidget *target);
virtual void enable_event(glow_eEvent event, glow_eEventType event_type, virtual void enable_event(glow_eEvent event, glow_eEventType event_type,
...@@ -250,7 +252,7 @@ public: ...@@ -250,7 +252,7 @@ public:
void set_customcolors(GlowCustomColors* cc); void set_customcolors(GlowCustomColors* cc);
void pop_customcolors(); void pop_customcolors();
GlowCustomColors* create_customcolors(); GlowCustomColors* create_customcolors();
GlowCustomColors* get_customcolors(); GlowCustomColorsQt* get_customcolors();
void reset_customcolors(GlowCustomColors* cc); void reset_customcolors(GlowCustomColors* cc);
private: private:
...@@ -293,4 +295,19 @@ public: ...@@ -293,4 +295,19 @@ public:
double y; double y;
}; };
class GlowCustomColorsQt : public GlowCustomColors {
public:
GlowCustomColorsQt() : color_vect_cnt(0)
{
memset(color_vect, 0, sizeof(color_vect));
}
~GlowCustomColorsQt()
{
}
QColor
color_vect[glow_eDrawType_CustomColor__ - glow_eDrawType_CustomColor1];
int color_vect_cnt;
};
#endif #endif
\ No newline at end of file
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#ifndef glow_customcolors_h #ifndef glow_customcolors_h
#define glow_customcolors_h #define glow_customcolors_h
#include <fstream>
#include "glow.h" #include "glow.h"
/*! \file glow_customcolors.h /*! \file glow_customcolors.h
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment