Commit f3ce01e4 authored by Andrey Kutejko's avatar Andrey Kutejko

Make cursors part of Asset interface

parent 6eebf733
Pipeline #219270 passed with stages
in 7 minutes and 38 seconds
......@@ -53,8 +53,6 @@ class RobotsApplication : Gtk.Application {
set_accels_for_action ("app.help", { "F1" });
set_accels_for_action ("app.quit", { "<Primary>q" });
make_cursors ();
try {
assets = new DirectoryAssets.from_directory (DATA_DIRECTORY);
game_configs = new GameConfigs.load ();
......
......@@ -22,6 +22,7 @@ public interface Assets : Object {
public abstract Bubble aieee_bubble { get; }
public abstract Bubble yahoo_bubble { get; }
public abstract Bubble splat_bubble { get; }
public abstract Array<Gdk.Cursor> cursors { get; }
}
public class DirectoryAssets : Object, Assets {
......@@ -37,15 +38,22 @@ public class DirectoryAssets : Object, Assets {
private Bubble _splat_bubble;
public override Bubble splat_bubble { get { return _splat_bubble; } }
private Array<Gdk.Cursor> _cursors;
public override Array<Gdk.Cursor> cursors { get { return _cursors; } }
public DirectoryAssets.from_directory (string directory) throws Error {
_themes = Themes.from_directory (
Path.build_filename (directory, "themes"));
_yahoo_bubble = new Bubble.from_file (
Path.build_filename (directory, "pixmaps", "yahoo.png"));
_aieee_bubble = new Bubble.from_file (
Path.build_filename (directory, "pixmaps", "aieee.png"));
_splat_bubble = new Bubble.from_file (
Path.build_filename (directory, "pixmaps", "splat.png"));
var display = Gdk.Display.get_default ();
_cursors = make_cursors_for_display (display);
}
}
......@@ -19,38 +19,54 @@
using Gdk;
Cursor make_cursor (Display display, string[] xpm, int hsx, int hsy) {
var pixbuf = new Pixbuf.from_xpm_data (xpm);
return new Cursor.from_pixbuf (display, pixbuf, hsx, hsy);
}
Cursor default_cursor;
Cursor cursors[9];
public void make_cursors () {
var display = Display.get_default ();
default_cursor = new Cursor.for_display (display, CursorType.LEFT_PTR);
cursors[0] = make_cursor (display, cursor_up_left, 3, 3);
cursors[1] = make_cursor (display, cursor_up, 10, 3);
cursors[2] = make_cursor (display, cursor_up_right, 17, 3);
cursors[3] = make_cursor (display, cursor_left, 3, 10);
cursors[4] = make_cursor (display, cursor_hold, 10, 10);
cursors[5] = make_cursor (display, cursor_right, 17, 10);
cursors[6] = make_cursor (display, cursor_down_left, 3, 17);
cursors[7] = make_cursor (display, cursor_down, 10, 17);
cursors[8] = make_cursor (display, cursor_down_right, 17, 17);
public Array<Cursor> make_cursors_for_display (Display display) {
Array<Cursor> cursors = new Array<Cursor> ();
cursors.append_val (make_cursor (display, cursor_up_left, 3, 3));
cursors.append_val (make_cursor (display, cursor_up, 10, 3));
cursors.append_val (make_cursor (display, cursor_up_right, 17, 3));
cursors.append_val (make_cursor (display, cursor_left, 3, 10));
cursors.append_val (make_cursor (display, cursor_hold, 10, 10));
cursors.append_val (make_cursor (display, cursor_right, 17, 10));
cursors.append_val (make_cursor (display, cursor_down_left, 3, 17));
cursors.append_val (make_cursor (display, cursor_down, 10, 17));
cursors.append_val (make_cursor (display, cursor_down_right, 17, 17));
return cursors;
}
public void set_cursor_default (Window window) {
window.set_cursor (default_cursor);
private Cursor make_cursor (Display display, string[] xpm, int hsx, int hsy) {
var pixbuf = new Pixbuf.from_xpm_data (xpm);
return new Cursor.from_pixbuf (display, pixbuf, hsx, hsy);
}
public void set_cursor_by_direction (Window window, int dx, int dy) {
int index = 3 * dy + dx + 4;
window.set_cursor (cursors[index]);
}
const string cursor_up_left[] = {
/* width height num_colors chars_per_pixel */
" 20 20 3 2",
/* colors */
".. c none",
"## c #ffffff",
"** c #000000",
/* pixels */
"........................................",
"..######################................",
"..##****************##..................",
"..##**************##....................",
"..##************##......................",
"..##**************##....................",
"..##****************##..................",
"..##******************##................",
"..##****##**************##..............",
"..##**##..##**************##............",
"..####......##**********##..............",
"..##..........##******##................",
"................##**##..................",
"..................##....................",
"........................................",
"........................................",
"........................................",
"........................................",
"........................................",
"........................................"
};
const string cursor_up[] = {
/* width height num_colors chars_per_pixel */
......@@ -112,7 +128,7 @@ const string cursor_up_right[] = {
"........................................"
};
const string cursor_right[] = {
const string cursor_left[] = {
/* width height num_colors chars_per_pixel */
" 20 20 3 2",
/* colors */
......@@ -122,27 +138,27 @@ const string cursor_right[] = {
/* pixels */
"........................................",
"........................................",
"......................##................",
"......................####..............",
"......................##**##............",
"......................##****##..........",
"......################********##........",
"................##......................",
"..............####......................",
"............##**##......................",
"..........##****##......................",
"........##********################......",
"......##************************##......",
"......##**************************##....",
"......##****************************##..",
"......##**************************##....",
"....##**************************##......",
"..##****************************##......",
"....##**************************##......",
"......##************************##......",
"......################********##........",
"......................##****##..........",
"......................##**##............",
"......................####..............",
"......................##................",
"........##********################......",
"..........##****##......................",
"............##**##......................",
"..............####......................",
"................##......................",
"........................................",
"........................................",
"........................................"
};
const string cursor_down_right[] = {
const string cursor_hold[] = {
/* width height num_colors chars_per_pixel */
" 20 20 3 2",
/* colors */
......@@ -154,25 +170,25 @@ const string cursor_down_right[] = {
"........................................",
"........................................",
"........................................",
"..............##########................",
"..........####**********####............",
"..........##**************##............",
"........##******************##..........",
"........##******************##..........",
"........##******************##..........",
"........##******************##..........",
"........##******************##..........",
"..........##**************##............",
"..........####**********####............",
"..............##########................",
"........................................",
"........................................",
"........................................",
"........................................",
"....................##..................",
"..................##**##................",
"................##******##..........##..",
"..............##**********##......####..",
"............##**************##..##**##..",
"..............##**************##****##..",
"................##******************##..",
"..................##****************##..",
"....................##**************##..",
"......................##************##..",
"....................##**************##..",
"..................##****************##..",
"................######################..",
"........................................"
};
const string cursor_down[] = {
const string cursor_right[] = {
/* width height num_colors chars_per_pixel */
" 20 20 3 2",
/* colors */
......@@ -182,23 +198,23 @@ const string cursor_down[] = {
/* pixels */
"........................................",
"........................................",
"......................##................",
"......................####..............",
"......................##**##............",
"......................##****##..........",
"......################********##........",
"......##************************##......",
"......##**************************##....",
"......##****************************##..",
"......##**************************##....",
"......##************************##......",
"......################********##........",
"......................##****##..........",
"......................##**##............",
"......................####..............",
"......................##................",
"........................................",
"........................................",
"..............##############............",
"..............##**********##............",
"..............##**********##............",
"..............##**********##............",
"..............##**********##............",
"..............##**********##............",
"..............##**********##............",
"..............##**********##............",
"......########**************########....",
"........##**********************##......",
"..........##******************##........",
"............##**************##..........",
"..............##**********##............",
"................##******##..............",
"..................##**##................",
"....................##..................",
"........................................"
};
......@@ -232,37 +248,7 @@ const string cursor_down_left[] = {
"........................................"
};
const string cursor_left[] = {
/* width height num_colors chars_per_pixel */
" 20 20 3 2",
/* colors */
".. c none",
"## c #ffffff",
"** c #000000",
/* pixels */
"........................................",
"........................................",
"................##......................",
"..............####......................",
"............##**##......................",
"..........##****##......................",
"........##********################......",
"......##************************##......",
"....##**************************##......",
"..##****************************##......",
"....##**************************##......",
"......##************************##......",
"........##********################......",
"..........##****##......................",
"............##**##......................",
"..............####......................",
"................##......................",
"........................................",
"........................................",
"........................................"
};
const string cursor_up_left[] = {
const string cursor_down[] = {
/* width height num_colors chars_per_pixel */
" 20 20 3 2",
/* colors */
......@@ -271,28 +257,28 @@ const string cursor_up_left[] = {
"** c #000000",
/* pixels */
"........................................",
"..######################................",
"..##****************##..................",
"..##**************##....................",
"..##************##......................",
"..##**************##....................",
"..##****************##..................",
"..##******************##................",
"..##****##**************##..............",
"..##**##..##**************##............",
"..####......##**********##..............",
"..##..........##******##................",
"................##**##..................",
"..................##....................",
"........................................",
"........................................",
"........................................",
"........................................",
"........................................",
"..............##############............",
"..............##**********##............",
"..............##**********##............",
"..............##**********##............",
"..............##**********##............",
"..............##**********##............",
"..............##**********##............",
"..............##**********##............",
"......########**************########....",
"........##**********************##......",
"..........##******************##........",
"............##**************##..........",
"..............##**********##............",
"................##******##..............",
"..................##**##................",
"....................##..................",
"........................................"
};
const string cursor_hold[] = {
const string cursor_down_right[] = {
/* width height num_colors chars_per_pixel */
" 20 20 3 2",
/* colors */
......@@ -304,21 +290,21 @@ const string cursor_hold[] = {
"........................................",
"........................................",
"........................................",
"..............##########................",
"..........####**********####............",
"..........##**************##............",
"........##******************##..........",
"........##******************##..........",
"........##******************##..........",
"........##******************##..........",
"........##******************##..........",
"..........##**************##............",
"..........####**********####............",
"..............##########................",
"........................................",
"........................................",
"........................................",
"........................................",
"....................##..................",
"..................##**##................",
"................##******##..........##..",
"..............##**********##......####..",
"............##**************##..##**##..",
"..............##**************##****##..",
"................##******************##..",
"..................##****************##..",
"....................##**************##..",
"......................##************##..",
"....................##**************##..",
"..................##****************##..",
"................######################..",
"........................................"
};
......@@ -261,11 +261,14 @@ public class GameArea : DrawingArea {
private void move_cb (double x, double y) {
var window = get_window ();
if (game.state != Game.State.PLAYING) {
set_cursor_default (window);
window.set_cursor (null);
} else {
int dx, dy;
get_dir (x, y, out dx, out dy);
set_cursor_by_direction (window, dx, dy);
var cursor_index = 3 * dy + dx + 4;
var cursor = assets.cursors.index(cursor_index);
window.set_cursor (cursor);
}
}
......
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