~ubuntu-branches/ubuntu/hardy/gnome-commander/hardy

« back to all changes in this revision

Viewing changes to tests/gviewer/imagerenderer.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-06-13 15:39:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060613153948-gvrt3mb2ddk5u62o
Tags: 1.2.0-3
added --disable-scrollkeeper on build

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  GNOME Commander - A GNOME based file manager
 
3
  Copyright (C) 2001-2006 Marcus Bjurman
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU General Public License as published by
 
7
  the Free Software Foundation; either version 2 of the License, or
 
8
  (at your option) any later version.
 
9
 
 
10
  This program is distributed in the hope that it will be useful,
 
11
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
  GNU General Public License for more details.
 
14
 
 
15
  You should have received a copy of the GNU General Public License
 
16
  along with this program; if not, write to the Free Software
 
17
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
   Author: Assaf Gordon  <agordon88@gmail.com>
 
20
*/
 
21
 
 
22
#include <glib.h>
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <unistd.h>
 
26
#include <err.h>
 
27
 
 
28
#include <glib.h>
 
29
#include <gtk/gtk.h>
 
30
 
 
31
#include <libgviewer/libgviewer.h>
 
32
 
 
33
static gchar* filename = NULL;
 
34
static gboolean best_fit = TRUE;
 
35
static double scale_factor = 1.0 ;
 
36
 
 
37
void usage()
 
38
{
 
39
    fprintf(stderr,"This program tests the image-render widget in 'libgviewer'.\n\n" ) ;
 
40
 
 
41
    fprintf(stderr,"Usage: test-imagerenderer [-s scale] filename\n\n" ) ;
 
42
    
 
43
    fprintf(stderr,"\t-s scale: use fixed scaling factor (0.1 to 3.0)\n\t\t(Default is using best-fit-to-window)\n");
 
44
    fprintf(stderr,"\tfilename: The file to display.\n");
 
45
    exit(0);
 
46
}
 
47
 
 
48
void parse_command_line(int argc, char* argv[])
 
49
{
 
50
    extern char* optarg;
 
51
    extern int optind, opterr, optopt ;
 
52
    int c;
 
53
 
 
54
    best_fit = TRUE ;
 
55
    scale_factor = 1.0 ;
 
56
    
 
57
    while ( (c=getopt(argc,argv,"s:")) != -1 ) {
 
58
        switch(c)
 
59
        {
 
60
        case 's':
 
61
            best_fit = FALSE ;
 
62
            scale_factor = atof(optarg);
 
63
            if (scale_factor<0.1 || scale_factor>3.0) {
 
64
                warnx("Invalid scale factor \"%f\".\n", scale_factor);
 
65
                usage();
 
66
            }
 
67
            break;
 
68
            
 
69
        default:
 
70
            usage();
 
71
            break;
 
72
        }
 
73
    }
 
74
    
 
75
    if ( optind == argc ) {
 
76
        warnx("Need file name to work with...\n");
 
77
        usage();
 
78
    }
 
79
    filename = g_strdup(argv[optind++]);
 
80
}
 
81
 
 
82
 
 
83
int main(int argc, char* argv[])
 
84
{
 
85
    GtkWidget *window;
 
86
    GtkWidget *scrollbox;
 
87
    GtkWidget *imgr;
 
88
    
 
89
    gtk_init(&argc,&argv);
 
90
    
 
91
    parse_command_line(argc,argv);
 
92
    
 
93
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
94
    gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
 
95
    gtk_widget_set_size_request(window,600,400);
 
96
 
 
97
    scrollbox = scroll_box_new() ;
 
98
 
 
99
    imgr = image_render_new() ;
 
100
 
 
101
    image_render_set_v_adjustment(IMAGE_RENDER(imgr),
 
102
        scroll_box_get_v_adjustment(SCROLL_BOX(scrollbox))) ;
 
103
    
 
104
    image_render_set_h_adjustment(IMAGE_RENDER(imgr),
 
105
        scroll_box_get_h_adjustment(SCROLL_BOX(scrollbox))) ;
 
106
 
 
107
    image_render_load_file(IMAGE_RENDER(imgr), filename ) ;
 
108
 
 
109
    image_render_set_best_fit(IMAGE_RENDER(imgr),best_fit);
 
110
    
 
111
    if (!best_fit)
 
112
        image_render_set_scale_factor(IMAGE_RENDER(imgr), scale_factor);
 
113
    
 
114
    scroll_box_set_client(SCROLL_BOX(scrollbox),imgr) ;
 
115
    
 
116
    gtk_container_add(GTK_CONTAINER(window), scrollbox) ;
 
117
    
 
118
    gtk_widget_show(imgr);
 
119
    gtk_widget_show(scrollbox);
 
120
    gtk_widget_show(window);
 
121
    
 
122
    gtk_main();
 
123
    
 
124
    return 0;
 
125
}