class_layer_box_selector.cpp 2.92 KB
Newer Older
1 2 3 4
#include <common.h>
#include <colors_selection.h>
#include <layers_id_colors_and_visibility.h>
#include <bitmaps.h>
5
#include <colors.h>
6

7
#include <wx/wx.h>
8 9
#include <wx/ownerdrw.h>
#include <wx/menuitem.h>
10
#include <wx/aui/aui.h>
11

12
#include <class_layer_box_selector.h>
13 14 15 16 17

/* class to display a layer list.
 *
 */

18
LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
Wayne Stambaugh's avatar
Wayne Stambaugh committed
19 20 21
                                        const wxPoint& pos, const wxSize& size,
                                        int n, const wxString choices[] ) :
    wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY )
22
{
23 24
    m_layerorder   = true;
    m_layerhotkeys = true;
25 26 27 28
    m_hotkeys      = NULL;

    if( choices != NULL )
        ResyncBitmapOnly();
29
}
30 31


32
LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
Wayne Stambaugh's avatar
Wayne Stambaugh committed
33 34 35
                                        const wxPoint& pos, const wxSize& size,
                                        const wxArrayString& choices ) :
    wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY )
36
{
37 38
    m_layerorder   = true;
    m_layerhotkeys = true;
39 40 41 42
    m_hotkeys      = NULL;

    if( !choices.IsEmpty() )
        ResyncBitmapOnly();
43 44 45
}


46
bool LAYER_BOX_SELECTOR::SetLayersOrdered( bool value )
47 48 49 50 51 52
{
    m_layerorder = value;
    return m_layerorder;
}


53
bool LAYER_BOX_SELECTOR::SetLayersHotkeys( bool value )
54 55 56
{
    m_layerhotkeys = value;
    return m_layerhotkeys;
57
}
58 59


60
// Get Current Item #
61
int LAYER_BOX_SELECTOR::GetChoice()
62 63 64
{
    return GetSelection();
}
65 66


67
// Get Current Layer
68
int LAYER_BOX_SELECTOR::GetLayerSelection()
69 70 71 72 73 74
{
    return (long) GetClientData( GetSelection() );
}


// Set Layer #
75
int LAYER_BOX_SELECTOR::SetLayerSelection( int layer )
76 77 78 79
{
    int elements = GetCount();

    for( int i = 0; i < elements; i++ )
80
    {
81
        if( GetClientData( i ) == (void*)(intptr_t) layer )
82
        {
83 84 85 86 87 88 89
            if( GetSelection() != i )   // Element (i) is not selected
            {
                SetSelection( i );
                return i;
            }
            else
                return i;               //If element already selected; do nothing
90 91 92
        }
    }

93 94 95 96 97
    // Not Found
    SetSelection( -1 );
    return -1;
}

98
void LAYER_BOX_SELECTOR::ResyncBitmapOnly()
99 100 101 102
{
    int elements = GetCount();
    for( int i = 0; i < elements; i++ )
    {
103 104
        wxBitmap layerbmp( 14, 14 );
        SetBitmapLayer( layerbmp, i );
105 106
    }
}
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124


void LAYER_BOX_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, int aLayerIndex )
{
    wxMemoryDC bmpDC;
    wxBrush    brush;

    // Prepare Bitmap
    bmpDC.SelectObject( aLayerbmp );
    brush.SetColour( MakeColour( GetLayerColor( aLayerIndex ) ) );
    brush.SetStyle( wxSOLID );

    bmpDC.SetBrush( brush );
    bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
    bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
    bmpDC.SetPen( *wxBLACK_PEN );
    bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
}