CaptureHandler Class Reference

An event handler to centralise the mouse handling during a drag. More...

#include <dragmgr.h>

List of all members.

Public Member Functions

 CaptureHandler (wxWindow *pWindow=NULL)
 CaptureHandler constructor.
 ~CaptureHandler ()
 CaptureWnd destructor.
void OnMouseMove (wxMouseEvent &event)
 call solid drag draw code.
void OnLButtonUp (wxMouseEvent &event)
void OnRButtonUp (wxMouseEvent &event)
BOOL StartCapture ()
 Attaches us to the window and starts mouse capture.
BOOL SetUpSolidDrag (wxPoint StartPos)
 Sets up Device Contexts / Bitmaps etc.. for Solid Drag.
BOOL CleanUpSolidDrag ()
 Removes any solid-drag stuff we may have on-screen at the moment and cleans up the solid drag system. Called at the end of a drag to clean up, and also whenever someone is redrawing underneath us, and we thus need to remove the drag stuff while they redraw.
BOOL CleanUpSolidDragInScreenArea (const wxRect &Area)
 Calls CleanUpSolidDrag. However, it ONLY calls that method if the compromised screen area overlaps the solid drag area - if not, then the solid drag stuff can't be overwritten, so there is no need to remove it. This can drastically reduce flicker when things are background redrawing on other parts of the screen.
BOOL DrawSolidDrag (wxPoint point)
 to allow solid flicker-free drag objects to be drawn. a helper function in the current drag is called - but this function looks after the rest.
BOOL DrawTransparentDrag (wxPoint point, INT32 Transparency)
 to allow solid flicker-free semi-transparent drag objects to be drawn. a helper function in the current drag is called - but this function looks after the rest.

Protected Attributes

wxWindow * m_pWindow
BOOL m_bHasCapture
wxScreenDC * m_pDisplayDC
wxBitmap * m_pBackBitmap
wxRect m_DragRect
wxBitmap * m_pMaskBitmap

Friends

class DragManagerOp
class DragInformation


Detailed Description

An event handler to centralise the mouse handling during a drag.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/01/95
See also:

Definition at line 124 of file dragmgr.h.


Constructor & Destructor Documentation

CaptureHandler::CaptureHandler wxWindow *  pWindow = NULL  ) 
 

CaptureHandler constructor.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/1/95

Definition at line 152 of file dragmgr.cpp.

00153 {
00154 //  TRACEUSER("Gerry", _T("CaptureHandler::CaptureHandler"));
00155     m_pWindow = pWindow;
00156     m_bHasCapture = FALSE;
00157     m_pDisplayDC = NULL;
00158     m_pBackBitmap = NULL;
00159     m_pMaskBitmap = NULL;
00160 }

CaptureHandler::~CaptureHandler  ) 
 

CaptureWnd destructor.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/1/95

Definition at line 173 of file dragmgr.cpp.

00174 {
00175 //  TRACEUSER("Gerry", _T("CaptureHandler::~CaptureHandler"));
00176     // Need to clean up all the pointers here...
00177 
00178     if (m_bHasCapture)
00179     {
00180         if (m_pWindow->PopEventHandler() != this)
00181         {
00182             TRACEUSER("Gerry", _T("Popped event handler is not this one, expect a crash"));
00183         }
00184 
00185         if (m_pWindow->HasCapture())
00186         {
00187             m_pWindow->ReleaseMouse();
00188             if (m_pWindow->HasCapture())
00189             {
00190                 TRACEUSER("Gerry", _T("Still got capture"));
00191             }
00192             else
00193             {
00194                 TRACEUSER("Gerry", _T("Capture released"));
00195             }
00196 
00197             CursorStack::GSetActive();
00198         }
00199         else
00200         {
00201             TRACEUSER("Gerry", _T("Haven't got capture"));
00202         }
00203         m_bHasCapture = FALSE;
00204     }
00205 }


Member Function Documentation

BOOL CaptureHandler::CleanUpSolidDrag  ) 
 

Removes any solid-drag stuff we may have on-screen at the moment and cleans up the solid drag system. Called at the end of a drag to clean up, and also whenever someone is redrawing underneath us, and we thus need to remove the drag stuff while they redraw.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/01/95
Parameters:
- [INPUTS]
Returns:
FALSE if it fails

Errors: -

See also:
CaptureHandler::CleanUpSolidDragInScreenArea

Definition at line 528 of file dragmgr.cpp.

00529 {
00530     TRACEUSER("Gerry", _T("CleanUpSolidDrag"));
00531 
00532     if (DragManagerOp::CurrentManager == NULL)
00533         return(FALSE);
00534 
00535     if (DragManagerOp::CurrentManager->CurrentDragInfo &&
00536         !DragManagerOp::CurrentManager->CurrentDragInfo->DoesSolidDrag)
00537        return TRUE;
00538 
00539     if (m_pDisplayDC == NULL)
00540         return FALSE;
00541 
00542     if (m_pBackBitmap)
00543     {
00544         wxMemoryDC BackGroundDC;
00545     
00546         // select bitmap into the dc
00547         BackGroundDC.SelectObject(*m_pBackBitmap);
00548 
00549         // remove the last drag draw (only if we drew something)
00550         if (!DragManagerOp::CurrentManager->DragPending)
00551         {
00552             m_pDisplayDC->Blit(m_DragRect.x,m_DragRect.y,m_DragRect.width, m_DragRect.height,&BackGroundDC,0,0);
00553         }
00554 
00555         // clean up  and delete the DC's
00556         BackGroundDC.SelectObject(wxNullBitmap);
00557     }
00558 
00559     if (m_pDisplayDC)
00560     {
00561         delete m_pDisplayDC;
00562         m_pDisplayDC = NULL;
00563     }
00564 
00565     if (m_pBackBitmap)
00566     {
00567         delete m_pBackBitmap;
00568         m_pBackBitmap = NULL;
00569     }
00570 
00571     if (m_pMaskBitmap)
00572     {
00573         delete m_pMaskBitmap;
00574         m_pMaskBitmap = NULL;
00575     }
00576 
00577     m_DragRect = wxRect(0, 0, 0, 0);
00578 
00579     return TRUE;
00580 }

BOOL CaptureHandler::CleanUpSolidDragInScreenArea const wxRect &  Area  ) 
 

Calls CleanUpSolidDrag. However, it ONLY calls that method if the compromised screen area overlaps the solid drag area - if not, then the solid drag stuff can't be overwritten, so there is no need to remove it. This can drastically reduce flicker when things are background redrawing on other parts of the screen.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/5/95
Parameters:
Area - The SCREEN coordinates of the area ofd screen which has become [INPUTS] compromised (usually because it is being redrawn).
Returns:
TRUE if it called CleanUpSolidDrag, FALSE if it didn't bother
See also:
CaptureHandler::CleanUpSolidDrag

Definition at line 606 of file dragmgr.cpp.

00607 {
00608 //  TRACEUSER("Gerry", _T("CleanUpSolidDragInScreenArea"));
00609 
00610     // No solid drag, so no need to do anything
00611     if (!DragManagerOp::CurrentManager->CurrentDragInfo->DoesSolidDrag)
00612        return(FALSE);
00613 
00614     // No solid stuff has yet been drawn, so no need to do anything
00615     if (DragManagerOp::CurrentManager->DragPending || m_DragRect.IsEmpty())
00616         return(FALSE);
00617 
00618     wxRect Isect(Area);
00619     if (!Isect.Intersect(m_DragRect).IsEmpty())
00620     {
00621         CleanUpSolidDrag();
00622         return(TRUE);
00623     }
00624 
00625     return(FALSE);
00626 }

BOOL CaptureHandler::DrawSolidDrag wxPoint  point  ) 
 

to allow solid flicker-free drag objects to be drawn. a helper function in the current drag is called - but this function looks after the rest.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/01/95
Parameters:
Screen Coord [INPUTS]
Returns:
Errors: -
See also:
-

Definition at line 682 of file dragmgr.cpp.

00683 {
00684     // ignore if not intialized
00685     if (!m_pBackBitmap || !m_pDisplayDC)
00686         return FALSE;
00687 
00688 //  TRACEUSER("Gerry", _T("DrawSolidDrag(%d, %d)"), point.x, point.y);
00689 
00690     ERROR2IF(DragManagerOp::CurrentManager == NULL ||
00691              DragManagerOp::CurrentManager->CurrentDragInfo == NULL,
00692              FALSE,
00693              "No current drag in CaptureHandler::DrawSolidDrag!");
00694     
00695     // not interested ? ...
00696     if(DragManagerOp::CurrentManager->DragPending)
00697         return TRUE;
00698     if(!DragManagerOp::CurrentManager->CurrentDragInfo->DoesSolidDrag)
00699         return TRUE;
00700 
00701     INT32 DragTransparency = DragManagerOp::CurrentManager->CurrentDragInfo->
00702                                                             GetDragTransparency();
00703     // If the Drag Info says it wants to be transparent,
00704     // then call the transparent drag routine.
00705     if (DragTransparency > 0 || m_pMaskBitmap != NULL)
00706     {
00707         if (DrawTransparentDrag(point, DragTransparency))
00708             return TRUE;
00709 
00710         // If the Transparency Drag fails (eg. not enough resources under Win32s !!)
00711         // then just fall though, and try a normal solid drag .....
00712     }
00713 
00714     // offset mouse pos by drag offset
00715     point += DragManagerOp::CurrentManager->CurrentDragInfo->SolidDragOffset;
00716 
00717     // size of solid drag draw bounds
00718     wxSize DSize = DragManagerOp::CurrentManager->CurrentDragInfo->SolidDragSize;
00719 
00720     // create a few DCs !!!
00721     
00722     // this one will hold the old background
00723     wxMemoryDC BackDC;
00724     
00725     // select bitmap into the dc
00726     BackDC.SelectObject(*m_pBackBitmap);
00727 
00728     // this one is just temp
00729     wxMemoryDC ScratchDC;
00730     wxBitmap ScratchBit(DSize.x, DSize.y);
00731 
00732     // select bitmap into the dc
00733     ScratchDC.SelectObject(ScratchBit);
00734     
00735     // make copy of last rect
00736     wxRect OldRect(m_DragRect);
00737     
00738     // set new drag draw bounds
00739     m_DragRect = wxRect(point.x, point.y, DSize.x, DSize.y);
00740     
00741     // Copy screen to new background
00742     ScratchDC.Blit(0,0,DSize.x,DSize.y,m_pDisplayDC,m_DragRect.x,m_DragRect.y);
00743     
00744     wxPoint Change = OldRect.GetPosition() - m_DragRect.GetPosition();
00745     
00746     // Replace part of new bkg with old background
00747     if (!OldRect.IsEmpty())
00748         ScratchDC.Blit(Change.x,Change.y,DSize.x,DSize.y,&BackDC,0,0);
00749 
00750     // Copy image to screen
00751     DragManagerOp::CurrentManager->CurrentDragInfo->
00752         OnDrawSolidDrag(m_DragRect.GetPosition(), m_pDisplayDC);
00753 
00754     // Copy part of image to old background
00755     DragManagerOp::CurrentManager->CurrentDragInfo->
00756         OnDrawSolidDrag(wxPoint(-Change.x,-Change.y), &BackDC);
00757     
00758     // Copy old background to screen
00759     if (!OldRect.IsEmpty())
00760         m_pDisplayDC->Blit(OldRect.x,OldRect.y,DSize.x,DSize.y,&BackDC,0,0);
00761 
00762     // copy new background into old for next time round
00763     BackDC.Blit(0,0,DSize.x,DSize.y,&ScratchDC,0,0);
00764 
00765     // clean up and delete scratch dc and bitmap
00766     ScratchDC.SelectObject(wxNullBitmap);
00767 
00768     BackDC.SelectObject(wxNullBitmap);
00769 
00770     return TRUE;
00771 }

BOOL CaptureHandler::DrawTransparentDrag wxPoint  point,
INT32  Transparency
 

to allow solid flicker-free semi-transparent drag objects to be drawn. a helper function in the current drag is called - but this function looks after the rest.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/03/95
Parameters:
Screen Coord [INPUTS]
Returns:
Errors: -
See also:
-

Definition at line 789 of file dragmgr.cpp.

00790 {
00791 //  TRACEUSER("Gerry", _T("DrawTransparentDrag(%d, %d, %d)"), point.x, point.y, Transparency);
00792 
00793     // offset mouse pos by drag offset
00794     point += DragManagerOp::CurrentManager->CurrentDragInfo->SolidDragOffset;
00795 
00796     // size of solid drag draw bounds
00797     wxSize DSize = DragManagerOp::CurrentManager->CurrentDragInfo->SolidDragSize;
00798 
00799     // create a few DCs !!!
00800     // this one will hold the old background
00801     wxMemoryDC BackDC;
00802 
00803     // select bitmap into the dc
00804     BackDC.SelectObject(*m_pBackBitmap);
00805 
00806     // this one is just temp
00807     wxMemoryDC ScratchDC;
00808     wxBitmap ScratchBit(DSize.x,DSize.y);
00809 
00810     wxBitmap TempBitmap(DSize.x, DSize.y);
00811     wxMemoryDC TempDC;
00812 
00813     wxMemoryDC MaskDC;
00814 
00815     // select bitmap into the dc
00816     ScratchDC.SelectObject(ScratchBit);
00817     
00818     // make copy of last rect
00819     wxRect OldRect = m_DragRect;
00820     
00821     // set new drag draw bounds
00822     m_DragRect = wxRect(point.x,point.y,DSize.x,DSize.y);
00823     
00824     // Copy screen to new background
00825     ScratchDC.Blit(0,0,DSize.x,DSize.y,m_pDisplayDC,m_DragRect.x,m_DragRect.y);
00826 
00827     wxPoint Change = OldRect.GetPosition() - m_DragRect.GetPosition();
00828 
00829     // Replace part of new bkg with old background
00830     if (!OldRect.IsEmpty())
00831         ScratchDC.Blit(Change.x,Change.y,DSize.x,DSize.y,&BackDC,0,0);
00832 
00833     TempDC.SelectObject(TempBitmap);
00834 
00835     // Render into the temporary bitmap
00836     DragManagerOp::CurrentManager->CurrentDragInfo->
00837         OnDrawSolidDrag(wxPoint(0,0), &TempDC);
00838 
00839     // set the colours for the masking
00840 //  TempDC.SetBkColor(RGB(0,0,0));
00841 //  TempDC.SetTextColor(RGB(255,255,255));
00842 
00843     MaskDC.SelectObject(*m_pMaskBitmap);
00844 
00845     TempDC.Blit(0, 0, DSize.x, DSize.y, &MaskDC, 0, 0, wxAND_INVERT);
00846 
00847     wxBitmap OffScreenBmp(DSize.x, DSize.y);
00848     wxMemoryDC OffScreenDC;
00849     OffScreenDC.SelectObject(OffScreenBmp);
00850 
00851     OffScreenDC.Blit(0, 0, DSize.x, DSize.y, &ScratchDC, 0, 0);
00852 
00853     OffScreenDC.Blit(0, 0, DSize.x, DSize.y, &MaskDC, 0, 0, wxAND);
00854 
00855     OffScreenDC.Blit(0, 0, DSize.x, DSize.y, &TempDC, 0, 0, wxOR);
00856 
00857     // Copy part of image to old background
00858     BackDC.Blit(-Change.x,-Change.y, DSize.x, DSize.y, &OffScreenDC, 0,0);
00859     
00860     // Copy image to screen
00861     m_pDisplayDC->Blit(m_DragRect.x, m_DragRect.y, DSize.x, DSize.y, &OffScreenDC, 0, 0);
00862 
00863     // Copy old background to screen
00864     if(!OldRect.IsEmpty())
00865         m_pDisplayDC->Blit(OldRect.x, OldRect.y, DSize.x, DSize.y, &BackDC, 0, 0);
00866     
00867     // copy new background into old for next time round
00868     BackDC.Blit(0, 0, DSize.x, DSize.y, &ScratchDC, 0, 0);
00869 
00870     // clean up and delete DCs and bitmaps
00871     OffScreenDC.SelectObject(wxNullBitmap);
00872     TempDC.SelectObject(wxNullBitmap);
00873     MaskDC.SelectObject(wxNullBitmap);
00874     ScratchDC.SelectObject(wxNullBitmap);
00875     BackDC.SelectObject(wxNullBitmap);
00876 
00877     return TRUE;
00878 }

void CaptureHandler::OnLButtonUp wxMouseEvent &  event  ) 
 

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/01/95
Parameters:
MFC [INPUTS]
Returns:
Errors: -
See also:
-

Definition at line 259 of file dragmgr.cpp.

00260 {
00261     if (m_pWindow)
00262     {
00263         wxPoint point = event.GetPosition();
00264         point = m_pWindow->ClientToScreen(point);
00265 
00266         if (DragManagerOp::CurrentManager && DragManagerOp::CurrentManager->CurrentDragInfo)
00267         {
00268             DragManagerOp::CurrentManager->CurrentDragInfo->OnMouseMove(point);
00269             DragManagerOp::CurrentManager->CurrentDragInfo->OnButtonUp(point);
00270         }
00271     }
00272 
00273     TRACEUSER("Gerry", _T("CaptureHandler::OnLButtonUp"));
00274     DragManagerOp::EndDrag(1);// 1 == left click for now
00275     // Don't call Skip as the window wont be expecting the button up
00276 //  event.Skip();
00277 }

void CaptureHandler::OnMouseMove wxMouseEvent &  event  ) 
 

call solid drag draw code.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/01/95
Parameters:
MFC [INPUTS]
Returns:
Errors: -
See also:
-

Definition at line 643 of file dragmgr.cpp.

00644 {
00645 //  TRACEUSER("Gerry", _T("CaptureHandler::OnMouseMove"));
00646     // Abort if the system has been disabled (for an error box)
00647     if (CCamApp::IsDisabled())
00648     {
00649 //      DragManagerOp::AbortDrag();     // This could be deeply scary - it mustn't cause a redraw!
00650         return;
00651     }
00652 
00653     if (DragManagerOp::CurrentManager && !DragManagerOp::CurrentManager->RedrawInProgress)
00654     {
00655         wxPoint point = event.GetPosition();
00656         point = m_pWindow->ClientToScreen(point);
00657 
00658         if (DragManagerOp::CurrentManager->CurrentDragInfo)
00659             DragManagerOp::CurrentManager->CurrentDragInfo->OnMouseMove(point);
00660 
00661         DrawSolidDrag(point);
00662     }
00663 }

void CaptureHandler::OnRButtonUp wxMouseEvent &  event  ) 
 

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/01/95
Parameters:
MFC [INPUTS]
Returns:
Errors: -
See also:
-

Definition at line 292 of file dragmgr.cpp.

00293 {
00294     if (m_pWindow)
00295     {
00296         wxPoint point = event.GetPosition();
00297         point = m_pWindow->ClientToScreen(point);
00298 
00299         if (DragManagerOp::CurrentManager && DragManagerOp::CurrentManager->CurrentDragInfo)
00300         {
00301             DragManagerOp::CurrentManager->CurrentDragInfo->OnMouseMove(point);
00302             DragManagerOp::CurrentManager->CurrentDragInfo->OnButtonUp(point);
00303         }
00304     }
00305 
00306     TRACEUSER("Gerry", _T("CaptureHandler::OnRButtonUp"));
00307     DragManagerOp::EndDrag(-1);//   -1 == Right click for now
00308 
00309     // Don't call Skip as the window wont be expecting the button up
00310 //  event.Skip();
00311 }

BOOL CaptureHandler::SetUpSolidDrag wxPoint  StartPos  ) 
 

Sets up Device Contexts / Bitmaps etc.. for Solid Drag.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/01/95
Parameters:
- [INPUTS]
Returns:
Errors: -
See also:
-

Definition at line 327 of file dragmgr.cpp.

00328 {
00329     TRACEUSER("Gerry", _T("SetUpSolidDrag(%d, %d)"), StartPos.x, StartPos.y);
00330 
00331     ERROR2IF(DragManagerOp::CurrentManager == NULL ||
00332              DragManagerOp::CurrentManager->CurrentDragInfo == NULL,
00333              FALSE,
00334              _T("CaptureHandler::SetUpSolidDrag - The current drag manager is invalid"));
00335 
00336     if (!DragManagerOp::CurrentManager->CurrentDragInfo->DoesSolidDrag)
00337         return TRUE;
00338 
00339     if (DragManagerOp::CurrentManager->RedrawInProgress || m_pDisplayDC != NULL)
00340         return FALSE;
00341 
00342     // get a couple of draggy bits
00343     wxPoint SolidDragOffset = DragManagerOp::CurrentManager->CurrentDragInfo->SolidDragOffset;
00344     wxSize DSize = DragManagerOp::CurrentManager->CurrentDragInfo->SolidDragSize;
00345 
00346     m_pDisplayDC = new wxScreenDC();
00347     wxMemoryDC BackGroundDC;
00348     m_pBackBitmap = new wxBitmap(DSize.x, DSize.y);
00349     
00350     if (m_pDisplayDC==NULL || m_pBackBitmap == NULL)
00351     {
00352         return FALSE;
00353     }
00354 
00355     // Offset the drag from the pointer
00356     wxPoint ClientPos = StartPos + SolidDragOffset;
00357 
00358     // select bitmap into the dc
00359     BackGroundDC.SelectObject(*m_pBackBitmap);
00360 
00361     ClientPos = m_pWindow->ScreenToClient(ClientPos);
00362 
00363     // init drag rect
00364     m_DragRect = wxRect(ClientPos.x, ClientPos.y, DSize.x, DSize.y);
00365 
00366     // blit the screen into the bitmap
00367     BackGroundDC.Blit(0,0,DSize.x,DSize.y,m_pDisplayDC,m_DragRect.x,m_DragRect.y);
00368 
00369     BackGroundDC.SelectObject(wxNullBitmap);
00370 
00371     INT32 DragTransparency = 
00372         DragManagerOp::CurrentManager->CurrentDragInfo->GetDragTransparency();
00373 
00374     KernelBitmap* DragMask = 
00375         DragManagerOp::CurrentManager->CurrentDragInfo->GetSolidDragMask();
00376     
00377     BOOL TransparentMask = DragManagerOp::CurrentManager->CurrentDragInfo->HasTransparentMask();
00378 
00379     if (DragTransparency > 0 || TransparentMask ||  DragMask != NULL)
00380     {
00381         // If we're doing a transparency drag, then we'll need
00382         // a monochome mask bitmap.
00383         // This will be a simple grey level, hatch pattern,
00384         // which will be used to 'knock' pixels out of the
00385         // drag bitmap.
00386 
00387         // Sadly, the world has conspired against us in terms of producing this
00388         // in any rational manner. 1bpp wxBitmaps do not work as brushes (random
00389         // memory). 24bpp wxBitmaps do not work as brushes into wxMemoryDCs backed
00390         // by 1bpp brushes. Conversion of 24bpp bitmaps to 1bpp does not dither.
00391         // making 1bpp brushes with a stipple does not dither. So we just manually
00392         // implement they bayer dithering algorithm.
00393 
00394         // Create a wxImage, don't initalize it
00395         wxImage MaskImage(DSize.x, DSize.y, false);
00396         unsigned char * pix=MaskImage.GetData();
00397         unsigned char * tpix = NULL;
00398 
00399         wxImage * pTransparentMask = NULL;
00400         if (TransparentMask)
00401         {
00402             wxBitmap *pTMbitmap=DragManagerOp::CurrentManager->CurrentDragInfo->GetTransparentMask();
00403             if (pTMbitmap)
00404                 pTransparentMask = new wxImage();
00405             if (!pTransparentMask)
00406                 TransparentMask=FALSE;
00407             else
00408             {
00409                 *pTransparentMask=pTMbitmap->ConvertToImage();
00410                 tpix=pTransparentMask->GetData();
00411             }
00412         }
00413 
00414         // DragTransparency is between 0 and 100,
00415         // and we need a grey level between 0 and 255.
00416         INT32 GreyLevel = (DragTransparency * 255) / 100;
00417 
00418         // for (i=0; i<4*4*3; i++) ImageData[i]=GreyLevel;
00419         // The above would be far too easy. wxWidgets doesn't seem to want to dither. Sigh
00420         // write our own ordered dither! And neither do 1bpp wxBitmaps work as brushes
00421         // sigh... And painting a 24bpp brush into a 1bpp bitmap dies horribly. Aaarrggghh
00422         // Bayer table
00423         INT32 OrderedDither[4*4]={ 1, 9, 3,11,
00424                                   13, 5,15, 7,
00425                                    4,12, 2,10,
00426                                   16, 8,14, 6};
00427         INT32 x, y;
00428 
00429         for (y=0; y<DSize.y; y++) for (x=0; x<DSize.x; x++)
00430         {
00431             INT32 tlevel=GreyLevel;
00432             if (TransparentMask)
00433             {
00434                 // Combine the transparency level with the transparency of the mask
00435                 // Note if EITHER are 255 we want full transparency. The appropriate
00436                 // operation is thus 1-((1-x)(1-y)), except of course they are 0..255
00437                 tlevel=((255*255+(255/2)) - // that's the maximum value (as we invert), but also add 255/2 for rounding when we divide by 255
00438                         ((255-GreyLevel)*(*tpix))
00439                         )/255;
00440                 tpix +=3;
00441             }
00442             BYTE thresh = (tlevel>(OrderedDither[(x&3)|((y&3)<<2)]*16-8))?0xff:0x00;
00443             // write three bytes (R, G, B)
00444             *pix++=thresh;
00445             *pix++=thresh;
00446             *pix++=thresh;
00447         }
00448 
00449         if (pTransparentMask)
00450             delete pTransparentMask;
00451 
00452         m_pMaskBitmap = new wxBitmap(MaskImage, 1);
00453         if (m_pMaskBitmap)
00454         {
00455             // Now combine the DragMask with the transparency mask.
00456             if (DragMask)
00457             {
00458                 wxMemoryDC MaskDC;
00459                 MaskDC.SelectObject(*m_pMaskBitmap);
00460 
00461                 // This needs to create a wxBitmap from DragMask
00462                 // and OR it into the MaskDC
00463 
00464                 CWxBitmap* pMaskBmp = (CWxBitmap*)DragMask->ActualBitmap;
00465                 RGBQUAD* Palette = (RGBQUAD *) (pMaskBmp->BMInfo->bmiColors);
00466 
00467                 // set the first colours to black and white
00468                 Palette[0].rgbRed = Palette[0].rgbBlue = Palette[0].rgbGreen = 0;
00469                 Palette[1].rgbRed = Palette[1].rgbBlue = Palette[1].rgbGreen = 255;
00470 
00471                 // set the reserved bytes to zero
00472                 Palette[0].rgbReserved = Palette[1].rgbReserved = 0;
00473 
00474                 UINT32 bpp=pMaskBmp->GetBPP();
00475 
00476                 wxMemoryDC MemDC;
00477                 wxBitmap MemBitmap(DSize.x, DSize.y, bpp);
00478                 MemDC.SelectObject(MemBitmap);
00479 
00480                 if (bpp>8)
00481                     bpp=32;
00482 
00483                 LPBYTE MemBBits;
00484                 LPBITMAPINFO MemBInfo = AllocDIB(DSize.x, DSize.y, bpp, &MemBBits);
00485 
00486                 GRenderRegion::StaticPlotBitmap(&MemDC, DIB_RGB_COLORS, MemBInfo, MemBBits, 0, 0, DSize.x, DSize.y, m_pMaskBitmap->GetPalette(), 0, 0);
00487     
00488                 // Now OR the Mask Bitmap into the MaskDC, so that
00489                 // it 'masks' the transparency mask.
00490                 MaskDC.Blit(0, 0, DSize.x, DSize.y, &MemDC, 0, 0, wxOR);
00491     
00492                 // clean up the dc
00493                 MaskDC.SetBrush(*wxTRANSPARENT_BRUSH);
00494                 MaskDC.SetPen(*wxTRANSPARENT_PEN);
00495                 MaskDC.SelectObject(wxNullBitmap);
00496             }
00497         }
00498     }
00499     else
00500         m_pMaskBitmap = NULL;
00501 
00502     DrawSolidDrag(StartPos);
00503 
00504     return TRUE;
00505 }

BOOL CaptureHandler::StartCapture  ) 
 

Attaches us to the window and starts mouse capture.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/05/2006

Definition at line 219 of file dragmgr.cpp.

00220 {
00221     TRACEUSER("Gerry", _T("CaptureHandler::StartCapture"));
00222     if (m_pWindow && !m_bHasCapture)
00223     {
00224         if (m_pWindow->HasCapture())
00225         {
00226             TRACEUSER("Gerry", _T("Already got capture"));
00227         }
00228 
00229         m_pWindow->CaptureMouse();
00230 
00231         if (m_pWindow->HasCapture())
00232         {
00233             TRACEUSER("Gerry", _T("Got capture"));
00234             m_bHasCapture = true;
00235             m_pWindow->PushEventHandler(this);
00236         }
00237     }
00238 
00239     return(TRUE);
00240 }


Friends And Related Function Documentation

friend class DragInformation [friend]
 

Definition at line 129 of file dragmgr.h.

friend class DragManagerOp [friend]
 

Definition at line 128 of file dragmgr.h.


Member Data Documentation

BOOL CaptureHandler::m_bHasCapture [protected]
 

Definition at line 154 of file dragmgr.h.

wxRect CaptureHandler::m_DragRect [protected]
 

Definition at line 158 of file dragmgr.h.

wxBitmap* CaptureHandler::m_pBackBitmap [protected]
 

Definition at line 157 of file dragmgr.h.

wxScreenDC* CaptureHandler::m_pDisplayDC [protected]
 

Definition at line 155 of file dragmgr.h.

wxBitmap* CaptureHandler::m_pMaskBitmap [protected]
 

Definition at line 161 of file dragmgr.h.

wxWindow* CaptureHandler::m_pWindow [protected]
 

Definition at line 153 of file dragmgr.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:51:51 2007 for Camelot by  doxygen 1.4.4