Lines Matching defs:sw

107 static void GetGC ( ScaleWidget sw );
108 static void GetInitialScaleValues ( ScaleWidget sw );
109 static void GetRectangleBuffer ( ScaleWidget sw, Cardinal buffer_size );
112 static void BuildTable ( ScaleWidget sw );
113 static void FlushRectangles ( ScaleWidget sw, Drawable drawable, GC gc );
114 static void FillRectangle ( ScaleWidget sw, Drawable drawable, GC gc,
117 static void ScaleImage ( ScaleWidget sw, Drawable drawable,
121 static int FindPixel ( ScaleWidget sw, Position x, Position y,
124 static void TryResize ( ScaleWidget sw );
125 static void Precision ( ScaleWidget sw );
126 static void Proportional ( ScaleWidget sw );
127 static void GetScaledSize ( ScaleWidget sw );
128 static void GetScaleValues ( ScaleWidget sw );
129 static void Unscale ( ScaleWidget sw );
130 static void Autoscale ( ScaleWidget sw );
131 static void PositionImage ( ScaleWidget sw );
216 GetGC(ScaleWidget sw)
220 values.foreground = sw->scale.foreground_pixel;
221 values.background = sw->core.background_pixel;
224 sw->scale.gc = XtGetGC((Widget) sw,
236 GetInitialScaleValues(ScaleWidget sw)
238 if (sw->scale.proportional) {
239 sw->scale.scale_x = sw->scale.scale_y =
240 ((sw->scale.aspect_ratio > 1.0) ?
241 sw->scale.aspect_ratio : 1.0 / sw->scale.aspect_ratio) *
242 (sw->scale.precision > 1.0 ?
243 sw->scale.precision : 1.0);
244 Proportional(sw); /* need to cut them down to proper values */
247 sw->scale.scale_x = sw->scale.scale_y = 1.0;
254 GetRectangleBuffer(ScaleWidget sw, Cardinal buffer_size)
265 sw->scale.rectangles = (XRectangle *)
266 XtRealloc((char *) sw->scale.rectangles,
268 sw->scale.buffer_size = buffer_size;
347 BuildTable(ScaleWidget sw)
355 XtFree((char *) sw->scale.table.x);
356 XtFree((char *) sw->scale.table.y);
357 XtFree((char *) sw->scale.table.width);
358 XtFree((char *) sw->scale.table.height);
359 sw->scale.table.x =
360 (Position *) XtMalloc(sizeof(Position) * sw->scale.image->width);
361 sw->scale.table.y =
362 (Position *) XtMalloc(sizeof(Position) * sw->scale.image->height);
363 sw->scale.table.width =
364 (Dimension *) XtMalloc(sizeof(Dimension) * sw->scale.image->width);
365 sw->scale.table.height =
366 (Dimension *) XtMalloc(sizeof(Dimension) * sw->scale.image->height);
369 for (x = 0; x < sw->scale.image->width; x++) {
370 sw->scale.table.x[(int) x] = (Position) myrint(sw->scale.scale_x * x);
371 sw->scale.table.width[(int) x] = (Dimension)
372 myrint(sw->scale.scale_x *(x + 1)) - myrint(sw->scale.scale_x * x);
374 for (y = 0; y < sw->scale.image->height; y++) {
375 sw->scale.table.y[(int) y] = (Position) myrint(sw->scale.scale_y * y);
376 sw->scale.table.height[(int) y] = (Dimension)
377 myrint(sw->scale.scale_y *(y + 1)) - myrint(sw->scale.scale_y * y);
385 FlushRectangles(ScaleWidget sw, Drawable drawable, GC gc)
387 XFillRectangles(XtDisplay(sw), drawable, gc,
388 sw->scale.rectangles, sw->scale.nrectangles);
390 sw->scale.nrectangles = 0;
397 FillRectangle(ScaleWidget sw, Drawable drawable, GC gc,
401 if (sw->scale.nrectangles == sw->scale.buffer_size)
402 FlushRectangles(sw, drawable, gc);
404 sw->scale.rectangles[(int) sw->scale.nrectangles].x = x;
405 sw->scale.rectangles[(int) sw->scale.nrectangles].y = y;
406 sw->scale.rectangles[(int) sw->scale.nrectangles].width = width;
407 sw->scale.rectangles[(int) sw->scale.nrectangles].height = height;
409 ++sw->scale.nrectangles;
416 ScaleImage(ScaleWidget sw, Drawable drawable, Position img_x, Position img_y,
430 img_x = min(max(img_x, 0), (Position) sw->scale.image->width - 1);
431 img_y = min(max(img_y, 0), (Position) sw->scale.image->height - 1);
433 min(img_width, (Dimension)(sw->scale.image->width - (Dimension)img_x));
435 min(img_height, (Dimension)(sw->scale.image->height - (Dimension)img_y));
437 if (sw->scale.scale_x == 1.0 && sw->scale.scale_y == 1.0)
438 XPutImage(XtDisplay(sw), drawable, sw->scale.gc, sw->scale.image,
442 dst_x = dst_x - sw->scale.table.x[(int) img_x];
443 dst_y = dst_y - sw->scale.table.y[(int) img_y];
445 gc = XCreateGC(XtDisplay(sw), drawable, 0, NULL);
448 XChangeGC(XtDisplay(sw), gc, GCFunction, &gcv);
451 gcv.background = sw->core.background_pixel;
452 XChangeGC(XtDisplay(sw), gc, GCBackground, &gcv);
457 XChangeGC(XtDisplay(sw), gc, GCForeground, &gcv);
458 XFillRectangle(XtDisplay(sw), drawable, gc,
459 sw->scale.table.x[(int) img_x] + dst_x,
460 sw->scale.table.y[(int) img_y] + dst_y,
461 sw->scale.table.x[(int) img_x + img_width - 1] -
462 sw->scale.table.x[(int) img_x],
463 sw->scale.table.y[(int) img_y + img_height - 1] -
464 sw->scale.table.y[(int) img_y]);
466 if (sw->scale.image->format == XYBitmap) {
469 pixel = XGetPixel(sw->scale.image, x, y);
471 FillRectangle(sw, drawable, sw->scale.gc,
472 sw->scale.table.x[(int) x] + dst_x,
473 sw->scale.table.y[(int) y] + dst_y,
474 sw->scale.table.width[(int) x],
475 sw->scale.table.height[(int) y]);
477 FlushRectangles(sw, drawable, sw->scale.gc);
482 pixel = XGetPixel(sw->scale.image, x, y);
486 XChangeGC(XtDisplay(sw), gc, GCForeground, &gcv);
488 XFillRectangle(XtDisplay(sw), drawable, gc,
489 sw->scale.table.x[(int) x] + dst_x,
490 sw->scale.table.y[(int) y] + dst_y,
491 sw->scale.table.width[(int) x],
492 sw->scale.table.height[(int) y]);
496 XFreeGC(XtDisplay(sw), gc);
504 FindPixel(ScaleWidget sw, Position x, Position y,
506 /* (x,y) == (0,0) where image starts in sw window*/
508 if (*img_x < 0 || *img_x >= sw->scale.image->width
510 *img_y < 0 || *img_y >= sw->scale.image->height)
513 if (sw->scale.table.x[(int) *img_x] >= x) {
515 return FindPixel(sw, x, y, img_x, img_y, img_pixel);
517 if (sw->scale.table.x[(int) *img_x] +
518 (Position)sw->scale.table.width[(int) *img_x] < x) {
520 return FindPixel(sw, x, y, img_x, img_y, img_pixel);
522 if (sw->scale.table.y[(int) *img_y] >= y) {
524 return FindPixel(sw, x, y, img_x, img_y, img_pixel);
526 if (sw->scale.table.y[(int) *img_y] +
527 (Position)sw->scale.table.height[(int) *img_y] < y) {
529 return FindPixel(sw, x, y, img_x, img_y, img_pixel);
532 *img_pixel = XGetPixel(sw->scale.image, *img_x, *img_y);
544 ScaleWidget sw = (ScaleWidget) w;
546 x -= sw->scale.x;
547 y -= sw->scale.y;
549 *img_x = (Position) floor(x / sw->scale.scale_x);
550 *img_y = (Position) floor(y / sw->scale.scale_y);
552 return FindPixel(sw, x, y, img_x, img_y, img_pixel);
561 ScaleWidget sw = (ScaleWidget) w;
567 if (event->xexpose.x < sw->scale.x) {
570 (sw->scale.x - event->xexpose.x);
573 x = event->xexpose.x - sw->scale.x;
577 if (event->xexpose.y < sw->scale.y) {
580 (sw->scale.y - event->xexpose.y);
583 y = event->xexpose.y - sw->scale.y;
587 img_x = min(max((Position) floor(x / sw->scale.scale_x), 0),
588 (Position) sw->scale.image->width - 1);
590 img_y = min(max((Position) floor(y / sw->scale.scale_y), 0),
591 (Position) sw->scale.image->height - 1);
593 if (sw->core.visible) {
594 ScaleImage(sw, XtWindow(w),
596 sw->scale.x + sw->scale.table.x[(int) img_x],
597 sw->scale.y + sw->scale.table.y[(int) img_y],
599 / sw->scale.scale_x) + 1,
601 / sw->scale.scale_y) + 1);
610 TryResize(ScaleWidget sw)
616 floor(sw->scale.image->width * sw->scale.scale_x)
617 + 2 * sw->scale.internal_width;
619 floor(sw->scale.image->height * sw->scale.scale_y)
620 + 2 * sw->scale.internal_height;
623 /* SUPPRESS 530 */XtMakeResizeRequest((Widget)sw,width,height,&width,&height))
627 sw->core.width = width;
628 sw->core.height = height;
636 Precision(ScaleWidget sw)
638 if (sw->scale.scale_x != 1.0)
639 sw->scale.scale_x = floor(sw->scale.scale_x / sw->scale.precision)
640 * sw->scale.precision;
642 if (sw->scale.scale_y != 1.0)
643 sw->scale.scale_y = floor(sw->scale.scale_y / sw->scale.precision)
644 * sw->scale.precision;
651 Proportional(ScaleWidget sw)
655 scale_x = sw->scale.scale_y / sw->scale.aspect_ratio;
656 scale_y = sw->scale.scale_x * sw->scale.aspect_ratio;
658 if (scale_x <= sw->scale.scale_x && scale_y <= sw->scale.scale_y) {
660 sw->scale.scale_x = scale_x;
662 sw->scale.scale_y = scale_y;
664 else if (scale_x <= sw->scale.scale_x)
665 sw->scale.scale_x = scale_x;
666 else if (scale_y <= sw->scale.scale_y)
667 sw->scale.scale_y = scale_y;
671 x_ratio = scale_x / sw->scale.scale_x;
672 y_ratio = scale_y / sw->scale.scale_y;
675 sw->scale.scale_y /= x_ratio;
677 sw->scale.scale_x /= y_ratio;
680 if (fabs(sw->scale.scale_x / sw->scale.scale_y * sw->scale.aspect_ratio
681 - 1.0) > sw->scale.precision)
689 GetScaledSize(ScaleWidget sw)
691 sw->scale.width = (Dimension)
692 max(myrint(sw->scale.scale_x * sw->scale.image->width), 1);
693 sw->scale.height = (Dimension)
694 max(myrint(sw->scale.scale_y * sw->scale.image->height), 1);
701 GetScaleValues(ScaleWidget sw)
707 sw->scale.scale_x =
708 max((int)(sw->core.width - 2 * sw->scale.internal_width), 1)
709 / sw->scale.image->width;
711 sw->scale.scale_y =
712 max((int)(sw->core.height - 2 * sw->scale.internal_height), 1)
713 / sw->scale.image->height;
720 Unscale(ScaleWidget sw)
722 sw->scale.scale_x = sw->scale.scale_y = 1.0;
724 GetScaledSize(sw);
726 BuildTable(sw);
733 Autoscale(ScaleWidget sw)
735 GetScaleValues(sw);
737 if (sw->scale.proportional) Proportional(sw);
739 Precision(sw);
741 GetScaledSize(sw);
743 BuildTable(sw);
750 PositionImage(ScaleWidget sw)
755 sw->scale.x = (Position)
756 (sw->core.width - sw->scale.width) / 2;
757 sw->scale.y = (Position)
758 (sw->core.height - sw->scale.height) / 2;
761 if (sw->scale.gravity & WestGravity) {
763 if (sw->scale.gravity & EastGravity) {
765 if (sw->scale.gravity & NorthGravity) {
767 if (sw->scale.gravity & SouthGravity) {
778 ScaleWidget sw = (ScaleWidget) w;
780 if (sw->scale.autoscale) Autoscale(sw);
782 PositionImage(sw);
791 ScaleWidget sw = (ScaleWidget) wid;
793 sw->scale.visual, *vmask, attr);
802 ScaleWidget sw = (ScaleWidget) w;
804 XtFree((char *) sw->scale.table.x);
805 XtFree((char *) sw->scale.table.y);
806 XtFree((char *) sw->scale.table.width);
807 XtFree((char *) sw->scale.table.height);
809 XtFree((char *) sw->scale.rectangles);
811 XtReleaseGC(w, sw->scale.gc);
813 XDestroyImage(sw->scale.image);
968 ScaleWidget sw = (ScaleWidget) w;
970 Unscale(sw);
971 PositionImage(sw);
982 ScaleWidget sw = (ScaleWidget) w;
984 Autoscale(sw);
985 PositionImage(sw);
996 ScaleWidget sw = (ScaleWidget) w;
998 GetInitialScaleValues(sw);
1000 if (sw->scale.proportional) Proportional(sw);
1001 Precision(sw);
1002 if (sw->scale.resize)
1003 TryResize(sw);
1004 GetScaledSize(sw);
1005 BuildTable(sw);
1006 PositionImage(sw);
1051 ScaleWidget sw = (ScaleWidget) w;
1055 sw->scale.width,
1056 sw->scale.height,
1057 sw->scale.image->depth);
1058 ScaleImage(sw, pixmap,
1060 (Dimension) sw->scale.image->width,
1061 (Dimension) sw->scale.image->height);