Skip to content

Commit

Permalink
Add a shadow to the text
Browse files Browse the repository at this point in the history
issues #32 and #21
  • Loading branch information
maoschanz committed Jun 30, 2019
1 parent 5d138c8 commit 54870af
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ def update_windows_menu_section(self, *args):
for window in self.get_windows():
if not isinstance(window, Gtk.ApplicationWindow):
continue
detailed_name = 'app.active-window(uint32 '+str(window.get_id())+')'
section.append(window.get_title(), detailed_name)
elif window.get_title() is None:
continue
else:
detailed_name = 'app.active-window(uint32 ' + \
str(window.get_id()) + ')'
section.append(window.get_title(), detailed_name)

def open_window_with_content(self, gfile, get_cb):
"""Open a new window with an optional Gio.File as an argument. If get_cb
Expand Down
24 changes: 20 additions & 4 deletions src/tools/classic_tools/tool_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, window, **kwargs):
self.should_cancel = False

self.add_tool_action_boolean('text_opaque_bg', False)
self.add_tool_action_boolean('text_shadow', False)

builder = Gtk.Builder().new_from_resource( \
'/com/github/maoschanz/drawing/tools/ui/tool_text.ui')
Expand All @@ -36,6 +37,7 @@ def __init__(self, window, **kwargs):
self.options_box = builder.get_object('options-widget')
self.font_btn = builder.get_object('font-chooser-widget')
self.backg_switch = builder.get_object('backg-switch')
self.shadow_switch = builder.get_object('shadow-switch')

self.font_btn.set_font('Sans 36')
self.font_fam = self.font_btn.get_font()
Expand Down Expand Up @@ -156,6 +158,7 @@ def build_operation(self):
'x': self.x_begin,
'y': self.y_begin,
'background': self.backg_switch.get_state(),
'shadow': self.shadow_switch.get_state(),
'text': self.text_string
}
return operation
Expand All @@ -177,7 +180,7 @@ def do_tool_operation(self, operation):
i = 0

main_color = operation['rgba_main']
secondary_color = operation['rgba_secd']
snd_color = operation['rgba_secd']
text_x = operation['x']
text_y = operation['y']

Expand All @@ -189,13 +192,26 @@ def do_tool_operation(self, operation):
cairo_context.rel_line_to(0, (-1)*font_size)
cairo_context.line_to(text_x, text_y + (i-0.8)*font_size)
cairo_context.line_to(text_x, text_y + (i+0.2)*font_size)
cairo_context.set_source_rgba(secondary_color.red, \
secondary_color.green, secondary_color.blue, secondary_color.alpha)
cairo_context.set_source_rgba(snd_color.red, snd_color.green, \
snd_color.blue, snd_color.alpha)
cairo_context.fill()
cairo_context.stroke()
actual_text_y = text_y + i*font_size
if operation['shadow']:
cairo_context.set_source_rgba(snd_color.red, snd_color.green, \
snd_color.blue, snd_color.alpha)
if font_size < 32:
cairo_context.move_to(text_x+1, actual_text_y+1)
cairo_context.show_text( a_line )
else:
cairo_context.move_to(text_x+2, actual_text_y+2)
cairo_context.show_text( a_line )
cairo_context.move_to(text_x-1, actual_text_y-1)
cairo_context.show_text( a_line )
####################################################################
cairo_context.set_source_rgba(main_color.red, main_color.green, \
main_color.blue, main_color.alpha)
cairo_context.move_to(text_x, text_y + i*font_size)
cairo_context.move_to(text_x, actual_text_y)
cairo_context.show_text( a_line )
i = i + 1
self.non_destructive_show_modif()
Expand Down
35 changes: 35 additions & 0 deletions src/tools/ui/tool_text.ui
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@
<property name="margin">10</property>
<property name="spacing">10</property>
<property name="orientation">vertical</property>

<child>
<object class="GtkFontChooserWidget" id="font-chooser-widget">
<property name="visible">True</property>
<property name="show-preview-entry">False</property>
</object>
</child>

<child>
<object class="GtkBox">
<property name="visible">True</property>
Expand All @@ -96,6 +98,33 @@
</child>
</object>
</child>

<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="spacing">10</property>
<property name="orientation">horizontal</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Use a shadow</property>
</object>
<packing>
<property name="pack-type">start</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="shadow-switch">
<property name="visible">True</property>
<property name="action-name">win.text_shadow</property>
</object>
<packing>
<property name="pack-type">end</property>
</packing>
</child>
</object>
</child>

</object>
</child>
</object>
Expand All @@ -106,10 +135,16 @@
<attribute name="label" translatable="yes">Font</attribute>
<attribute name="action">win.options_menu</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">Opaque background</attribute>
<attribute name="action">win.text_opaque_bg</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Use a shadow</attribute>
<attribute name="action">win.text_shadow</attribute>
</item>
</section>
</menu>
</interface>

0 comments on commit 54870af

Please sign in to comment.