Marked color as disabled, if disabled

presentation
Andreas Butti 7 years ago
parent c2667c7b70
commit 3f483c285b
  1. 5
      src/gui/toolbarMenubar/ColorToolItem.cpp
  2. 28
      src/gui/toolbarMenubar/icon/ColorSelectImage.cpp
  3. 17
      src/gui/toolbarMenubar/icon/ColorSelectImage.h

@ -193,12 +193,11 @@ void ColorToolItem::enable(bool enabled)
if (enabled)
{
//TODO!!!!!!!!!!!!
icon->setState(COLOR_ICON_STATE_ENABLED);
}
else
{
// cairo_surface_t* surface = ColorSelectImage::newColorIconSurface(color, 16, !isSelector());
// gtk_image_set_from_surface(GTK_IMAGE(this->iconWidget), surface);
icon->setState(COLOR_ICON_STATE_DISABLED);
}
}

@ -37,7 +37,7 @@ void ColorSelectImage::drawWidget(cairo_t* cr)
XOJ_CHECK_TYPE(ColorSelectImage);
int y = (gtk_widget_get_allocated_height(widget) - size) / 2;
drawWidget(cr, color, size, y, circle);
drawWidget(cr, color, size, y, state, circle);
}
/**
@ -61,6 +61,17 @@ void ColorSelectImage::setColor(int color)
gtk_widget_queue_draw(widget);
}
/**
* Set State of the Icon
*/
void ColorSelectImage::setState(ColorIconState state)
{
XOJ_CHECK_TYPE(ColorSelectImage);
this->state = state;
gtk_widget_queue_draw(widget);
}
/**
* Create a new GtkImage with preview color
*/
@ -76,15 +87,22 @@ GtkWidget* ColorSelectImage::newColorIcon(int color, int size, bool circle)
/**
* Draw the widget
*/
void ColorSelectImage::drawWidget(cairo_t* cr, int color, int size, int y, bool circle)
void ColorSelectImage::drawWidget(cairo_t* cr, int color, int size, int y, ColorIconState state, bool circle)
{
float alpha = 1.0;
if (state == COLOR_ICON_STATE_DISABLED)
{
alpha = 0.5;
}
// Fill transparent
cairo_set_source_rgba(cr, 1, 1, 1, 0);
cairo_fill(cr);
double r = ((color & 0xff0000) >> 16) / 255.0;
double g = ((color & 0xff00) >> 8) / 255.0;
double b = ((color & 0xff)) / 255.0;
cairo_set_source_rgb(cr, r, g, b);
cairo_set_source_rgba(cr, r, g, b, alpha);
int x = 0;
int width = size;
@ -101,7 +119,7 @@ void ColorSelectImage::drawWidget(cairo_t* cr, int color, int size, int y, bool
}
cairo_fill(cr);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_set_source_rgba(cr, 0, 0, 0, alpha);
if (circle)
{
@ -123,7 +141,7 @@ cairo_surface_t* ColorSelectImage::newColorIconSurface(int color, int size, bool
{
cairo_surface_t* crBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size, size);
cairo_t* cr = cairo_create(crBuffer);
drawWidget(cr, color, size, 0, circle);
drawWidget(cr, color, size, 0, COLOR_ICON_STATE_ENABLED, circle);
cairo_destroy(cr);
return crBuffer;

@ -14,6 +14,11 @@
#include <XournalType.h>
#include <gtk/gtk.h>
enum ColorIconState {
COLOR_ICON_STATE_ENABLED,
COLOR_ICON_STATE_DISABLED
};
class ColorSelectImage
{
public:
@ -31,6 +36,11 @@ public:
*/
void setColor(int color);
/**
* Set State of the Icon
*/
void setState(ColorIconState state);
/**
* Create a new GtkImage with preview color
*/
@ -55,7 +65,7 @@ private:
/**
* Draw the widget
*/
static void drawWidget(cairo_t* cr, int color, int size, int y, bool circle);
static void drawWidget(cairo_t* cr, int color, int size, int y, ColorIconState state, bool circle);
private:
XOJ_TYPE_ATTRIB;
@ -79,4 +89,9 @@ private:
* Draw as circle
*/
bool circle = true;
/**
* State of the icon
*/
ColorIconState state = COLOR_ICON_STATE_ENABLED;
};

Loading…
Cancel
Save