#include <csrstack.h>
Public Member Functions | |
CursorStack (INT32 maxdepth=10) | |
Constructs an empty stack of Cursor objects, with a maximum depth (by default this is 10 deep). | |
virtual | ~CursorStack () |
Destroys a CursorStack object. | |
void | BeginBusy () |
Tells the cursor stack to show the busy cursor. Multiple calls will increment a usage count, and the cursor won't disappear until the usage count drops to zero. | |
void | EndBusy () |
Turns off the busy cursor (if there has only been one call to BeginBusy) for this cursor stack. Waits until BusyCount reaches zero before turning off the busy cursor. | |
void | SmashBusy () |
Turns off the busy cursor (without exceptions) for this cursor stack. Resets the Busy count to zero. Called by Progress.cpp's SmashBusyJob to ensure the cursor is off. | |
Static Public Member Functions | |
static BOOL | Init () |
Initialises the cursor system, loading the standard OS-provided cursors, such as the arrow and the hour-glass, creating the application's cursor stack etc. | |
static void | DeInit () |
Shuts down the cursor system, releasing resources allocated by the Init() member function. | |
static BOOL | GIsValid () |
static INT32 | GPush (Cursor *pCursor, BOOL ActivateNow=TRUE) |
static Cursor * | GPop (INT32 cursorID) |
static Cursor * | GSetTop (Cursor *pCursor, INT32 cursorID) |
static void | GSetActive () |
static BOOL | GIsActive (const Cursor *pCursor) |
static Cursor * | GetActive () |
Private Member Functions | |
CC_DECLARE_MEMDUMP (CursorStack) | |
BOOL | IsValid () const |
Tests if the object was successfully constructed, and is coherent. | |
INT32 | Push (Cursor *pCursor, BOOL ActivateNow=TRUE) |
Pushes the parameter onto the stack, making it top-most and hence the Cursor which will become active when SetActive() is called (this is done automatically by default, or if you pass in ActivateNow == TRUE) The Unique ID returned will be required by calls to SetTop and Pop so that we don't have any problems with the wrong cursors being popped and deleted. | |
Cursor * | Pop (INT32 cursorID=0) |
Removes a cursor from the stack. Because of the strange, asynchronous nature of Camelot, and the way cursors are seemingly added and removed from the stack at random, when popping a cursor from the stack, a unique ID is used to identify which cursor you actually want to remove. That one is removed, whether it's at the top of the stack or not. | |
Cursor * | SetTop (Cursor *pCursor, INT32 cursorID=0) |
Replaces a cursor on the stack with a new Cursor object. Combines a pop and a push. Note that the function detects if the stack is empty and will skip the initial pop if it is. The unique ID is used to find which cursor is actually to be replaced. If the cursor passed to this function is the same as the one already occupying the slot, no switching is done, otherwise the top cursor on the stack will be switched on (not necessarily the one passed to this function). | |
void | SetActive (bool fOnlyRendWnd=true) const |
Makes the Cursor object on the top of the stack the active cursor. | |
BOOL | IsActive (const Cursor *pCursor) const |
Tests if a particular cursor is on the top of the stack, ie. is currently visible and active. | |
Private Attributes | |
CursorIdent * | pcStack |
INT32 | nNextFreeSlot |
INT32 | nSentinel |
INT32 | BusyCount |
Static Private Attributes | |
static CursorStack * | Global |
Friends | |
void | BeginBusyCursor () |
Tells the global cursor stack to display a busy cursor. | |
void | EndBusyCursor () |
Tells the global cursor stack to stop displaying the busy cursor. If more than one call has been previously made to beginBusyCursor, the busy cursor isn't removed - a usage count is decremented. | |
void | SmashBusyCursor () |
Tells the global cursor stack to stop displaying the busy cursor, regardless of how many calls have been previously made to beginBusyCursor. |
Definition at line 145 of file csrstack.h.
|
Constructs an empty stack of Cursor objects, with a maximum depth (by default this is 10 deep).
Definition at line 201 of file csrstack.cpp. 00202 { 00203 nSentinel = maxdepth; 00204 nNextFreeSlot = 0; 00205 BusyCount = 0; 00206 00207 pcStack = new CursorIdent[maxdepth]; // array of CursorIdent objects 00208 00209 #ifdef _DEBUG 00210 if( !pcStack ) 00211 TRACEUSER( "JustinF", _T("Failed to allocate stack in CursorStack::CursorStack!\n")); 00212 #endif // _DEBUG 00213 }
|
|
Destroys a CursorStack object.
Definition at line 231 of file csrstack.cpp. 00232 { 00233 #ifdef _DEBUG 00234 if (nNextFreeSlot != 0) 00235 TRACE( _T("WARNING: Cursor Stack at 0x%p not empty (%d deep) upon destruction!\n"), 00236 this, nNextFreeSlot); 00237 #endif // _DEBUG 00238 00239 delete[] pcStack; 00240 }
|
|
Tells the cursor stack to show the busy cursor. Multiple calls will increment a usage count, and the cursor won't disappear until the usage count drops to zero.
Definition at line 553 of file csrstack.cpp.
|
|
|
|
Shuts down the cursor system, releasing resources allocated by the Init() member function.
Definition at line 174 of file csrstack.cpp. 00175 { 00176 if (!Global) return; 00177 Global->Pop(); // undo the push done in Init() 00178 delete Global; 00179 Global = 0; 00180 Cursor::DeInit(); 00181 }
|
|
Turns off the busy cursor (if there has only been one call to BeginBusy) for this cursor stack. Waits until BusyCount reaches zero before turning off the busy cursor.
Definition at line 576 of file csrstack.cpp. 00577 { 00578 if ((--BusyCount) < 0) 00579 { 00580 BusyCount=0; 00581 ERROR3("Too many calls to CursorStack::EndBusy\n"); 00582 } 00583 SetActive(); 00584 }
|
|
Definition at line 482 of file csrstack.cpp. 00483 { 00484 if( Global->nNextFreeSlot <= 0 ) 00485 { 00486 ERROR3("Stack empty in CursorStack::SetActive!\n"); 00487 return NULL; 00488 } 00489 00490 // If BusyCount > 0 show the busy cursor instead of the topmost one 00491 if( Global->BusyCount > 0 ) 00492 { 00493 return Cursor::Busy; 00494 } 00495 else 00496 { 00497 return Global->pcStack[Global->nNextFreeSlot - 1].pCursor; 00498 } 00499 }
|
|
Definition at line 716 of file csrstack.cpp.
|
|
Definition at line 691 of file csrstack.cpp.
|
|
Definition at line 701 of file csrstack.cpp.
|
|
Definition at line 696 of file csrstack.cpp.
|
|
Definition at line 711 of file csrstack.cpp.
|
|
Definition at line 706 of file csrstack.cpp.
|
|
Initialises the cursor system, loading the standard OS-provided cursors, such as the arrow and the hour-glass, creating the application's cursor stack etc.
Definition at line 141 of file csrstack.cpp. 00142 { 00143 Global = new CursorStack; 00144 if (!Global || !Global->IsValid() || !Cursor::Init()) 00145 { 00146 delete Global; 00147 Global = 0; 00148 return FALSE; 00149 } 00150 Global->Push(Cursor::Arrow); // This is about the only occurrence of Push 00151 // that can legitimately ignore the return value, since 00152 // this cursor should always be on the stack. 00153 Global->SetActive(); 00154 return TRUE; 00155 }
|
|
Tests if a particular cursor is on the top of the stack, ie. is currently visible and active.
Definition at line 516 of file csrstack.cpp. 00517 { 00518 // return (nNextFreeSlot > 0) ? (pcStack[nNextFreeSlot - 1] == pCursor) : FALSE; 00519 00520 // if BusyCount>0 that means the busy cursor is active, so check for that situation 00521 00522 if (BusyCount > 0) 00523 { 00524 return (pCursor == Cursor::Busy); 00525 } 00526 else 00527 { 00528 if (nNextFreeSlot>0 && (pcStack[nNextFreeSlot - 1].pCursor == pCursor)) 00529 00530 return TRUE; 00531 00532 return FALSE; 00533 } 00534 }
|
|
Tests if the object was successfully constructed, and is coherent.
Definition at line 258 of file csrstack.cpp. 00259 { 00260 return pcStack != 0 && (nNextFreeSlot >= 0 && nNextFreeSlot <= nSentinel); 00261 }
|
|
Removes a cursor from the stack. Because of the strange, asynchronous nature of Camelot, and the way cursors are seemingly added and removed from the stack at random, when popping a cursor from the stack, a unique ID is used to identify which cursor you actually want to remove. That one is removed, whether it's at the top of the stack or not.
Definition at line 323 of file csrstack.cpp. 00324 { 00325 ERROR2IF(nNextFreeSlot <= 0,NULL, "Underflow in CursorStack::Pop!\n"); 00326 00327 // For old code which doesn't pass the ID, we'll pop the top one off and hope 00328 if (cursorID == 0) 00329 { 00330 Cursor* pc = pcStack[--nNextFreeSlot].pCursor; 00331 return pc; 00332 } 00333 else 00334 { 00335 INT32 n=0; // Counter to go through the stack 00336 00337 // Yes, I know this while loop could be more cleverly implemented, but I'm 00338 // sticking with easier to understand code, and letting the optimiser do 00339 // the hard work. 00340 00341 // Find the ID on the stack and remove it, sealing the hole up 00342 while(n<nNextFreeSlot) 00343 { 00344 if (pcStack[n].UniqueID == cursorID) 00345 { 00346 Cursor* pc = pcStack[n].pCursor; // for return 00347 00348 // Now, what's the best way of closing up the gap? 00349 INT32 m = n+1; // Point at the next item on stack 00350 while (m<nNextFreeSlot) // Don't copy anything if n is the last one 00351 { 00352 pcStack[n].pCursor = pcStack[m].pCursor; 00353 pcStack[n].UniqueID = pcStack[m].UniqueID; 00354 n++; 00355 m++; 00356 } 00357 00358 // Now the gap has been closed, let's decrement the nextfree counter 00359 nNextFreeSlot--; 00360 if (nNextFreeSlot > 0) 00361 SetActive(); 00362 00363 // Finally, return the pointer to the cursor we've just removed from the stack 00364 return pc; 00365 00366 } 00367 n++; 00368 } 00369 00370 // If we arrive here, there wasn't a valid cursor on the stack, so complain 00371 ERROR2(NULL,"Unique ID not found in cursor stack\n"); 00372 00373 } 00374 00375 }
|
|
Pushes the parameter onto the stack, making it top-most and hence the Cursor which will become active when SetActive() is called (this is done automatically by default, or if you pass in ActivateNow == TRUE) The Unique ID returned will be required by calls to SetTop and Pop so that we don't have any problems with the wrong cursors being popped and deleted.
Definition at line 289 of file csrstack.cpp. 00290 { 00291 ENSURE(nNextFreeSlot < nSentinel, "Overflow in CursorStack::Push!\n"); 00292 00293 INT32 retID = pcStack[nNextFreeSlot++].StoreNewCursor(pCursor); 00294 if (ActivateNow) 00295 SetActive(); 00296 00297 return retID; 00298 }
|
|
Makes the Cursor object on the top of the stack the active cursor.
Definition at line 467 of file csrstack.cpp. 00468 { 00469 if (nNextFreeSlot <= 0) 00470 { 00471 ERROR3("Stack empty in CursorStack::SetActive!\n"); 00472 return; 00473 } 00474 00475 // If BusyCount > 0 show the busy cursor instead of the topmost one 00476 if (BusyCount > 0) 00477 Cursor::Busy->SetActive(); 00478 else 00479 pcStack[nNextFreeSlot - 1].pCursor->SetActive( fOnlyRendWnd ); 00480 }
|
|
Replaces a cursor on the stack with a new Cursor object. Combines a pop and a push. Note that the function detects if the stack is empty and will skip the initial pop if it is. The unique ID is used to find which cursor is actually to be replaced. If the cursor passed to this function is the same as the one already occupying the slot, no switching is done, otherwise the top cursor on the stack will be switched on (not necessarily the one passed to this function).
Definition at line 401 of file csrstack.cpp. 00402 { 00403 // cursorID will be zero if unmodified code is used. 00404 if (cursorID == 0) 00405 { 00406 ERROR3("CursorStack::SetTop called without a valid cursorID. Please change the offending code.\n"); 00407 Cursor* pc; 00408 if (nNextFreeSlot > 0) 00409 { 00410 pc = pcStack[nNextFreeSlot - 1].pCursor; 00411 pcStack[nNextFreeSlot - 1].pCursor = pCursor; 00412 } 00413 else 00414 { 00415 pc = NULL; 00416 Push(pCursor); 00417 } 00418 SetActive(); 00419 return pc; 00420 } 00421 else 00422 { 00423 // This is the new case 00424 INT32 n=0; // Counter to go through the stack 00425 00426 // Find the ID on the stack and replace it with the new cursor 00427 while(n<nNextFreeSlot) 00428 { 00429 if (pcStack[n].UniqueID == cursorID) 00430 { 00431 Cursor* pc = pcStack[n].pCursor; // for return 00432 if (pc == pCursor) 00433 return pc; // Don't try and set the cursor if it's the same 00434 00435 // Replace this cursor with the new one 00436 pcStack[n].pCursor = pCursor; 00437 00438 if (nNextFreeSlot > 0) SetActive(); 00439 00440 // Finally, return the pointer to the cursor we've just removed from the stack 00441 return pc; 00442 00443 } 00444 n++; 00445 } 00446 // Oh dear, we seem not to have found this cursorID on the stack. 00447 ERROR2(NULL,"cursorID not found on stack in SetTop.\n"); 00448 } 00449 }
|
|
Turns off the busy cursor (without exceptions) for this cursor stack. Resets the Busy count to zero. Called by Progress.cpp's SmashBusyJob to ensure the cursor is off.
Definition at line 605 of file csrstack.cpp. 00606 { 00607 if (BusyCount == 0) // Not showing a busy cursor, so return ASAP 00608 return; 00609 00610 // Turn off the busy cursor 00611 BusyCount = 0; 00612 SetActive(); 00613 }
|
|
Tells the global cursor stack to display a busy cursor.
Definition at line 632 of file csrstack.cpp. 00633 { 00634 //CursorStack::Global->Push(Cursor::Busy); 00635 if (CursorStack::Global) 00636 CursorStack::Global->BeginBusy(); 00637 }
|
|
Tells the global cursor stack to stop displaying the busy cursor. If more than one call has been previously made to beginBusyCursor, the busy cursor isn't removed - a usage count is decremented.
Definition at line 658 of file csrstack.cpp. 00659 { 00660 if (CursorStack::Global) 00661 CursorStack::Global->EndBusy(); 00662 }
|
|
Tells the global cursor stack to stop displaying the busy cursor, regardless of how many calls have been previously made to beginBusyCursor.
Definition at line 681 of file csrstack.cpp. 00682 { 00683 if (CursorStack::Global) 00684 CursorStack::Global->SmashBusy(); 00685 }
|
|
Definition at line 193 of file csrstack.h. |
|
Definition at line 187 of file csrstack.h. |
|
Definition at line 190 of file csrstack.h. |
|
Definition at line 191 of file csrstack.h. |
|
Definition at line 189 of file csrstack.h. |