Ignore:
Timestamp:
Jan 1, 2001, 4:30:29 PM (25 years ago)
Author:
umoeller
Message:

Tons of updates.

File:
1 edited

Legend:

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

    r14 r18  
    100100 */
    101101
    102 VOID PaintProgress(PPROGRESSBARDATA pData, HWND hwndBar, HPS hps)
     102VOID PaintProgress(PPROGRESSBARDATA pData,
     103                   HWND hwndBar,
     104                   PRECTL prclWin,      // in: window rectangle (WinQueryWindowRect)
     105                   HPS hps)
    103106{
    104     POINTL  ptl1, ptlText, aptlText[TXTBOX_COUNT];
    105     RECTL   rcl, rcl2;
    106 
     107    POINTL  ptlText; // , aptlText[TXTBOX_COUNT];
     108    BOOL    fBackgroundPainted = FALSE;
    107109    CHAR    szPercent[10] = "";
     110    RECTL   rclInnerButton;
     111    LONG    lcolScrollbar = WinQuerySysColor(HWND_DESKTOP,
     112                                             SYSCLR_SCROLLBAR,
     113                                             0);
    108114
    109115    // switch to RGB mode
    110     GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL);
     116    gpihSwitchToRGB(hps);
    111117
    112118    if (pData->ulPaintX <= pData->ulOldPaintX)
    113119    {
    114         // draw frame and background only if this is either
    115         //    a "real" WM_PAINT (i.e., the window was overlapped
    116         //   and needs repainting; then ulPaintX == ulOldPaintX)
    117         //   or if ulNow has _de_creased
    118         GpiSetColor(hps, WinQuerySysColor(HWND_DESKTOP, SYSCLR_BUTTONDARK, 0));
    119         ptl1.x = 0;
    120         ptl1.y = 0;
    121         GpiMove(hps, &ptl1);
    122         ptl1.y = (pData->rclBar.yTop);
    123         GpiLine(hps, &ptl1);
    124         ptl1.x = (pData->rclBar.xRight);
    125         GpiLine(hps, &ptl1);
    126         GpiSetColor(hps, WinQuerySysColor(HWND_DESKTOP, SYSCLR_BUTTONLIGHT, 0));
    127         ptl1.y = 0;
    128         GpiLine(hps, &ptl1);
    129         ptl1.x = 0;
    130         GpiLine(hps, &ptl1);
    131 
    132         pData->rclBar.xLeft = 1;
    133         pData->rclBar.yBottom = 1;
    134         WinFillRect(hps, &(pData->rclBar),
    135             WinQuerySysColor(HWND_DESKTOP, SYSCLR_SCROLLBAR, 0));
    136     }
    137 
    138     // draw percentage?
     120        RECTL rclOuterFrame;        // inclusive
     121        rclOuterFrame.xLeft = 0;
     122        rclOuterFrame.yBottom = 0;
     123        rclOuterFrame.xRight = prclWin->xRight - 1;
     124        rclOuterFrame.yTop = prclWin->yTop - 1;
     125
     126        gpihDraw3DFrame(hps,
     127                        &rclOuterFrame,     // inclusive
     128                        1,
     129                        WinQuerySysColor(HWND_DESKTOP, SYSCLR_BUTTONDARK, 0),
     130                        WinQuerySysColor(HWND_DESKTOP, SYSCLR_BUTTONLIGHT, 0));
     131
     132        rclOuterFrame.xLeft++;
     133        rclOuterFrame.yBottom++;
     134        WinFillRect(hps,
     135                    &rclOuterFrame,     // exclusive, top right not drawn
     136                    lcolScrollbar);
     137        fBackgroundPainted = TRUE;
     138    }
     139
     140    // now draw the actual progress;
     141    // rclInnerButton receives an _inclusive_ rectangle
     142    rclInnerButton.xLeft = 1;
     143    rclInnerButton.xRight = (pData->ulPaintX > (rclInnerButton.xLeft + 3))
     144                                 ? pData->ulPaintX
     145                                 : rclInnerButton.xLeft +
     146                                       ((pData->ulAttr & PBA_BUTTONSTYLE)
     147                                           ? 3 : 1);
     148    rclInnerButton.yBottom = 1;
     149    rclInnerButton.yTop = prclWin->yTop     // exclusive
     150                            - 2;            // 1 to make inclusive, 1 for outer frame
     151
    139152    if (pData->ulAttr & PBA_PERCENTFLAGS)
    140153    {
    141         // make string
     154        // percentage desired:
     155
     156        POINTL  aptlText[TXTBOX_COUNT];
     157        LONG    lLineSpacing = 1;
     158        FONTMETRICS fm;
     159        if (GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm))
     160            lLineSpacing = fm.lEmHeight;
     161
    142162        sprintf(szPercent, "%lu %%", ((100 * pData->ulNow) / pData->ulMax) );
    143 
    144163        // calculate string space
    145         GpiQueryTextBox(hps, strlen(szPercent), szPercent,
    146                 TXTBOX_COUNT, (PPOINTL)&aptlText);
    147 
    148         // calculate coordinates
    149         ptlText.x = pData->rclBar.xLeft +
    150                         (   (   (pData->rclBar.xRight-pData->rclBar.xLeft)
    151                               - (aptlText[TXTBOX_BOTTOMRIGHT].x-aptlText[TXTBOX_BOTTOMLEFT].x)
     164        GpiQueryTextBox(hps,
     165                        strlen(szPercent),
     166                        szPercent,
     167                        TXTBOX_COUNT,
     168                        (PPOINTL)&aptlText);
     169
     170        ptlText.x =
     171                        (   (   (prclWin->xRight)     // cx
     172                              - (aptlText[TXTBOX_BOTTOMRIGHT].x - aptlText[TXTBOX_BOTTOMLEFT].x)
    152173                            )
    153174                        / 2);
    154         ptlText.y = 2 + pData->rclBar.yBottom +     // fixed V0.9.5 (2000-09-22) [umoeller]
    155                         (   (   (pData->rclBar.yTop-pData->rclBar.yBottom)
    156                               - (aptlText[TXTBOX_TOPLEFT].y-aptlText[TXTBOX_BOTTOMLEFT].y)
     175        ptlText.y =
     176                        (   (   (prclWin->yTop)       // cy
     177                              - (lLineSpacing)
    157178                            )
    158                         / 2);
    159 
    160         // do we need to repaint the background under the percentage?
    161         if (    (   (ptlText.x
    162                         + (  aptlText[TXTBOX_BOTTOMRIGHT].x
    163                            - aptlText[TXTBOX_BOTTOMLEFT].x)
    164                     )
    165                   > pData->ulPaintX)
    166             &&  (pData->ulPaintX > pData->ulOldPaintX)
    167            )
     179                        / 2) + 2;
     180
     181        if (!fBackgroundPainted)
    168182        {
    169183            // if we haven't drawn the background already,
    170184            // we'll need to do it now for the percentage area
    171             rcl.xLeft      = ptlText.x;
    172             rcl.xRight     = ptlText.x + (aptlText[TXTBOX_BOTTOMRIGHT].x-aptlText[TXTBOX_BOTTOMLEFT].x);
    173             rcl.yBottom    = ptlText.y;
    174             rcl.yTop       = ptlText.y + (aptlText[TXTBOX_TOPLEFT].y-aptlText[TXTBOX_BOTTOMLEFT].y);
    175             WinFillRect(hps, &rcl,
    176                 WinQuerySysColor(HWND_DESKTOP, SYSCLR_SCROLLBAR, 0));
     185            RECTL rcl2;
     186            rcl2.xLeft      = ptlText.x;
     187            rcl2.xRight     = ptlText.x + (aptlText[TXTBOX_BOTTOMRIGHT].x-aptlText[TXTBOX_BOTTOMLEFT].x);
     188            rcl2.yBottom    = ptlText.y;
     189            rcl2.yTop       = ptlText.y + lLineSpacing;
     190            WinFillRect(hps,
     191                        &rcl2,
     192                        lcolScrollbar);
    177193        }
    178194    }
    179195
    180     // now draw the actual progress
    181     rcl2.xLeft = pData->rclBar.xLeft;
    182     rcl2.xRight = (pData->ulPaintX > (rcl2.xLeft + 3))
    183             ? pData->ulPaintX
    184             : rcl2.xLeft + ((pData->ulAttr & PBA_BUTTONSTYLE)
    185                            ? 3 : 1);
    186     rcl2.yBottom = pData->rclBar.yBottom;
    187     rcl2.yTop = pData->rclBar.yTop-1;
    188 
    189196    if (pData->ulAttr & PBA_BUTTONSTYLE)
    190197    {
    191         RECTL rcl3 = rcl2;
    192198        // draw "raised" inner rect
    193         rcl3.xLeft = rcl2.xLeft;
    194         rcl3.yBottom = rcl2.yBottom;
    195         rcl3.yTop = rcl2.yTop+1;
    196         rcl3.xRight = rcl2.xRight+1;
    197         gpihDraw3DFrame(hps, &rcl3, 2,
     199        gpihDraw3DFrame(hps,
     200                        &rclInnerButton,
     201                        2,
    198202                        WinQuerySysColor(HWND_DESKTOP, SYSCLR_BUTTONLIGHT, 0),
    199203                        WinQuerySysColor(HWND_DESKTOP, SYSCLR_BUTTONDARK, 0));
    200         // WinInflateRect(WinQueryAnchorBlock(hwndBar), &rcl2, -2, -2);
    201         rcl2.xLeft += 2;
    202         rcl2.yBottom += 2;
    203         rcl2.yTop -= 2;
    204         rcl2.xRight -= 2;
    205     }
    206 
    207     if (rcl2.xRight > rcl2.xLeft)
    208     {
     204    }
     205
     206    rclInnerButton.xLeft += 2;
     207    rclInnerButton.yBottom += 2;
     208    rclInnerButton.yTop -= 2;
     209    rclInnerButton.xRight -= 2;
     210
     211    if (rclInnerButton.xRight > rclInnerButton.xLeft)
     212    {
     213        POINTL ptl1;
     214        // draw interior of inner rect
    209215        GpiSetColor(hps, WinQuerySysColor(HWND_DESKTOP,
    210                     // SYSCLR_HILITEBACKGROUND,
    211                     SYSCLR_BUTTONMIDDLE,
    212                 0));
    213         ptl1.x = rcl2.xLeft;
    214         ptl1.y = rcl2.yBottom;
     216                                          SYSCLR_BUTTONMIDDLE,
     217                                          0));
     218        ptl1.x = rclInnerButton.xLeft;
     219        ptl1.y = rclInnerButton.yBottom;
    215220        GpiMove(hps, &ptl1);
    216         ptl1.x = rcl2.xRight;
    217         ptl1.y = rcl2.yTop;
    218         GpiBox(hps, DRO_FILL | DRO_OUTLINE,
    219             &ptl1,
    220             0,
    221             0);
     221        ptl1.x = rclInnerButton.xRight;
     222        ptl1.y = rclInnerButton.yTop;
     223        GpiBox(hps,
     224               DRO_FILL | DRO_OUTLINE,
     225               &ptl1,       // inclusive!
     226               0,
     227               0);
    222228    }
    223229
     
    227233        GpiMove(hps, &ptlText);
    228234        GpiSetColor(hps, WinQuerySysColor(HWND_DESKTOP,
    229                 // SYSCLR_HILITEFOREGROUND,
    230                 SYSCLR_BUTTONDEFAULT,
    231             0));
     235                                          SYSCLR_BUTTONDEFAULT,
     236                                          0));
    232237        GpiCharString(hps, strlen(szPercent), szPercent);
    233238    }
     
    284289            case WM_UPDATEPROGRESSBAR:
    285290            {
     291                RECTL rclWin;
     292                WinQueryWindowRect(hwndBar, &rclWin);
    286293                if (    (ppd->ulNow != (ULONG)mp1)
    287294                     || (ppd->ulMax != (ULONG)mp2)
     
    309316                ppd->ulPaintX =
    310317                    (ULONG)(
    311                               (    (ULONG)(ppd->rclBar.xRight - ppd->rclBar.xLeft)
     318                              (    (ULONG)(rclWin.xRight - rclWin.xLeft - 2)
    312319                                 * (ULONG)(ppd->ulNow)
    313320                              )
     
    319326                    // WinInvalidateRect(hwndBar, NULL, FALSE);
    320327                    hps = WinGetPS(hwndBar);
    321                     PaintProgress(ppd, hwndBar, hps);
     328                    PaintProgress(ppd, hwndBar, &rclWin, hps);
    322329                    WinReleasePS(hps);
    323330                }
     
    326333            case WM_PAINT:
    327334            {
    328                 RECTL rcl;
    329                 hps = WinBeginPaint(hwndBar, NULLHANDLE, &rcl);
    330                 PaintProgress(ppd, hwndBar, hps);
     335                RECTL rclWin;
     336                WinQueryWindowRect(hwndBar, &rclWin);
     337                hps = WinBeginPaint(hwndBar, NULLHANDLE, NULL);
     338                PaintProgress(ppd, hwndBar, &rclWin, hps);
    331339                WinEndPaint(hps);
    332340            break; }
     
    401409        pData->ulAttr = ulAttr;
    402410        pData->OldStaticProc = OldStaticProc;
    403         WinQueryWindowRect(hwndChart, &(pData->rclBar));
    404         (pData->rclBar.xRight)--;
    405         (pData->rclBar.yTop)--;
    406411
    407412        WinSetWindowULong(hwndChart, QWL_USER, (ULONG)pData);
Note: See TracChangeset for help on using the changeset viewer.