Compare commits
No commits in common. "be6f3dfe991ed6f8d4868a215415dd9ecb6a0c5c" and "57ac392431bf8bf7c32e7204771aca296096672b" have entirely different histories.
be6f3dfe99
...
57ac392431
@ -29,9 +29,6 @@ Low priority:
|
|||||||
- display 16-bit pictures smoothly, using the 30-bit depth under X.org
|
- display 16-bit pictures smoothly, using the 30-bit depth under X.org
|
||||||
- make RAW as fast as it can possibly be
|
- make RAW as fast as it can possibly be
|
||||||
- load everything that resembles a picture, potentially even play video
|
- load everything that resembles a picture, potentially even play video
|
||||||
- port to something less hostile than the current GNOME stack, such as SDL,
|
|
||||||
although it may involve a lot of reimplemented code,
|
|
||||||
or result in reduced functionality
|
|
||||||
|
|
||||||
Non-goals:
|
Non-goals:
|
||||||
|
|
||||||
|
@ -88,25 +88,8 @@ fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
|
|||||||
if (!self->surface)
|
if (!self->surface)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
// TODO(p): Make this adjustable later.
|
|
||||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
|
||||||
cairo_paint(cr);
|
|
||||||
|
|
||||||
GtkAllocation allocation;
|
|
||||||
gtk_widget_get_allocation(widget, &allocation);
|
|
||||||
|
|
||||||
int w = cairo_image_surface_get_width(self->surface);
|
|
||||||
int h = cairo_image_surface_get_height(self->surface);
|
|
||||||
|
|
||||||
double x = 0;
|
|
||||||
double y = 0;
|
|
||||||
if (w < allocation.width)
|
|
||||||
x = (allocation.width - w) / 2;
|
|
||||||
if (h < allocation.height)
|
|
||||||
y = (allocation.height - h) / 2;
|
|
||||||
|
|
||||||
// TODO(p): Times the zoom.
|
// TODO(p): Times the zoom.
|
||||||
cairo_set_source_surface(cr, self->surface, x, y);
|
cairo_set_source_surface(cr, self->surface, 0, 0);
|
||||||
cairo_paint(cr);
|
cairo_paint(cr);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
65
fastiv.c
65
fastiv.c
@ -48,44 +48,10 @@ exit_fatal(const gchar *format, ...)
|
|||||||
// --- Main --------------------------------------------------------------------
|
// --- Main --------------------------------------------------------------------
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
// TODO(p): Directory filenames, index within the list, ...
|
// TODO(p): Add some state variables.
|
||||||
GtkWidget *window;
|
// - Directory filenames, index within the list.
|
||||||
GtkWidget *view;
|
|
||||||
} g;
|
} g;
|
||||||
|
|
||||||
static void
|
|
||||||
open(const gchar *path)
|
|
||||||
{
|
|
||||||
GError *error = NULL;
|
|
||||||
if (!fastiv_view_open(FASTIV_VIEW(g.view), path, &error)) {
|
|
||||||
GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(g.window),
|
|
||||||
GTK_DIALOG_MODAL,
|
|
||||||
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message);
|
|
||||||
gtk_dialog_run(GTK_DIALOG(dialog));
|
|
||||||
gtk_widget_destroy(dialog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_window_set_title(GTK_WINDOW(g.window), path);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
on_open(void)
|
|
||||||
{
|
|
||||||
GtkWidget *dialog = gtk_file_chooser_dialog_new("Open file",
|
|
||||||
GTK_WINDOW(g.window), GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
||||||
"_Cancel", GTK_RESPONSE_CANCEL,
|
|
||||||
"_Open", GTK_RESPONSE_ACCEPT, NULL);
|
|
||||||
|
|
||||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
|
||||||
gchar *path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
|
||||||
open(path);
|
|
||||||
g_free(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_widget_destroy(dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -113,22 +79,10 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
gtk_window_set_default_icon_name(PROJECT_NAME);
|
gtk_window_set_default_icon_name(PROJECT_NAME);
|
||||||
|
|
||||||
g.view = g_object_new(FASTIV_TYPE_VIEW, NULL);
|
GtkWidget *view = g_object_new(FASTIV_TYPE_VIEW, NULL);
|
||||||
g.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
g_signal_connect(g.window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
||||||
gtk_container_add(GTK_CONTAINER(g.window), g.view);
|
gtk_container_add(GTK_CONTAINER(window), view);
|
||||||
|
|
||||||
// The references to closures are initially floating and sunk on connect.
|
|
||||||
GtkAccelGroup *accel_group = gtk_accel_group_new();
|
|
||||||
gtk_accel_group_connect(accel_group, GDK_KEY_Escape, 0, 0,
|
|
||||||
g_cclosure_new(G_CALLBACK(gtk_main_quit), NULL, NULL));
|
|
||||||
gtk_accel_group_connect(accel_group, GDK_KEY_q, 0, 0,
|
|
||||||
g_cclosure_new(G_CALLBACK(gtk_main_quit), NULL, NULL));
|
|
||||||
gtk_accel_group_connect(accel_group, GDK_KEY_o, 0, 0,
|
|
||||||
g_cclosure_new(G_CALLBACK(on_open), NULL, NULL));
|
|
||||||
gtk_accel_group_connect(accel_group, GDK_KEY_o, GDK_CONTROL_MASK, 0,
|
|
||||||
g_cclosure_new(G_CALLBACK(on_open), NULL, NULL));
|
|
||||||
gtk_window_add_accel_group(GTK_WINDOW(g.window), accel_group);
|
|
||||||
|
|
||||||
// TODO(p): Load directory entries, store in `g`.
|
// TODO(p): Load directory entries, store in `g`.
|
||||||
// - Only when there's just one filename.
|
// - Only when there's just one filename.
|
||||||
@ -150,10 +104,13 @@ main(int argc, char *argv[])
|
|||||||
g_dir_close(dir);
|
g_dir_close(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
open(files[0]);
|
if (!fastiv_view_open(FASTIV_VIEW(view), files[0], &error))
|
||||||
|
g_printerr("error: %s\n", error->message);
|
||||||
|
else
|
||||||
|
gtk_window_set_title(GTK_WINDOW(window), files[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_widget_show_all(g.window);
|
gtk_widget_show_all(window);
|
||||||
gtk_main();
|
gtk_main();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user