Commit d61c2811 authored by Arnaud B.'s avatar Arnaud B.

Add a texture.

parent d1b061d5
Pipeline #62032 passed with stages
in 1 minute and 9 seconds
......@@ -5,5 +5,6 @@
<file preprocess="xml-stripblanks" compressed="true" alias="themes.ui">ui/iagno-themes.ui</file>
<file preprocess="xml-stripblanks" compressed="true" alias="iagno-screens.ui">ui/iagno-screens.ui</file>
<file compressed="true">iagno.css</file>
<file>noise.png</file>
</gresource>
</gresources>
File added
......@@ -14,6 +14,7 @@ Green=0.4
Blue=0.6
# Radius=9
Radius=2
TextureAlpha=0.25
[Mark]
Red=0.2
......
......@@ -13,6 +13,7 @@ Red=0.2
Green=0.6
Blue=0.4
Radius=2
TextureAlpha=0.25
[Mark]
Red=0.5
......
......@@ -14,6 +14,7 @@ Green=1.0
Blue=1.0
# Radius=9
Radius=0
TextureAlpha=0.0
[Mark]
Red=0.4
......
......@@ -13,6 +13,7 @@ Red=0.2
Green=0.6
Blue=0.4
Radius=2
TextureAlpha=0.25
[Mark]
Red=0.2
......
......@@ -38,6 +38,9 @@ private class GameView : Gtk.DrawingArea
private double background_blue = 0.4;
private int background_radius = 0;
private double texture_alpha = 0.25;
private bool apply_texture = false;
private double mark_red = 0.2;
private double mark_green = 0.6;
private double mark_blue = 0.4;
......@@ -82,6 +85,10 @@ private class GameView : Gtk.DrawingArea
private Cairo.Pattern? tiles_pattern = null;
private Cairo.Pattern? scoreboard_tiles_pattern = null;
private bool noise_pixbuf_loaded = false;
private Gdk.Pixbuf? noise_pixbuf = null;
private Cairo.Pattern? noise_pattern = null;
/* The images being showed on each location */
private int [,] pixmaps;
......@@ -212,6 +219,9 @@ private class GameView : Gtk.DrawingArea
background_blue = key.get_double ("Background", "Blue");
background_radius = key.get_integer ("Background", "Radius");
texture_alpha = key.get_double ("Background", "TextureAlpha");
apply_texture = (texture_alpha > 0.0) && (texture_alpha <= 1.0);
mark_red = key.get_double ("Mark", "Red");
mark_green = key.get_double ("Mark", "Green");
mark_blue = key.get_double ("Mark", "Blue");
......@@ -271,10 +281,40 @@ private class GameView : Gtk.DrawingArea
if (tiles_pattern == null || render_size != tile_size)
{
render_size = tile_size;
var surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, tile_size * 8, tile_size * 4);
var c = new Cairo.Context (surface);
load_image (c, tile_size * 8, tile_size * 4);
Cairo.Surface surface;
Cairo.Context context;
surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, tile_size * 8,
tile_size * 4);
context = new Cairo.Context (surface);
load_image (context, tile_size * 8, tile_size * 4);
tiles_pattern = new Cairo.Pattern.for_surface (surface);
if (apply_texture)
{
try
{
noise_pixbuf = new Gdk.Pixbuf.from_resource_at_scale ("/org/gnome/Reversi/ui/noise.png",
/* x */ tile_size,
/* y */ tile_size,
/* preserve aspect ratio */ false);
}
catch (Error e) { warning (e.message); }
noise_pixbuf_loaded = noise_pixbuf != null;
if (noise_pixbuf_loaded)
{
surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, tile_size,
tile_size);
context = new Cairo.Context (surface);
Gdk.cairo_set_source_pixbuf (context, (!) noise_pixbuf, 0, 0);
context.paint_with_alpha (texture_alpha);
// or surface = Gdk.cairo_surface_create_from_pixbuf ((!) noise_pixbuf, 0, null); ?
noise_pattern = new Cairo.Pattern.for_surface (surface);
// ((!) noise_pattern).set_extend (Cairo.Extend.REPEAT);
}
}
}
cr.translate (board_x, board_y);
......@@ -298,6 +338,15 @@ private class GameView : Gtk.DrawingArea
/* draw background */
cr.set_source_rgba (background_red, background_green, background_blue, 1.0);
rounded_square (cr, tile_x, tile_y, tile_size, 0, background_radius);
if (apply_texture && noise_pixbuf_loaded)
{
cr.fill_preserve ();
var matrix = Cairo.Matrix.identity ();
matrix.translate (-tile_x, -tile_y);
((!) noise_pattern).set_matrix (matrix);
cr.set_source ((!) noise_pattern);
}
cr.fill ();
if ((highlight_x == x && highlight_y == y)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment