AƱadido drawing area con scroll y cairo
authordanigm <danigm>
Sun, 13 Dec 2009 16:21:21 +0000 (16:21 +0000)
committerdanigm <danigm@aa302d1f-72b1-406a-902b-8593ca2b2744>
Sun, 13 Dec 2009 16:21:21 +0000 (16:21 +0000)
git-svn-id: https://forja.rediris.es/svn/cusl4-tbo@6 aa302d1f-72b1-406a-902b-8593ca2b2744

test/ctest/Makefile
test/ctest/cairosamples/Makefile [new file with mode: 0644]
test/ctest/cairosamples/togtk.c [new file with mode: 0644]
test/ctest/cairosamples/topdf.c [new file with mode: 0644]
test/ctest/cairosamples/topng.c [new file with mode: 0644]
test/ctest/tbo.c
test/ctest/ui-drawing.c [new file with mode: 0644]
test/ctest/ui-drawing.h [new file with mode: 0644]

index 51902cf..f7381a2 100644 (file)
@@ -10,3 +10,7 @@ ui-menu.o: ui-menu.c ui-menu.h
 
 ui-toolbar.o: ui-toolbar.c ui-toolbar.h
        gcc -c ui-toolbar.c $(GTK)
+
+ui-drawing.o: ui-drawing.c ui-drawing.h
+       gcc -c ui-drawing.c $(GTK)
+
diff --git a/test/ctest/cairosamples/Makefile b/test/ctest/cairosamples/Makefile
new file mode 100644 (file)
index 0000000..c90d1be
--- /dev/null
@@ -0,0 +1,11 @@
+GTK = `pkg-config --cflags --libs gtk+-2.0`
+
+topng: topng.c
+       gcc topng.c -o topng $(GTK)
+
+topdf: topdf.c
+       gcc topdf.c -o topdf $(GTK)
+
+togtk: 
+       gcc togtk.c -o togtk $(GTK)
+
diff --git a/test/ctest/cairosamples/togtk.c b/test/ctest/cairosamples/togtk.c
new file mode 100644 (file)
index 0000000..9ab62e5
--- /dev/null
@@ -0,0 +1,54 @@
+#include <cairo.h>
+#include <gtk/gtk.h>
+
+static gboolean
+on_expose_event(GtkWidget *widget,
+        GdkEventExpose *event,
+        gpointer        data)
+{
+    cairo_t *cr;
+
+    cr = gdk_cairo_create(widget->window);
+
+    cairo_set_source_rgb(cr, 255, 255, 255);
+    cairo_rectangle(cr, 0, 0, 400, 90);
+    cairo_fill(cr);
+    cairo_set_source_rgb(cr, 0, 0, 0);
+    cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
+            CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_set_font_size(cr, 40.0);
+
+    cairo_move_to(cr, 10.0, 50.0);
+    cairo_show_text(cr, "Disziplin ist Macht.");
+
+    cairo_destroy(cr);
+
+    return FALSE;
+}
+
+int
+main (int argc, char *argv[])
+{
+
+    GtkWidget *window;
+
+    gtk_init(&argc, &argv);
+
+    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+    g_signal_connect(window, "expose-event",
+            G_CALLBACK (on_expose_event), NULL);
+    g_signal_connect(window, "destroy",
+            G_CALLBACK (gtk_main_quit), NULL);
+
+    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
+    gtk_window_set_default_size(GTK_WINDOW(window), 400, 90); 
+    gtk_widget_set_app_paintable(window, TRUE);
+
+    gtk_widget_show_all(window);
+
+    gtk_main();
+
+    return 0;
+}
+
diff --git a/test/ctest/cairosamples/topdf.c b/test/ctest/cairosamples/topdf.c
new file mode 100644 (file)
index 0000000..5719ec0
--- /dev/null
@@ -0,0 +1,27 @@
+#include <cairo/cairo.h>
+#include <cairo/cairo-pdf.h>
+
+int main() {
+
+    cairo_surface_t *surface;
+    cairo_t *cr;
+
+    surface = cairo_pdf_surface_create("pdffile.pdf", 504, 648);
+    cr = cairo_create(surface);
+
+    cairo_set_source_rgb(cr, 0, 0, 0);
+    cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
+            CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_set_font_size (cr, 40.0);
+
+    cairo_move_to(cr, 10.0, 50.0);
+    cairo_show_text(cr, "Disziplin ist Macht.");
+
+    cairo_show_page(cr);
+
+    cairo_surface_destroy(surface);
+    cairo_destroy(cr);
+
+    return 0;
+}
+
diff --git a/test/ctest/cairosamples/topng.c b/test/ctest/cairosamples/topng.c
new file mode 100644 (file)
index 0000000..5783c63
--- /dev/null
@@ -0,0 +1,26 @@
+#include <cairo.h>
+
+int main (int argc, char *argv[])
+{
+    cairo_surface_t *surface;
+    cairo_t *cr;
+
+    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 390, 60);
+    cr = cairo_create(surface);
+
+    cairo_set_source_rgb(cr, 0, 0, 0);
+    cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
+            CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_set_font_size(cr, 40.0);
+
+    cairo_move_to(cr, 10.0, 50.0);
+    cairo_show_text(cr, "Disziplin ist Macht.");
+
+    cairo_surface_write_to_png(surface, "image.png");
+
+    cairo_destroy(cr);
+    cairo_surface_destroy(surface);
+
+    return 0;
+}
+
index 564fa2e..2b60a6a 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "ui-menu.h"
 #include "ui-toolbar.h"
+#include "ui-drawing.h"
 
 GdkPixbuf *create_pixbuf (const gchar * filename)
 {
@@ -44,7 +45,9 @@ int main (int argc, char**argv){
     toolbar = generate_toolbar ();
     gtk_box_pack_start (GTK_BOX (container), toolbar, FALSE, FALSE, 0);
 
-    darea = gtk_drawing_area_new();
+    //darea = get_drawing_area();
+    darea = gtk_scrolled_window_new(NULL, NULL);
+    gtk_container_add (GTK_CONTAINER (darea), get_drawing_area(800, 450));
     gtk_container_add (GTK_CONTAINER (container), darea);
 
     gtk_widget_show_all (window);
diff --git a/test/ctest/ui-drawing.c b/test/ctest/ui-drawing.c
new file mode 100644 (file)
index 0000000..1fa828a
--- /dev/null
@@ -0,0 +1,88 @@
+#include <stdio.h>
+#include <cairo.h>
+#include <gtk/gtk.h>
+
+#include "ui-drawing.h"
+
+gboolean
+on_expose_cb(GtkWidget      *widget,
+             GdkEventExpose *event,
+             gpointer       data)
+{
+    cairo_t *cr;
+    int width, height;
+    char *text = "TBO rulz!";
+    cairo_text_extents_t extents;
+    int *size = (int *) data;
+
+    width = size[0];
+    height = size[1];
+
+    cr = gdk_cairo_create(GTK_LAYOUT (widget)->bin_window);
+
+    cairo_set_source_rgb(cr, 1, 1, 1);
+    cairo_rectangle(cr, 0, 0, size[0], size[1]);
+    cairo_fill(cr);
+    cairo_set_source_rgb(cr, 0, 0, 0);
+    cairo_rectangle (cr, 0, 0, size[0], size[1]);
+    cairo_stroke (cr);
+
+    cairo_set_source_rgb(cr, 0, 0, 0);
+    cairo_select_font_face(cr, "Courier", CAIRO_FONT_SLANT_NORMAL,
+            CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_set_font_size(cr, 90.0);
+
+    cairo_text_extents(cr, text, &extents);
+    cairo_move_to(cr, (width-extents.width)/2, (height+extents.height)/2);
+    
+    cairo_show_text(cr, text);
+
+    cairo_destroy(cr);
+
+    return FALSE;
+}
+
+gboolean
+on_move_cb (GtkWidget      *widget,
+           GdkEventExpose *event,
+           gpointer       data)
+{
+    printf ("move\n");
+}
+
+gboolean
+on_click_cb (GtkWidget      *widget,
+           GdkEventExpose *event,
+           gpointer       data)
+{
+    printf ("click\n");
+}
+
+GtkWidget *
+get_drawing_area (int width, int height)
+{
+
+    GtkWidget *drawing;
+    static int size[2];
+    
+    size[0] = width;
+    size[1] = height;
+
+    drawing = gtk_layout_new(NULL, NULL);
+    gtk_layout_set_size(GTK_LAYOUT (drawing), size[0], size[1]);
+
+    g_signal_connect(drawing, "expose-event",
+            G_CALLBACK (on_expose_cb),  (gpointer) size);
+
+    gtk_widget_add_events (drawing, GDK_BUTTON_PRESS_MASK |
+                                    GDK_POINTER_MOTION_MASK);
+
+    g_signal_connect (drawing, "button_press_event",
+            G_CALLBACK (on_click_cb), NULL);
+
+    g_signal_connect (drawing, "motion_notify_event",
+            G_CALLBACK (on_move_cb), (gpointer) size);
+
+    return drawing;
+}
+
diff --git a/test/ctest/ui-drawing.h b/test/ctest/ui-drawing.h
new file mode 100644 (file)
index 0000000..e280c05
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef __UI_DRAWING_
+#define __UI_DRAWING_
+
+#include <gtk/gtk.h>
+#include <cairo.h>
+
+
+gboolean on_expose_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data);
+gboolean on_move_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data);
+gboolean on_click_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data);
+GtkWidget * get_drawing_area (int width, int height);
+
+#endif