aboutsummaryrefslogtreecommitdiffstats
path: root/lvc
diff options
context:
space:
mode:
Diffstat (limited to 'lvc')
-rw-r--r--lvc/widgets/gtk/drawing.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/lvc/widgets/gtk/drawing.py b/lvc/widgets/gtk/drawing.py
index 5888851..3c481e4 100644
--- a/lvc/widgets/gtk/drawing.py
+++ b/lvc/widgets/gtk/drawing.py
@@ -39,10 +39,12 @@ import wrappermap
from .base import Widget, Bin
from .layoutmanager import LayoutManager
+
def css_to_color(css_string):
parts = (css_string[1:3], css_string[3:5], css_string[5:7])
return tuple((int(value, 16) / 255.0) for value in parts)
+
class ImageSurface:
def __init__(self, image):
format = cairo.FORMAT_RGB24
@@ -83,7 +85,7 @@ class ImageSurface:
cairo_context.restore()
def draw_rect(self, context, dest_x, dest_y, source_x, source_y,
- width, height, fraction=1.0):
+ width, height, fraction=1.0):
self._align_pattern(dest_x-source_x, dest_y-source_y)
cairo_context = context.context
@@ -98,6 +100,7 @@ class ImageSurface:
cairo_context.paint_with_alpha(fraction)
cairo_context.restore()
+
class DrawingStyle(object):
def __init__(self, widget, use_base_color=False, state=None):
if state is None:
@@ -110,6 +113,7 @@ class DrawingStyle(object):
else:
self.bg_color = widget.convert_gtk_color(self.style.bg[state])
+
class DrawingContext(object):
"""DrawingContext. This basically just wraps a Cairo context and adds a
couple convenience methods.
@@ -119,7 +123,7 @@ class DrawingContext(object):
self.window = window
self.context = window.cairo_create()
self.context.rectangle(expose_area.x, expose_area.y,
- expose_area.width, expose_area.height)
+ expose_area.width, expose_area.height)
self.context.clip()
self.width = drawing_area.width
self.height = drawing_area.height
@@ -146,6 +150,7 @@ class DrawingContext(object):
self.context.fill_preserve()
self.context.set_source(old_source)
+
class Gradient(object):
def __init__(self, x1, y1, x2, y2):
self.pattern = cairo.LinearGradient(x1, y1, x2, y2)
@@ -156,6 +161,7 @@ class Gradient(object):
def set_end_color(self, (red, green, blue)):
self.pattern.add_color_stop_rgb(1, red, green, blue)
+
class CustomDrawingMixin(object):
def do_expose_event(self, event):
wrapper = wrappermap.wrapper(self)
@@ -163,12 +169,13 @@ class CustomDrawingMixin(object):
drawing_area = self.allocation
else:
drawing_area = gtk.gdk.Rectangle(0, 0,
- self.allocation.width, self.allocation.height)
+ self.allocation.width,
+ self.allocation.height)
context = DrawingContext(event.window, drawing_area, event.area)
context.style = DrawingStyle(wrapper)
if self.flags() & gtk.CAN_FOCUS:
focus_space = (self.style_get_property('focus-padding') +
- self.style_get_property('focus-line-width'))
+ self.style_get_property('focus-line-width'))
if not wrapper.squish_width:
context.width -= focus_space * 2
translate_x = focus_space
@@ -194,18 +201,20 @@ class CustomDrawingMixin(object):
requesition.height = height
if self.flags() & gtk.CAN_FOCUS:
focus_space = (self.style_get_property('focus-padding') +
- self.style_get_property('focus-line-width'))
+ self.style_get_property('focus-line-width'))
if not wrapper.squish_width:
requesition.width += focus_space * 2
if not wrapper.squish_height:
requesition.height += focus_space * 2
+
class MiroDrawingArea(CustomDrawingMixin, gtk.Widget):
def __init__(self):
gtk.Widget.__init__(self)
CustomDrawingMixin.__init__(self)
self.set_flags(gtk.NO_WINDOW)
+
class BackgroundWidget(CustomDrawingMixin, gtk.Bin):
def do_size_request(self, requesition):
CustomDrawingMixin.do_size_request(self, requesition)
@@ -227,6 +236,7 @@ class BackgroundWidget(CustomDrawingMixin, gtk.Bin):
gobject.type_register(MiroDrawingArea)
gobject.type_register(BackgroundWidget)
+
class Drawable:
def __init__(self):
self.squish_width = self.squish_height = False
@@ -255,12 +265,14 @@ class Drawable:
def is_opaque(self):
return False
+
class DrawingArea(Drawable, Widget):
def __init__(self):
Widget.__init__(self)
Drawable.__init__(self)
self.set_widget(MiroDrawingArea())
+
class Background(Drawable, Bin):
def __init__(self):
Bin.__init__(self)