Ignore:
Timestamp:
Jun 20, 2002, 10:46:29 PM (23 years ago)
Author:
umoeller
Message:

More pager fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/gpih.c

    r173 r178  
    17471747    HPS     hpsMem;
    17481748    BITMAPINFOHEADER2 bmi;
    1749     // RECTL   rclSource;
    17501749
    17511750    if (hbmSource)
     
    23422341
    23432342/*
    2344  *@@ gpihIcon2Bitmap:
     2343 * gpihIcon2Bitmap:
    23452344 *      this paints the given icon/pointer into
    23462345 *      a bitmap. Note that if the bitmap is
     
    23512350 *      Returns FALSE upon errors.
    23522351 *
    2353  *@@added V0.9.0 [umoeller]
    2354  *@@changed V0.9.16 (2001-10-15) [umoeller]: added pptlLowerLeft
    2355  *@@changed V0.9.16 (2001-10-15) [umoeller]: fixed inclusive/exclusive confusion (sigh...)
    2356  *@@changed V0.9.19 (2002-06-13) [umoeller]: fixed funny colors when scaling
    2357  */
     2352 *added V0.9.0 [umoeller]
     2353 *changed V0.9.16 (2001-10-15) [umoeller]: added pptlLowerLeft
     2354 *changed V0.9.16 (2001-10-15) [umoeller]: fixed inclusive/exclusive confusion (sigh...)
     2355 *changed V0.9.19 (2002-06-13) [umoeller]: fixed funny colors when scaling
     2356 *removed V0.9.19 (2002-06-18) [umoeller]
     2357 */
     2358
     2359#if 0
    23582360
    23592361BOOL gpihIcon2Bitmap(HPS hpsMem,         // in: target memory PS with bitmap selected into it
     
    24492451}
    24502452
     2453#endif
     2454
     2455/*
     2456 *@@ gpihDrawPointer:
     2457 *      replacement for WinDrawPointer that can do clipping.
     2458 *
     2459 *      To do clipping with WinDrawPointer, one has to
     2460 *      limit the clip rectangle for the current HPS,
     2461 *      which is quite an overhead. This function instead
     2462 *      allows for specifying a clip rectangle directly.
     2463 *      Besides, since it uses GpiWCBitBlt, it should
     2464 *      probably work with all types of device contexts.
     2465 *
     2466 *      This also replaces gpihIcon2Bitmap, which wasn't quite
     2467 *      working in the first place and couldn't to clipping
     2468 *      either.
     2469 *
     2470 *      If you don't need clipping and are drawing to the
     2471 *      screen only, this function has no advantage over
     2472 *      WinDrawPointer because it's presumably slower.
     2473 *
     2474 *      Flags presently supported in fl:
     2475 *
     2476 *      --  DP_MINI (not DP_MINIICON, as stated in PMREF):
     2477 *          use mini-icon.
     2478 *
     2479 *      Preconditions:
     2480 *
     2481 *      --  The hps is assumed to be in RGB mode.
     2482 *
     2483 *      Post conditions:
     2484 *
     2485 *      --  This uses GpiSet(Back)Color, so the foreground
     2486 *          and background colors are undefined after the
     2487 *          call.
     2488 *
     2489 *@@added V0.9.19 (2002-06-18) [umoeller]
     2490 */
     2491
     2492BOOL gpihDrawPointer(HPS hps,           // in: target presentation space
     2493                     LONG x,            // in: lower left target position of icon
     2494                     LONG y,            // in: lower left target position of icon
     2495                     HPOINTER hptr,     // in: icon to be drawn
     2496                     PSIZEL pszlIcon,   // in: icon size (req., should be sysvalues SV_CXICON, SV_CYICON always)
     2497                     PRECTL prclClip,   // in: clip rectangle (inclusive!) or NULL
     2498                     ULONG fl)          // in: DP_* flags
     2499{
     2500    POINTERINFO pi;
     2501
     2502    if (    (pszlIcon)
     2503         && (hptr)
     2504         && (WinQueryPointerInfo(hptr, &pi))
     2505       )
     2506    {
     2507        POINTL  aptl[4];
     2508        HBITMAP hbmThis;
     2509        BITMAPINFOHEADER2 bmi;
     2510
     2511        // A HPOINTER really consists of two bitmaps,
     2512        // one monochrome bitmap that has twice the icon
     2513        // height and contains an AND mask in the upper
     2514        // half and an XOR mask in the lower half, and
     2515        // a (probably color) bitmap with the regular
     2516        // icon height.
     2517
     2518        // Drawing the icon means (1) blitting the AND
     2519        // mask with ROP_SRCAND, (2) blitting the color
     2520        // bitmap with ROP_SRCPAINT, (3) blitting the
     2521        // XOR mask with ROP_SRCINVERT. Hence the slightly
     2522        // complicated code that follows.
     2523
     2524        /*
     2525         * 0)   preparations
     2526         */
     2527
     2528        // set up a bunch of variables that are used
     2529        // by the below calculations. We use cx|yIcon
     2530        // to quickly get the system icon dimensions
     2531        // and set up the clip offsets here too,
     2532        // if a clip rectangle is specified.
     2533
     2534        LONG    cxIcon = pszlIcon->cx,
     2535                cyIcon = pszlIcon->cy,
     2536                cySrc,
     2537                xRight,
     2538                yTop,
     2539        // clip "rectangle"... this is not really a
     2540        // recangle because it specifies _offsets_
     2541        // towards the center of the icon to be
     2542        // clipped
     2543                lClipLeft = 0,
     2544                lClipBottom = 0,
     2545                lClipRight = 0,
     2546                lClipTop = 0;
     2547
     2548        BOOL    fMini;
     2549
     2550        if (fMini = !!(fl & DP_MINI))
     2551        {
     2552            cxIcon /= 2;
     2553            cyIcon /= 2;
     2554        }
     2555
     2556        // target top right (inclusive)
     2557        xRight = x + cxIcon - 1;
     2558        yTop = y + cyIcon - 1;
     2559
     2560        if (prclClip)
     2561        {
     2562            // we have a clip rectangle:
     2563            // set up the clip offsets that are used
     2564            // in both the target and source coordinates
     2565            // for blitting
     2566            if (x < prclClip->xLeft)
     2567                lClipLeft = prclClip->xLeft - x;
     2568            if (xRight > prclClip->xRight)
     2569                lClipRight = xRight - prclClip->xRight;
     2570            if (y < prclClip->yBottom)
     2571                lClipBottom = prclClip->yBottom - y;
     2572            if (yTop > prclClip->yTop)
     2573                lClipTop = yTop - prclClip->yTop;
     2574        }
     2575
     2576        // set up target coordinates that are constant
     2577        // for all the three blits
     2578
     2579        // aptl[0]: target bottom-left
     2580        aptl[0].x = x + lClipLeft;
     2581        aptl[0].y = y + lClipBottom;
     2582
     2583        // aptl[1]: target top-right (inclusive!)
     2584        aptl[1].x = xRight - lClipRight;
     2585        aptl[1].y = yTop - lClipTop;
     2586
     2587        if (    (aptl[0].x < aptl[1].x)
     2588             && (aptl[0].y < aptl[1].y)
     2589           )
     2590        {
     2591            // colors are constant too
     2592            GpiSetColor(hps, RGBCOL_WHITE);
     2593            GpiSetBackColor(hps, RGBCOL_BLACK);
     2594
     2595            /*
     2596             * 1)   work on the AND image
     2597             *      (upper part of the monochrome image)
     2598             */
     2599
     2600            if (    (    (fMini)
     2601                      && (hbmThis = pi.hbmMiniPointer)
     2602                    )
     2603                 || (hbmThis = pi.hbmPointer)
     2604               )
     2605            {
     2606                bmi.cbFix = sizeof(bmi);
     2607                GpiQueryBitmapInfoHeader(hbmThis, &bmi);
     2608
     2609                // use only half the bitmap height
     2610                cySrc = bmi.cy / 2;
     2611
     2612                // aptl[2]: source bottom-left
     2613                aptl[2].x =   0
     2614                            + lClipLeft   * bmi.cx / cxIcon;
     2615                aptl[2].y =   cySrc
     2616                            + lClipBottom * cySrc / cyIcon;
     2617
     2618                // aptl[3]: source top-right (exclusive!)
     2619                aptl[3].x =   bmi.cx
     2620                            - lClipRight  * bmi.cx / cxIcon;
     2621                aptl[3].y =   bmi.cy
     2622                            - lClipTop    * cySrc / cyIcon;
     2623
     2624                GpiWCBitBlt(hps,        // target
     2625                            hbmThis,    // src bmp
     2626                            4L,         // must always be 4
     2627                            aptl,       // point array
     2628                            ROP_SRCAND,   // source AND target
     2629                            BBO_IGNORE);
     2630            }
     2631
     2632            /*
     2633             * 2)   paint the color image; the parts that
     2634             *      are to be transparent are black
     2635             */
     2636
     2637            if (    (    (fMini)
     2638                      && (hbmThis = pi.hbmMiniColor)
     2639                    )
     2640                 || (hbmThis = pi.hbmColor)
     2641               )
     2642            {
     2643                bmi.cbFix = sizeof(bmi);
     2644                GpiQueryBitmapInfoHeader(hbmThis, &bmi);
     2645
     2646                // aptl[2]: source bottom-left
     2647                aptl[2].x =   0
     2648                            + lClipLeft   * bmi.cx / cxIcon;
     2649                aptl[2].y =   0
     2650                            + lClipBottom * bmi.cy / cyIcon;
     2651
     2652                // aptl[3]: source top-right (exclusive!)
     2653                aptl[3].x =   bmi.cx
     2654                            - lClipRight  * bmi.cx / cxIcon;
     2655                aptl[3].y =   bmi.cy
     2656                            - lClipTop    * bmi.cy / cyIcon;
     2657
     2658                GpiWCBitBlt(hps,        // target
     2659                            hbmThis,    // src bmp
     2660                            4L,         // must always be 4
     2661                            aptl,       // point array
     2662                            ROP_SRCPAINT,
     2663                            BBO_IGNORE);
     2664            }
     2665
     2666            /*
     2667             *  3)  work on the XOR image:
     2668             *      (lower part of monochrome bitmap)
     2669             */
     2670
     2671            if (    (    (fMini)
     2672                      && (hbmThis = pi.hbmMiniPointer)
     2673                    )
     2674                 || (hbmThis = pi.hbmPointer)
     2675               )
     2676            {
     2677                bmi.cbFix = sizeof(bmi);
     2678                GpiQueryBitmapInfoHeader(hbmThis, &bmi);
     2679
     2680                // use only half the bitmap height
     2681                cySrc = bmi.cy / 2;
     2682
     2683                // aptl[2]: source bottom-left
     2684                aptl[2].x =   0
     2685                            + lClipLeft   * bmi.cx / cxIcon;
     2686                aptl[2].y =   0
     2687                            + lClipBottom * cySrc / cyIcon;
     2688
     2689                // aptl[3]: source top-right (exclusive!)
     2690                aptl[3].x =   bmi.cx
     2691                            - lClipRight  * bmi.cx / cxIcon;
     2692                aptl[3].y =   cySrc
     2693                            - lClipTop    * cySrc / cyIcon;
     2694
     2695                GpiWCBitBlt(hps,        // target
     2696                            hbmThis,    // src bmp
     2697                            4L,         // must always be 4
     2698                            aptl,       // point array
     2699                            ROP_SRCINVERT,   // source XOR target
     2700                            BBO_IGNORE);
     2701            }
     2702
     2703            return TRUE;
     2704        }
     2705    }
     2706
     2707    return FALSE;
     2708}
     2709
    24512710/*
    24522711 *@@category: Helpers\PM helpers\GPI helpers\XBitmaps
Note: See TracChangeset for help on using the changeset viewer.