parent
1a2784a60c
commit
8cd2fdb850
25 changed files with 565 additions and 73 deletions
@ -0,0 +1,85 @@ |
||||
#include "FillTransparencyDialog.h" |
||||
|
||||
FillTransparencyDialog::FillTransparencyDialog(GladeSearchpath* gladeSearchPath, int alpha) |
||||
: GladeGui(gladeSearchPath, "fillTransparency.glade", "fillTransparencyDialog"), |
||||
resultAlpha(-1) |
||||
{ |
||||
XOJ_INIT_TYPE(FillTransparencyDialog); |
||||
|
||||
GtkWidget* scaleAlpha = get("scaleAlpha"); |
||||
|
||||
gtk_range_set_value(GTK_RANGE(scaleAlpha), alpha / 255.0 * 100); |
||||
|
||||
setPreviewImage(alpha); |
||||
|
||||
g_signal_connect(scaleAlpha, "change-value", G_CALLBACK( |
||||
+[](GtkRange* range, GtkScrollType scroll, gdouble value, FillTransparencyDialog* self) |
||||
{ |
||||
XOJ_CHECK_TYPE_OBJ(self, FillTransparencyDialog); |
||||
self->setPreviewImage((int)(value / 100 * 255)); |
||||
}), this); |
||||
} |
||||
|
||||
FillTransparencyDialog::~FillTransparencyDialog() |
||||
{ |
||||
XOJ_RELEASE_TYPE(FillTransparencyDialog); |
||||
} |
||||
|
||||
const int PREVIEW_WIDTH = 70; |
||||
const int PREVIEW_HEIGTH = 50; |
||||
const int PREVIEW_BORDER = 10; |
||||
|
||||
void FillTransparencyDialog::setPreviewImage(int alpha) |
||||
{ |
||||
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, PREVIEW_WIDTH, PREVIEW_HEIGTH); |
||||
cairo_t* cr = cairo_create(surface); |
||||
|
||||
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
||||
cairo_set_source_rgb(cr, 255, 255, 255); |
||||
cairo_rectangle(cr, 0, 0, PREVIEW_WIDTH, PREVIEW_WIDTH); |
||||
cairo_fill(cr); |
||||
|
||||
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
||||
cairo_set_source_rgba(cr, 0, 0x80 / 255.0, 0, alpha / 255.0); |
||||
cairo_rectangle(cr, PREVIEW_BORDER, PREVIEW_BORDER, PREVIEW_WIDTH - PREVIEW_BORDER * 2, PREVIEW_HEIGTH - PREVIEW_BORDER * 2); |
||||
cairo_fill(cr); |
||||
|
||||
cairo_set_line_width(cr, 5); |
||||
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
||||
cairo_set_source_rgb(cr, 0, 0x80 / 255.0, 0); |
||||
cairo_rectangle(cr, PREVIEW_BORDER, PREVIEW_BORDER, PREVIEW_WIDTH - PREVIEW_BORDER * 2, PREVIEW_HEIGTH - PREVIEW_BORDER * 2); |
||||
cairo_stroke(cr); |
||||
|
||||
cairo_destroy(cr); |
||||
|
||||
GtkWidget* preview = get("imgPreview"); |
||||
gtk_image_set_from_surface(GTK_IMAGE(preview), surface); |
||||
} |
||||
|
||||
int FillTransparencyDialog::getResultAlpha() |
||||
{ |
||||
XOJ_CHECK_TYPE(FillTransparencyDialog); |
||||
|
||||
return resultAlpha; |
||||
} |
||||
|
||||
void FillTransparencyDialog::show(GtkWindow* parent) |
||||
{ |
||||
XOJ_CHECK_TYPE(FillTransparencyDialog); |
||||
|
||||
gtk_window_set_transient_for(GTK_WINDOW(this->window), parent); |
||||
int result = gtk_dialog_run(GTK_DIALOG(this->window)); |
||||
gtk_widget_hide(this->window); |
||||
|
||||
// OK Button
|
||||
if (result == 1) |
||||
{ |
||||
|
||||
GtkWidget* scaleAlpha = get("scaleAlpha"); |
||||
resultAlpha = gtk_range_get_value(GTK_RANGE(scaleAlpha)); |
||||
} |
||||
else |
||||
{ |
||||
resultAlpha = -1; |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* The about dialog |
||||
* |
||||
* @author Xournal++ Team |
||||
* https://github.com/xournalpp/xournalpp
|
||||
* |
||||
* @license GNU GPLv2 or later |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include "gui/GladeGui.h" |
||||
|
||||
class FillTransparencyDialog : public GladeGui |
||||
{ |
||||
public: |
||||
FillTransparencyDialog(GladeSearchpath* gladeSearchPath, int alpha); |
||||
virtual ~FillTransparencyDialog(); |
||||
|
||||
public: |
||||
virtual void show(GtkWindow* parent); |
||||
|
||||
int getResultAlpha(); |
||||
|
||||
private: |
||||
void setPreviewImage(int alpha); |
||||
|
||||
private: |
||||
XOJ_TYPE_ATTRIB; |
||||
|
||||
int resultAlpha; |
||||
}; |
||||
@ -0,0 +1,139 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- Generated with glade 3.18.3 --> |
||||
<interface> |
||||
<requires lib="gtk+" version="3.0"/> |
||||
<object class="GtkAdjustment" id="adjustment1"> |
||||
<property name="lower">1</property> |
||||
<property name="upper">100</property> |
||||
<property name="step_increment">1</property> |
||||
<property name="page_increment">10</property> |
||||
</object> |
||||
<object class="GtkDialog" id="fillTransparencyDialog"> |
||||
<property name="can_focus">False</property> |
||||
<property name="title" translatable="yes">Transparency settings</property> |
||||
<property name="window_position">center</property> |
||||
<property name="icon">pixmaps/xournalpp.svg</property> |
||||
<property name="type_hint">dialog</property> |
||||
<child internal-child="vbox"> |
||||
<object class="GtkBox" id="dialog-vbox2"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="orientation">vertical</property> |
||||
<property name="spacing">4</property> |
||||
<child internal-child="action_area"> |
||||
<object class="GtkButtonBox" id="dialog-action_area2"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="layout_style">end</property> |
||||
<child> |
||||
<object class="GtkButton" id="btCancel"> |
||||
<property name="label">gtk-cancel</property> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">True</property> |
||||
<property name="can_default">True</property> |
||||
<property name="receives_default">False</property> |
||||
<property name="use_stock">True</property> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="fill">False</property> |
||||
<property name="position">2</property> |
||||
</packing> |
||||
</child> |
||||
<child> |
||||
<object class="GtkButton" id="btOk"> |
||||
<property name="label">gtk-ok</property> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">True</property> |
||||
<property name="receives_default">True</property> |
||||
<property name="use_stock">True</property> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="fill">False</property> |
||||
<property name="position">3</property> |
||||
</packing> |
||||
</child> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="fill">False</property> |
||||
<property name="pack_type">end</property> |
||||
<property name="position">0</property> |
||||
</packing> |
||||
</child> |
||||
<child> |
||||
<object class="GtkBox" id="vbox1"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="orientation">vertical</property> |
||||
<property name="spacing">10</property> |
||||
<child> |
||||
<object class="GtkLabel" id="label1"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="label" translatable="yes"><b>Fill transparency settings</b> |
||||
Select transparency for fill color</property> |
||||
<property name="use_markup">True</property> |
||||
<property name="xalign">0</property> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="fill">True</property> |
||||
<property name="position">0</property> |
||||
</packing> |
||||
</child> |
||||
<child> |
||||
<object class="GtkBox" id="box1"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="spacing">10</property> |
||||
<child> |
||||
<object class="GtkImage" id="imgPreview"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="stock">gtk-missing-image</property> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="fill">True</property> |
||||
<property name="position">0</property> |
||||
</packing> |
||||
</child> |
||||
<child> |
||||
<object class="GtkScale" id="scaleAlpha"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">True</property> |
||||
<property name="adjustment">adjustment1</property> |
||||
<property name="show_fill_level">True</property> |
||||
<property name="fill_level">100</property> |
||||
<property name="round_digits">0</property> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">True</property> |
||||
<property name="fill">True</property> |
||||
<property name="position">1</property> |
||||
</packing> |
||||
</child> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">True</property> |
||||
<property name="fill">True</property> |
||||
<property name="position">1</property> |
||||
</packing> |
||||
</child> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">True</property> |
||||
<property name="fill">True</property> |
||||
<property name="position">2</property> |
||||
</packing> |
||||
</child> |
||||
</object> |
||||
</child> |
||||
<action-widgets> |
||||
<action-widget response="2">btCancel</action-widget> |
||||
<action-widget response="1">btOk</action-widget> |
||||
</action-widgets> |
||||
</object> |
||||
</interface> |
||||
Loading…
Reference in new issue