diff options
Diffstat (limited to 'converter/other/fiasco/buttons.c')
-rw-r--r-- | converter/other/fiasco/buttons.c | 412 |
1 files changed, 206 insertions, 206 deletions
diff --git a/converter/other/fiasco/buttons.c b/converter/other/fiasco/buttons.c index fc54d84a..7a6c77a3 100644 --- a/converter/other/fiasco/buttons.c +++ b/converter/other/fiasco/buttons.c @@ -1,8 +1,8 @@ /* - * buttons.c: Draw MWFA player buttons in X11 window + * buttons.c: Draw MWFA player buttons in X11 window + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -23,7 +23,7 @@ #include <X11/StringDefs.h> #if STDC_HEADERS -# include <stdlib.h> +# include <stdlib.h> #endif /* not STDC_HEADERS */ #include "types.h" @@ -35,38 +35,38 @@ /***************************************************************************** - local variables - + local variables + *****************************************************************************/ static const int EVENT_MASK = (KeyPressMask | ButtonPressMask | - ButtonReleaseMask | ExposureMask); + ButtonReleaseMask | ExposureMask); /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ static void draw_progress_bar (x11_info_t *xinfo, binfo_t *binfo, unsigned n, - unsigned n_frames); + unsigned n_frames); static void draw_button (x11_info_t *xinfo, binfo_t *binfo, - buttons_t button, bool_t pressed); + buttons_t button, bool_t pressed); static void draw_control_panel (x11_info_t *xinfo, binfo_t *binfo, - unsigned n, unsigned n_frames); + unsigned n, unsigned n_frames); /***************************************************************************** - public code - + public code + *****************************************************************************/ -binfo_t * +binfo_t * init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, - unsigned buttons_height, unsigned progbar_height) + unsigned buttons_height, unsigned progbar_height) /* * Initialize a toolbar with the typical collection of video player * buttons (pause, play, record, next, etc.) in the window given by 'xinfo'. @@ -76,7 +76,7 @@ init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, * the size of the progressbar is given by 'progbar_height'. * * Return value: - * struct managing the toolbar and progressbar information + * struct managing the toolbar and progressbar information */ { XGCValues values; @@ -84,12 +84,12 @@ init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, Colormap cmap; XColor gray, dgray, lgray, red; XColor graye, dgraye, lgraye, rede; - buttons_t button; /* counter */ + buttons_t button; /* counter */ binfo_t *binfo = calloc (1, sizeof (binfo_t)); if (!binfo) error ("Out of memory."); - + binfo->width = xinfo->ximage->width; binfo->height = buttons_height; binfo->progbar_height = progbar_height; @@ -99,12 +99,12 @@ init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, * Generate sub-window for control panel */ binfo->window = XCreateSimpleWindow (xinfo->display, xinfo->window, - 0, xinfo->ximage->height, - binfo->width, binfo->height, 0, - BlackPixel (xinfo->display, - xinfo->screen), - WhitePixel (xinfo->display, - xinfo->screen)); + 0, xinfo->ximage->height, + binfo->width, binfo->height, 0, + BlackPixel (xinfo->display, + xinfo->screen), + WhitePixel (xinfo->display, + xinfo->screen)); XSelectInput(xinfo->display, binfo->window, StructureNotifyMask); XMapWindow (xinfo->display, binfo->window); do @@ -122,47 +122,47 @@ init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, XAllocNamedColor (xinfo->display, cmap, "white", &lgray, &lgraye); XAllocNamedColor (xinfo->display, cmap, "#a8a8a8", &gray, &graye); XAllocNamedColor (xinfo->display, cmap, "red", &red, &rede); - + values.foreground = BlackPixel (xinfo->display, xinfo->screen); values.background = WhitePixel (xinfo->display, xinfo->screen); binfo->gc [BLACK] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, xinfo->screen), - (GCForeground | GCBackground), &values); + RootWindow (xinfo->display, xinfo->screen), + (GCForeground | GCBackground), &values); values.foreground = BlackPixel (xinfo->display, xinfo->screen); values.background = WhitePixel (xinfo->display, xinfo->screen); values.line_width = 3; values.join_style = JoinRound; binfo->gc [THICKBLACK] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, - xinfo->screen), - (GCForeground | GCBackground - | GCLineWidth | GCJoinStyle), &values); + RootWindow (xinfo->display, + xinfo->screen), + (GCForeground | GCBackground + | GCLineWidth | GCJoinStyle), &values); values.foreground = gray.pixel; values.background = WhitePixel (xinfo->display, xinfo->screen); binfo->gc [NGRAY] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, xinfo->screen), - (GCForeground | GCBackground), &values); + RootWindow (xinfo->display, xinfo->screen), + (GCForeground | GCBackground), &values); values.foreground = lgray.pixel; values.background = WhitePixel (xinfo->display, xinfo->screen); binfo->gc [LGRAY] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, xinfo->screen), - (GCForeground | GCBackground), &values); + RootWindow (xinfo->display, xinfo->screen), + (GCForeground | GCBackground), &values); values.foreground = dgray.pixel; values.background = WhitePixel (xinfo->display, xinfo->screen); binfo->gc [DGRAY] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, xinfo->screen), - (GCForeground | GCBackground), &values); + RootWindow (xinfo->display, xinfo->screen), + (GCForeground | GCBackground), &values); values.foreground = red.pixel; values.background = WhitePixel (xinfo->display, xinfo->screen); binfo->gc [RED] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, xinfo->screen), - (GCForeground | GCBackground), &values); + RootWindow (xinfo->display, xinfo->screen), + (GCForeground | GCBackground), &values); for (button = 0; button < NO_BUTTON; button++) binfo->pressed [button] = NO; - draw_control_panel (xinfo, binfo, n, n_frames); - + draw_control_panel (xinfo, binfo, n, n_frames); + return binfo; } @@ -176,11 +176,11 @@ wait_for_input (x11_info_t *xinfo) * No return value. * * Side effect: - * program is terminated after key press or mouse click. + * program is terminated after key press or mouse click. */ { bool_t leave_loop = NO; - + XSelectInput (xinfo->display, xinfo->window, EVENT_MASK); while (!leave_loop) @@ -190,13 +190,13 @@ wait_for_input (x11_info_t *xinfo) XMaskEvent (xinfo->display, EVENT_MASK, &event); switch (event.type) { - case ButtonPress: - case KeyPress: - leave_loop = YES; - break; - default: - display_image (0, 0, xinfo); - break; + case ButtonPress: + case KeyPress: + leave_loop = YES; + break; + default: + display_image (0, 0, xinfo); + break; } } } @@ -214,17 +214,17 @@ check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n, unsigned n_frames) * No return values. * * Side effects: - * status of buttons (binfo->pressed [button]) is changed accordingly. + * status of buttons (binfo->pressed [button]) is changed accordingly. */ { bool_t leave_eventloop; leave_eventloop = (!binfo->pressed [PAUSE_BUTTON] - && binfo->pressed [PLAY_BUTTON]) - || (!binfo->pressed [PAUSE_BUTTON] - && binfo->record_is_rewind - && binfo->pressed [RECORD_BUTTON]) - || binfo->pressed [RECORD_BUTTON]; + && binfo->pressed [PLAY_BUTTON]) + || (!binfo->pressed [PAUSE_BUTTON] + && binfo->record_is_rewind + && binfo->pressed [RECORD_BUTTON]) + || binfo->pressed [RECORD_BUTTON]; draw_progress_bar (xinfo, binfo, n, n_frames); if (binfo->pressed [PAUSE_BUTTON] && binfo->pressed [PLAY_BUTTON]) @@ -253,48 +253,48 @@ check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n, unsigned n_frames) XEvent event; int button; bool_t wait_release = NO; - - + + if (XCheckMaskEvent (xinfo->display, EVENT_MASK, &event)) { - switch (event.type) - { - case ButtonPress: - wait_release = NO; - if (!(binfo->pressed [RECORD_BUTTON] && - !binfo->record_is_rewind)) - for (button = 0; button < NO_BUTTON; button++) - { - int x0, y0, x1, y1; /* button coordinates */ - - x0 = button * (binfo->width / NO_BUTTON); - y0 = binfo->progbar_height; - x1 = x0 + binfo->width / NO_BUTTON; - y1 = y0 + binfo->height - binfo->progbar_height - 1; - if (event.xbutton.x > x0 && event.xbutton.x < x1 - && event.xbutton.y > y0 && event.xbutton.y < y1) - { - draw_button (xinfo, binfo, button, - !binfo->pressed [button]); - wait_release = YES; - break; - } - } - break; - case ButtonRelease: - wait_release = NO; - break; - default: - wait_release = NO; - draw_control_panel (xinfo, binfo, n, n_frames); - display_image (0, 0, xinfo); - break; - } - leave_eventloop = !wait_release - && (binfo->pressed [PLAY_BUTTON] - || binfo->pressed [STOP_BUTTON] - || binfo->pressed [RECORD_BUTTON] - || binfo->pressed [QUIT_BUTTON]); + switch (event.type) + { + case ButtonPress: + wait_release = NO; + if (!(binfo->pressed [RECORD_BUTTON] && + !binfo->record_is_rewind)) + for (button = 0; button < NO_BUTTON; button++) + { + int x0, y0, x1, y1; /* button coordinates */ + + x0 = button * (binfo->width / NO_BUTTON); + y0 = binfo->progbar_height; + x1 = x0 + binfo->width / NO_BUTTON; + y1 = y0 + binfo->height - binfo->progbar_height - 1; + if (event.xbutton.x > x0 && event.xbutton.x < x1 + && event.xbutton.y > y0 && event.xbutton.y < y1) + { + draw_button (xinfo, binfo, button, + !binfo->pressed [button]); + wait_release = YES; + break; + } + } + break; + case ButtonRelease: + wait_release = NO; + break; + default: + wait_release = NO; + draw_control_panel (xinfo, binfo, n, n_frames); + display_image (0, 0, xinfo); + break; + } + leave_eventloop = !wait_release + && (binfo->pressed [PLAY_BUTTON] + || binfo->pressed [STOP_BUTTON] + || binfo->pressed [RECORD_BUTTON] + || binfo->pressed [QUIT_BUTTON]); } } while (!leave_eventloop); @@ -308,13 +308,13 @@ check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n, unsigned n_frames) /***************************************************************************** - private code - + private code + *****************************************************************************/ static void draw_control_panel (x11_info_t *xinfo, binfo_t *binfo, - unsigned n, unsigned n_frames) + unsigned n, unsigned n_frames) /* * Draw control panel 'binfo' with all buttons and progressbar in * the given 'window'. @@ -325,9 +325,9 @@ draw_control_panel (x11_info_t *xinfo, binfo_t *binfo, */ { buttons_t button; - + XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY], - 0, 0, binfo->width, binfo->height); + 0, 0, binfo->width, binfo->height); draw_progress_bar (xinfo, binfo, n, n_frames); for (button = 0; button < NO_BUTTON; button++) draw_button (xinfo, binfo, button, binfo->pressed [button]); @@ -335,7 +335,7 @@ draw_control_panel (x11_info_t *xinfo, binfo_t *binfo, static void draw_progress_bar (x11_info_t *xinfo, binfo_t *binfo, unsigned n, - unsigned n_frames) + unsigned n_frames) /* * Draw progressbar of control panel 'binfo' in the given 'window'. * 'n' gives the current frame, whereas 'n_frames' is the total number of @@ -346,32 +346,32 @@ draw_progress_bar (x11_info_t *xinfo, binfo_t *binfo, unsigned n, { unsigned x, y, width, height; - x = 2; - y = 1; + x = 2; + y = 1; width = binfo->width - 5; height = binfo->progbar_height - 3; - + XDrawLine (xinfo->display, binfo->window, binfo->gc [DGRAY], - x, y, x + width, y); + x, y, x + width, y); XDrawLine (xinfo->display, binfo->window, binfo->gc [DGRAY], - x, y, x, y + height - 1); + x, y, x, y + height - 1); XDrawLine (xinfo->display, binfo->window, binfo->gc [LGRAY], - x + width, y + 1, x + width, y + height); + x + width, y + 1, x + width, y + height); XDrawLine (xinfo->display, binfo->window, binfo->gc [LGRAY], - x, y + height, x + width, y + height); + x, y + height, x + width, y + height); x++; y++; width -= 2; height -= 2; XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY], - x, y, width, height); + x, y, width, height); XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], - x + n * max (1, width / n_frames), y, - max (1, width / n_frames), height); + x + n * max (1, width / n_frames), y, + max (1, width / n_frames), height); } static void draw_button (x11_info_t *xinfo, binfo_t *binfo, - buttons_t button, bool_t pressed) + buttons_t button, bool_t pressed) /* * Draw 'button' of control panel 'binfo' in the given 'window'. * 'pressed' indicates whether the button is pressed or not. @@ -379,17 +379,17 @@ draw_button (x11_info_t *xinfo, binfo_t *binfo, * No return value. */ { - grayscale_t top, bottom; /* index of GC */ - unsigned x, y, width, height; /* coordinates of button */ - - x = button * (binfo->width / NO_BUTTON); - y = binfo->progbar_height; + grayscale_t top, bottom; /* index of GC */ + unsigned x, y, width, height; /* coordinates of button */ + + x = button * (binfo->width / NO_BUTTON); + y = binfo->progbar_height; width = binfo->width / NO_BUTTON; height = binfo->height - binfo->progbar_height - 1; - + if (width < 4 || height < 4) return; - + if (pressed) { top = DGRAY; @@ -401,108 +401,108 @@ draw_button (x11_info_t *xinfo, binfo_t *binfo, bottom = DGRAY; } - x += 2; + x += 2; width -= 4; - + XDrawLine (xinfo->display, binfo->window, binfo->gc [top], - x, y, x + width, y); + x, y, x + width, y); XDrawLine (xinfo->display, binfo->window, binfo->gc [top], - x, y, x, y + height - 1); + x, y, x, y + height - 1); XDrawLine (xinfo->display, binfo->window, binfo->gc [bottom], - x + width, y + 1, x + width, y + height); + x + width, y + 1, x + width, y + height); XDrawLine (xinfo->display, binfo->window, binfo->gc [bottom], - x, y + height, x + width, y + height); + x, y + height, x + width, y + height); x++; y++; width -= 2; height -= 2; XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY], - x, y, width, height); + x, y, width, height); switch (button) { case STOP_BUTTON: - XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], - x + width / 2 - 6, y + height / 2 - 4, 11, 11); - if (pressed && !binfo->pressed [STOP_BUTTON]) - { - draw_button (xinfo, binfo, PLAY_BUTTON, NO); - draw_button (xinfo, binfo, PAUSE_BUTTON, NO); - draw_button (xinfo, binfo, RECORD_BUTTON, NO); - } - break; + XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], + x + width / 2 - 6, y + height / 2 - 4, 11, 11); + if (pressed && !binfo->pressed [STOP_BUTTON]) + { + draw_button (xinfo, binfo, PLAY_BUTTON, NO); + draw_button (xinfo, binfo, PAUSE_BUTTON, NO); + draw_button (xinfo, binfo, RECORD_BUTTON, NO); + } + break; case PAUSE_BUTTON: - XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], - x + width / 2 - 6, y + height / 2 - 4, 5, 11); - XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], - x + width / 2 + 1, y + height / 2 - 4, 5, 11); - break; + XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], + x + width / 2 - 6, y + height / 2 - 4, 5, 11); + XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], + x + width / 2 + 1, y + height / 2 - 4, 5, 11); + break; case PLAY_BUTTON: - { - XPoint triangle [3]; - - triangle [0].x = x + width / 2 - 5; - triangle [0].y = y + height / 2 - 5; - triangle [1].x = 10; - triangle [1].y = 6; - triangle [2].x = -10; - triangle [2].y = 6; - - XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], - triangle, 3, Convex, CoordModePrevious); - if (pressed && !binfo->pressed [PLAY_BUTTON] - && binfo->pressed [RECORD_BUTTON]) - draw_button (xinfo, binfo, RECORD_BUTTON, NO); - } - break; + { + XPoint triangle [3]; + + triangle [0].x = x + width / 2 - 5; + triangle [0].y = y + height / 2 - 5; + triangle [1].x = 10; + triangle [1].y = 6; + triangle [2].x = -10; + triangle [2].y = 6; + + XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], + triangle, 3, Convex, CoordModePrevious); + if (pressed && !binfo->pressed [PLAY_BUTTON] + && binfo->pressed [RECORD_BUTTON]) + draw_button (xinfo, binfo, RECORD_BUTTON, NO); + } + break; case RECORD_BUTTON: - if (!binfo->record_is_rewind) - { - XFillArc (xinfo->display, binfo->window, binfo->gc [RED], - x + width / 2 - 5, y + height / 2 - 5, 11, 11, 0, - 360 * 64); - if (pressed && !binfo->pressed [RECORD_BUTTON]) - { - draw_button (xinfo, binfo, STOP_BUTTON, YES); - draw_button (xinfo, binfo, PLAY_BUTTON, NO); - draw_button (xinfo, binfo, PAUSE_BUTTON, NO); - } - } - else - { - XPoint triangle [3]; - - triangle [0].x = x + width / 2 + 5; - triangle [0].y = y + height / 2 - 5; - triangle [1].x = -10; - triangle [1].y = 6; - triangle [2].x = 10; - triangle [2].y = 6; - - XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], - triangle, 3, Convex, CoordModePrevious); - if (pressed && !binfo->pressed [RECORD_BUTTON] - && binfo->pressed [PLAY_BUTTON]) - draw_button (xinfo, binfo, PLAY_BUTTON, NO); - } - break; + if (!binfo->record_is_rewind) + { + XFillArc (xinfo->display, binfo->window, binfo->gc [RED], + x + width / 2 - 5, y + height / 2 - 5, 11, 11, 0, + 360 * 64); + if (pressed && !binfo->pressed [RECORD_BUTTON]) + { + draw_button (xinfo, binfo, STOP_BUTTON, YES); + draw_button (xinfo, binfo, PLAY_BUTTON, NO); + draw_button (xinfo, binfo, PAUSE_BUTTON, NO); + } + } + else + { + XPoint triangle [3]; + + triangle [0].x = x + width / 2 + 5; + triangle [0].y = y + height / 2 - 5; + triangle [1].x = -10; + triangle [1].y = 6; + triangle [2].x = 10; + triangle [2].y = 6; + + XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], + triangle, 3, Convex, CoordModePrevious); + if (pressed && !binfo->pressed [RECORD_BUTTON] + && binfo->pressed [PLAY_BUTTON]) + draw_button (xinfo, binfo, PLAY_BUTTON, NO); + } + break; case QUIT_BUTTON: - { - XPoint triangle [3]; - - triangle [0].x = x + width / 2 - 6; - triangle [0].y = y + height / 2 + 2; - triangle [1].x = 6; - triangle [1].y = -7; - triangle [2].x = 6; - triangle [2].y = 7; - - XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], - triangle, 3, Convex, CoordModePrevious); - XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], - x + width / 2 - 5, y + height / 2 + 4, 11, 3); - } - break; + { + XPoint triangle [3]; + + triangle [0].x = x + width / 2 - 6; + triangle [0].y = y + height / 2 + 2; + triangle [1].x = 6; + triangle [1].y = -7; + triangle [2].x = 6; + triangle [2].y = 7; + + XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], + triangle, 3, Convex, CoordModePrevious); + XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], + x + width / 2 - 5, y + height / 2 + 4, 11, 3); + } + break; default: - break; + break; } binfo->pressed [button] = pressed; } |