If the eraser is active switch to pen on color change

fixed #888
presentation
Andreas Butti 7 years ago
parent 4e72eda358
commit ece3edc9cd
  1. 23
      src/gui/Cursor.cpp
  2. 15
      src/gui/toolbarMenubar/ColorToolItem.cpp
  3. 5
      src/gui/toolbarMenubar/ColorToolItem.h
  4. 62
      src/gui/toolbarMenubar/icon/ColorSelectImage.cpp
  5. 50
      src/gui/toolbarMenubar/icon/ColorSelectImage.h

@ -338,7 +338,7 @@ GdkCursor* Cursor::createHighlighterOrPenCursor(int size, double alpha)
if (big)
{
// When using highlighter, paint the icon with the current color
if(size == 5)
if (size == 5)
{
cairo_set_source_rgb(cr, r, g, b);
}
@ -374,18 +374,17 @@ GdkCursor* Cursor::createHighlighterOrPenCursor(int size, double alpha)
cairo_fill_preserve(cr);
}
if(highlightPosition)
{
// A yellow transparent circle with no border
cairo_set_line_width(cr, 0);
cairo_set_source_rgba(cr, 255, 255, 0, 0.5);
cairo_arc(cr, centerX, centerY, 45, 0, 2 * 3.1415);
cairo_fill_preserve(cr);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_stroke(cr);
if (highlightPosition)
{
// A yellow transparent circle with no border
cairo_set_line_width(cr, 0);
cairo_set_source_rgba(cr, 255, 255, 0, 0.5);
cairo_arc(cr, centerX, centerY, 45, 0, 2 * 3.1415);
cairo_fill_preserve(cr);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_stroke(cr);
}
}
cairo_set_source_rgba(cr, r, g, b, alpha);
// Correct the offset of the coloured dot for big-cursor mode

@ -189,8 +189,16 @@ void ColorToolItem::showColorchooser()
*/
void ColorToolItem::enable(bool enabled)
{
AbstractToolItem::enable(enabled);
if (!enabled && toolHandler->getToolType() == TOOL_ERASER)
{
icon->setState(COLOR_ICON_STATE_PEN);
AbstractToolItem::enable(true);
switchToPen = true;
return;
}
switchToPen = false;
AbstractToolItem::enable(enabled);
if (enabled)
{
icon->setState(COLOR_ICON_STATE_ENABLED);
@ -205,6 +213,11 @@ void ColorToolItem::activated(GdkEvent* event, GtkMenuItem* menuitem, GtkToolBut
{
XOJ_CHECK_TYPE(ColorToolItem);
if (switchToPen)
{
toolHandler->selectTool(TOOL_PEN, true);
}
if (inUpdate)
{
return;

@ -76,6 +76,11 @@ private:
*/
ColorSelectImage* icon = NULL;
/**
* Switch to pen if the color icon is pressed
*/
bool switchToPen = false;
GtkWindow* parent = NULL;
ToolHandler* toolHandler = NULL;

@ -19,7 +19,6 @@ ColorSelectImage::ColorSelectImage(int color, bool circle)
XOJ_CHECK_TYPE_OBJ(self, ColorSelectImage);
self->drawWidget(cr);
}), this);
}
ColorSelectImage::~ColorSelectImage()
@ -36,8 +35,16 @@ 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, state, circle);
IconConfig config;
config.color = color;
config.size = size;
config.state = COLOR_ICON_STATE_ENABLED;
config.circle = circle;
config.state = state;
config.width = gtk_widget_get_allocated_width(widget);
config.height = gtk_widget_get_allocated_height(widget);
drawWidget(cr, config);
}
/**
@ -87,10 +94,10 @@ GtkWidget* ColorSelectImage::newColorIcon(int color, int size, bool circle)
/**
* Draw the widget
*/
void ColorSelectImage::drawWidget(cairo_t* cr, int color, int size, int y, ColorIconState state, bool circle)
void ColorSelectImage::drawWidget(cairo_t* cr, const IconConfig& config)
{
float alpha = 1.0;
if (state == COLOR_ICON_STATE_DISABLED)
if (config.state == COLOR_ICON_STATE_DISABLED)
{
alpha = 0.5;
}
@ -99,17 +106,19 @@ void ColorSelectImage::drawWidget(cairo_t* cr, int color, int size, int y, Color
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;
int y = (config.height - config.size) / 2;
double r = ((config.color & 0xff0000) >> 16) / 255.0;
double g = ((config.color & 0xff00) >> 8) / 255.0;
double b = ((config.color & 0xff)) / 255.0;
cairo_set_source_rgba(cr, r, g, b, alpha);
int x = 0;
int width = size;
int width = config.size;
double radius = size / 2.0;
double radius = config.size / 2.0;
if (circle)
if (config.circle)
{
cairo_arc(cr, radius + x, radius + y, radius - 1, 0, 2 * M_PI);
}
@ -121,7 +130,7 @@ void ColorSelectImage::drawWidget(cairo_t* cr, int color, int size, int y, Color
cairo_set_source_rgba(cr, 0, 0, 0, alpha);
if (circle)
if (config.circle)
{
cairo_arc(cr, radius + x, radius + y, radius - 1, 0, 2 * M_PI);
}
@ -132,6 +141,26 @@ void ColorSelectImage::drawWidget(cairo_t* cr, int color, int size, int y, Color
cairo_set_line_width(cr, 0.8);
cairo_stroke(cr);
if (config.state == COLOR_ICON_STATE_PEN)
{
// Pencil cursor from cursor drawing, a little shrinked, so that it fits to the color item
cairo_move_to(cr, x, y + 16);
cairo_line_to(cr, x, y + 16 - 4);
cairo_line_to(cr, x + 13, y + 16 - 16);
cairo_line_to(cr, x + 16, y + 16 - 14);
cairo_line_to(cr, x + 4, y + 16);
cairo_close_path(cr);
cairo_set_source_rgba(cr, 1, 1, 1, 0.9);
cairo_fill_preserve(cr);
cairo_set_source_rgba(cr, 0, 0, 0, 0.7);
cairo_set_line_width(cr, 0.8);
cairo_stroke(cr);
}
}
/**
@ -141,7 +170,14 @@ 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, COLOR_ICON_STATE_ENABLED, circle);
IconConfig config;
config.color = color;
config.size = size;
config.state = COLOR_ICON_STATE_ENABLED;
config.circle = circle;
drawWidget(cr, config);
cairo_destroy(cr);
return crBuffer;

@ -15,8 +15,54 @@
#include <gtk/gtk.h>
enum ColorIconState {
/**
* Draw color icon enabled
*/
COLOR_ICON_STATE_ENABLED,
COLOR_ICON_STATE_DISABLED
/**
* Draw color icon disabled
*/
COLOR_ICON_STATE_DISABLED,
/**
* Draw color icon with a pen symbol, switch to pen when clicked
*/
COLOR_ICON_STATE_PEN
};
class IconConfig
{
public:
/**
* Color of the icon
*/
int color = 0;
/**
* Size of the icon
*/
int size = 16;
/**
* Draw as circle
*/
bool circle = true;
/**
* Size of the widget
*/
int width = 16;
/**
* Size of the widget
*/
int height = 16;
/**
* State of the icon
*/
ColorIconState state = COLOR_ICON_STATE_ENABLED;
};
class ColorSelectImage
@ -65,7 +111,7 @@ private:
/**
* Draw the widget
*/
static void drawWidget(cairo_t* cr, int color, int size, int y, ColorIconState state, bool circle);
static void drawWidget(cairo_t* cr, const IconConfig& config);
private:
XOJ_TYPE_ATTRIB;

Loading…
Cancel
Save