Changeset c064b58 in mainline
- Timestamp:
- 2016-03-13T00:00:57Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 722bb5a
- Parents:
- c1b8ad4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/viewer/viewer.c
rc1b8ad4 rc064b58 51 51 #define WINDOW_HEIGHT 768 52 52 53 #define DECORATION_WIDTH 8 54 #define DECORATION_HEIGHT 28 55 53 56 static size_t imgs_count; 54 57 static size_t imgs_current = 0; … … 59 62 static canvas_t *canvas = NULL; 60 63 61 static bool img_load(const char *); 64 static surface_coord_t img_width; 65 static surface_coord_t img_height; 66 67 static bool img_load(const char *, surface_t **); 68 static bool img_setup(surface_t *); 62 69 63 70 static void on_keyboard_event(widget_t *widget, void *data) … … 88 95 89 96 if (update) { 90 if (!img_load(imgs[imgs_current])) { 97 surface_t *lsface; 98 99 if (!img_load(imgs[imgs_current], &lsface)) { 91 100 printf("Cannot load image \"%s\".\n", imgs[imgs_current]); 92 exit(2); 93 } 94 } 95 } 96 97 static bool img_load(const char *fname) 101 exit(4); 102 } 103 if (!img_setup(lsface)) { 104 printf("Cannot setup image \"%s\".\n", imgs[imgs_current]); 105 exit(6); 106 } 107 } 108 } 109 110 static bool img_load(const char *fname, surface_t **p_local_surface) 98 111 { 99 112 int fd = open(fname, O_RDONLY); … … 123 136 close(fd); 124 137 125 surface_t *local_surface = decode_tga(tga, stat.size, 0);126 if ( local_surface == NULL) {138 *p_local_surface = decode_tga(tga, stat.size, 0); 139 if (*p_local_surface == NULL) { 127 140 free(tga); 128 141 return false; … … 130 143 131 144 free(tga); 132 145 146 surface_get_resolution(*p_local_surface, &img_width, &img_height); 147 148 return true; 149 } 150 151 static bool img_setup(surface_t *local_surface) 152 { 133 153 if (canvas != NULL) { 134 154 if (!update_canvas(canvas, local_surface)) { … … 138 158 } else { 139 159 canvas = create_canvas(window_root(main_window), 140 WINDOW_WIDTH, WINDOW_HEIGHT, local_surface);160 img_width, img_height, local_surface); 141 161 if (canvas == NULL) { 142 162 surface_destroy(local_surface); … … 151 171 152 172 surface = local_surface; 153 154 173 return true; 155 174 } … … 157 176 int main(int argc, char *argv[]) 158 177 { 178 window_flags_t flags; 179 surface_t *lsface; 180 bool fullscreen; 181 sysarg_t dwidth; 182 sysarg_t dheight; 183 159 184 if (argc < 2) { 160 185 printf("Compositor server not specified.\n"); … … 166 191 return 1; 167 192 } 168 169 main_window = window_open(argv[1], WINDOW_MAIN, "viewer"); 170 if (!main_window) { 171 printf("Cannot open main window.\n"); 172 return 2; 173 } 174 193 175 194 imgs_count = argc - 2; 176 195 imgs = calloc(imgs_count, sizeof(char *)); 177 196 if (imgs == NULL) { 178 197 printf("Out of memory.\n"); 179 return 3;198 return 2; 180 199 } 181 200 … … 184 203 if (imgs[i] == NULL) { 185 204 printf("Out of memory.\n"); 186 return 4;187 } 188 } 189 190 if (!img_load(imgs[imgs_current] )) {205 return 3; 206 } 207 } 208 209 if (!img_load(imgs[imgs_current], &lsface)) { 191 210 printf("Cannot load image \"%s\".\n", imgs[imgs_current]); 192 return 2; 193 } 194 195 window_resize(main_window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 196 WINDOW_PLACEMENT_ABSOLUTE); 211 return 4; 212 } 213 214 fullscreen = ((img_width == WINDOW_WIDTH) && 215 (img_height == WINDOW_HEIGHT)); 216 217 flags = WINDOW_MAIN; 218 if (!fullscreen) 219 flags |= WINDOW_DECORATED; 220 221 main_window = window_open(argv[1], flags, "viewer"); 222 if (!main_window) { 223 printf("Cannot open main window.\n"); 224 return 5; 225 } 226 227 228 if (!img_setup(lsface)) { 229 printf("Cannot setup image \"%s\".\n", imgs[imgs_current]); 230 return 6; 231 } 232 233 if (!fullscreen) { 234 dwidth = DECORATION_WIDTH; 235 dheight = DECORATION_HEIGHT; 236 } else { 237 dwidth = 0; 238 dheight = 0; 239 } 240 241 window_resize(main_window, 0, 0, img_width + dwidth, 242 img_height + dheight, WINDOW_PLACEMENT_ANY); 197 243 window_exec(main_window); 198 244
Note:
See TracChangeset
for help on using the changeset viewer.