Ignore:
Timestamp:
Dec 5, 2002, 9:36:28 PM (23 years ago)
Author:
umoeller
Message:

New toolbar control.

File:
1 edited

Legend:

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

    r229 r232  
    134134{
    135135    if (prcl)
    136     {
    137136        return (    (x >= prcl->xLeft)
    138137                 && (x <= prcl->xRight)
     
    140139                 && (y <= prcl->yTop)
    141140               );
    142     }
    143141
    144142    return FALSE;
     
    163161        prcl->yTop += l;
    164162    }
     163}
     164
     165/*
     166 *@@ gpihCopyRectIncl:
     167 *      copies prclWin to prclGpi, making it
     168 *      inclusive-inclusive for use with GPI
     169 *      functions.
     170 *
     171 *@@added V1.0.1 (2002-11-30) [umoeller]
     172 */
     173
     174VOID gpihCopyRectIncl(PRECTL prclGpi,       // out: GPI rectangle
     175                      PRECTL prclWin)       // in: WIN rectangle
     176{
     177    prclGpi->xLeft = prclWin->xLeft;
     178    prclGpi->yBottom = prclWin->yBottom;
     179    prclGpi->xRight = prclWin->xRight - 1;
     180    prclGpi->yTop = prclWin->yTop - 1;
    165181}
    166182
     
    16871703}
    16881704
     1705static const BITMAPINFOHEADER2 G_bih2Template[] =
     1706    {
     1707        sizeof(BITMAPINFOHEADER2), // ULONG      cbFix;
     1708        0,                  // ULONG      cx;               // tbr
     1709        0,                  // ULONG      cy;               // tbr
     1710        0,                  // USHORT     cPlanes;          // tbr
     1711        0,                  // USHORT     cBitCount;        // tbr
     1712        BCA_UNCOMP,         // ULONG      ulCompression;
     1713        0,                  // ULONG      cbImage;
     1714        70,                 // ULONG      cxResolution;
     1715        70,                 // ULONG      cyResolution;
     1716        2,                  // ULONG      cclrUsed;
     1717        0,                  // ULONG      cclrImportant;
     1718        BRU_METRIC,         // USHORT     usUnits;
     1719                                    // measure units for cxResolution/cyResolution: pels per meter
     1720        0,                  // USHORT     usReserved;
     1721        BRA_BOTTOMUP,       // USHORT     usRecording;
     1722                                    // scan lines are bottom to top (default)
     1723
     1724        BRH_NOTHALFTONED,   // USHORT     usRendering;
     1725                                    // other algorithms aren't documented anyway
     1726        0,                  // ULONG      cSize1;
     1727                                    // parameter for halftoning (undocumented anyway)
     1728        0,                  // ULONG      cSize2;
     1729                                    // parameter for halftoning (undocumented anyway)
     1730        BCE_RGB,            // ULONG      ulColorEncoding;
     1731                                    // only possible value
     1732        0                   // ULONG      ulIdentifier;
     1733                                    // application-specific data
     1734    };
     1735
    16891736/*
    16901737 *@@ gpihCreateBitmap2:
     
    17031750 *
    17041751 *@@added V0.9.16 (2001-12-18) [umoeller]
     1752 *@@changed V1.0.1 (2002-11-30) [umoeller]: optimized
    17051753 */
    17061754
     
    17111759                          ULONG cBitCount)   // in: either 1, 4, or 24; if 0, current screen value
    17121760{
    1713     HBITMAP hbm = NULLHANDLE;
    17141761    LONG alData[2];
    17151762    BITMAPINFOHEADER2 bih2;
    1716     // PBITMAPINFO2 pbmi = NULL;
    17171763
    17181764    // determine the device's plane/bit-count format;
     
    17211767    if (GpiQueryDeviceBitmapFormats(hpsMem, 2, alData))
    17221768    {
    1723         // set up the BITMAPINFOHEADER2 and BITMAPINFO2 structures
    1724         bih2.cbFix = (ULONG)sizeof(BITMAPINFOHEADER2);
     1769        // copy values from global template V1.0.1 (2002-11-30) [umoeller]
     1770        memcpy(&bih2, &G_bih2Template, sizeof(bih2));
     1771
     1772        // fix variable fields V1.0.1 (2002-11-30) [umoeller]
    17251773        bih2.cx = cx;
    17261774        bih2.cy = cy;
    17271775        bih2.cPlanes = (cPlanes) ? cPlanes : alData[0];
    17281776        bih2.cBitCount = (cBitCount) ? cBitCount : alData[1];
    1729         bih2.ulCompression = BCA_UNCOMP;
    17301777        bih2.cbImage = (    (   (bih2.cx
    17311778                                    * (1 << bih2.cPlanes)
     
    17341781                            ) / 32
    17351782                       ) * bih2.cy;
    1736         bih2.cxResolution = 70;
    1737         bih2.cyResolution = 70;
    1738         bih2.cclrUsed = 2;
    1739         bih2.cclrImportant = 0;
    1740         bih2.usUnits = BRU_METRIC;  // measure units for cxResolution/cyResolution: pels per meter
    1741         bih2.usReserved = 0;
    1742         bih2.usRecording = BRA_BOTTOMUP;        // scan lines are bottom to top (default)
    1743         bih2.usRendering = BRH_NOTHALFTONED;    // other algorithms aren't documented anyway
    1744         bih2.cSize1 = 0;            // parameter for halftoning (undocumented anyway)
    1745         bih2.cSize2 = 0;            // parameter for halftoning (undocumented anyway)
    1746         bih2.ulColorEncoding = BCE_RGB;     // only possible value
    1747         bih2.ulIdentifier = 0;              // application-specific data
    17481783
    17491784        // create a bit map that is compatible with the display
    1750         hbm = GpiCreateBitmap(hpsMem,
    1751                               &bih2,
    1752                               0,            // do not initialize
    1753                               NULL,         // init data
    1754                               NULL);
     1785        return GpiCreateBitmap(hpsMem,
     1786                               &bih2,
     1787                               0,            // do not initialize
     1788                               NULL,         // init data
     1789                               NULL);
    17551790    }
    17561791
    1757     return hbm;
     1792    return NULLHANDLE;
     1793}
     1794
     1795/*
     1796 *@@ gpihQueryBitmapSize:
     1797 *      returns the width and height of the given bitmap.
     1798 *
     1799 *@@added V1.0.1 (2002-11-30) [umoeller]
     1800 */
     1801
     1802BOOL gpihQueryBitmapSize(HBITMAP hbm,       // in: bitmap handle for query
     1803                         PSIZEL pszl)       // out: size (cx, cy) of bitmap
     1804{
     1805    BITMAPINFOHEADER2 bmi2;
     1806    // query bitmap info
     1807    bmi2.cbFix = sizeof(bmi2);
     1808    if (    (hbm)
     1809         && (GpiQueryBitmapInfoHeader(hbm, &bmi2))
     1810       )
     1811    {
     1812        pszl->cx = bmi2.cx;
     1813        pszl->cy = bmi2.cy;
     1814        return TRUE;
     1815    }
     1816
     1817    return FALSE;
    17581818}
    17591819
     
    17761836 *
    17771837 *@added V0.9.0
     1838 *@@changed V1.0.1 (2002-11-30) [umoeller]: optimized
    17781839 */
    17791840
     
    17861847    HDC     hdcMem;
    17871848    HPS     hpsMem;
    1788     BITMAPINFOHEADER2 bmi;
    1789 
    1790     if (hbmSource)
     1849    SIZEL   szlPage;
     1850
     1851    if (gpihQueryBitmapSize(hbmSource, &szlPage))       // V1.0.1 (2002-11-30) [umoeller]
    17911852    {
    1792         SIZEL szlPage;
    1793         // query bitmap info
    1794         bmi.cbFix = sizeof(bmi);
    1795         GpiQueryBitmapInfoHeader(hbmSource, &bmi);
    1796 
    1797         szlPage.cx = bmi.cx;
    1798         szlPage.cy = bmi.cy;
    17991853        if (gpihCreateMemPS(hab, &szlPage, &hdcMem, &hpsMem))
    18001854        {
    18011855            if ((hbmReturn = gpihCreateBitmap(hpsMem,
    1802                                               bmi.cx,
    1803                                               bmi.cy)))
     1856                                              szlPage.cx,
     1857                                              szlPage.cy)))
    18041858            {
    18051859                if (GpiSetBitmap(hpsMem, hbmReturn) != HBM_ERROR)
     
    18111865                    // aptl[0]: target bottom-left, is all 0
    18121866                    // aptl[1]: target top-right (inclusive!)
    1813                     aptl[1].x = bmi.cx - 1;
    1814                     aptl[1].y = bmi.cy - 1;
     1867                    aptl[1].x = szlPage.cx - 1;
     1868                    aptl[1].y = szlPage.cy - 1;
    18151869                    // aptl[2]: source bottom-left, is all 0
    18161870
    18171871                    // aptl[3]: source top-right (exclusive!)
    1818                     aptl[3].x = bmi.cx;
    1819                     aptl[3].y = bmi.cy;
     1872                    aptl[3].x = szlPage.cx;
     1873                    aptl[3].y = szlPage.cy;
    18201874                    GpiWCBitBlt(hpsMem,     // target HPS (bmp selected)
    18211875                                hbmSource,
     
    18321886
    18331887                    GpiMove(hpsMem, &aptl[0]);  // still 0, 0
    1834                     aptl[0].x = bmi.cx - 1;
    1835                     aptl[0].y = bmi.cy - 1;
     1888                    aptl[0].x = szlPage.cx - 1;
     1889                    aptl[0].y = szlPage.cy - 1;
    18361890                    GpiSetColor(hpsMem, lColorGray);
    18371891                    GpiSetPattern(hpsMem, PATSYM_HALFTONE);
     
    23262380 *
    23272381 *@added V0.9.0
     2382 *@@changed V1.0.1 (2002-11-30) [umoeller]: optimized
    23282383 */
    23292384
     
    23342389                       BOOL fProportional)  // in: preserve proportions when stretching?
    23352390{
    2336     BITMAPINFOHEADER2   bih2;
     2391    SIZEL               szlBmp;
    23372392    POINTL              aptl[4];
    23382393    BOOL                fCalculated = FALSE;
    23392394
     2395    if (!gpihQueryBitmapSize(hbmSource, &szlBmp))       // V1.0.1 (2002-11-30) [umoeller]
     2396        return GPI_ERROR;
     2397
    23402398    memset(aptl, 0, sizeof(POINTL) * 4);
    2341 
    2342     bih2.cbFix = sizeof(bih2);
    2343     GpiQueryBitmapInfoHeader(hbmSource,
    2344                              &bih2);
    23452399
    23462400    // aptl[2]: source bottom-left, is all 0
    23472401    // aptl[3]: source top-right (exclusive!)
    2348     aptl[3].x = bih2.cx;
    2349     aptl[3].y = bih2.cy;
     2402    aptl[3].x = szlBmp.cx;
     2403    aptl[3].y = szlBmp.cy;
    23502404
    23512405    if (fProportional)
     
    23562410        // large
    23572411
    2358         ULONG ulPropSource = (bih2.cx * 1000)
    2359                                     / bih2.cy;
     2412        ULONG ulPropSource = (szlBmp.cx * 1000)
     2413                                    / szlBmp.cy;
    23602414                // e.g. if the bmp is 200 x 100, we now have 2000
    23612415        ULONG ulPropTarget = ((prclTarget->xRight - prclTarget->xLeft) * 1000)
     
    24302484
    24312485/*
    2432  * gpihIcon2Bitmap:
    2433  *      this paints the given icon/pointer into
    2434  *      a bitmap. Note that if the bitmap is
    2435  *      larget than the system icon size, only
    2436  *      the rectangle of the icon will be filled
    2437  *      with lBkgndColor.
    2438  *
    2439  *      Returns FALSE upon errors.
    2440  *
    2441  *added V0.9.0 [umoeller]
    2442  *changed V0.9.16 (2001-10-15) [umoeller]: added pptlLowerLeft
    2443  *changed V0.9.16 (2001-10-15) [umoeller]: fixed inclusive/exclusive confusion (sigh...)
    2444  *changed V0.9.19 (2002-06-13) [umoeller]: fixed funny colors when scaling
    2445  *removed V0.9.19 (2002-06-18) [umoeller]
    2446  */
    2447 
    2448 #if 0
    2449 
    2450 BOOL gpihIcon2Bitmap(HPS hpsMem,         // in: target memory PS with bitmap selected into it
    2451                      HPOINTER hptr,      // in: source icon
    2452                      LONG lBkgndColor,   // in: background color for transparent areas
    2453                      PPOINTL pptlLowerLeft, // in: lower left corner of where to paint (ptr can be NULL)
    2454                      ULONG ulIconSize)   // in: icon size (should be the value of WinQuerySysValue(HWND_DESKTOP, SV_CXICON))
    2455 {
    2456     BOOL        brc = FALSE;
    2457     POINTERINFO pi;
    2458 
    2459     // Each icon consists of two (really three)
    2460     // bitmaps, which are stored in the POINTERINFO
    2461     // structure:
    2462     //   pi.hbmColor    is the actual bitmap to be
    2463     //                  drawn. The parts that are
    2464     //                  to be transparent or inverted
    2465     //                  are black in this image.
    2466     //   pi.hbmPointer  has twice the height of
    2467     //                  hbmColor. The upper bitmap
    2468     //                  contains an XOR mask (for
    2469     //                  inverting parts), the lower
    2470     //                  bitmap an AND mask (for
    2471     //                  transparent parts).
    2472     if (WinQueryPointerInfo(hptr, &pi))
    2473     {
    2474         POINTL  ptlLowerLeft = {0, 0};
    2475         POINTL  aptl[4];
    2476         memset(aptl, 0, sizeof(POINTL) * 4);
    2477 
    2478         if (pptlLowerLeft)
    2479             // lower left specified: V0.9.16 (2001-10-15) [umoeller]
    2480             memcpy(&ptlLowerLeft, pptlLowerLeft, sizeof(POINTL));
    2481 
    2482         // aptl[0]: target bottom-left, is all 0
    2483         aptl[0].x = ptlLowerLeft.x;
    2484         aptl[0].y = ptlLowerLeft.y;
    2485 
    2486         // aptl[1]: target top-right (inclusive!)
    2487         // V0.9.16 (2001-10-15) [umoeller]: fixed rectangle confusion
    2488         aptl[1].x = ptlLowerLeft.x + ulIconSize - 1;
    2489         aptl[1].y = ptlLowerLeft.y + ulIconSize - 1;
    2490 
    2491         // aptl[2]: source bottom-left, is all 0
    2492 
    2493         // aptl[3]: source top-right (exclusive!)
    2494         // V0.9.16 (2001-10-15) [umoeller]: fixed rectangle confusion
    2495         aptl[3].x = ulIconSize; //  + 1;
    2496         aptl[3].y = ulIconSize; //  + 1;
    2497 
    2498         GpiSetColor(hpsMem, CLR_WHITE);
    2499         GpiSetBackColor(hpsMem, CLR_BLACK);
    2500 
    2501         // GpiErase(hpsMem);
    2502 
    2503         // V0.9.19 (2002-06-13) [umoeller]:
    2504         // use BBO_IGNORE instead of BBO_OR or we get funny colors
    2505         // when scaling down
    2506 
    2507         // work on the AND image
    2508         GpiWCBitBlt(hpsMem,     // target
    2509                     pi.hbmPointer,  // src bmp
    2510                     4L,         // must always be 4
    2511                     &aptl[0],   // point array
    2512                     ROP_SRCAND,   // source AND target
    2513                     BBO_IGNORE);        // V0.9.19 (2002-06-13) [umoeller]
    2514 
    2515         // paint the real image
    2516         if (pi.hbmColor)
    2517             GpiWCBitBlt(hpsMem,
    2518                         pi.hbmColor,
    2519                         4L,         // must always be 4
    2520                         &aptl[0],   // point array
    2521                         ROP_SRCPAINT,    // source OR target
    2522                         BBO_IGNORE);        // V0.9.19 (2002-06-13) [umoeller]
    2523 
    2524         GpiSetColor(hpsMem, lBkgndColor);
    2525         // work on the XOR image
    2526         aptl[2].y = ulIconSize;                 // exclusive
    2527         aptl[3].y = (ulIconSize * 2); //  /* + 1; */       // exclusive
    2528         // V0.9.16 (2001-10-15) [umoeller]: fixed rectangle confusion
    2529         GpiWCBitBlt(hpsMem,
    2530                     pi.hbmPointer,
    2531                     4L,         // must always be 4
    2532                     &aptl[0],   // point array
    2533                     ROP_SRCINVERT,
    2534                     BBO_IGNORE);        // V0.9.19 (2002-06-13) [umoeller]
    2535 
    2536         brc = TRUE;
    2537     }
    2538 
    2539     return brc;
    2540 }
    2541 
    2542 #endif
    2543 
    2544 /*
    25452486 *@@ gpihDrawPointer:
    25462487 *      replacement for WinDrawPointer that can do clipping.
     
    25852526 *@@changed V0.9.20 (2002-07-31) [umoeller]: optimized, saved one GpiQueryBitmapInfoHeader
    25862527 *@@changed V0.9.20 (2002-08-04) [umoeller]: added DP_HALFTONED
     2528 *@@changed V1.0.1 (2002-11-30) [umoeller]: optimized
    25872529 */
    25882530
     
    26042546        POINTL  aptl[4];
    26052547        HBITMAP hbmThis;
    2606         BITMAPINFOHEADER2 bmiAndXor,
    2607                           bmiColor;
     2548        SIZEL   szlAndXor,      // V1.0.1 (2002-11-30) [umoeller]
     2549                szlColor;
    26082550
    26092551        // A HPOINTER really consists of two bitmaps,
     
    27162658               )
    27172659            {
    2718                 bmiAndXor.cbFix = sizeof(bmiAndXor);
    2719                 GpiQueryBitmapInfoHeader(hbmThis, &bmiAndXor);
     2660                gpihQueryBitmapSize(hbmThis, &szlAndXor);   // V1.0.1 (2002-11-30) [umoeller]
    27202661
    27212662                // use only half the bitmap height
    2722                 cySrc = bmiAndXor.cy / 2;
     2663                cySrc = szlAndXor.cy / 2;
    27232664
    27242665                // aptl[2]: source bottom-left
    27252666                aptl[2].x =   0
    2726                             + lClipLeft   * bmiAndXor.cx / cxIcon;
     2667                            + lClipLeft   * szlAndXor.cx / cxIcon;
    27272668                aptl[2].y =   cySrc
    27282669                            + lClipBottom * cySrc / cyIcon;
    27292670
    27302671                // aptl[3]: source top-right (exclusive!)
    2731                 aptl[3].x =   bmiAndXor.cx
    2732                             - lClipRight  * bmiAndXor.cx / cxIcon;
    2733                 aptl[3].y =   bmiAndXor.cy
     2672                aptl[3].x =   szlAndXor.cx
     2673                            - lClipRight  * szlAndXor.cx / cxIcon;
     2674                aptl[3].y =   szlAndXor.cy
    27342675                            - lClipTop    * cySrc / cyIcon;
    27352676
     
    27532694               )
    27542695            {
    2755                 bmiColor.cbFix = sizeof(bmiColor);
    2756                 GpiQueryBitmapInfoHeader(hbmThis, &bmiColor);
     2696                gpihQueryBitmapSize(hbmThis, &szlColor);        // V1.0.1 (2002-11-30) [umoeller]
    27572697
    27582698                // aptl[2]: source bottom-left
    27592699                aptl[2].x =   0
    2760                             + lClipLeft   * bmiColor.cx / cxIcon;
     2700                            + lClipLeft   * szlColor.cx / cxIcon;
    27612701                aptl[2].y =   0
    2762                             + lClipBottom * bmiColor.cy / cyIcon;
     2702                            + lClipBottom * szlColor.cy / cyIcon;
    27632703
    27642704                // aptl[3]: source top-right (exclusive!)
    2765                 aptl[3].x =   bmiColor.cx
    2766                             - lClipRight  * bmiColor.cx / cxIcon;
    2767                 aptl[3].y =   bmiColor.cy
    2768                             - lClipTop    * bmiColor.cy / cyIcon;
     2705                aptl[3].x =   szlColor.cx
     2706                            - lClipRight  * szlColor.cx / cxIcon;
     2707                aptl[3].y =   szlColor.cy
     2708                            - lClipTop    * szlColor.cy / cyIcon;
    27692709
    27702710                GpiWCBitBlt(hps,        // target
     
    27872727               )
    27882728            {
    2789                 /*  we queried this one above V0.9.20 (2002-07-31) [umoeller]
    2790                 bmiAndXor.cbFix = sizeof(bmiAndXor);
    2791                 GpiQueryBitmapInfoHeader(hbmThis, &bmiAndXor);
    2792                 */
     2729                // we queried the size of this one above V0.9.20 (2002-07-31) [umoeller]
    27932730
    27942731                // use only half the bitmap height
    2795                 cySrc = bmiAndXor.cy / 2;
     2732                cySrc = szlAndXor.cy / 2;
    27962733
    27972734                // aptl[2]: source bottom-left
    27982735                aptl[2].x =   0
    2799                             + lClipLeft   * bmiAndXor.cx / cxIcon;
     2736                            + lClipLeft   * szlAndXor.cx / cxIcon;
    28002737                aptl[2].y =   0
    28012738                            + lClipBottom * cySrc / cyIcon;
    28022739
    28032740                // aptl[3]: source top-right (exclusive!)
    2804                 aptl[3].x =   bmiAndXor.cx
    2805                             - lClipRight  * bmiAndXor.cx / cxIcon;
     2741                aptl[3].x =   szlAndXor.cx
     2742                            - lClipRight  * szlAndXor.cx / cxIcon;
    28062743                aptl[3].y =   cySrc
    28072744                            - lClipTop    * cySrc / cyIcon;
Note: See TracChangeset for help on using the changeset viewer.