[gnome-2048] Scale text with window resizing - v2
- From: Juan R. Garcia Blanco <juanrgar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-2048] Scale text with window resizing - v2
- Date: Fri, 20 Feb 2015 22:48:20 +0000 (UTC)
commit b2286a482cad378ae6b9277c220041f0b4c5d643
Author: Yanko Kaneti <yaneti declera com>
Date: Sun Feb 15 21:00:44 2015 +0200
Scale text with window resizing - v2
Drop ClutterText and draw the number directly using pango+cairo
src/view.vala | 40 +++++++++++++++++++++++-----------------
1 files changed, 23 insertions(+), 17 deletions(-)
---
diff --git a/src/view.vala b/src/view.vala
index aef124e..b97fced 100644
--- a/src/view.vala
+++ b/src/view.vala
@@ -73,7 +73,8 @@ public class RoundedRectangle : GLib.Object
public void idle_resize ()
{
- _canvas.invalidate ();
+ if (!_canvas.set_size ((int)Math.ceilf (_actor.width), (int)Math.ceilf (_actor.height)))
+ _canvas.invalidate ();
}
protected virtual bool _draw (Cairo.Context ctx, int width, int height)
@@ -104,36 +105,41 @@ public class RoundedRectangle : GLib.Object
public class TileView : RoundedRectangle
{
- private Clutter.Text _text;
-
public TileView (float x, float y, float width, float height, uint val)
{
base (x, y, width, height, null);
- _text = new Clutter.Text ();
- _text.set_font_name ("Sans 22");
- _text.set_color (Clutter.Color.from_string ("#ffffff"));
- _actor.add_child (_text);
-
_value = val;
_color = _pick_color ();
-
- _text.text = val.to_string ();
- _text.x = _actor.width/2.0f - _text.width/2.0f;
- _text.y = _actor.height/2.0f - _text.height/2.0f;
- _text.show ();
}
public uint value {
get; set; default = 2;
}
- public new void idle_resize ()
+
+ protected override bool _draw (Cairo.Context ctx, int width, int height)
{
- base.idle_resize ();
+ Pango.Rectangle logical_rect;
+ Pango.Layout layout;
+ Pango.FontDescription font_desc;
+
+ base._draw (ctx, width, height);
- _text.x = _actor.width/2.0f - _text.width/2.0f;
- _text.y = _actor.height/2.0f - _text.height/2.0f;
+ ctx.set_source_rgb (255, 255, 255);
+
+ layout = Pango.cairo_create_layout (ctx);
+ font_desc = Pango.FontDescription.from_string ("Sans Bold %dpx".printf (height / 4));
+ layout.set_font_description (font_desc);
+
+ layout.set_text (value.to_string(), -1);
+
+ layout.get_extents (null, out logical_rect);
+ ctx.move_to ((width / 2) - (logical_rect.width / 2 / Pango.SCALE),
+ (height / 2) - (logical_rect.height / 2 / Pango.SCALE));
+ Pango.cairo_show_layout (ctx, layout);
+
+ return false;
}
private Clutter.Color _pick_color ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]