2000-06-11 18:18:28 +00:00
|
|
|
|
/* GdkPixbuf library - Scaling and compositing demo
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 1999 The Free Software Foundation
|
|
|
|
|
*
|
|
|
|
|
* Authors: Federico Mena-Quintero <federico@gimp.org>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
2000-06-11 18:18:28 +00:00
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Lesser General Public License for more details.
|
2000-06-11 18:18:28 +00:00
|
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2000-06-11 18:18:28 +00:00
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2000-06-11 18:18:28 +00:00
|
|
|
|
#include <stdlib.h>
|
2000-06-22 00:05:44 +00:00
|
|
|
|
#include <gtk/gtk.h>
|
2000-06-11 18:18:28 +00:00
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define FRAME_DELAY 50
|
|
|
|
|
|
|
|
|
|
#define BACKGROUND_NAME "background.jpg"
|
|
|
|
|
|
|
|
|
|
static const char *image_names[] = {
|
|
|
|
|
"apple-red.png",
|
|
|
|
|
"gnome-applets.png",
|
|
|
|
|
"gnome-calendar.png",
|
|
|
|
|
"gnome-foot.png",
|
|
|
|
|
"gnome-gmush.png",
|
|
|
|
|
"gnome-gimp.png",
|
|
|
|
|
"gnome-gsame.png",
|
|
|
|
|
"gnu-keys.png"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define N_IMAGES (sizeof (image_names) / sizeof (image_names[0]))
|
|
|
|
|
|
|
|
|
|
/* Current frame */
|
|
|
|
|
static GdkPixbuf *frame;
|
|
|
|
|
|
|
|
|
|
/* Background image */
|
|
|
|
|
static GdkPixbuf *background;
|
2001-04-18 18:09:18 +00:00
|
|
|
|
static int back_width, back_height;
|
2000-06-11 18:18:28 +00:00
|
|
|
|
|
|
|
|
|
/* Images */
|
|
|
|
|
static GdkPixbuf *images[N_IMAGES];
|
|
|
|
|
|
|
|
|
|
/* Widgets */
|
2001-04-18 18:09:18 +00:00
|
|
|
|
static GtkWidget *da;
|
2000-06-11 18:18:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Loads the images for the demo and returns whether the operation succeeded */
|
|
|
|
|
static gboolean
|
|
|
|
|
load_pixbufs (void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2000-10-18 18:42:54 +00:00
|
|
|
|
/* We pass NULL for the error return location, we don't care
|
|
|
|
|
* about the error message.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
background = gdk_pixbuf_new_from_file (BACKGROUND_NAME, NULL);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
if (!background)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
back_width = gdk_pixbuf_get_width (background);
|
|
|
|
|
back_height = gdk_pixbuf_get_height (background);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < N_IMAGES; i++) {
|
2000-10-18 18:42:54 +00:00
|
|
|
|
images[i] = gdk_pixbuf_new_from_file (image_names[i], NULL);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
if (!images[i])
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Expose callback for the drawing area */
|
|
|
|
|
static gint
|
|
|
|
|
expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
|
|
|
|
|
{
|
2010-07-13 15:17:19 +00:00
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
|
|
cr = gdk_cairo_create (event->window);
|
|
|
|
|
gdk_cairo_set_source_pixbuf (cr, frame, 0, 0);
|
|
|
|
|
gdk_cairo_rectangle (cr, &event->area);
|
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define CYCLE_LEN 60
|
|
|
|
|
|
|
|
|
|
static int frame_num;
|
|
|
|
|
|
|
|
|
|
/* Timeout handler to regenerate the frame */
|
|
|
|
|
static gint
|
|
|
|
|
timeout (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
double f;
|
|
|
|
|
int i;
|
|
|
|
|
double xmid, ymid;
|
|
|
|
|
double radius;
|
|
|
|
|
|
|
|
|
|
gdk_pixbuf_copy_area (background, 0, 0, back_width, back_height,
|
|
|
|
|
frame, 0, 0);
|
|
|
|
|
|
|
|
|
|
f = (double) (frame_num % CYCLE_LEN) / CYCLE_LEN;
|
|
|
|
|
|
|
|
|
|
xmid = back_width / 2.0;
|
|
|
|
|
ymid = back_height / 2.0;
|
|
|
|
|
|
|
|
|
|
radius = MIN (xmid, ymid) / 2.0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < N_IMAGES; i++) {
|
|
|
|
|
double ang;
|
|
|
|
|
int xpos, ypos;
|
|
|
|
|
int iw, ih;
|
|
|
|
|
double r;
|
|
|
|
|
GdkRectangle r1, r2, dest;
|
|
|
|
|
double k;
|
|
|
|
|
|
2001-11-25 23:36:29 +00:00
|
|
|
|
ang = 2.0 * G_PI * (double) i / N_IMAGES - f * 2.0 * G_PI;
|
2000-06-11 18:18:28 +00:00
|
|
|
|
|
|
|
|
|
iw = gdk_pixbuf_get_width (images[i]);
|
|
|
|
|
ih = gdk_pixbuf_get_height (images[i]);
|
|
|
|
|
|
2001-11-25 23:36:29 +00:00
|
|
|
|
r = radius + (radius / 3.0) * sin (f * 2.0 * G_PI);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
|
|
|
|
|
xpos = floor (xmid + r * cos (ang) - iw / 2.0 + 0.5);
|
|
|
|
|
ypos = floor (ymid + r * sin (ang) - ih / 2.0 + 0.5);
|
|
|
|
|
|
2001-11-25 23:36:29 +00:00
|
|
|
|
k = (i & 1) ? sin (f * 2.0 * G_PI) : cos (f * 2.0 * G_PI);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
k = 2.0 * k * k;
|
|
|
|
|
k = MAX (0.25, k);
|
|
|
|
|
|
|
|
|
|
r1.x = xpos;
|
|
|
|
|
r1.y = ypos;
|
|
|
|
|
r1.width = iw * k;
|
|
|
|
|
r1.height = ih * k;
|
|
|
|
|
|
|
|
|
|
r2.x = 0;
|
|
|
|
|
r2.y = 0;
|
|
|
|
|
r2.width = back_width;
|
|
|
|
|
r2.height = back_height;
|
|
|
|
|
|
|
|
|
|
if (gdk_rectangle_intersect (&r1, &r2, &dest))
|
|
|
|
|
gdk_pixbuf_composite (images[i],
|
|
|
|
|
frame,
|
|
|
|
|
dest.x, dest.y,
|
|
|
|
|
dest.width, dest.height,
|
|
|
|
|
xpos, ypos,
|
|
|
|
|
k, k,
|
|
|
|
|
GDK_INTERP_NEAREST,
|
|
|
|
|
((i & 1)
|
2001-11-25 23:36:29 +00:00
|
|
|
|
? MAX (127, fabs (255 * sin (f * 2.0 * G_PI)))
|
|
|
|
|
: MAX (127, fabs (255 * cos (f * 2.0 * G_PI)))));
|
2000-06-11 18:18:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
remove validation idle
2001-02-08 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (gtk_text_view_destroy_layout): remove
validation idle
* demos/gtk-demo/main.c (create_tree): adjust to changes in text
cell renderer
* demos/pixbuf-demo.c (timeout): remove deprecated
gtk_widget_draw
* demos/testpixbuf-save.c (main): remove deprecated
gtk_drawing_area_size
* gtk/gtktreeview.c (gtk_tree_view_size_allocate): allocate
buttons even if the model isn't setup. gtk_tree_view_check_dirty()
at the start of the allocation.
(gtk_tree_view_check_dirty): handle column->button == NULL, handle
unsetup or NULL model.
* gtk/gtkstyle.c (gtk_default_draw_flat_box): drawing for the
even/odd/sorted cells in the tree view.
* gtk/gtktreeselection.c (gtk_tree_selection_real_unselect_all):
bugfixes
* gtk/gtktreeview.c: assorted bugfixy stuff. Draw the row
backgrounds with draw_flat_box using different detail for even/odd
rows.
* gtk/gtkrbtree.c, gtkrbtree.h: Keep track of the parity of each
row, so we can draw the alternating colors thing
* gtk/gtktexttag.c (gtk_text_tag_set_property): if we change a
property from a synonym property, notify for the synonym.
Also, nuke the background_gdk_set and foreground_gdk_set synonyms
(gtk_text_tag_get_property): Always return the font, even if
all its fields aren't set
* gtk/gtkcellrenderertext.h (struct _GtkCellRendererText): don't
store the attr list; it leaves us with no way to change attributes
in _render according to the render flags, and no way to implement
get_property. Instead store all the specific text attributes.
Separate whether an attribute is enabled from its value. Sync all
properties with GtkTextTag, make them all consistent, etc.
* gtk/gtkcellrenderer.h: Add a flag GTK_CELL_RENDERER_SORTED so
renderers can highlight the sort row/column
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_get_property): use
accessor functions to get values; this has the side effect of
showing up which accessor functions were missing. Added those.
* gtk/gtktreeviewcolumn.h: Replace set_justification with
set_alignment, to be consistent with GtkLabel, GtkMisc
* gtk/gtktreeviewcolumn.c: Added code to display sort indicator
arrow.
* gtk/Makefile.am (gtk_public_h_sources): add gtktreesortable.h
* gtk/gtktreesortable.h: updates in here
2001-02-08 23:36:53 +00:00
|
|
|
|
gtk_widget_queue_draw (da);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
|
|
|
|
|
frame_num++;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static guint timeout_id;
|
|
|
|
|
|
|
|
|
|
/* Destroy handler for the window */
|
|
|
|
|
static void
|
|
|
|
|
destroy_cb (GtkObject *object, gpointer data)
|
|
|
|
|
{
|
2003-02-01 01:47:01 +00:00
|
|
|
|
g_source_remove (timeout_id);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
timeout_id = 0;
|
|
|
|
|
|
|
|
|
|
gtk_main_quit ();
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-21 20:47:22 +00:00
|
|
|
|
extern void pixbuf_init();
|
|
|
|
|
|
2000-06-11 18:18:28 +00:00
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *window;
|
|
|
|
|
|
2000-06-21 20:47:22 +00:00
|
|
|
|
pixbuf_init ();
|
2000-06-11 18:18:28 +00:00
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
|
|
|
|
if (!load_pixbufs ()) {
|
|
|
|
|
g_message ("main(): Could not load all the pixbufs!");
|
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
frame = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, back_width, back_height);
|
|
|
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
fix a typo.
2001-08-07 Havoc Pennington <hp@pobox.com>
* gtk/gtkfilesel.c (open_ref_dir): fix a typo.
* gtk/gtkplug.c (gtk_plug_init): remove setting of auto_shrink;
some fixage is needed here, but nothing simple. Owen understands
it. ;-)
* gtk/gtkwindow.h, gtk/gtkwindow.c: Rework code and API for window
sizing and positioning. Also, fix bug in compute_geometry_hints
(width/height confusion for setting min size).
(gtk_window_move): new function
(gtk_window_resize): new function
(gtk_window_get_size): new function
(gtk_window_get_position): new function
(gtk_window_parse_geometry): new function
* gtk/gtkwidget.c (gtk_widget_set_size_request): new function
(gtk_widget_get_size_request): new function
(gtk_widget_get_usize): delete, that was a short-lived function
;-)
(gtk_widget_set_usize): deprecate
(gtk_widget_set_uposition): deprecate, make it a trivial
gtk_window_move() wrapper
(gtk_widget_class_init): remove x/y/width/height properties,
add width_request height_request
* demos/*: update to avoid deprecated functions
* gtk/gtklayout.c: add x/y child properties
* gtk/gtkfixed.c: add x/y child properties, and get rid of
uses of "gint16"
* tests/testgtk.c (create_window_sizing): lots of tweaks to window
sizing test
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Ensure that
configure events on toplevel windows are always in root window
coordinates, following ICCCM spec that all synthetic events
are in root window coords already, while real events are
in parent window coords. Previously the code assumed that
coords of 0,0 were parent window coords, which was
really broken.
* gtk/gtkcontainer.c (gtk_container_get_focus_chain): fix
warning
* gdk/gdkwindow.h (GdkWindowHints): add GDK_HINT_USER_POS
and GDK_HINT_USER_SIZE so we can set USSize and USPosition
hints in gtk_window_parse_geometry()
* gdk/x11/gdkwindow-x11.c (gdk_window_set_geometry_hints): support
new USER_POS USER_SIZE hints
2001-08-10 03:46:08 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_set_size_request (window, back_width, back_height);
|
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
|
2001-10-20 23:39:32 +00:00
|
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
|
G_CALLBACK (destroy_cb), NULL);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
|
|
|
|
|
da = gtk_drawing_area_new ();
|
|
|
|
|
|
2001-10-20 23:39:32 +00:00
|
|
|
|
g_signal_connect (da, "expose_event",
|
|
|
|
|
G_CALLBACK (expose_cb), NULL);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), da);
|
|
|
|
|
|
2006-12-22 19:10:43 +00:00
|
|
|
|
timeout_id = gdk_threads_add_timeout (FRAME_DELAY, timeout, NULL);
|
2000-06-11 18:18:28 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_show_all (window);
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|