Image code

This commit is contained in:
Markus Koch 2016-06-04 22:25:51 +02:00
parent bdd19cf4b8
commit a897006a56
4 changed files with 75 additions and 11 deletions

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkBox" id="previewWidget">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage" id="image">
<property name="width_request">200</property>
<property name="height_request">150</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixbuf">Screenshot from 2015-10-22 18-13-07.png</property>
<property name="use_fallback">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinner" id="spinner">
<property name="width_request">200</property>
<property name="height_request">150</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button">
<property name="label" translatable="yes">Download @ 0000 x 0000</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="kona_download_image" object="previewWidget" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</interface>

View File

@ -14,6 +14,8 @@ int buildWindow() {
GtkWidget *previewContainer;
GtkWidget *temp;
KonaImage *ki;
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "glade/mainWindow.glade", NULL);
@ -26,7 +28,9 @@ int buildWindow() {
gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(previewLayout), 200);
for (int i = 0; i < 100; ++i) {
// CUSTOM!!!!!
temp = PreviewWidget_new();
ki = kona_image_new();
temp = PreviewWidget_new(ki);
gtk_flow_box_insert(GTK_FLOW_BOX(previewLayout),temp,0);
gtk_widget_show(temp);
// -------------------
@ -48,7 +52,6 @@ int buildWindow() {
GValue val = G_VALUE_INIT;
GValue sval = G_VALUE_INIT;
KonaImage *ki;
kona_image_meta meta;
ki = kona_image_new();
g_value_init(&val, G_TYPE_POINTER);

View File

@ -1,23 +1,30 @@
#include "previewwidget.h"
G_DEFINE_TYPE(PreviewWidget, PreviewWidget, GTK_TYPE_BIN)
void kona_download_image( GtkWidget *widget, gpointer data )
{
PreviewWidget_set_image(data, ""); // DEBUG ONLY!
PreviewWidget_set_image(data, "/home/kurisu/Pictures/a.xpm"); // DEBUG ONLY!
}
void PreviewWidget_set_image(PreviewWidget *widget, gchar *url) {
GtkWidget *spinner;
GtkWidget *w;
GList *widgets;
widgets = gtk_container_get_children(GTK_CONTAINER(widget));
spinner = widgets->data;
gtk_widget_set_visible(spinner, TRUE);
w = widgets->data; // Grab GtkImage
spinner = g_list_next(widgets)->data;
gtk_widget_set_visible(spinner, FALSE);
GdkPixbuf *p;
p = gdk_pixbuf_new_from_file(url, NULL);
p = gdk_pixbuf_scale_simple(p, 200, 150, GDK_INTERP_BILINEAR);
gtk_image_set_from_pixbuf(GTK_IMAGE(w), p);
gtk_widget_set_visible(w, TRUE);
w = g_list_next(widgets)->data; // Grab Spinner
gtk_widget_set_visible(w, FALSE);
}
@ -47,7 +54,7 @@ void PreviewWidget_init(PreviewWidget *klass)
g_object_unref(G_OBJECT(builder));
}
GtkWidget *PreviewWidget_new()
GtkWidget *PreviewWidget_new(KonaImage* ki)
{
return g_object_new (TYPE_PREVIEWWIDGET, NULL);
}

View File

@ -2,9 +2,10 @@
#define PREVIEWWIDGET_H
#include <gtk/gtk.h>
#include <glib.h>
#include "konaimage.h"
G_BEGIN_DECLS
#define TYPE_PREVIEWWIDGET (PreviewWidget_get_type ())
@ -25,7 +26,7 @@ struct _PreviewWidgetClass {
};
GType PreviewWidget_get_type (void) G_GNUC_CONST;
GtkWidget* PreviewWidget_new (void);
GtkWidget* PreviewWidget_new (KonaImage* ki);
void PreviewWidget_set_image(PreviewWidget *widget, gchar *url);