1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| public class Test : Gtk.Window
{
private double zoom = 1.0;
private double angle = 0.0;
private SDL.Surface bmp;
private GtkSdl gtk_sdl;
construct
{
this.destroy += Gtk.main_quit;
this.maximize ();
Gtk.VBox vbox = new Gtk.VBox (false, 0);
this.add (vbox);
this.gtk_sdl = GtkSdl.get_instance ();
SDL.Key.set_repeat (SDL.DefaultRepeat.DELAY, SDL.DefaultRepeat.INTERVAL);
vbox.pack_start (this.gtk_sdl, true, true, 0);
Gtk.HBox hbox = new Gtk.HBox (false, 0);
vbox.pack_start (hbox, false, true, 0);
Gtk.HScale scale = new Gtk.HScale.with_range (-180.0, 180.0, 1.0);
scale.set_value (0.0);
hbox.pack_start (scale, true, true, 0);
scale.value_changed += (s) => {
this.angle = s.get_value ();
this.gtk_sdl.draw ();
};
Gtk.Button button = new Gtk.Button.from_stock (Gtk.STOCK_ZOOM_IN);
hbox.pack_start (button, false, true, 0);
button.clicked += () => {
this.zoom += 0.1;
this.gtk_sdl.draw ();
};
button = new Gtk.Button.from_stock (Gtk.STOCK_ZOOM_OUT);
hbox.pack_start (button, false, true, 0);
button.clicked += () => {
this.zoom -= 0.1;
this.gtk_sdl.draw ();
};
bmp = SDL.Surface.load_bmp ("./src/gtksdl.bmp");
if (bmp != null)
{
gtk_sdl.draw += (s) => {
s.screen.fill (null, s.screen.format.map_rgb (0, 0, 0));
SDL.Surface tmp = SDLGraphics.RotoZoom.rotozoom (this.bmp, this.angle,
this.zoom, 1);
SDL.Rect dstrect;
dstrect.x = (int16)(s.screen.w - tmp.w) / 2;
dstrect.y = (int16)(s.screen.h - tmp.h) / 2;
tmp.blit_surface (null, s.screen, dstrect);
s.screen.flip ();
};
}
else
{
print ("Unable to load bitmap: %s\n", SDL.get_error ());
}
}
public void run ()
{
this.show_all ();
}
public static int main (string[] args)
{
Gtk.init (ref args);
new Test ().run ();
Gtk.main ();
return 0;
}
} |
Partager