void
XawViewportSetLocation
(
 Widget gw,
#if NeedWidePrototypes
 double xoff, double yoff
#else
 float xoff, float yoff
#endif
 )
{
    ViewportWidget w = (ViewportWidget)gw;
    Widget child = w->viewport.child;
    int x, y;

    if (xoff > 1.0)			/* scroll to right */
	x = XtWidth(child);
    else if (xoff < 0.0)		/* if the offset is < 0.0 nothing */
	x = XtX(child);
    else
	x = (float)XtWidth(child) * xoff;

    if (yoff > 1.0)
	y = XtHeight(child);
    else if (yoff < 0.0)
	y = XtY(child);
    else
	y = (float)XtHeight(child) * yoff;

    MoveChild (w, -x, -y);
}
Example #2
0
void *HouseThread(void *arg) {
	UpdateObjectType *msg;
	int x;
	int timeCounter = 0;
	int childCounter = 0;

	signal(SIGUSR1, FastExit);

	srand48(time(NULL));

	for(;;) {
		pthread_mutex_lock(&updateMutex);
		if(updateQueue) {
			msg = Dequeue(&updateQueue);
			pthread_mutex_unlock(&updateMutex);
			pthread_mutex_lock(&clientMutex);
			for(x = 0; x < MAX_CLIENTS; x++) {
				if(client[x].ns > -1) {
					write(client[x].ns, msg, sizeof(UpdateObjectType));
				}
			}
			pthread_mutex_unlock(&clientMutex);
			free(msg);
			pthread_mutex_lock(&updateMutex);
		}
		pthread_mutex_unlock(&updateMutex);
		usleep(SLEEP_TIME);

		++timeCounter;
		if(timeCounter == TIME_MODULUS) {
			timeCounter = 0;
			pthread_mutex_lock(&houseMutex);
			houseObject.level[1] += 5;
			if((houseObject.level[1] & 0xFF) >= 60) {
				houseObject.level[1] &= ~0xFF;
				houseObject.level[1]
					= (houseObject.level[1] + 0x100) % (24 << 8);
			}
			pthread_mutex_unlock(&houseMutex);
			msg = GetHouseUpdate();
			pthread_mutex_lock(&updateMutex);
			if(!updateQueue) {
				CreateQueue(&updateQueue);
			}
			Enqueue(&updateQueue, msg);
			pthread_mutex_unlock(&updateMutex);
		}

		childCounter = (childCounter + 1) % CHILD_MODULUS;
		if(!childCounter) {
			MoveChild();
		}
	}

	return NULL;
}
static void
ScrollUpDownProc(Widget widget, XtPointer closure, XtPointer call_data)
{
    ViewportWidget w = (ViewportWidget)closure;
    Widget child = w->viewport.child;
    int pix = (long)call_data;
    int x, y;

    if (child == NULL)
	return;

    x = XtX(child) - (widget == w->viewport.horiz_bar ? pix : 0);
    y = XtY(child) - (widget == w->viewport.vert_bar ? pix : 0);
    MoveChild(w, x, y);
}
/*ARGSUSED*/
static void
ThumbProc(Widget widget, XtPointer closure, XtPointer call_data)
{
    ViewportWidget w = (ViewportWidget)closure;
    Widget child = w->viewport.child;
    float percent = *(float *)call_data;
    int x, y;

    if (child == NULL)
	return;

    if (widget == w->viewport.horiz_bar)
	x = -percent * XtWidth(child);
    else
	x = XtX(child);

    if (widget == w->viewport.vert_bar)
	y = -percent * XtHeight(child);
    else
	y = XtY(child);

    MoveChild(w, x, y);
}
void
XawViewportSetCoordinates(Widget gw,
#if NeedWidePrototypes
	int x, int y
#else
	Position x, Position y
#endif
)
{
    ViewportWidget w = (ViewportWidget)gw;
    Widget child = w->viewport.child;

    if (x > XtWidth(child))
	x = XtWidth(child);
    else if (x < 0)
	x = XtX(child);

    if (y > XtHeight(child))
	y = XtHeight(child);
    else if (y < 0)
	y = XtY(child);

    MoveChild (w, -x, -y);
}
static void
ComputeLayout(Widget widget, Bool query, Bool destroy_scrollbars)
{
    ViewportWidget w = (ViewportWidget)widget;
    Widget child = w->viewport.child;
    Widget clip = w->viewport.clip;
    ViewportConstraints constraints =
	(ViewportConstraints)clip->core.constraints;
    Bool needshoriz, needsvert;
    int clip_width, clip_height;
    XtWidgetGeometry intended;

    if (child == NULL)
	return;

    clip_width = XtWidth(w);
    clip_height = XtHeight(w);
    intended.request_mode = CWBorderWidth;
    intended.border_width = 0;

    if (w->viewport.forcebars) {
	needsvert = w->viewport.allowvert;
	needshoriz = w->viewport.allowhoriz;
	ComputeWithForceBars(widget, query, &intended,
			     &clip_width, &clip_height);
    }
    else {
	Dimension prev_width, prev_height;
	XtGeometryMask prev_mode;
	XtWidgetGeometry preferred;

	needshoriz = needsvert = False;

	/*
	 * intended.{width,height} caches the eventual child dimensions,
	 * but we don't set the mode bits until after we decide that the
	 * child's preferences are not acceptable
	 */
	if (!w->viewport.allowhoriz)
	    intended.request_mode |= CWWidth;

	if (XtWidth(child) < clip_width)
	    intended.width = clip_width;
	else
	    intended.width = XtWidth(child);

	if (XtHeight(child) < clip_height)
	    intended.height = clip_height;
	else
	    intended.height = XtHeight(child);

	if (!w->viewport.allowvert)
	    intended.request_mode |= CWHeight;

	if (!query) {
	    preferred.width = XtWidth(child);
	    preferred.height = XtHeight(child);
	}
	do { /* while intended != prev  */
	    if (query) {
		(void)XtQueryGeometry(child, &intended, &preferred);
		if (!(preferred.request_mode & CWWidth))
		    preferred.width = intended.width;
		if (!(preferred.request_mode & CWHeight))
		    preferred.height = intended.height;
	    }
	    prev_width = intended.width;
	    prev_height = intended.height;
	    prev_mode = intended.request_mode;
	    /*
	     * note that having once decided to turn on either bar
	     * we'll not change our mind until we're next resized,
	     * thus avoiding potential oscillations
	     */
#define CheckHoriz() \
	    if (w->viewport.allowhoriz &&				\
		preferred.width > clip_width) {				\
		if (!needshoriz) {					\
		    Widget bar;						\
									\
		    needshoriz = True;					\
		    if ((bar = w->viewport.horiz_bar) == NULL)		\
			bar = CreateScrollbar(w, True);			\
		    clip_height -= XtHeight(bar) + XtBorderWidth(bar);	\
		    if (clip_height < 1)				\
			clip_height = 1;				\
		}							\
		intended.width = preferred.width;			\
	    }

	    CheckHoriz();
	    if (w->viewport.allowvert && preferred.height > clip_height) {
		if (!needsvert) {
		    Widget bar;
		    needsvert = True;
		    if ((bar = w->viewport.vert_bar) == NULL)
			bar = CreateScrollbar(w, False);
		    clip_width -= XtWidth(bar) + XtBorderWidth(bar);
		    if (clip_width < 1)
			clip_width = 1;
		    CheckHoriz();
		}
		intended.height = preferred.height;
	    }
	    if (!w->viewport.allowhoriz || preferred.width < clip_width) {
		intended.width = clip_width;
		intended.request_mode |= CWWidth;
	    }
	    if (!w->viewport.allowvert || preferred.height < clip_height) {
		intended.height = clip_height;
		intended.request_mode |= CWHeight;
	    }
	} while (intended.request_mode != prev_mode
		 || (intended.request_mode & CWWidth
		     && intended.width != prev_width)
		 || (intended.request_mode & CWHeight
		     && intended.height != prev_height));
    }

    if (XtIsRealized(clip))
	XRaiseWindow(XtDisplay(clip), XtWindow(clip));

    XtMoveWidget(clip,
		 needsvert ? w->viewport.useright ? 0 :
		 XtWidth(w->viewport.vert_bar)
		 + XtBorderWidth(w->viewport.vert_bar) : 0,
		 needshoriz ? w->viewport.usebottom ? 0 :
		 XtHeight(w->viewport.horiz_bar)
		 + XtBorderWidth(w->viewport.horiz_bar) : 0);
    XtResizeWidget(clip, clip_width, clip_height, 0);

    if (w->viewport.horiz_bar != NULL) {
	Widget bar = w->viewport.horiz_bar;

	if (!needshoriz) {
	    constraints->form.vert_base = NULL;
	    if (destroy_scrollbars) {
		XtDestroyWidget(bar);
		w->viewport.horiz_bar = NULL;
	    }
	}
	else {
	    int bw = XtBorderWidth(bar);

	    XtResizeWidget(bar, clip_width, XtHeight(bar), bw);
	    XtMoveWidget(bar,
			 needsvert && !w->viewport.useright
			 ? XtWidth(w->viewport.vert_bar) : -bw,
			 w->viewport.usebottom
			 ? XtHeight(w) - XtHeight(bar) - bw : -bw);
	    XtSetMappedWhenManaged(bar, True);
	}
    }

    if (w->viewport.vert_bar != NULL) {
	Widget bar = w->viewport.vert_bar;

	if (!needsvert)	{
	    constraints->form.horiz_base = NULL;
	    if (destroy_scrollbars) {
		XtDestroyWidget(bar);
		w->viewport.vert_bar = NULL;
	    }
	}
	else {
	    int bw = bar->core.border_width;

	    XtResizeWidget(bar, XtWidth(bar), clip_height, bw);
	    XtMoveWidget(bar,
			w->viewport.useright
			? XtWidth(w) - XtWidth(bar) - bw : -bw,
			needshoriz && !w->viewport.usebottom
			? XtHeight(w->viewport.horiz_bar) : -bw);
	   XtSetMappedWhenManaged(bar, True);
	}
    }

    if (child != NULL) {
	XtResizeWidget(child, intended.width, intended.height, 0);
	MoveChild(w, needshoriz ? XtX(child) : 0,	needsvert ? XtY(child) : 0);
    }

    SendReport (w, XawPRAll);
}