MCPcopy Create free account
hub / github.com/SimHacker/micropolis / CanvasSetOrigin

Function CanvasSetOrigin

micropolis-activity/src/tk/tkcanvas.c:3461–3520  ·  view source on GitHub ↗
(canvasPtr, xOrigin, yOrigin)

Source from the content-addressed store, hash-verified

3459 result = Tcl_VarEval(canvasPtr->interp, canvasPtr->yScrollCmd, args,
3460 (char *) NULL);
3461 if (result != TCL_OK) {
3462 TkBindError(canvasPtr->interp);
3463 }
3464 Tcl_ResetResult(canvasPtr->interp);
3465 }
3466}
3467
3468
3469/*
3470 *--------------------------------------------------------------
3471 *
3472 * CanvasSetOrigin --
3473 *
3474 * This procedure is invoked to change the mapping between
3475 * canvas coordinates and screen coordinates in the canvas
3476 * window.
3477 *
3478 * Results:
3479 * None.
3480 *
3481 * Side effects:
3482 * The canvas will be redisplayed to reflect the change in
3483 * view. In addition, scrollbars will be updated if there
3484 * are any.
3485 *
3486 *--------------------------------------------------------------
3487 */
3488
3489static void
3490CanvasSetOrigin(canvasPtr, xOrigin, yOrigin)
3491 register Tk_Canvas *canvasPtr; /* Information about canvas. */
3492 int xOrigin; /* New X origin for canvas (canvas
3493 * x-coord corresponding to left edge
3494 * of canvas window). */
3495 int yOrigin; /* New Y origin for canvas (canvas
3496 * y-coord corresponding to top edge
3497 * of canvas window). */
3498{
3499 /*
3500 * Adjust the origin if necessary to keep as much as possible of the
3501 * canvas in the view.
3502 */
3503
3504 if ((canvasPtr->confine) && (canvasPtr->regionString != NULL)) {
3505 int windowWidth, windowHeight, canvasWidth, canvasHeight;
3506
3507 windowWidth = Tk_Width(canvasPtr->tkwin);
3508 windowHeight = Tk_Height(canvasPtr->tkwin);
3509 canvasWidth = canvasPtr->scrollX2 - canvasPtr->scrollX1;
3510 canvasHeight = canvasPtr->scrollY2 - canvasPtr->scrollY1;
3511 if (canvasWidth < windowWidth) {
3512 xOrigin = (canvasPtr->scrollX1) - (windowWidth-canvasWidth)/2;
3513 } else if (xOrigin < canvasPtr->scrollX1) {
3514 xOrigin = canvasPtr->scrollX1;
3515 } else if (xOrigin > (canvasPtr->scrollX2 - windowWidth)) {
3516 xOrigin = canvasPtr->scrollX2 - windowWidth;
3517 }
3518 if (canvasHeight < windowHeight) {

Callers 3

CanvasWidgetCmdFunction · 0.85
ConfigureCanvasFunction · 0.85
CanvasEventProcFunction · 0.85

Calls 1

EventuallyRedrawAreaFunction · 0.85

Tested by

no test coverage detected