2006-10-06 17:42:59 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2006 Richard Wilson <info@tinct.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-10-06 17:42:59 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Progress bar (implementation).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2008-07-27 02:29:15 +04:00
|
|
|
#include "swis.h"
|
2006-10-06 17:42:59 +04:00
|
|
|
#include "oslib/colourtrans.h"
|
|
|
|
#include "oslib/os.h"
|
2008-07-27 02:29:15 +04:00
|
|
|
#include "oslib/osspriteop.h"
|
2006-10-06 17:42:59 +04:00
|
|
|
#include "oslib/wimp.h"
|
|
|
|
#include "oslib/wimpspriteop.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "utils/log.h"
|
2011-03-14 01:50:54 +03:00
|
|
|
#include "utils/schedule.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "riscos/gui.h"
|
|
|
|
#include "riscos/tinct.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
|
|
|
#include "riscos/gui/progress_bar.h"
|
2006-10-06 17:42:59 +04:00
|
|
|
|
|
|
|
#define MARGIN 6
|
|
|
|
|
|
|
|
struct progress_bar {
|
|
|
|
wimp_w w; /**< progress bar window handle */
|
|
|
|
unsigned int range; /**< progress bar range */
|
|
|
|
unsigned int value; /**< progress bar value */
|
|
|
|
char icon[13]; /**< current icon */
|
|
|
|
int offset; /**< progress bar rotation */
|
|
|
|
os_box visible; /**< progress bar position */
|
|
|
|
int icon_x0; /**< icon x0 */
|
|
|
|
int icon_y0; /**< icon y0 */
|
|
|
|
osspriteop_header *icon_img; /**< icon image */
|
|
|
|
bool animating; /**< progress bar is animating */
|
|
|
|
bool recalculate; /**< recalculation required */
|
|
|
|
int cur_width; /**< current calculated width */
|
|
|
|
int cur_height; /**< current calculated height */
|
2006-10-12 17:36:28 +04:00
|
|
|
bool icon_obscured; /**< icon is partially obscured */
|
2006-10-06 17:42:59 +04:00
|
|
|
};
|
|
|
|
|
2009-02-01 16:37:32 +03:00
|
|
|
static char progress_animation_sprite[] = "progress";
|
2006-10-12 17:36:28 +04:00
|
|
|
static osspriteop_header *progress_icon;
|
|
|
|
static unsigned int progress_width;
|
|
|
|
static unsigned int progress_height;
|
2006-10-12 03:23:40 +04:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
struct wimp_window_base progress_bar_definition = {
|
|
|
|
{0, 0, 1, 1},
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
wimp_TOP,
|
|
|
|
wimp_WINDOW_NEW_FORMAT | wimp_WINDOW_MOVEABLE | wimp_WINDOW_NO_BOUNDS,
|
|
|
|
0xff,
|
|
|
|
wimp_COLOUR_LIGHT_GREY,
|
|
|
|
wimp_COLOUR_LIGHT_GREY,
|
|
|
|
wimp_COLOUR_VERY_LIGHT_GREY,
|
|
|
|
wimp_COLOUR_DARK_GREY,
|
|
|
|
wimp_COLOUR_MID_LIGHT_GREY,
|
|
|
|
wimp_COLOUR_CREAM,
|
|
|
|
wimp_WINDOW_NEVER3D | 0x16u /* RISC OS 5.03+ */,
|
|
|
|
{0, 0, 65535, 65535},
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
wimpspriteop_AREA,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
{""},
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void ro_gui_progress_bar_calculate(struct progress_bar *pb, int width,
|
|
|
|
int height);
|
|
|
|
static void ro_gui_progress_bar_redraw(wimp_draw *redraw);
|
|
|
|
static void ro_gui_progress_bar_redraw_window(wimp_draw *redraw,
|
|
|
|
struct progress_bar *pb);
|
|
|
|
static void ro_gui_progress_bar_animate(void *p);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the progress bar
|
|
|
|
*
|
|
|
|
* \param icons the sprite area to use for icons
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_progress_bar_init(osspriteop_area *icons)
|
|
|
|
{
|
2009-03-28 04:11:50 +03:00
|
|
|
const char *name = progress_animation_sprite;
|
2006-10-06 17:42:59 +04:00
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
progress_bar_definition.sprite_area = icons;
|
|
|
|
|
|
|
|
progress_icon = NULL;
|
|
|
|
error = xosspriteop_select_sprite(osspriteop_USER_AREA,
|
|
|
|
progress_bar_definition.sprite_area,
|
2009-03-28 04:11:50 +03:00
|
|
|
(osspriteop_id) name, &progress_icon);
|
2006-10-06 17:42:59 +04:00
|
|
|
if (!error) {
|
|
|
|
xosspriteop_read_sprite_info(osspriteop_USER_AREA,
|
|
|
|
progress_bar_definition.sprite_area,
|
2009-03-28 04:11:50 +03:00
|
|
|
(osspriteop_id) name,
|
2009-03-27 05:19:38 +03:00
|
|
|
(int *) &progress_width, (int *) &progress_height,
|
|
|
|
0, 0);
|
2006-10-06 17:42:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new progress bar
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
struct progress_bar *ro_gui_progress_bar_create(void)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
struct progress_bar *pb;
|
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
pb = calloc(1, sizeof(*pb));
|
|
|
|
if (!pb)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
error = xwimp_create_window((wimp_window *)&progress_bar_definition,
|
|
|
|
&pb->w);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_create_window: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
free(pb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ro_gui_wimp_event_register_redraw_window(pb->w,
|
|
|
|
ro_gui_progress_bar_redraw);
|
|
|
|
ro_gui_wimp_event_set_user_data(pb->w, pb);
|
|
|
|
return pb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy a progress bar and free all associated resources
|
|
|
|
*
|
|
|
|
* \param pb the progress bar to destroy
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_progress_bar_destroy(struct progress_bar *pb)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
os_error *error;
|
|
|
|
assert(pb);
|
|
|
|
|
|
|
|
if (pb->animating)
|
|
|
|
schedule_remove(ro_gui_progress_bar_animate, pb);
|
|
|
|
ro_gui_wimp_event_finalise(pb->w);
|
|
|
|
error = xwimp_delete_window(pb->w);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_delete_window: 0x%x:%s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the handle of the window that represents a progress bar
|
|
|
|
*
|
|
|
|
* \param pb the progress bar to get the window handle of
|
|
|
|
* \return the progress bar's window handle
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
wimp_w ro_gui_progress_bar_get_window(struct progress_bar *pb)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
assert(pb);
|
|
|
|
|
|
|
|
return pb->w;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the icon for a progress bar
|
|
|
|
*
|
|
|
|
* \param pb the progress bar to set the icon for
|
|
|
|
* \param icon the icon to use, or NULL for no icon
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_progress_bar_set_icon(struct progress_bar *pb, const char *icon)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
assert(pb);
|
|
|
|
|
|
|
|
if (!strcmp(icon, pb->icon))
|
|
|
|
return;
|
|
|
|
if (!icon)
|
|
|
|
pb->icon[0] = '\0';
|
|
|
|
else {
|
|
|
|
strncpy(pb->icon, icon, 12);
|
|
|
|
pb->icon[12] = '\0';
|
|
|
|
}
|
|
|
|
pb->recalculate = true;
|
|
|
|
xwimp_force_redraw(pb->w, 0, 0, 32, 32);
|
2006-10-12 17:36:28 +04:00
|
|
|
ro_gui_progress_bar_update(pb, pb->cur_width, pb->cur_height);
|
2006-10-06 17:42:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the value of a progress bar
|
|
|
|
*
|
|
|
|
* \param pb the progress bar to set the value for
|
|
|
|
* \param value the value to use
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_progress_bar_set_value(struct progress_bar *pb, unsigned int value)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
assert(pb);
|
|
|
|
|
|
|
|
pb->value = value;
|
|
|
|
if (pb->value > pb->range)
|
|
|
|
pb->range = pb->value;
|
2006-10-12 17:36:28 +04:00
|
|
|
ro_gui_progress_bar_update(pb, pb->cur_width, pb->cur_height);
|
2006-10-06 17:42:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of a progress bar
|
|
|
|
*
|
|
|
|
* \param pb the progress bar to get the value of
|
|
|
|
* \return the current value
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
unsigned int ro_gui_progress_bar_get_value(struct progress_bar *pb)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
assert(pb);
|
|
|
|
|
|
|
|
return pb->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the range of a progress bar
|
|
|
|
*
|
|
|
|
* \param pb the progress bar to set the range for
|
|
|
|
* \param range the range to use
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_progress_bar_set_range(struct progress_bar *pb, unsigned int range)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
assert(pb);
|
|
|
|
|
|
|
|
pb->range = range;
|
|
|
|
if (pb->value > pb->range)
|
|
|
|
pb->value = pb->range;
|
2006-10-12 17:36:28 +04:00
|
|
|
ro_gui_progress_bar_update(pb, pb->cur_width, pb->cur_height);
|
2006-10-06 17:42:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the range of a progress bar
|
|
|
|
*
|
|
|
|
* \param pb the progress bar to get the range of
|
|
|
|
* \return the current range
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
unsigned int ro_gui_progress_bar_get_range(struct progress_bar *pb)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
assert(pb);
|
|
|
|
|
|
|
|
return pb->range;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-10-12 17:36:28 +04:00
|
|
|
* Update the progress bar to a new dimension.
|
2006-10-06 17:42:59 +04:00
|
|
|
*
|
|
|
|
* \param pb the progress bar to update
|
2006-10-12 17:36:28 +04:00
|
|
|
* \param width the new progress bar width
|
|
|
|
* \param height the new progress bar height
|
2006-10-06 17:42:59 +04:00
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_progress_bar_update(struct progress_bar *pb, int width, int height)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
wimp_draw redraw;
|
|
|
|
os_error *error;
|
|
|
|
osbool more;
|
|
|
|
os_box cur;
|
|
|
|
|
2006-10-12 17:36:28 +04:00
|
|
|
/* don't allow negative dimensions */
|
|
|
|
width = max(width, 0);
|
|
|
|
height = max(height, 0);
|
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
/* update the animation state */
|
|
|
|
if ((pb->value == 0) || (pb->value == pb->range)) {
|
|
|
|
if (pb->animating)
|
|
|
|
schedule_remove(ro_gui_progress_bar_animate, pb);
|
|
|
|
pb->animating = false;
|
|
|
|
} else {
|
|
|
|
if (!pb->animating)
|
|
|
|
schedule(20, ro_gui_progress_bar_animate, pb);
|
|
|
|
pb->animating = true;
|
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
/* get old and new positions */
|
|
|
|
cur = pb->visible;
|
|
|
|
pb->recalculate = true;
|
2006-10-12 17:36:28 +04:00
|
|
|
ro_gui_progress_bar_calculate(pb, width, height);
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
/* see if the progress bar hasn't moved. we don't need to consider
|
|
|
|
* the left edge moving as this is handled by the icon setting
|
|
|
|
* function */
|
|
|
|
if (cur.x1 == pb->visible.x1)
|
|
|
|
return;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
/* if size has decreased then we must force a redraw */
|
|
|
|
if (cur.x1 > pb->visible.x1) {
|
|
|
|
xwimp_force_redraw(pb->w, pb->visible.x1, pb->visible.y0,
|
|
|
|
cur.x1, pb->visible.y1);
|
|
|
|
return;
|
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
/* perform a minimal redraw update */
|
|
|
|
redraw.w = pb->w;
|
|
|
|
redraw.box = pb->visible;
|
|
|
|
redraw.box.x0 = cur.x1;
|
|
|
|
error = xwimp_update_window(&redraw, &more);
|
|
|
|
if (more)
|
|
|
|
ro_gui_progress_bar_redraw_window(&redraw, pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process a WIMP redraw request
|
|
|
|
*
|
|
|
|
* \param redraw the redraw request to process
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_progress_bar_redraw(wimp_draw *redraw)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
struct progress_bar *pb;
|
|
|
|
os_error *error;
|
|
|
|
osbool more;
|
|
|
|
|
|
|
|
pb = (struct progress_bar *)ro_gui_wimp_event_get_user_data(redraw->w);
|
|
|
|
assert(pb);
|
|
|
|
|
|
|
|
error = xwimp_redraw_window(redraw, &more);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_redraw_window: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (more)
|
|
|
|
ro_gui_progress_bar_redraw_window(redraw, pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Animate the progress bar
|
|
|
|
*
|
|
|
|
* \param p the progress bar to animate
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_progress_bar_animate(void *p)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
wimp_draw redraw;
|
|
|
|
os_error *error;
|
|
|
|
osbool more;
|
|
|
|
struct progress_bar *pb = p;
|
|
|
|
|
|
|
|
if (!progress_icon)
|
2006-11-27 18:35:18 +03:00
|
|
|
return;
|
2006-10-06 17:42:59 +04:00
|
|
|
pb->offset -= 6;
|
|
|
|
if (pb->offset < 0)
|
|
|
|
pb->offset += progress_width * 2;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
if (pb->animating)
|
|
|
|
schedule(20, ro_gui_progress_bar_animate, pb);
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
redraw.w = pb->w;
|
|
|
|
redraw.box = pb->visible;
|
|
|
|
error = xwimp_update_window(&redraw, &more);
|
|
|
|
if (more)
|
|
|
|
ro_gui_progress_bar_redraw_window(&redraw, pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the position of the progress bar
|
|
|
|
*
|
|
|
|
* \param pb the progress bar to recalculate
|
|
|
|
* \param width the width of the progress bar
|
|
|
|
* \param height the height of the progress bar
|
|
|
|
* \return the address of the associated icon, or NULL
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_progress_bar_calculate(struct progress_bar *pb, int width,
|
|
|
|
int height)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
os_error *error;
|
|
|
|
int icon_width, icon_height;
|
|
|
|
int icon_x0 = 0, icon_y0 = 0, progress_x0, progress_x1, progress_ymid = 0;
|
|
|
|
osspriteop_header *icon = NULL;
|
2006-10-12 17:36:28 +04:00
|
|
|
bool icon_redraw = false;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
/* try to use cached values */
|
|
|
|
if ((!pb->recalculate) && (pb->cur_width == width) &&
|
|
|
|
(pb->cur_height == height))
|
|
|
|
return;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
/* update cache status */
|
|
|
|
pb->recalculate = false;
|
|
|
|
pb->cur_width = width;
|
|
|
|
pb->cur_height = height;
|
|
|
|
|
|
|
|
/* get the window dimensions */
|
|
|
|
width -= MARGIN * 2;
|
|
|
|
icon_width = icon_height = 0;
|
|
|
|
progress_x0 = MARGIN;
|
|
|
|
|
|
|
|
/* get the icon information */
|
|
|
|
if (progress_bar_definition.sprite_area != wimpspriteop_AREA) {
|
|
|
|
progress_ymid = height / 2;
|
|
|
|
error = xosspriteop_read_sprite_info(osspriteop_USER_AREA,
|
|
|
|
progress_bar_definition.sprite_area,
|
|
|
|
(osspriteop_id)pb->icon,
|
|
|
|
&icon_width, &icon_height, 0, 0);
|
|
|
|
error = xosspriteop_select_sprite(osspriteop_USER_AREA,
|
|
|
|
progress_bar_definition.sprite_area,
|
|
|
|
(osspriteop_id)pb->icon, &icon);
|
|
|
|
if (!error) {
|
2006-10-13 21:52:30 +04:00
|
|
|
progress_x0 += 32 + MARGIN;
|
|
|
|
width -= 32 + MARGIN;
|
|
|
|
icon_x0 = MARGIN + 16 - icon_width;
|
2006-10-06 17:42:59 +04:00
|
|
|
icon_y0 = progress_ymid - icon_height;
|
2006-10-13 21:52:30 +04:00
|
|
|
if (width < -MARGIN) {
|
|
|
|
icon_x0 += width + MARGIN;
|
2006-10-12 17:36:28 +04:00
|
|
|
icon_redraw = true;
|
|
|
|
}
|
2006-10-06 17:42:59 +04:00
|
|
|
}
|
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-12 17:36:28 +04:00
|
|
|
/* update the icon */
|
|
|
|
if ((pb->icon_obscured) || (icon_redraw)) {
|
|
|
|
if (icon_x0 != pb->icon_x0)
|
2006-10-13 21:52:30 +04:00
|
|
|
xwimp_force_redraw(pb->w, 0, 0, 32 + MARGIN, 65536);
|
2006-10-12 17:36:28 +04:00
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
pb->icon_obscured = icon_redraw;
|
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
progress_x1 = progress_x0;
|
2006-10-13 21:52:30 +04:00
|
|
|
if ((pb->range > 0) && (width > 0))
|
2006-10-06 17:42:59 +04:00
|
|
|
progress_x1 += (width * pb->value) / pb->range;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
pb->visible.x0 = progress_x0;
|
|
|
|
pb->visible.y0 = MARGIN;
|
|
|
|
pb->visible.x1 = progress_x1;
|
|
|
|
pb->visible.y1 = height - MARGIN;
|
|
|
|
pb->icon_x0 = icon_x0;
|
|
|
|
pb->icon_y0 = icon_y0;
|
|
|
|
pb->icon_img = icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraw a section of a progress bar window
|
|
|
|
*
|
|
|
|
* \param redraw the section of the window to redraw
|
|
|
|
* \param pb the progress bar to redraw
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_progress_bar_redraw_window(wimp_draw *redraw,
|
|
|
|
struct progress_bar *pb)
|
|
|
|
{
|
2006-10-06 17:42:59 +04:00
|
|
|
os_error *error;
|
|
|
|
osbool more = true;
|
2011-02-15 01:05:39 +03:00
|
|
|
struct rect clip;
|
2006-10-06 17:42:59 +04:00
|
|
|
int progress_ymid;
|
|
|
|
|
|
|
|
/* initialise the plotters */
|
|
|
|
plot = ro_plotters;
|
|
|
|
ro_plot_origin_x = 0;
|
|
|
|
ro_plot_origin_y = 0;
|
|
|
|
|
|
|
|
/* recalculate the progress bar */
|
|
|
|
ro_gui_progress_bar_calculate(pb, redraw->box.x1 - redraw->box.x0,
|
|
|
|
redraw->box.y1 - redraw->box.y0);
|
|
|
|
progress_ymid = redraw->box.y0 + pb->visible.y0 +
|
|
|
|
((pb->visible.y1 - pb->visible.y0) >> 1);
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-10-06 17:42:59 +04:00
|
|
|
/* redraw the window */
|
|
|
|
while (more) {
|
|
|
|
if (pb->icon)
|
2006-10-12 17:36:28 +04:00
|
|
|
_swix(Tinct_PlotAlpha, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
2006-10-06 17:42:59 +04:00
|
|
|
pb->icon_img,
|
|
|
|
redraw->box.x0 + pb->icon_x0,
|
|
|
|
redraw->box.y0 + pb->icon_y0,
|
|
|
|
tinct_ERROR_DIFFUSE);
|
2006-10-13 21:52:30 +04:00
|
|
|
if (!pb->icon_obscured) {
|
2011-02-15 01:05:39 +03:00
|
|
|
clip.x0 = max(redraw->clip.x0,
|
2006-11-27 18:35:18 +03:00
|
|
|
redraw->box.x0 + pb->visible.x0) >> 1;
|
2011-02-15 01:05:39 +03:00
|
|
|
clip.y0 = -min(redraw->clip.y1,
|
2006-11-27 18:35:18 +03:00
|
|
|
redraw->box.y0 + pb->visible.y1) >> 1;
|
2011-02-15 01:05:39 +03:00
|
|
|
clip.x1 = min(redraw->clip.x1,
|
2006-11-27 18:35:18 +03:00
|
|
|
redraw->box.x0 + pb->visible.x1) >> 1;
|
2011-02-15 01:05:39 +03:00
|
|
|
clip.y1 = -max(redraw->clip.y0,
|
2006-10-13 21:52:30 +04:00
|
|
|
redraw->box.y0 + pb->visible.y0) >> 1;
|
2011-02-15 01:05:39 +03:00
|
|
|
if ((clip.x0 < clip.x1) && (clip.y0 < clip.y1)) {
|
2006-10-13 21:52:30 +04:00
|
|
|
if (progress_icon) {
|
2011-02-15 01:05:39 +03:00
|
|
|
plot.clip(&clip);
|
2006-10-13 21:52:30 +04:00
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
progress_icon,
|
|
|
|
redraw->box.x0 - pb->offset,
|
2006-11-27 18:35:18 +03:00
|
|
|
progress_ymid - progress_height,
|
2006-10-13 21:52:30 +04:00
|
|
|
tinct_FILL_HORIZONTALLY);
|
|
|
|
} else {
|
2011-02-15 01:05:39 +03:00
|
|
|
plot.rectangle(clip.x0, clip.y0,
|
|
|
|
clip.x1, clip.y1,
|
2009-07-09 02:04:40 +04:00
|
|
|
plot_style_fill_red);
|
2006-10-13 21:52:30 +04:00
|
|
|
}
|
2006-10-06 17:42:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
error = xwimp_get_rectangle(redraw, &more);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_rectangle: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|