Reply
Thread Tools
ArnimS's Avatar
Posts: 1,107 | Thanked: 720 times | Joined on Mar 2007 @ Germany
#1
Code:
/*
   Posted by someone who may or may not want their name on this 
   gcc -Wall -o parent-test parent-test.c \
       `pkg-config --cflags --libs gtk+-2.0 hildon-1`
  
 */

#include <cairo.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <math.h>
#include <stdlib.h>
#include <hildon/hildon.h>

static gint X_SIZE = 320;
static gint Y_SIZE = 240;

static gint X_POS = 0;
static gint Y_POS = 56;

static gint X_FULL = 800;
static gint Y_FULL = 424;

static gdouble X_SCALE = 2.5;  /* X_FULL / X_SIZE */
static gdouble Y_SCALE = 1.77; /* Y_FULL / Y_SIZE */


/** Simple drawing widget **/

static void
drawing_button_event (GtkWidget *drawing,
		      GdkEventButton *event,
		      cairo_t *context)
{
  cairo_new_path (context);
  cairo_move_to (context, event->x + 5, event->y);
  cairo_arc (context, event->x, event->y, 5, 0, 2 * M_PI);
  if (event->type == GDK_BUTTON_PRESS)
    cairo_set_source_rgb (context, 1.0, 0.0, 0.0);
  else
    cairo_set_source_rgb (context, 0.0, 0.0, 1.0);
  cairo_fill (context);
}

static void
drawing_realize (GtkWidget *drawing,
		 gpointer user_data)
{
  cairo_t *context;
  context = gdk_cairo_create (GDK_DRAWABLE (drawing->window));
  gtk_widget_add_events (drawing,
			 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
  g_signal_connect (drawing, "button-press-event",
		    G_CALLBACK (drawing_button_event), context);
  g_signal_connect (drawing, "button-release-event",
		    G_CALLBACK (drawing_button_event), context);
}

static GtkWidget *
get_drawing_widget (void)
{
  GtkWidget *drawing = gtk_drawing_area_new ();
  GtkRequisition *req;
  g_signal_connect (drawing, "realize",
		    G_CALLBACK (drawing_realize), NULL);
  return drawing;
}

/** Test application **/

static void
window_button_proxy (GtkWidget *widget,
		     GdkEventButton *event,
		     GtkWidget *proxy)
{
  GdkEventButton *newev = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event);
  newev->window = proxy->window;
  newev->x = (gint) (newev->x / X_SCALE);
  newev->y = (gint) (newev->y / Y_SCALE);
  gdk_event_put ((GdkEvent *) newev);
}

static void
button_clicked (GtkWidget *widget, HildonAnimationActor *actor)
{
  static gboolean fullscreen = FALSE;

  if (fullscreen) {
    hildon_animation_actor_set_scale (actor, 1.0, 1.0);
    fullscreen = FALSE;
  }
  else {
    hildon_animation_actor_set_scale (actor, X_SCALE, Y_SCALE);
    fullscreen = TRUE;
  }
}


int
main (int argc,
      char *argv[])
{
  HildonAnimationActor *actor;
  GtkWidget *window, *drawing;
  HildonProgram *program;
  GdkColor pink = { .red = 0xffff, .green = 0x9999, .blue = 0x9999 };

  gtk_init (&argc, &argv);

  window = hildon_stackable_window_new ();
  gtk_widget_modify_bg (GTK_WIDGET (window), GTK_STATE_NORMAL, &pink);
  g_signal_connect (G_OBJECT (window), "delete_event",
		    G_CALLBACK (gtk_main_quit), NULL);
  gtk_widget_add_events (window,
			 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);

  actor = HILDON_ANIMATION_ACTOR (hildon_animation_actor_new());
  gtk_widget_add_events (GTK_WIDGET (actor),
			 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
  gtk_window_resize (GTK_WINDOW (actor), X_SIZE, Y_SIZE);
  hildon_animation_actor_set_position (actor, X_POS, Y_POS);
  hildon_animation_actor_set_parent (actor, GTK_WINDOW (window));
  hildon_animation_actor_set_scale (actor, X_SCALE, Y_SCALE);

  drawing = get_drawing_widget ();
  gtk_container_add (GTK_CONTAINER (actor), drawing);

  g_signal_connect (window, "button-press-event",
		    G_CALLBACK (window_button_proxy), drawing);
  g_signal_connect (window, "button-release-event",
		    G_CALLBACK (window_button_proxy), drawing);

  gtk_widget_show_all (GTK_WIDGET (actor));
  gtk_widget_show_all (GTK_WIDGET (window));

  gtk_main ();
  return 0;
}
 

The Following 6 Users Say Thank You to ArnimS For This Useful Post:
lcuk's Avatar
Posts: 1,635 | Thanked: 1,816 times | Joined on Apr 2008 @ Manchester, England
#2
pupnik,
anonymous code drops hurt more than they help.
please explain what problem it solves and who might need it.
__________________
liqbase sketching the future.
like what i say? hit the Thanks, thanks!
twitter.com/lcuk
 

The Following 3 Users Say Thank You to lcuk For This Useful Post:
mikec's Avatar
Posts: 1,366 | Thanked: 1,185 times | Joined on Jan 2006
#3
lcuk

isnt that World or Warcraft port in 10 lines

Mike C
 
lcuk's Avatar
Posts: 1,635 | Thanked: 1,816 times | Joined on Apr 2008 @ Manchester, England
#4
lol mikec
i see the code, but i dont see what to do with it.
its not needed by normal gtk apps, and i doubt pupnik would just randomly post something like this without reason.
i am just interested to know how it should be used and when we might need it.
__________________
liqbase sketching the future.
like what i say? hit the Thanks, thanks!
twitter.com/lcuk
 
b-man's Avatar
Posts: 549 | Thanked: 502 times | Joined on Feb 2008 @ Bowling Green Ohio (united states)
#5
screenshot

__________________
I'm an advanced user and a bit of a modder.
----------------------------------------------
I am involved with Mer, Deblet, and NITdroid.
My ports/creations/hacks: GNOME (for Deblet), Cdeb2», Ubuntu, playable flash games in the "Get Started" app, DBS, ect...


enhanced fedora port has been canceled in favor of NITDebian (TBA)
 
Bundyo's Avatar
Posts: 4,708 | Thanked: 4,649 times | Joined on Oct 2007 @ Bulgaria
#6
I don't see anything top secret in here, hildon_animation_actor is documented and was discussed on the mailing list.
__________________
Technically, there are three determinate states the cat could be in: Alive, Dead, and Bloody Furious.
 

The Following User Says Thank You to Bundyo For This Useful Post:
javispedro's Avatar
Posts: 2,355 | Thanked: 5,249 times | Joined on Jan 2009 @ Barcelona
#7
It was commented by Konttori (sorry, but can't think why he wouldn't want his name on it, specially if he posted it publicly on IRC ) that the scaling part wouldn't work in the first firmware version -- but will in later versions.

The snippet's method should be basically the fastest way to scale 2d output in the N900 since:

-Software scaling:

Source bitmap ---(scale in soft)---> scaled bitmap ---(XPutImage/XSHMPut) ---> scaled X11 pixmap ---(hildon-desktop: texture-from-pixmap)--> scaled powervr texture ---(powervr render)--> screen

(2d buffer is uploaded once to the powervr, in scaled, "large" form)

- Use a EGL window context:

Source bitmap ---(glTexImage)---> powervr texture ---(powervr scale&render) ---> scaled framebuffer ---(XPutImage/XSHMPut) ---> scaled X11 pixmap ---(hildon-desktop: texture-from-pixmap)--> scaled powervr texture ---(powervr render)--> screen

(longer path, the texture might even be uploaded _twice_ to powervr! -- in which case it is even slower than pure software scaling)

- Snippet's method:

Source bitmap ---(XPutImage/XSHMPut) ---> X11 pixmap ---(hildon-desktop: texture-from-pixmap)--> powervr texture ---(powervr scale&render)--> screen

As you can see, the 2d buffer is uploaded once to powervr and in non scaled form, and hildon-desktop manages the scaling -- less bandwidth used, thus fastest.
 

The Following 4 Users Say Thank You to javispedro For This Useful Post:
Posts: 1,038 | Thanked: 737 times | Joined on Nov 2005 @ Helsinki
#8
Fullscreen windowns will be able to also use non-composited mode, so some of the steps can be skipped for those.

What the compositor scaling provides also is bilinear filtering, which should also look pretty good, but might not be as good as some dedicated game scalers.
 

The Following 3 Users Say Thank You to konttori For This Useful Post:
Reply

Tags
cairo, code, compositor, gtk, scaling


 
Forum Jump


All times are GMT. The time now is 09:58.