download didcfgview.h
Language: C++
Copyright: (c) 1999-2000 Microsoft Corporation. All rights reserved.
LOC: 481
Project Info
Cratered
Server: SourceForge
Type: cvs
...d\cratered\Libs\DX\include\
   activecf.h
   amaudio.h
   amparse.h
   amstream.h
   amva.h
   amvideo.h
   atsmedia.h
   audevcod.h
   austream.h
   aviriff.h
   basetsd.h
   bdaiface.h
   bdamedia.h
   bdatypes.h
   comlite.h
   control.h
   d3d.h
   d3d8.h
   d3d8caps.h
   d3d8types.h
   d3dapp.h
   d3dcaps.h
   d3dfile.h
   d3dfont.h
   d3dres.h
   d3drm.h
   d3drmdef.h
   d3drmobj.h
   d3drmwin.h
   d3dtypes.h
   d3dutil.h
   d3dvec.inl
   d3dx.h
   d3dx8.h
   d3dx8core.h
   d3dx8effect.h
   d3dx8math.h
   d3dx8math.inl
   d3dx8mesh.h
   d3dx8shape.h
   d3dx8tex.h
   d3dxcore.h
   d3dxerr.h
   d3dxmath.h
   d3dxmath.inl
   d3dxshapes.h
   d3dxsprite.h
   ddraw.h
   ddrawex.h
   ddstream.h
   ddutil.h
   didcfgview.h
   dinput.h
   dinputd.h
   diutil.h
   dls1.h
   dls2.h
   dmdls.h
   dmerror.h
   dmksctrl.h
   dmo.h
   dmodshow.h
   dmoimpl.h
   dmoreg.h
   dmort.h
   dmplugin.h
   dmusbuff.h
   dmusicc.h
   dmusicf.h
   dmusici.h
   dmusics.h
   dmutil.h
   dpaddr.h
   dplay.h
   dplay8.h
   dplobby.h
   dplobby8.h
   dsetup.h
   DShow.h
   dshowasf.h
   dsound.h
   dsutil.h
   dv.h
   dvdevcod.h
   dvdmedia.h
   dvoice.h
   dvp.h
   dx7todx8.h
   dxerr8.h
   dxfile.h
   dxsdk.inc
   dxtrans.h
   dxutil.h
   dxva.h
   edevdefs.h
   errors.h
   evcode.h
   il21dec.h
   ks.h
   ksguid.h
   ksmedia.h
   ksproxy.h
   ksuuids.h
   mediaerr.h
   mediaobj.h
   medparam.h
   mmstream.h
   mpconfig.h
   mpegtype.h
   multimon.h
   netclient.h
   netclientres.h
   netconnect.h
   netconnectres.h
   netvoice.h
   playlist.h
   qedit.h
   qnetwork.h
   regbag.h
   rmxfguid.h
   rmxftmpl.h
   tune.h
   tuner.h
   uuids.h
   vfwmsgs.h
   videoacc.h
   vpconfig.h
   vpnotify.h
   vptype.h
   xprtdefs.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
//-----------------------------------------------------------------------------
// File: didcfgview.h
//
// Desc: Header file for DIDCfgView, a class that encapsulates a view of a
//       DirectInput device.  The DIDCfgView class exists to make it easier 
//       to make custom interfaces to view or configure action mappings for 
//       input devices(instead of using IDirectInput8::ConfigureDevices).
//
//       To use the DIDCfgView class, you initialize it for a particular
//       DirectInput device.  You then set up state information for how the
//       image should be drawn: colors, fonts, and details for callouts(the
//       lines drawn from each axis/button to a label).  Finally, you can 
//       call RenderView, passing in a bitmap or HDC for DIDCfgView to draw
//       the image to.
//
//       DIDCfgView is the only class in this file that you need to understand 
//       or interface to.  The other classes shown here are only used to 
//       implement the DIDCfgView class.
//
//
// Copyright (c) 1999-2000 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------

#ifndef __DIDCV_H__
#define __DIDCV_H__




#include <windows.h>
#include <dinput.h>




// invalid id, used for unique, signed identifiers
#define DIDCV_INVALID_ID                            -1

// flags for callout states
#define DIDCV_DRAWCALLOUT                           0x1
#define DIDCV_DRAWOVERLAY                           0x2
#define DIDCV_DRAWHIGHLIGHT                         0x4
#define DIDCV_DRAWEMPTYCALLOUT                      0x8
#define DIDCV_DRAWFULLNAME                          0x10

// all flags set
#define DIDCV_ALL_CALLOUT_STATE_SET                 0xFFFFFFFF

// default dimensions
#define DIDCV_MAX_IMAGE_WIDTH                       512
#define DIDCV_MAX_IMAGE_HEIGHT                      512
#define DIDCV_CUSTOM_VIEW_WIDTH                     400
#define DIDCV_CUSTOM_VIEW_HEIGHT                    300

// DidcvCreateFont attribute flags
#define DIDCV_FONT_BOLD                             0x1
#define DIDCV_FONT_ITALIC                           0x2
#define DIDCV_FONT_UNDERLINE                        0x4
#define DIDCV_FONT_STRIKEOUT                        0x8

// default font point width
#define DIDCV_DEFAULT_FONT_SIZE                     90

// default size of callout array in DidcvCalloutManager
#define DIDCV_DEFAULT_CALLOUT_MANAGER_ARRAY_SIZE    0

// default size of callout array in DidcvCalloutSet
#define DIDCV_DEFAULT_CALLOUT_SET_ARRAY_SIZE        8




// forward declarations
class DidcvViewManager;
class DidcvCalloutManager;
class DidcvBitmap;
class DidcvCallout;
class DidcvCalloutSet;
struct DIDCfgViewInfo;
struct DidcvCalloutData;
struct DidcvCalloutState;
struct DidcvActionMap;
struct DidcvCustomViewInfo;




//-----------------------------------------------------------------------------
// Name: class DIDCfgView
// Desc: main interface for retrieving and rendering device configuration views
//
//       Init() - initializes the object for a particular DirectInputDevice
//       SetActionFormat() - sets the action mapping for the device
//       SetCalloutState() - specifies state for a given callout
//       SetAllCalloutState() - sets the state for all callouts
//       GetObjectIDByLocation() - gets object id at location of current view
//       SetCurrentView() - sets the current view to be rendered
//       RebuildViews() - collapses or expand the views for this device
//       RenderView() - renders device configuration view with image,
//                       callout information, action mapping.
//-----------------------------------------------------------------------------
class DIDCfgView
{
public:
    DIDCfgView();
    ~DIDCfgView();

public:
    // main device configuration view interface
    HRESULT Init( LPDIRECTINPUTDEVICE8 pDevice );
    HRESULT SetActionFormat( LPDIACTIONFORMAT pDiaf );
    HRESULT SetCalloutState( DWORD dwFlags, DWORD dwObjID );
    HRESULT SetAllCalloutState( DWORD dwFlags );
    HRESULT GetObjectIDByLocation( LPDWORD pdwObjID, LPPOINT pPt );
    HRESULT SetCurrentView( INT nView );
    HRESULT RebuildViews( BOOL bCompact );
    HRESULT RenderView( HBITMAP hBitmap, BOOL bIsDib );
    HRESULT RenderView( HDC hdc );

    // rendering options
    HRESULT SetViewOrigin( const POINT* pPtOrg, POINT* pPtOldOrg );
    HRESULT CalcCenterOrgForCurrentView( const SIZE* pImgSize, POINT* pPtOrg, BOOL bSetOrigin = FALSE );
    VOID    SetDefaultText( const TCHAR* pctszDefaultText, DWORD length );
    VOID    SetColors( COLORREF crFore, COLORREF crBack, COLORREF crHighlight, COLORREF crHighlightLine );
    VOID    GetColors( COLORREF* pCrFore, COLORREF* pCrBack, COLORREF* pCrHighlight, COLORREF* pCrHighlightLine );
    HRESULT SetFont( const TCHAR*  pctszFontName, DWORD dwAttributes );
    HFONT   GetFont();

    // information access functios
    HRESULT GetInfo( DIDCfgViewInfo* pCfgViewInfo );
    HRESULT GetCurrentView( LPINT lpnView );
    HRESULT GetCalloutState( LPDWORD lpdwFlags, DWORD dwObjID );

protected:
    // protected helper functions
    VOID    CleanUp();
    HRESULT InitAlloc();
    HRESULT InitImageInfoRetrieve( LPDIRECTINPUTDEVICE8 pDevice );
    HRESULT InitImageInfoProcess();
    VOID    CalcSizes( const DIDEVICEIMAGEINFO* prgImageInfoArray, DWORD dwNumElements, const LPDWORD pNumViews, LPDWORD pNumCallouts, LPDWORD pNumDistinctObjID );
    HRESULT RenderView( HDC hdc, VOID* pBits, INT width, INT height );

    HRESULT InitCustomViews( LPDIRECTINPUTDEVICE8 pDevice, BOOL bUseInternal = FALSE );
    HRESULT BuildCustomViews();
    VOID    RenderFullname( HDC hdc, const TCHAR* pctszFullname, const RECT* pRect );
    BOOL    CopyActionMap( LPDIACTIONFORMAT pDiaf );

protected:
    // data structures for managing views and callouts
    DidcvViewManager* m_lpViewManager;
    DidcvCalloutManager* m_lpCalloutManager;

    // keeps track of whether this has been initialized
    BOOL m_bIsInit;
    // the index of the next view to render
    INT m_nView;
    // pointer to the DIDEVICEIMAGEINFOHEADER
    LPDIDEVICEIMAGEINFOHEADER m_lpDidImgHeader;
    // custom device view data
    DidcvCustomViewInfo* m_lpCustomViewInfo;

    // device reference
    LPDIRECTINPUTDEVICE8 m_lpDIDevice;
    // action mapping copy
    LPDIACTIONFORMAT m_lpDiaf;
    // can this view be collapsed
    BOOL m_bCanBeCollapsed;
    // is this view compacted
    BOOL m_bIsCollapsed;

    // rendering options
    COLORREF m_crFore;
    COLORREF m_crBack;
    COLORREF m_crHighlight;
    COLORREF m_crHighlightLine;
    POINT    m_ptOrigin;
    HFONT    m_hFont;
    TCHAR m_tszDefaultText [MAX_PATH];
};




//-----------------------------------------------------------------------------
// Name: struct DIDCfgViewInfo
// Desc: struct containing current information about DIDCfgView states
//-----------------------------------------------------------------------------
struct DIDCfgViewInfo
{
    BOOL  bIsInit;              // is the CfgView object initialized
    INT   iCurrentViewID;       // the ID of the current view
    INT   iNumTotalViews;       // total number of views
    DWORD dwNumUniqueCallouts;  // number of unique
    BOOL  bCanBeCollapsed;      // can views for this CfgView object be compacted
    BOOL  bIsCollapsed;         // is the CfgView currently using collapsed views


    DIDCfgViewInfo()
        : bIsInit( FALSE ),
          iCurrentViewID( DIDCV_INVALID_ID ),
          iNumTotalViews( 0 ),
          dwNumUniqueCallouts( 0 ),
          bCanBeCollapsed( FALSE ),
          bIsCollapsed( FALSE )
    { }
};




//-----------------------------------------------------------------------------
// Name: struct DidcvCustomViewInfo
// Desc: object containing information about custom views
//-----------------------------------------------------------------------------
struct DidcvCustomViewInfo
{
    DWORD dwType;               // type of the operation(count or save)
    DWORD dwCount;              // the total count of items
    DWORD dwSize;               // number of items actually in array
    LPDIDEVICEOBJECTINSTANCE* rgObjData;   // array of control info

    DidcvCustomViewInfo()
        : dwType( 0 ),
          dwCount( 0 ),
          dwSize( 0 ),
          rgObjData( NULL )
    { }

    ~DidcvCustomViewInfo() { CleanUp(); }
    
    VOID CleanUp();
};




//-----------------------------------------------------------------------------
// Name: class DidcvView
// Desc: data structure for representing one view of a device
//-----------------------------------------------------------------------------
class DidcvView
{
public:
    virtual ~DidcvView() { };

    // DidcvView interface
    void SetOffset( INT nOffset );
    void SetID( INT nID );
    INT  GetOffset() const;
    INT  GetID() const;

    // rendering
    virtual BOOL GetViewSize( SIZE* pSize ) const = 0;
    virtual void Render( HDC hdc, VOID* pBits, INT width, INT height, const POINT* pPtOrigin ) = 0;

protected:
    // constructor
    DidcvView();
    // the original offset in the array returned by DirectInputDevice8::GetImage
    INT m_nOffset;
    // the internally assigned unique identifier
    INT m_nID;
};




//-----------------------------------------------------------------------------
// Name: class DidcvBitmapView
// Desc: subclass of DidcvView that renders a bitmap
//-----------------------------------------------------------------------------
class DidcvBitmapView : public DidcvView
{
public:
    ~DidcvBitmapView();

    // interface
    virtual BOOL GetViewSize( SIZE* pSize ) const;
    virtual void Render( HDC hdc, VOID* pBits, INT width, INT height, const POINT* pPtOrigin );

public:
    // function to instantiate a DidcvBitmapView
    static DidcvBitmapView* Create( LPCTSTR ptszImagePath, DWORD dwFlags );

private:
    // constructor
    DidcvBitmapView();

protected:
    // bitmap of the view
    DidcvBitmap* m_lpBitmap;
};




//-----------------------------------------------------------------------------
// Name: class DidcvCustomView
// Desc: subclass of DidcvView that renders a view from custom data
//-----------------------------------------------------------------------------
class DidcvCustomView : public DidcvView
{
public:
    ~DidcvCustomView() { }

    // interface
    virtual BOOL GetViewSize( SIZE* pSize ) const;
    virtual void Render( HDC hdc, VOID* pBits, INT width, INT height, const POINT* pPtOrigin );

public:
    // static function to instantiate a DidcvCustomView
    static DidcvCustomView* Create( const DidcvCustomViewInfo* pInfo, DWORD dwStartIndex, DWORD* pFinishIndex );
    static BOOL CalcImageInfo( DWORD index, LPRECT rcOverlay, LPDWORD pNumPoints, LPPOINT rgptCalloutLine, LPRECT rcCalloutRect );
    static DWORD CalcNumViews( DWORD dwCount );

private:
    // constructor
    DidcvCustomView( const DidcvCustomViewInfo* pInfo, DWORD dwStartIndex, DWORD dwEndIndex );

protected:
    // returns coordinates for a given index
    void CalcCoordinates( DWORD dwIndex, LPRECT lpRect );

    // custom data from which to render the view
    const DidcvCustomViewInfo* m_lpCustomViewInfoRef;
    DWORD m_dwStartIndex;
    DWORD m_dwEndIndex;
};




//-----------------------------------------------------------------------------
// Name: class DidcvViewManager
// Desc: stores and manages all the views for particular device
//-----------------------------------------------------------------------------
class DidcvViewManager
{
public:
    DidcvViewManager();
    ~DidcvViewManager();

    // interface
    BOOL SetCapacity( UINT uCapacity, BOOL bDeleteContent = TRUE );
    BOOL AddImage( DidcvView* pView, INT nOffset = DIDCV_INVALID_ID );
    DidcvView* GetImage( INT nID );
    DidcvView* GetImageByOffset( INT nOffset );
    UINT GetNumViews() const;
    void CleanUp();

protected:
    // table holding references to views, indexed by the internal unique identifier
    DidcvView ** m_ppViewTable;
    UINT m_capacity;
    UINT m_size;
};




//-----------------------------------------------------------------------------
// Name: class DidcvCallout
// Desc: data structure for representing one callout on a particular view
//       A callout is the line drawn from each axis/button to a label
//-----------------------------------------------------------------------------
class DidcvCallout
{
public:
    ~DidcvCallout();

    // accessor functions to information retrieved from DirectInput
    DWORD GetObjID() const;
    const RECT & GetOverlayRect() const;
    const RECT & GetCalloutRect() const;
    const POINT* GetCalloutLine( DWORD* lpNumPts ) const;
    DWORD GetTextAlign() const;
    DWORD GetOverlayOffset() const;

    // accessor functions to internal data
    void  SetAssociatedViewID( INT nViewRef );
    INT   GetAssociatedViewID() const;
    void  SetDataRef( const DidcvCalloutData* lpData );
    const DidcvCalloutData* GetDataRef() const;

    // hit test for a given point
    DWORD HitTest( LPPOINT lpPt ) const;

    // draw the overlay
    DWORD DrawOverlay( HDC hDC, VOID* lpBits, INT width, INT height, const POINT* pptOrigin );

public:
    // static functions to instantiate a callout object
    static DidcvCallout* Create( LPDIDEVICEIMAGEINFO devImgInfo );

private:
    // private constructor
    DidcvCallout();

protected:
    // copy of device information
    DIDEVICEIMAGEINFO m_devImgInfo;
    // the view that this particular callout is associated with
    INT m_nViewRef;
    // pointer to callout state/data
    const DidcvCalloutData* m_lpDataRef;
    // the bitmap of the overlay
    DidcvBitmap* m_lpOverlayBitmap;
};




// default array size
#define GW_ARRAY_DEFAULT_SIZE       4

//-----------------------------------------------------------------------------
// Name: class GwArray
// Desc: templated c-style array class for PRIMITIVE data types only
//-----------------------------------------------------------------------------
template <class Item> 
class GwArray
{
public:
    // constructors
    GwArray() { this->Alloc( GW_ARRAY_DEFAULT_SIZE ); m_size = 0; }
    GwArray( UINT initCap ) { this->Alloc( initCap ); m_size = 0; }
    ~GwArray() { this->DeAlloc(); m_size = 0; }

public:
    void SetSize( UINT newCap )
    {
        if( newCap == m_capacity )
            return;

        m_size =( newCap < m_size ? newCap : m_size );

        UINT old_cap = m_capacity;
        UINT numoverlap =( newCap > m_capacity ? m_capacity : newCap );

        Item* oldList = m_list;
        this->Alloc( newCap );

        if( oldList )
        {
            memcpy( m_list, oldList, sizeof( Item )* numoverlap );

            // free( oldList );
            delete [] oldList;
        }
    }

    Item & operator[]( UINT index )
    {
        if( index >= m_capacity )
            assert( index >= 0 && index < m_capacity );

        return m_list[index];
    }

    const Item & operator[]( UINT index ) const
    {
        if( index >= m_capacity )
            assert( index >= 0 && index < m_capacity );

        return m_list[index];
    }

    void PushBack( const Item & item )
    {
        if( m_capacity == 0 )
            SetSize( 2 );
        else if( m_size >= m_capacity )
            SetSize( m_capacity* 2 );

        m_list[m_size] = item;
        m_size++;
    }

    void Resize( UINT newCap ) { SetSize( newCap ); }
    void PopBack()        { if( m_size ) m_size--; }
    void Clear()          { m_size = 0; }
    void Trim()           { Resize( m_size ); }
    UINT Capacity() const { return m_capacity; }
    UINT Size() const     { return m_size; }

protected:
    inline void Alloc( UINT cap )
    {
        if( cap == 0 )
            m_list = NULL;
        else
        {
            m_list = new Item[cap];
            assert( m_list );
            memset( m_list, 0, sizeof( Item )* cap );
        }

        m_capacity = cap;
    }

    inline void DeAlloc()
    {
        if( m_list != NULL )
        {
            //free( m_list );
            delete [] m_list;
            m_list = NULL;
        }

        m_capacity = 0;
    }

protected:
    // array
    Item* m_list;
    // number of entries the array can hold
    UINT m_capacity;
    // number of entries added using PushBack() minus # removed using PopBack()
    UINT m_size;
};




//-----------------------------------------------------------------------------
// Name: class DidcvCalloutApplicant
// Desc: abstract base class for processing DidcvCallout
//-----------------------------------------------------------------------------
class DidcvCalloutApplicant
{
public:
    virtual ~DidcvCalloutApplicant() { }
    virtual BOOL Apply( DidcvCallout* pCallout ) = 0;
};




//-----------------------------------------------------------------------------
// Name: class DidcvCalloutSet
// Desc: a group of DidcvCallout references
//       A callout is the line drawn from each axis/button to a label
//-----------------------------------------------------------------------------
class DidcvCalloutSet
{
public:
    DidcvCalloutSet();
    ~DidcvCalloutSet();

public:
    BOOL  AddCallout( DidcvCallout* pCallout );
    void  Apply( DidcvCalloutApplicant* pCalloutApp );
    void  SetIdentifier( DWORD dwID );
    DWORD GetIdentifier() const;
    void  SetData( void* pData );
    void* GetData() const;

    const GwArray <DidcvCallout*> & GetInternalArrayRef() const;
    void  TrimArrays();  

protected:
    void CleanUp();

protected:
    GwArray <DidcvCallout*> m_calloutList;
    DWORD m_dwSetID;
    void* m_lpData;
};




//-----------------------------------------------------------------------------
// Name: class DidcvCalloutManager
// Desc: data structure for storing and managing callouts
//       A callout is the line drawn from each axis/button to a label
//-----------------------------------------------------------------------------
class DidcvCalloutManager
{
public:
    DidcvCalloutManager();
    ~DidcvCalloutManager();

    // main interface
    BOOL  AddCallout( DidcvCallout* pCallout, INT nView );
    BOOL  SetCalloutState( const DidcvCalloutState* pCalloutState, DWORD dwObjID );
    BOOL  SetAllCalloutState( const DidcvCalloutState* pCalloutState );
    BOOL  SetActionMap( const LPDIACTION pAction, DWORD dwObjID );
    void  ClearAllActionMaps();

    // information
    DWORD GetObjectIDByLocation( const LPPOINT pPt, INT nView );
    BOOL  GetCalloutState( DidcvCalloutState* pCalloutState, DWORD dwObjID );
    BOOL  GetActionMap( DidcvActionMap* pActionMap, DWORD dwObjID );
    const DidcvCalloutSet* GetCalloutSetByView( INT nView ) const;
    const DidcvCalloutSet* GetCalloutSetByObjID( DWORD dwObjID ) const;
    const DidcvCalloutData* GetCalloutDataRef( DWORD dwObjID ) const;
    UINT  GetNumUniqueCallouts() const;

    BOOL  EnumObjects( LPDIRECTINPUTDEVICE8 pDevice, LPDIENUMDEVICEOBJECTSCALLBACK pCallback, LPVOID pvRef, DWORD dwMapOnly );
    BOOL  CalcCanBeCollapsed();

    // allocation
    BOOL  SetCapacity( DWORD dwNumCallouts, DWORD dwNumUniqueObjID, DWORD dwNumViews, BOOL bDeleteContent = TRUE );
    void  TrimArrays();
    void  CleanUp();

protected:
    // helper functions
    DidcvCalloutSet*  Find( const GwArray <DidcvCalloutSet*> & array, DWORD dwIdentifier ) const;
    DidcvCalloutData* GetCalloutData( DWORD dwObjID ) const;

protected:
    // list of all callouts added
    GwArray <DidcvCallout*> m_calloutList;
    // list of callout sets, one for each unique callout id
    GwArray <DidcvCalloutSet*> m_calloutSetListByObjID;
    // list of callout sets, one for each view
    GwArray <DidcvCalloutSet*> m_calloutSetListByView;
};




//-----------------------------------------------------------------------------
// Name: struct DidcvCalloutData
// Desc: data structure holding references to callout data components
//-----------------------------------------------------------------------------
struct DidcvCalloutData
{
    DidcvCalloutState* lpState;    // callout state info
    DidcvActionMap* lpActionMap;   // action mapped this callout

    DidcvCalloutData( DidcvCalloutState* s, DidcvActionMap* a )
        : lpState( s ), lpActionMap( a )
    { }
};




//-----------------------------------------------------------------------------
// Name: struct DidcvCalloutState
// Desc: state information for a callout
//-----------------------------------------------------------------------------
struct DidcvCalloutState
{
    // whether to draw
    BOOL bDrawCallout;
    BOOL bDrawOverlay;
    BOOL bDrawHighlight;
    BOOL bDrawEmptyCallout;
    BOOL bDrawFullname;

    // specifies which state is valid
    DWORD dwFlags;

    // --- member functions ---
    DidcvCalloutState( DWORD f = 0, BOOL c = FALSE, BOOL o = FALSE, 
        BOOL h = FALSE, BOOL e = FALSE, BOOL d = FALSE )
        : dwFlags( f ), bDrawCallout( c ), bDrawOverlay( o ), bDrawHighlight( h ), 
          bDrawEmptyCallout( e ), bDrawFullname( d )
    { }

    void SmartSet( const DidcvCalloutState* other );
    void Copy( const DidcvCalloutState* other ) { *this = *other; }
    DWORD MakeFlag() const;
    void SetFlag( DWORD dwExtFlags );
};




//-----------------------------------------------------------------------------
// Name: struct DidcvActionMap
// Desc: action mapping information for a callout
//-----------------------------------------------------------------------------
struct DidcvActionMap
{
    DIACTION dia;

    DidcvActionMap() { ZeroMemory( &dia, sizeof( DIACTION ) ); }
    void Copy( const DidcvActionMap* other ) { this->dia = other->dia; }

    LPCSTR GetActionName() const { return dia.lptszActionName; }
};




// utility functions
void  DidcvPolyLineArrow( HDC hDC, const POINT* rgpt, INT nPoints, BOOL bDoShadow = FALSE );
HFONT DidcvCreateFont( HDC hdc, const TCHAR* szFaceName, int iDeciPtHeight, int iDeciPtWidth, int iAttributes, BOOL fLogRes);




//-----------------------------------------------------------------------------
// Name: struct rgref
// Desc: templated lightweight c-style array
//-----------------------------------------------------------------------------
template <class T>
struct rgref {
    rgref( T* p ) : pt( p ) {}

    T & operator []( int i ) { return pt[i]; }
    const T & operator []( int i ) const { return pt[i]; }

private:
    T *pt;
};




//-----------------------------------------------------------------------------
// Name: struct SPOINT
// Desc: used by line drawing routine
//-----------------------------------------------------------------------------
struct SPOINT {
    SPOINT()
#define SPOINT_INITIALIZERS \
        p( u.p ), \
        s( u.s ), \
        a((( int* )( void* ) u.a ) ), \
        x( u.p.x ), \
        y( u.p.y ), \
        cx( u.s.cx ), \
        cy( u.s.cy )
        : SPOINT_INITIALIZERS
        { x = y = 0; }

    SPOINT( int, POINT *r ) 
        : p( *r ),
          s( *(( SIZE* )( void* ) r ) ),
          a((( int* )( void* ) r ) ),
          x( r->x ),
          y( r->y ),
          cx( r->x ),
          cy( r->y )
    { }

    SPOINT( const SPOINT & sp ) 
        : SPOINT_INITIALIZERS
    { p = sp.p; }

    SPOINT( int b, int c ) 
        : SPOINT_INITIALIZERS
    { x = b; y = c; }

    SPOINT( const POINT &point )
        : SPOINT_INITIALIZERS
    { p = point; }

    SPOINT( const SIZE &size )
        : SPOINT_INITIALIZERS
    { s = size; }

#undef SPOINT_INITIALIZERS

    SPOINT operator =( const SPOINT &sp ) { p = sp.p; return *this; }
    SPOINT operator =( const POINT &_p ) { p = _p; return *this; }
    SPOINT operator =( const SIZE &_s ) { s = _s; return *this; }

    operator POINT() const { return p; }
    operator SIZE() const { return s; }

    long &x, &y, &cx, &cy;
    POINT &p;
    SIZE &s;
    rgref<int> a;

private:
    union {
        POINT p;
        SIZE s;
        int a[2];
    } u;
};




//-----------------------------------------------------------------------------
// Name: class DidcvBitmap
// Desc: object containing a bitmap
//-----------------------------------------------------------------------------
class DidcvBitmap
{
public:
    ~DidcvBitmap();

    // drawing interface
    BOOL Draw( HDC hDC, INT xStart, INT yStart);
    BOOL Blend( HDC hDC, INT xStart, INT yStart );
    BOOL Blend( VOID* lpBits, INT xStart, INT yStart, INT width, INT height );

    // information
    BOOL GetSize( SIZE* lpSize ) const;
    HBITMAP GetHandle();
    LPVOID GetBits();

public:
    // static function for instantiating a DidcvBitmap
    static DidcvBitmap* Create( LPCTSTR tszFilename );
    static DidcvBitmap* Create( INT width, INT height );

private:
    // private constructor
    DidcvBitmap();

protected:
    // helper functions
    void CleanUp();
    void FigureSize();

    static DidcvBitmap* CreateViaD3dx( LPCTSTR tszFilename );
    static DidcvBitmap* CreateViaLoadImage( HINSTANCE hinst, LPCTSTR tszName, 
        UINT uType, int cx, int cy, UINT fuLoad );

protected:
    // GDI handle to bitmap
    HBITMAP m_hbitmap;
    VOID* m_lpBits;
    SIZE m_size;
};




// alpha blending information
#define DIDCV_ALPHABLEND_DLL_NAME   TEXT( "MSIMG32.DLL" )
#define DIDCV_ALPHABLEND_PROC_NAME  TEXT( "AlphaBlend" )

#if( WINVER >= 0x400 )
  typedef WINGDIAPI BOOL( WINAPI* DIDCV_ALPHABLEND )( HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION );
#else
  typedef DIDCV_ALPHABLEND DWORD
#endif

//-----------------------------------------------------------------------------
// Name: class DidcvAlphaBlend
// Desc: utility class for alpha blending
//-----------------------------------------------------------------------------
class DidcvAlphaBlend
{
public:
    // reference counting interface
    static BOOL AddClient();
    static BOOL ReleaseClient();

    // functions to perform blending
    static BOOL Blend( HDC hDC, INT xStart, INT yStart, INT width, INT height, HBITMAP hbitmap, const SIZE* lpSize );
    static BOOL Blend( VOID* lpDestBits, INT xStart, INT yStart, INT destWidth, INT destHeight, VOID* lpSrcBits, INT srcWidth, INT srcHeight );

protected:
    static DIDCV_ALPHABLEND s_alphaBlendProc;
    static HMODULE s_hDll;
    static DWORD s_dwNumClients;

};




#endif // #ifndef __DIDCV_H__

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us