examples/Graphics/WS/PtBuffer/PointerMoveBuffer.cpp

00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // License: "Symbian Foundation License v1.0" to Symbian Foundation
00004 // members and "Symbian Foundation End User License Agreement v1.0"
00005 // to non-members at the URL
00006 // "http://www.symbianfoundation.org/legal/licencesv10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // Hold down the SHIFT key and drag the mouse (with left mouse button down)
00015 // for freehand drawing.
00016 //
00017 
00018 #include <w32std.h>
00019 #include "Base.h"
00020 #include "PointerMoveBuffer.h"
00021 
00022 
00023 
00025 //                                       CMainWindow implementation
00027 
00028 
00029 /****************************************************************************\
00030 |       Function:       Constructor/Destructor for CMainWindow
00031 |       Input:          aClient         Client application that owns the window
00032 \****************************************************************************/
00033 CMainWindow::CMainWindow (CWsClient* aClient)
00034 : CWindow (aClient)
00035         {
00036         }
00037 
00038 
00039 CMainWindow::~CMainWindow ()
00040         {
00041         iWindow.Close();
00042         }
00043 
00044 /****************************************************************************\
00045 |       Function:       CMainWindow::Draw
00046 |       Purpose:        Redraws the contents of CMainWindow within a given
00047 |                               rectangle.
00048 |       Input:          aRect   Rectangle that needs redrawing
00049 |       Output:         None
00050 \****************************************************************************/
00051 
00052 void CMainWindow::Draw(const TRect& aRect)
00053         {
00054         CWindowGc* gc=SystemGc(); // get a gc
00055         gc->SetClippingRect(aRect); // clip outside this rect
00056         gc->Clear(aRect); // clear
00057 }
00058 
00059 /****************************************************************************\
00060 |       Function:       CMainWindow::HandlePointerBufferReady
00061 \****************************************************************************/
00062 
00063 void CMainWindow::HandlePointerMoveBufferReady ()
00064         {               
00065         TPoint pnts[KPointerMoveBufferSize];
00066         TPtr8 ptr((TUint8 *)&pnts,sizeof(pnts));
00067         TInt numPnts=Window().RetrievePointerMoveBuffer(ptr);
00068         TSize size = Window().Size();
00069         TPoint position = Window().Position();
00070         TRect redrawRect (position, size);
00071         CWindowGc* gc=SystemGc();
00072         gc->Activate(Window());
00073         Window().Invalidate();
00074         Window().BeginRedraw(redrawRect); // N.B. Redrawer::RunL() gets called with this 
00075                                                                           // rectangle - must give it a non-zero value
00076         for(TInt index=0;index<numPnts;index++) gc->DrawLineTo(pnts[index]);
00077         Window().EndRedraw();
00078         gc->Deactivate();
00079         }
00080 
00081 /****************************************************************************\
00082 |       Function:       CMainWindow::HandlePointerEvent
00083 |       Purpose:        Handles pointer events for CMainWindow.
00084 |       Input:          aPointerEvent   The pointer event!
00085 |       Output:         None
00086 \****************************************************************************/
00087 
00088 void CMainWindow::HandlePointerEvent (TPointerEvent& aPointerEvent)
00089         {       
00090         switch (aPointerEvent.iType)
00091                 {
00092                 case TPointerEvent::EButton1Down:
00093                         {
00094                         if (aPointerEvent.iModifiers&EModifierShift)
00095                                 {
00096                                 Window().EnablePointerMoveBuffer();
00097                                 CWindowGc* gc = SystemGc();
00098                                 gc->Activate(Window());
00099                                 gc->MoveTo(aPointerEvent.iPosition);
00100                                 gc->Deactivate();
00101                                 }
00102                         break;
00103                         }
00104                 case TPointerEvent::EButton1Up:
00105                         {
00106                         Window().DisablePointerMoveBuffer();
00107                         break;
00108                         }
00109                 default:
00110                         break;
00111                 }
00112 }
00113 
00114 
00116 //                                       CExampleWsClient implementation
00118 
00119 CExampleWsClient* CExampleWsClient::NewL(const TRect& aRect)
00120         {
00121         // make new client
00122         CExampleWsClient* client=new (ELeave) CExampleWsClient(aRect); 
00123         CleanupStack::PushL(client); // push, just in case
00124         client->ConstructL(); // construct and run
00125         CleanupStack::Pop();
00126         return client;
00127         }
00128 
00129 /****************************************************************************\
00130 |       Function:       Constructor/Destructor for CExampleWsClient
00131 |                               Destructor deletes everything that was allocated by
00132 |                               ConstructMainWindowL()
00133 \****************************************************************************/
00134 
00135 CExampleWsClient::CExampleWsClient(const TRect& aRect)
00136 :iRect(aRect)
00137         {
00138         }
00139 
00140 CExampleWsClient::~CExampleWsClient ()
00141         {
00142         delete iMainWindow;
00143         }
00144 
00145 
00146 /****************************************************************************\
00147 |       Function:       CExampleWsClient::ConstructMainWindowL()
00148 |                               Called by base class's ConstructL
00149 |       Purpose:        Allocates and creates all the windows owned by this client
00150 |                               (See list of windows in CExampleWsCLient declaration).
00151 \****************************************************************************/
00152 
00153 void CExampleWsClient::ConstructMainWindowL()
00154         {
00155         // Resources allocated in this function are freed in the CExampleWsClient destructor            
00156         iMainWindow=new (ELeave) CMainWindow(this);
00157         iMainWindow->ConstructL(iRect, TRgb (255,255,255));
00158         }
00159 
00160 /****************************************************************************\
00161 |       Function:       CExampleWsClient::HandleKeyEventL()
00162 |       Purpose:        Processes key events for CExampleWsClient
00163 \****************************************************************************/
00164 void CExampleWsClient::HandleKeyEventL (TKeyEvent& /*aKeyEvent*/)
00165         {
00166         }
00167 
00168 
00169 /****************************************************************************\
00170 |       Function:       CExampleWsClient::RunL()
00171 |                               Called by active scheduler when an even occurs
00172 |       Purpose:        Processes events according to their type
00173 |                               For key events: calls HandleKeyEventL() (global to client)
00174 |                               For pointer event: calls HandlePointerEvent() for window
00175 |                                  event occurred in.
00176 \****************************************************************************/
00177 void CExampleWsClient::RunL()
00178         {
00179         // get the event
00180         iWs.GetEvent(iWsEvent);
00181         TInt eventType=iWsEvent.Type();
00182         // take action on it
00183         switch (eventType)
00184                 {
00185         // events global within window group
00186         case EEventNull:
00187         case EEventKey:
00188         case EEventModifiersChanged:
00189         case EEventKeyUp:
00190         case EEventKeyDown:
00191         case EEventFocusLost:
00192         case EEventFocusGained:
00193         case EEventSwitchOn:
00194         case EEventPassword:
00195         case EEventWindowGroupsChanged:
00196         case EEventErrorMessage:
00197                 break;
00198         // events local to specific windows
00199         case EEventPointer:
00200                 {
00201                 CWindow* window=(CWindow*)(iWsEvent.Handle()); // get window
00202                 TPointerEvent& pointerEvent=*iWsEvent.Pointer();
00203                 window->HandlePointerEvent (pointerEvent);
00204                 break;
00205                 }
00206         case EEventPointerExit:
00207         case EEventPointerEnter:
00208                 break;
00209         case EEventPointerBufferReady:
00210                 {
00211                 CWindow* window=(CWindow*)(iWsEvent.Handle()); // get window
00212                 window->HandlePointerMoveBufferReady ();
00213                 break;
00214                 }
00215         case EEventDragDrop:
00216                 break;
00217         default:
00218                 break;
00219                 }
00220         IssueRequest(); // maintain outstanding request
00221         }

Generated by  doxygen 1.6.2