Ignore:
Timestamp:
May 20, 2001, 5:38:55 PM (24 years ago)
Author:
umoeller
Message:

misc updates

File:
1 edited

Legend:

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

    r63 r70  
    14791479        bih2.usReserved = 0;
    14801480        bih2.usRecording = BRA_BOTTOMUP;        // scan lines are bottom to top (default)
    1481         bih2.usRendering = BRH_NOTHALFTONED;    // other algorithms aren't documented anyways
    1482         bih2.cSize1 = 0;            // parameter for halftoning (undocumented anyways)
    1483         bih2.cSize2 = 0;            // parameter for halftoning (undocumented anyways)
     1481        bih2.usRendering = BRH_NOTHALFTONED;    // other algorithms aren't documented anyway
     1482        bih2.cSize1 = 0;            // parameter for halftoning (undocumented anyway)
     1483        bih2.cSize2 = 0;            // parameter for halftoning (undocumented anyway)
    14841484        bih2.ulColorEncoding = BCE_RGB;     // only possible value
    14851485        bih2.ulIdentifier = 0;              // application-specific data
     
    15451545 *      which can then be used for WinDrawBitmap and such, or
    15461546 *      NULLHANDLE upon errors.
     1547 *
     1548 *@@changed V0.9.12 (2001-05-20) [umoeller]: fixed excessive mem PS size
    15471549 */
    15481550
     
    15641566    POINTL aptl[3];
    15651567
    1566     SIZEL szlPage = {0, 0};
    1567     if (gpihCreateMemPS(hab, &szlPage, &hdcMem, &hpsMem))
     1568    SIZEL szlPage = {prcl->xRight - prcl->xLeft,
     1569                     prcl->yTop - prcl->yBottom};       // fixed V0.9.12 (2001-05-20) [umoeller]
     1570    if (gpihCreateMemPS(hab,
     1571                        &szlPage,
     1572                        &hdcMem,
     1573                        &hpsMem))
    15681574    {
    15691575        if ((hbm = gpihCreateBitmap(hpsMem,
    1570                                     prcl->xRight - prcl->xLeft,
    1571                                     prcl->yTop - prcl->yBottom)))
     1576                                    szlPage.cx,
     1577                                    szlPage.cy)))
    15721578        {
    15731579            // Associate the bit map and the memory presentation space.
     
    15951601                    hbm = NULLHANDLE; // for return code
    15961602                }
    1597             } else {
     1603            }
     1604            else
     1605            {
    15981606                // error selecting bitmap for hpsMem:
    15991607                GpiDeleteBitmap(hbm);
     
    20192027}
    20202028
     2029/*
     2030 *@@category: Helpers\PM helpers\GPI helpers\XBitmaps
     2031 *      Extended bitmaps. See gpihCreateXBitmap for an introduction.
     2032 */
     2033
     2034/* ******************************************************************
     2035 *
     2036 *   XBitmap functions
     2037 *
     2038 ********************************************************************/
     2039
     2040/*
     2041 *@@ gpihCreateXBitmap:
     2042 *      creates an XBitmap, which is returned in an
     2043 *      _XBITMAP structure.
     2044 *
     2045 *      The problem with all the GPI bitmap functions
     2046 *      is that they are quite complex and it is easy
     2047 *      to forget one of the "disassociate" and "deselect"
     2048 *      functions, which then simply leads to enormous
     2049 *      resource leaks in the application.
     2050 *
     2051 *      This function may relieve this a bit. This
     2052 *      creates a memory DC, an memory PS, and a bitmap,
     2053 *      and selects the bitmap into the memory PS.
     2054 *      You can then use any GPI function on the memory
     2055 *      PS to draw into the bitmap. Use the fields from
     2056 *      _XBITMAP for that.
     2057 *
     2058 *      The bitmap is created in RGB mode.
     2059 *
     2060 *      Use gpihDestroyXBitmap to destroy the XBitmap
     2061 *      again.
     2062 *
     2063 *      Example:
     2064 *
     2065 +          PXBITMAP pbmp = gpihCreateXBitmap(hab, 100, 100);
     2066 +          if (pbmp)
     2067 +          {
     2068 +              GpiMove(pbmp->hpsMem, ...);
     2069 +              GpiBox(pbmp->hpsMem, ...);
     2070 +
     2071 +              WinDrawBitmap(hpsScreen,
     2072 +                            pbmp->hbm,       // bitmap handle
     2073 +                            ...);
     2074 +              gpihDestroyXBitmap(&pbmp);
     2075 +          }
     2076 *
     2077 *      Without the gpih* functions, the above would expand
     2078 *      to more than 100 lines.
     2079 *
     2080 *@@added V0.9.12 (2001-05-20) [umoeller]
     2081 */
     2082
     2083PXBITMAP gpihCreateXBitmap(HAB hab,         // in: anchor block
     2084                           LONG cx,         // in: bitmap width
     2085                           LONG cy)         // in: bitmap height
     2086{
     2087    BOOL fOK = FALSE;
     2088    PXBITMAP pbmp = (PXBITMAP)malloc(sizeof(XBITMAP));
     2089    if (pbmp)
     2090    {
     2091        memset(pbmp, 0, sizeof(XBITMAP));
     2092
     2093        // create memory PS for bitmap
     2094        pbmp->szl.cx = cx;
     2095        pbmp->szl.cy = cy;
     2096        if (gpihCreateMemPS(hab,
     2097                            &pbmp->szl,
     2098                            &pbmp->hdcMem,
     2099                            &pbmp->hpsMem))
     2100        {
     2101            gpihSwitchToRGB(pbmp->hpsMem);
     2102            if (pbmp->hbm = gpihCreateBitmap(pbmp->hpsMem,
     2103                                             cx,
     2104                                             cy))
     2105            {
     2106                if (GpiSetBitmap(pbmp->hpsMem,
     2107                                 pbmp->hbm)
     2108                        != HBM_ERROR)
     2109                    fOK = TRUE;
     2110            }
     2111        }
     2112
     2113        if (!fOK)
     2114            gpihDestroyXBitmap(&pbmp);
     2115    }
     2116
     2117    return (pbmp);
     2118}
     2119
     2120/*
     2121 *@@ gpihDestroyXBitmap:
     2122 *      destroys an XBitmap created with gpihCreateXBitmap.
     2123 *
     2124 *      To be on the safe side, this sets the
     2125 *      bitmap pointer to NULL as well.
     2126 *
     2127 *@@added V0.9.12 (2001-05-20) [umoeller]
     2128 */
     2129
     2130VOID gpihDestroyXBitmap(PXBITMAP *ppbmp)
     2131{
     2132    if (ppbmp)
     2133    {
     2134        PXBITMAP pbmp;
     2135        if (pbmp = *ppbmp)
     2136        {
     2137            if (pbmp->hbm)
     2138            {
     2139                if (pbmp->hpsMem)
     2140                    GpiSetBitmap(pbmp->hpsMem, NULLHANDLE);
     2141                GpiDeleteBitmap(pbmp->hbm);
     2142            }
     2143            if (pbmp->hpsMem)
     2144            {
     2145                GpiAssociate(pbmp->hpsMem, NULLHANDLE);
     2146                GpiDestroyPS(pbmp->hpsMem);
     2147            }
     2148            if (pbmp->hdcMem)
     2149                DevCloseDC(pbmp->hdcMem);
     2150
     2151            free(pbmp);
     2152
     2153            *ppbmp = NULL;
     2154        }
     2155    }
     2156}
     2157
     2158
Note: See TracChangeset for help on using the changeset viewer.