From a4a9062e3efe80627d7a9574351283cb02242b1f Mon Sep 17 00:00:00 2001
From: Guillermo Trinidad <gui.trini@gmail.com>
Date: Sat, 17 Jan 2015 14:22:33 -0200
Subject: [PATCH] scale only if bigger than background
The activity used to always scale the characters to be as big as the background,
not allowing the user to have smaller ones. With this patch,
the character is only scaled if it is biggen than the background size.
SL#1459
Signed-off-by: Guillermo Trinidad <gui.trini@gmail.com>
---
screenbuil.py | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/screenbuil.py b/screenbuil.py
index 29ed2b7..d57826e 100644
a
|
b
|
class Screen(gtk.DrawingArea): |
26 | 26 | def __init__(self): |
27 | 27 | gtk.DrawingArea.__init__(self) |
28 | 28 | self.gc = None # initialized in realize-event handler |
29 | | self.width = 0 # updated in size-allocate handler |
30 | | self.height = 0 # idem |
| 29 | # self.width = 0 # updated in size-allocate handler |
| 30 | # self.height = 0 # idem |
31 | 31 | self.bgpixbuf = None |
32 | 32 | self.fgpixbuf = None |
33 | | self.connect('size-allocate', self.on_size_allocate) |
| 33 | # self.connect('size-allocate', self.on_size_allocate) |
34 | 34 | self.connect('expose-event', self.on_expose_event) |
35 | 35 | self.connect('realize', self.on_realize) |
36 | 36 | |
37 | 37 | def on_realize(self, widget): |
38 | 38 | self.gc = widget.window.new_gc() |
39 | 39 | |
40 | | def on_size_allocate(self, widget, allocation): |
41 | | self.height = self.width = min(allocation.width, allocation.height) |
| 40 | # def on_size_allocate(self, widget, allocation): |
| 41 | # self.height = self.width = min(allocation.width, allocation.height) |
42 | 42 | |
43 | 43 | def on_expose_event(self, widget, event): |
44 | | # This is where the drawing takes place |
| 44 | # This is where the drawing takes placie |
| 45 | allocation = self.get_allocation() |
| 46 | |
| 47 | value = min(allocation.width, allocation.height) |
| 48 | |
45 | 49 | if self.bgpixbuf: |
46 | 50 | pixbuf = self.bgpixbuf |
47 | | if pixbuf.get_width != self.width: |
48 | | pixbuf = theme.scale(pixbuf, self.width) |
| 51 | if pixbuf.get_width != value: |
| 52 | pixbuf = theme.scale(pixbuf, value) |
49 | 53 | widget.window.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, -1, -1, 0, 0) |
50 | | |
51 | 54 | if self.fgpixbuf: |
52 | 55 | pixbuf = self.fgpixbuf |
53 | | if pixbuf.get_width != self.width: |
54 | | pixbuf = theme.scale(pixbuf, self.width) |
55 | | widget.window.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, -1, -1, 0, 0) |
56 | | |
| 56 | if pixbuf.get_width() > value: |
| 57 | pixbuf = theme.scale(pixbuf, value) |
| 58 | width = height = pixbuf.get_width() |
| 59 | x = (value-width)/2 |
| 60 | y = x |
| 61 | widget.window.draw_pixbuf(self.gc, pixbuf, 0, 0, x, y, -1, -1, 0, 0) |
| 62 | |
57 | 63 | def draw(self): |
58 | 64 | self.queue_draw() |