Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/overlayer.py
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius/overlayer.py')
-rw-r--r--tutorius/overlayer.py80
1 files changed, 75 insertions, 5 deletions
diff --git a/tutorius/overlayer.py b/tutorius/overlayer.py
index 9e4adbf..fcb6974 100644
--- a/tutorius/overlayer.py
+++ b/tutorius/overlayer.py
@@ -25,6 +25,7 @@ import pangocairo
from math import pi
from sugar import profile
+from .constants import *
# for easy profile access from cairo
color = profile.get_color().get_stroke_color()
@@ -70,6 +71,13 @@ class Overlayer(gtk.Layout):
self.__render_handle = None
+ # Allow drag and drop
+ self.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
+ gtk.DEST_DEFAULT_HIGHLIGHT |
+ gtk.DEST_DEFAULT_DROP,
+ [ ( WIDGET_ID, 0, TARGET_TYPE_WIDGET ) ],
+ gtk.gdk.ACTION_MOVE)
+
def put(self, child, x, y):
"""
Adds a child widget to be overlayed. This can be, overlay widgets or
@@ -149,8 +157,63 @@ class Overlayer(gtk.Layout):
# Since widget is laid out in a Layout box, the Layout will honor the
# requested size. Using size_allocate could make a nasty nested loop in
# some cases.
- if self._overlayed:
- self._overlayed.set_size_request(allocation.width, allocation.height)
+ self._overlayed.set_size_request(allocation.width, allocation.height)
+
+
+class FrameOverlayer(gtk.Window):
+ def __init__(self):
+ gtk.Window.__init__(self)
+ self._vbox = gtk.VBox()
+ self._overlayer = Overlayer(self._vbox)
+ self.add(self._overlayer)
+ self._vbox.show()
+ self._overlayer.show()
+ self.show_all()
+
+ self._overlayer.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
+ gtk.DEST_DEFAULT_HIGHLIGHT |
+ gtk.DEST_DEFAULT_DROP,
+ [ ( WIDGET_ID, 0, TARGET_TYPE_WIDGET ) ],
+ gtk.gdk.ACTION_MOVE)
+
+ self._widgets = []
+
+
+ def show(self):
+ self.set_decorated(False) # Remove borders and title bar
+ self.set_keep_above(True) # Always on top
+ self.fullscreen() # Cover the entire screen
+
+ gtk.Window.show(self)
+ self.expose = self.connect("expose-event", self.apply_mask)
+
+ def apply_mask(self,*args):
+ self.px = gtk.gdk.Pixmap(None, 1173, 800, 1) # source, size, colors
+ self.cr = self.px.cairo_create()
+ self.cr.set_operator(cairo.OPERATOR_CLEAR)
+ self.cr.paint()
+ self.cr.set_source_rgb(1,1,1)
+ self.cr.set_operator(cairo.OPERATOR_SOURCE)
+
+ for widget in self._widgets:
+ widget.draw_with_context(self.cr)
+ self.shape_combine_mask(self.px, 0, 0) # pixmap, offset
+
+ def put(self,widget, offset_x, offset_y):
+ self._widgets.append(widget)
+ widget.show()
+ self._overlayer.put(widget, offset_x, offset_y)
+ self._overlayer.queue_draw()
+
+ def move(self, widget, x, y):
+ self._overlayer.move(widget,x,y)
+
+ def remove(self, widget):
+ self._widgets.remove(widget)
+ self._overlayer.remove(widget)
+
+ def queue_draw(self):
+ self._overlayer.queue_draw()
class TextBubble(gtk.Widget):
"""
@@ -424,13 +487,20 @@ class TextBubbleWImg(gtk.Widget):
#ct = cairo.Context(surface)
# paint image
+ img_upper_left_x = int((self.allocation.width-self.imgsize[0])/2)
+ img_upper_left_y = int(self.line_width+self.padding/2)
context.set_source_pixbuf(
self.pixbuf,
- int((self.allocation.width-self.imgsize[0])/2),
- int(self.line_width+self.padding/2))
+ img_upper_left_x,
+ img_upper_left_y)
+ # Set a rectangle
+ context.rectangle(img_upper_left_x, img_upper_left_y,
+ self.imgsize[0], self.imgsize[1])
+ context.clip()
context.paint()
-
+ context.reset_clip()
+
# work done. Be kind to next cairo widgets and reset matrix.
context.identity_matrix()