add & document D. Greaves marquee patch, clean up render.c

This commit is contained in:
marschap
2004-12-30 17:34:02 +00:00
parent df637e1349
commit 72bae4afde
4 changed files with 108 additions and 84 deletions
+1 -1
View File
@@ -348,7 +348,7 @@
<left> <top> <right> <bottom> <direction> <speed> <text> <left> <top> <right> <bottom> <direction> <speed> <text>
</para> </para>
<para> <para>
direction can be "h" or "v". direction can be "h", "m" or "v".
</para> </para>
<para> <para>
speed is the number of movements per rendering stroke (8 times/second). speed is the number of movements per rendering stroke (8 times/second).
+3 -1
View File
@@ -194,7 +194,9 @@ widget_set #screen #id data
The speed is how many display frames to delay The speed is how many display frames to delay
between scrolling. Each display frame is between scrolling. Each display frame is
1/8th of a second, by default. 1/8th of a second, by default.
Direction must be "h" or "v". Direction must be "h" for horizontal, "m" for
marquee style horizontal or "v" for vertical
scrolling..
Positive speeds indicate frames per movement. Positive speeds indicate frames per movement.
Negative speeds indicate movements per frame. Negative speeds indicate movements per frame.
+3 -2
View File
@@ -373,8 +373,9 @@ widget_set_func (Client * c, int argc, char **argv)
/*debug("dir: %c",(char)direction);*/ /*debug("dir: %c",(char)direction);*/
speed = atoi (argv[i + 5]); speed = atoi (argv[i + 5]);
/*debug("speed: %d",speed);*/ /*debug("speed: %d",speed);*/
/* Direction must be v or h*/ /* Direction must be m, v or h*/
if (((char) direction != 'h') && ((char) direction != 'v')) { if (((char) direction != 'h') && ((char) direction != 'v') &&
((char) direction != 'm')) {
sock_send_string (c->sock, "huh? Invalid direction\n"); sock_send_string (c->sock, "huh? Invalid direction\n");
} else { } else {
w->left = left; w->left = left;
+79 -58
View File
@@ -171,16 +171,12 @@ render_frame (LinkedList * list,
#define VerticalScrolling (fscroll == 'v') #define VerticalScrolling (fscroll == 'v')
#define HorizontalScrolling (fscroll == 'h') #define HorizontalScrolling (fscroll == 'h')
char str[BUFSIZE]; /* scratch buffer */ int vis_width = right - left; /* width of visible frame area */
Widget * w; int vis_height = bottom - top; /* height of visible frame area */
int vis_width, vis_height; /* Width and height of visible frame area */
int x, y; int x, y;
int fx, fy; /* Scrolling offset for the frame... */ int fx = 0, fy = 0; /* Scrolling offset for the frame... */
int length, speed; int length, speed;
/*int lines; */
int str_length = BUFSIZE-1; int str_length = BUFSIZE-1;
int reset = 1; int reset = 1;
debug( RPT_DEBUG, "%s( list=%p, fscroll='%c', left=%d, top=%d, " debug( RPT_DEBUG, "%s( list=%p, fscroll='%c', left=%d, top=%d, "
@@ -188,59 +184,56 @@ render_frame (LinkedList * list,
__FUNCTION__, list, fscroll, left,top, right, bottom, __FUNCTION__, list, fscroll, left,top, right, bottom,
fwid, fhgt, fspeed, timer ); fwid, fhgt, fspeed, timer );
vis_width = right - left; /* This is the size of the visible frame area */ /* return on no data or illegal height */
vis_height = bottom - top; if (!list || (fhgt <= 0))
return -1;
fx = 0;
fy = 0;
if (VerticalScrolling) { if (VerticalScrolling) {
if (fspeed > 0) // FIXME: timer may be negative (this should be changed generally)
fy = (timer - fspeed) / fspeed; // only set offset !=0 when fspeed is != 0 and there is something to scroll
else if (fspeed < 0) if (fspeed && (fhgt > vis_height)) {
fy = (-fspeed) * timer; int fy_max = fhgt - vis_height + 1;
if (fy < 0) fy = (fspeed > 0)
fy = 0; ? (timer / fspeed) % fy_max
: (-fspeed * timer) % fy_max;
if (fhgt == 0) { fy = 0; } else { fy %= fhgt; }
if (fy > fhgt - vis_height)
fy = fhgt - vis_height;
fy = max(fy, 0); // safeguard against negative values
}
} else if (HorizontalScrolling) { } else if (HorizontalScrolling) {
/* TODO: Frames don't scroll horizontally yet! */ /* TODO: Frames don't scroll horizontally yet! */
} }
if (!list) /* reset widget list */
return -1;
LL_Rewind (list); LL_Rewind (list);
/* loop over all widgets */
do { do {
w = (Widget *) LL_Get (list); char str[BUFSIZE]; /* scratch buffer */
Widget *w = (Widget *) LL_Get (list);
if (!w) if (!w)
return -1; return -1;
/* TODO: Make this cleaner and more flexible!*/ /* TODO: Make this cleaner and more flexible!*/
switch (w->type) { switch (w->type) {
case WID_STRING: case WID_STRING:
if (w->x>0 && w->y>0 && w->text) { if ((w->x > 0) && (w->y > 0) && (w->text) &&
if ((w->y <= vis_height + fy) && (w->y > fy)) { (w->y <= vis_height + fy) && (w->y > fy)) {
if (w->x > vis_width) w->x=vis_width; w->x = min(w->x, vis_width);
str_length = abs(vis_width - w->x + 1); str_length = min(vis_width - w->x + 1, BUFSIZE - 1);
if (str_length >= BUFSIZE)
str_length = BUFSIZE - 1;
strncpy (str, w->text, str_length); strncpy (str, w->text, str_length);
str[str_length] = 0; str[str_length] = 0;
drivers_string (w->x + left, w->y + top - fy, str); drivers_string (w->x + left, w->y + top - fy, str);
} }
}
break; break;
case WID_HBAR: case WID_HBAR:
if (reset) { if (reset) {
//drivers_init_hbar (); //drivers_init_hbar ();
reset = 0; reset = 0;
} }
if ((w->x > 0) && (w->y > 0)) { if ((w->x > 0) && (w->y > 0) &&
if ((w->y <= vis_height + fy) && (w->y > fy)) { (w->y <= vis_height + fy) && (w->y > fy)) {
if (w->length > 0) { if (w->length > 0) {
if ((w->length / display_props->cellwidth) < vis_width - w->x + 1) { if ((w->length / display_props->cellwidth) < vis_width - w->x + 1) {
/*was: drivers_hbar (w->x + left, w->y + top - fy, w->length); */ /*was: drivers_hbar (w->x + left, w->y + top - fy, w->length); */
@@ -263,7 +256,6 @@ render_frame (LinkedList * list,
*/ */
} }
} }
}
break; break;
case WID_VBAR: /* FIXME: Vbars don't work in frames!*/ case WID_VBAR: /* FIXME: Vbars don't work in frames!*/
if (reset) { if (reset) {
@@ -299,8 +291,7 @@ render_frame (LinkedList * list,
drivers_icon (w->x + left + 1, w->y + top, ICON_BLOCK_FILLED); drivers_icon (w->x + left + 1, w->y + top, ICON_BLOCK_FILLED);
length = strlen (w->text); length = strlen (w->text);
if (length >= BUFSIZE) length = min(length, BUFSIZE - 1);
length = BUFSIZE - 1;
if (length <= vis_width - 6) { if (length <= vis_width - 6) {
strncpy (str, w->text, length); strncpy (str, w->text, length);
str[length] = 0; str[length] = 0;
@@ -311,19 +302,15 @@ render_frame (LinkedList * list,
x = timer / speed; x = timer / speed;
y = x / length; y = x / length;
x %= (length); x %= length;
if (x < 0) x = max(x, 0);
x = 0;
if (x > length - (vis_width - 6)) if (x > length - (vis_width - 6))
x = length - (vis_width - 6); x = length - (vis_width - 6);
if (y & 1) /* Scrolling backwards...*/ if (y & 1) /* Scrolling backwards...*/
{
x = (length - (vis_width - 6)) - x; x = (length - (vis_width - 6)) - x;
}
str_length = abs(vis_width - 6); str_length = abs(vis_width - 6);
if (str_length >= BUFSIZE) str_length = min(str_length, BUFSIZE -1);
str_length = BUFSIZE -1;
strncpy (str, w->text + x, str_length); strncpy (str, w->text + x, str_length);
str[str_length] = 0; str[str_length] = 0;
x = vis_width - 1; x = vis_width - 1;
@@ -340,18 +327,54 @@ render_frame (LinkedList * list,
{ {
int offset; int offset;
int screen_width; int screen_width;
if (!w->text) if (!w->text)
break; break;
if (w->right < w->left) if (w->right < w->left)
break; break;
/*debug(RPT_DEBUG, "%s: %s %d",__FUNCTION__,w->text,timer);*/ /*debug(RPT_DEBUG, "%s: %s %d",__FUNCTION__,w->text,timer);*/
screen_width = abs(w->right - w->left + 1); screen_width = abs(w->right - w->left + 1);
if (screen_width >= BUFSIZE) screen_width = min(screen_width, BUFSIZE -1);
screen_width = BUFSIZE -1;
switch (w->length) { /* actually, direction...*/ switch (w->length) { /* actually, direction...*/
/* FIXED: Horz scrollers don't show the /* FIXED: Horz scrollers don't show the
* last letter in the string... (1-off error?) * last letter in the string... (1-off error?)
*/ */
case 'm': // Marquee
length = strlen (w->text);
if (length <= screen_width) {
/* it fits within the box, just render it */
drivers_string (w->left, w->top, w->text);
} else {
int necessaryTimeUnits = 0;
if (w->speed > 0) {
necessaryTimeUnits = length * w->speed;
offset = (timer % (length * w->speed)) / w->speed;
} else if (w->speed < 0) {
necessaryTimeUnits = length / (w->speed * -1);
offset = (timer % (length / (w->speed * -1))) * w->speed * -1;
} else {
offset = 0;
}
if (offset <= length) {
int room = screen_width - (length - offset);
strncpy (str, &w->text[offset], screen_width);
// if there's more room, restart at the beginning
if (room > 0) {
strncat (str, w->text, room);
}
str[screen_width] = '\0';
/*debug(RPT_DEBUG, "scroller %s : %d", str, length-offset);*/
} else {
str[0] = '\0';
}
drivers_string (w->left, w->top, str);
}
break;
case 'h': case 'h':
length = strlen (w->text) + 1; length = strlen (w->text) + 1;
if (length <= screen_width) { if (length <= screen_width) {
@@ -360,6 +383,7 @@ render_frame (LinkedList * list,
} else { } else {
int effLength = length - screen_width; int effLength = length - screen_width;
int necessaryTimeUnits = 0; int necessaryTimeUnits = 0;
if (w->speed > 0) { if (w->speed > 0) {
necessaryTimeUnits = effLength * w->speed; necessaryTimeUnits = effLength * w->speed;
if (((timer / (effLength * w->speed)) % 2) == 0) { if (((timer / (effLength * w->speed)) % 2) == 0) {
@@ -400,6 +424,7 @@ render_frame (LinkedList * list,
case 'v': case 'v':
{ {
int i = 0; int i = 0;
length = strlen (w->text); length = strlen (w->text);
if (length <= screen_width) { if (length <= screen_width) {
/* no scrolling required... */ /* no scrolling required... */
@@ -408,6 +433,7 @@ render_frame (LinkedList * list,
int lines_required = (length / screen_width) int lines_required = (length / screen_width)
+ (length % screen_width ? 1 : 0); + (length % screen_width ? 1 : 0);
int available_lines = (w->bottom - w->top + 1); int available_lines = (w->bottom - w->top + 1);
if (lines_required <= available_lines) { if (lines_required <= available_lines) {
/* easy...*/ /* easy...*/
for (i = 0; i < lines_required; i++) { for (i = 0; i < lines_required; i++) {
@@ -419,6 +445,7 @@ render_frame (LinkedList * list,
int necessaryTimeUnits = 0; int necessaryTimeUnits = 0;
int effLines = lines_required - available_lines + 1; int effLines = lines_required - available_lines + 1;
int begin = 0; int begin = 0;
/*debug(RPT_DEBUG, "length: %d sw: %d lines req: %d avail lines: %d effLines: %d ",length,screen_width,lines_required,available_lines,effLines);*/ /*debug(RPT_DEBUG, "length: %d sw: %d lines req: %d avail lines: %d effLines: %d ",length,screen_width,lines_required,available_lines,effLines);*/
if (w->speed > 0) { if (w->speed > 0) {
necessaryTimeUnits = effLines * w->speed; necessaryTimeUnits = effLines * w->speed;
@@ -465,20 +492,14 @@ render_frame (LinkedList * list,
/* FIXME: doesn't handle nested frames quite right! /* FIXME: doesn't handle nested frames quite right!
* doesn't handle scrolling in nested frames at all... * doesn't handle scrolling in nested frames at all...
*/ */
int new_left, new_top, new_right, new_bottom; int new_left = left + w->left - 1;
new_left = left + w->left - 1; int new_top = top + w->top - 1;
new_top = top + w->top - 1; int new_right = min(left + w->right, right);
new_right = left + w->right; int new_bottom = min(top + w->bottom, bottom);
new_bottom = top + w->bottom;
if (new_right > right) if ((new_left < right) && (new_top < bottom)) /* Render only if it's visible...*/
new_right = right;
if (new_bottom > bottom)
new_bottom = bottom;
if (new_left >= right || new_top >= bottom) { /* Do nothing if it's invisible...*/
} else {
render_frame (w->frame_screen->widgetlist, w->length, new_left, new_top, new_right, new_bottom, w->width, w->height, w->speed, timer); render_frame (w->frame_screen->widgetlist, w->length, new_left, new_top, new_right, new_bottom, w->width, w->height, w->speed, timer);
} }
}
break; break;
case WID_NUM: /* FIXME: doesn't work in frames...*/ case WID_NUM: /* FIXME: doesn't work in frames...*/
/* NOTE: y=10 means COLON (:)*/ /* NOTE: y=10 means COLON (:)*/