oilprog.cpp File Reference

(r1785/r1282)

#include "camtypes.h"
#include <string.h>
#include "csrstack.h"
#include "oilprog.h"
#include "keypress.h"
#include "unicdman.h"

Go to the source code of this file.

Classes

struct  MaskPair
struct  CursorMask

Functions

 DECLARE_SOURCE ("$Revision: 1282 $")
BOOL InitProgressCursor ()
 Does initial calculations and creates all the GDI objects that UpdateProgressCursor() requires.
CursorUpdateProgressCursor (INT32 percent)
 (If percent >= 0 it draws the percentage text into the cursor masks and then) creates and sets a new cursor.
void DeInitProgressCursor ()
 Deallocates all objects created in InitProgressCursor().
BOOL BreakKeyHit ()
 Checks if the user is trying to interrupt or cancel a task.
void Beep ()
 Makes a beep sound, stupid!

Variables

const INT32 nFrameCount = 9
INT32 CurrentFrame
CursorMask CursorSeq [nFrameCount]
const MaskPair CursorMaskID [nFrameCount]
CDCpMemoryDC1
CDCpMemoryDC2
CBitmap * pAndBmp
CBitmap * pXorBmp
CFont * pCursorFont
CRect TextRect
CRect MaskRect


Function Documentation

void Beep  )  [inline]
 

Makes a beep sound, stupid!

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
BreakKeyHit; ContinueSlowJob

Definition at line 496 of file oilprog.cpp.

00497 {
00498     ::MessageBeep(MB_OK);
00499 }

BOOL BreakKeyHit  ) 
 

Checks if the user is trying to interrupt or cancel a task.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the Escape key is pressed.

Errors: -

See also:
ContinueSlowJob

Definition at line 457 of file oilprog.cpp.

00458 {
00459     return KeyPress::IsEscapePressed();
00460 /*
00461     if (::GetAsyncKeyState(CAMKEY(ESCAPE)) <0 )
00462     {
00463         MSG msg;
00464         BOOL Again;
00465         // if Esc is pressed down, lets throw away all key messages otherwise the Esc is likely
00466         // to get passed on e.g. to the next dialog box
00467         do
00468         {
00469             Again = PeekMessage( &msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE );
00470         } while (Again);
00471 
00472         return TRUE;
00473     }
00474     return FALSE;
00475 */
00476 }

DECLARE_SOURCE "$Revision: 1282 $"   ) 
 

void DeInitProgressCursor  ) 
 

Deallocates all objects created in InitProgressCursor().

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
InitProgressCursor; UpdateProgressCursor

Definition at line 414 of file oilprog.cpp.

00415 {
00416     // Deallocate the mask bitmaps.
00417     for (INT32 i = 0; i < nFrameCount; i++)
00418     {
00419         CursorSeq[i].pAndMask->DeleteObject();
00420         CursorSeq[i].pXorMask->DeleteObject();
00421         delete CursorSeq[i].pAndMask;
00422         delete CursorSeq[i].pXorMask;
00423     }
00424 
00425     // Destroy the other GDI objects.
00426     pMemoryDC1->DeleteDC();
00427     delete pMemoryDC1;
00428 
00429     pMemoryDC2->DeleteDC();
00430     delete pMemoryDC2;
00431 
00432     pAndBmp->DeleteObject();
00433     delete pAndBmp;
00434 
00435     pXorBmp->DeleteObject();
00436     delete pXorBmp;
00437 
00438     delete pCursorFont;
00439 }

BOOL InitProgressCursor  ) 
 

Does initial calculations and creates all the GDI objects that UpdateProgressCursor() requires.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if initialisation was successful.

Errors: -

See also:
UpdateProgressCursor; DeInitProgressCursor

Definition at line 194 of file oilprog.cpp.

00195 {
00196     // Load in the mask bitmap pairs which make up the cursor animation sequence.
00197     for (INT32 i = 0; i < nFrameCount; i++)
00198     {
00199         // Allocate two new bitmap objects on the heap.
00200         CursorSeq[i].pAndMask = new CBitmap;
00201         CursorSeq[i].pXorMask = new CBitmap;
00202         if (!CursorSeq[i].pAndMask || !CursorSeq[i].pXorMask)
00203         {
00204             if (IsUserName("JustinF"))
00205                 TRACE( _T("Couldn't allocate CBitmap objects in InitProgressCursor()!\n"));
00206             return FALSE;
00207         }
00208 
00209         // Load the appropriate bitmaps from resources.
00210         if (!CursorSeq[i].pAndMask->LoadBitmap(CursorMaskID[i].AndID) ||
00211             !CursorSeq[i].pXorMask->LoadBitmap(CursorMaskID[i].XorID))
00212         {
00213             if (IsUserName("JustinF"))
00214                 TRACE( _T("Couldn't load bitmap resources in InitProgressCursor()!\n"));
00215             return FALSE;
00216         }
00217 
00218         // In the debugging version, check for AppStudio sabotage (it converts monochrome
00219         // bitmaps to colour - b*st*rd!)
00220         #ifdef  _DEBUG
00221             BITMAP andinfo, xorinfo;
00222             CursorSeq[i].pAndMask->GetObject(sizeof(andinfo), &andinfo);
00223             CursorSeq[i].pXorMask->GetObject(sizeof(xorinfo), &xorinfo);
00224             ENSURE(andinfo.bmBitsPixel == 1 && andinfo.bmPlanes == 1 &&
00225                    xorinfo.bmBitsPixel == 1 && xorinfo.bmPlanes == 1,
00226                    "Bitmaps in InitProgressCursor() are not monochrome!\n");
00227         #endif  // _DEBUG
00228     }
00229 
00230     // Make two scratch bitmaps with the same size as cursors.  These bitmaps are
00231     // monochrome, like standard Windows cursors.
00232     pAndBmp = new CBitmap;
00233     pXorBmp = new CBitmap;
00234     if (!pAndBmp || !pXorBmp ||
00235         !pAndBmp->CreateBitmap(Cursor::Width(), Cursor::Height(), 1, 1, 0) ||
00236         !pXorBmp->CreateBitmap(Cursor::Width(), Cursor::Height(), 1, 1, 0))
00237     {
00238         if (IsUserName("JustinF"))
00239             TRACE( _T("Couldn't create scratch bitmaps in InitProgressCursor()!\n"));
00240         return FALSE;
00241     }
00242 
00243     // Create a font to write the percentage text with.
00244     LOGFONT fontinfo;
00245     memset(&fontinfo, 0, sizeof(fontinfo));             // all fields zero means use default values
00246     fontinfo.lfCharSet = UnicodeManager::GetFontCharSet();
00247     fontinfo.lfHeight = -Cursor::Width() / 3;
00248 
00249     pCursorFont = new CFont;
00250     if (!pCursorFont || !pCursorFont->CreateFontIndirect(&fontinfo))
00251     {
00252         if (IsUserName("JustinF"))
00253             TRACE( _T("Couldn't create font object in InitProgressCursor()!\n"));
00254         return FALSE;
00255     }
00256 
00257     // Make a device context in memory which is compatible with the screen.
00258     pMemoryDC1 = new CDC;
00259     pMemoryDC2 = new CDC;
00260     if (!pMemoryDC1 || !pMemoryDC2 ||
00261         !pMemoryDC1->CreateCompatibleDC(0) ||
00262         !pMemoryDC2->CreateCompatibleDC(0))
00263     {
00264         if (IsUserName("JustinF"))
00265             TRACE( _T("Couldn't create memory DC's in InitProgressCursor()!\n"));
00266         return FALSE;
00267     }
00268 
00269     // Find out how large the font we created REALLY is, so we can calculate where within
00270     // the cursor we can write the text.
00271     TEXTMETRIC textinfo;
00272     CFont* pf = pMemoryDC1->SelectObject(pCursorFont);
00273     pMemoryDC1->GetTextMetrics(&textinfo);
00274     pMemoryDC1->SelectObject(pf);
00275 
00276     // The text appears at the bottom of the cursor.  Calculate its bounding rectangle, which
00277     // includes room for a two-pixel wide border
00278     TextRect.left   = 0;
00279     TextRect.top    = Cursor::Height() - textinfo.tmAscent;
00280     TextRect.right  = Cursor::Width();
00281     TextRect.bottom = Cursor::Height();
00282 
00283     // The mask bitmaps are stretched into the remaining square space.
00284     MaskRect.top    = 0;
00285     MaskRect.bottom = Cursor::Height() - textinfo.tmHeight;
00286     MaskRect.left   = Cursor::Width() / 2 - MaskRect.bottom / 2;
00287     MaskRect.right  = Cursor::Width() / 2 + MaskRect.bottom / 2;
00288 
00289     // Finally, set the animation to begin with the first frame and . . . success!
00290     CurrentFrame = 0;
00291     return TRUE;
00292 }

Cursor* UpdateProgressCursor INT32  percent  ) 
 

(If percent >= 0 it draws the percentage text into the cursor masks and then) creates and sets a new cursor.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Messed around by Jason)
Date:
19/11/93
Parameters:
percent - A value between 0% and 100% to be displayed under the pointer, OR [INPUTS] -1 to indicate that no percentage should be displayed.
- [OUTPUTS]
Returns:
A pointer to the new progress cursor object if successful, NULL otherwise.

Errors: -

See also:
InitProgressCursor; DeInitProgressCursor

Definition at line 313 of file oilprog.cpp.

00314 {
00315     // Before we get too confused, the truth table for the combination of the 2 bitmaps is:
00316     //
00317     //      ANDbmp  XORbmp  Result in cursor
00318     //      Black   Black   Black
00319     //      Black   White   White
00320     //      White   Black   Transparent
00321     //      White   White   Invert screen colour at this point
00322     //
00323     // First, we set AND/XOR to White/Black respectively so that the cursor is transparent...
00324 
00325     CBitmap* poldbmp1 = pMemoryDC1->SelectObject(pAndBmp);
00326     pMemoryDC1->PatBlt(0, 0, Cursor::Width(), Cursor::Height(), WHITENESS);
00327 
00328     CBitmap* poldbmp2 = pMemoryDC2->SelectObject(pXorBmp);
00329     pMemoryDC2->PatBlt(0, 0, Cursor::Width(), Cursor::Height(), BLACKNESS);
00330 
00331     // Find out how large the mask bitmaps are (they are assumed to all be of the same size).
00332     BITMAP bmpinfo;
00333     CursorSeq[CurrentFrame].pAndMask->GetObject(sizeof(bmpinfo), &bmpinfo);
00334 
00335     // Stretch the cursor masks for the current animation frame into the scratch bitmaps.
00336     // First the XOR mask, then the AND mask.
00337     pMemoryDC2->SelectObject(CursorSeq[CurrentFrame].pXorMask);         // source
00338     pMemoryDC1->SelectObject(pXorBmp);                                  // destination
00339     pMemoryDC1->StretchBlt(MaskRect.left, MaskRect.top, MaskRect.Width(), MaskRect.Height(),
00340                            pMemoryDC2, 0, 0, bmpinfo.bmWidth, bmpinfo.bmHeight, SRCCOPY);
00341 
00342     pMemoryDC2->SelectObject(CursorSeq[CurrentFrame].pAndMask);         // source
00343     pMemoryDC1->SelectObject(pAndBmp);                                  // destination
00344     pMemoryDC1->StretchBlt(MaskRect.left, MaskRect.top, MaskRect.Width(), MaskRect.Height(),
00345                            pMemoryDC2, 0, 0, bmpinfo.bmWidth, bmpinfo.bmHeight, SRCCOPY);
00346 
00347     if (percent >= 0)       // Only display percentage text if 'percent' >= 0
00348     {
00349         // Next, write the percentage text inside the text rectangle.
00350         // We want this to be black text on a white rub-out box, so we plot black-on-white text
00351         // into the XOR bitmap, and black-on-black into the AND bitmap (rather than plotting a
00352         // rectangle, because we want the rub-out box to be only slightly bigger than the text
00353         // sitting upon it...)
00354         pMemoryDC1->SelectObject(pXorBmp);
00355 
00356         pMemoryDC1->SetTextColor(RGB(0, 0, 0));
00357         pMemoryDC1->SetBkColor(RGB(255, 255, 255));
00358 
00359         CFont   *poldfont1 = pMemoryDC1->SelectObject(pCursorFont);
00360         TCHAR   txt[8];                     // Cache - percentage text
00361         INT32       numchars;                   // Cache - number of chars in the above %age text
00362 
00363         String_32 jcf(_R(IDS_PERCENT_FORMAT));
00364         numchars = ::wsprintf(txt, jcf, (INT32) percent);
00365         pMemoryDC1->DrawText(txt, numchars, &TextRect,
00366                              DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX);
00367 
00368         pMemoryDC1->SelectObject(pAndBmp);
00369         pMemoryDC1->SetTextColor(RGB(0, 0, 0));
00370         pMemoryDC1->SetBkColor(RGB(0, 0, 0));
00371 
00372         pMemoryDC1->DrawText(txt, numchars, &TextRect,
00373                              DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX);
00374 
00375         pMemoryDC1->SelectObject(poldfont1);
00376     }
00377 
00378     // Deselect the bitmaps.
00379     pMemoryDC1->SelectObject(poldbmp1);
00380     pMemoryDC2->SelectObject(poldbmp2);
00381 
00382     // Finally, create and set the new cursor.
00383     Cursor* pnc = new Cursor(pAndBmp, pXorBmp);
00384     if (!pnc || !pnc->IsValid())
00385     {
00386         if (IsUserName("JustinF"))
00387             TRACE( _T("Couldn't create new Cursor object in UpdateProgressCursor()!\n"));
00388         delete pnc;
00389         return 0;
00390     }
00391 
00392     // Update the animation frame counter.
00393     if (++CurrentFrame >= nFrameCount) CurrentFrame = 0;
00394     return pnc;
00395 }


Variable Documentation

INT32 CurrentFrame
 

Definition at line 143 of file oilprog.cpp.

const MaskPair CursorMaskID[nFrameCount]
 

Initial value:

{
    { _R(IDB_AND_PROGRESS_0), _R(IDB_XOR_PROGRESS_0) },
    { _R(IDB_AND_PROGRESS_1), _R(IDB_XOR_PROGRESS_1) },
    { _R(IDB_AND_PROGRESS_2), _R(IDB_XOR_PROGRESS_2) },
    { _R(IDB_AND_PROGRESS_3), _R(IDB_XOR_PROGRESS_3) },
    { _R(IDB_AND_PROGRESS_4), _R(IDB_XOR_PROGRESS_4) },
    { _R(IDB_AND_PROGRESS_5), _R(IDB_XOR_PROGRESS_5) },
    { _R(IDB_AND_PROGRESS_6), _R(IDB_XOR_PROGRESS_6) },             
    { _R(IDB_AND_PROGRESS_7), _R(IDB_XOR_PROGRESS_7) },
    { _R(IDB_AND_PROGRESS_8), _R(IDB_XOR_PROGRESS_8) }
}

Definition at line 151 of file oilprog.cpp.

CursorMask CursorSeq[nFrameCount]
 

Definition at line 145 of file oilprog.cpp.

CRect MaskRect
 

Definition at line 175 of file oilprog.cpp.

const INT32 nFrameCount = 9
 

Definition at line 142 of file oilprog.cpp.

CBitmap* pAndBmp
 

Definition at line 170 of file oilprog.cpp.

CFont* pCursorFont
 

Definition at line 172 of file oilprog.cpp.

CDC* pMemoryDC1
 

Definition at line 168 of file oilprog.cpp.

CDC* pMemoryDC2
 

Definition at line 169 of file oilprog.cpp.

CBitmap* pXorBmp
 

Definition at line 171 of file oilprog.cpp.

CRect TextRect
 

Definition at line 174 of file oilprog.cpp.


Generated on Sat Nov 10 03:49:35 2007 for Camelot by  doxygen 1.4.4