1 /////////////////////////////////////////////////////////////////////////////
2 // Name: contrib/samples/ogl/studio/cspalette.cpp
3 // Purpose: OGLEdit palette
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/laywin.h"
32 #include "cspalette.h"
36 #include "bitmaps/arrow.xpm"
37 #include "bitmaps/texttool.xpm"
41 * Object editor tool palette
45 csEditorToolPalette::csEditorToolPalette(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
47 TOOLPALETTECLASS(parent
, id
, pos
, size
, style
)
49 m_currentlySelected
= -1;
51 SetMaxRowsCols(1, 1000);
54 bool csEditorToolPalette::OnLeftClick(int toolIndex
, bool toggled
)
56 // BEGIN mutual exclusivity code
57 if (toggled
&& (m_currentlySelected
!= -1) && (toolIndex
!= m_currentlySelected
))
58 ToggleTool(m_currentlySelected
, false);
61 m_currentlySelected
= toolIndex
;
62 else if (m_currentlySelected
== toolIndex
)
63 m_currentlySelected
= -1;
64 // END mutual exclusivity code
69 void csEditorToolPalette::OnMouseEnter(int toolIndex
)
72 wxString msg
= wxEmptyString
;
73 if (toolIndex
== PALETTE_ARROW
)
75 else if (toolIndex
!= -1)
77 csSymbol
* symbol
= wxGetApp().GetSymbolDatabase()->FindSymbol(toolIndex
);
79 msg
= symbol
->GetName();
81 ((wxFrame
*) wxGetApp().GetTopWindow())->SetStatusText(msg
);
83 wxUnusedVar(toolIndex
);
84 #endif // wxUSE_STATUSBAR
87 void csEditorToolPalette::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
89 TOOLPALETTECLASS::SetSize(x
, y
, width
, height
, sizeFlags
);
92 void csEditorToolPalette::SetSelection(int sel
)
94 if ((sel
!= m_currentlySelected
) && (m_currentlySelected
!= -1))
96 ToggleTool(m_currentlySelected
, false);
98 m_currentlySelected
= sel
;
99 ToggleTool(m_currentlySelected
, true);
102 bool csApp::CreatePalette(wxFrame
*parent
)
104 // First create a layout window
105 wxSashLayoutWindow
* win
= new wxSashLayoutWindow(parent
, ID_LAYOUT_WINDOW_PALETTE
, wxDefaultPosition
, wxSize(200, 30), wxNO_BORDER
|wxSW_3D
|wxCLIP_CHILDREN
);
106 win
->SetDefaultSize(wxSize(10000, 40));
107 win
->SetOrientation(wxLAYOUT_HORIZONTAL
);
108 win
->SetAlignment(wxLAYOUT_TOP
);
109 win
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
110 win
->SetSashVisible(wxSASH_BOTTOM
, true);
112 m_diagramPaletteSashWindow
= win
;
114 m_diagramPaletteSashWindow
->Show(false);
116 // Load palette bitmaps
118 wxBitmap
PaletteArrow(_T("arrowtool"));
119 wxBitmap
TextTool(_T("texttool"));
120 wxSize
toolBitmapSize(32, 32);
122 wxBitmap
PaletteArrow(arrow_xpm
);
123 wxBitmap
TextTool(texttool_xpm
);
124 wxSize
toolBitmapSize(22, 22);
127 csEditorToolPalette
*palette
= new csEditorToolPalette(m_diagramPaletteSashWindow
, ID_DIAGRAM_PALETTE
, wxPoint(0, 0), wxDefaultSize
, wxTB_HORIZONTAL
|wxNO_BORDER
);
129 palette
->SetMargins(2, 2);
131 palette
->SetToolBitmapSize(toolBitmapSize
);
133 palette
->AddTool(PALETTE_ARROW
, PaletteArrow
, wxNullBitmap
, true, 0, wxDefaultCoord
, NULL
, _T("Pointer"));
134 palette
->AddTool(PALETTE_TEXT_TOOL
, TextTool
, wxNullBitmap
, true, 0, wxDefaultCoord
, NULL
, _T("Text"));
136 wxChar
** symbols
= new wxChar
*[20];
139 symbols
[noSymbols
] = _T("Wide Rectangle");
142 symbols
[noSymbols
] = _T("Thin Rectangle");
145 symbols
[noSymbols
] = _T("Triangle");
148 symbols
[noSymbols
] = _T("Octagon");
151 // For some reason, we're getting Gdk errors with
152 // some shapes, such as ones that use DrawEllipse.
154 symbols
[noSymbols
] = _T("Group");
157 symbols
[noSymbols
] = _T("Circle");
160 symbols
[noSymbols
] = _T("Circle shadow");
163 symbols
[noSymbols
] = _T("SemiCircle");
168 for (i
= 0; i
< noSymbols
; i
++)
170 csSymbol
* symbol
= GetSymbolDatabase()->FindSymbol(symbols
[i
]);
173 wxBitmap
* bitmap
= GetSymbolDatabase()->CreateToolBitmap(symbol
, toolBitmapSize
);
174 palette
->AddTool(symbol
->GetToolId(), *bitmap
, wxNullBitmap
, true, 0, wxDefaultCoord
, NULL
, symbol
->GetName());
182 wxNode
* node
= GetSymbolDatabase()->GetSymbols().First();
185 csSymbol
* symbol
= (csSymbol
*) node
->Data();
187 wxBitmap
* bitmap
= GetSymbolDatabase()->CreateToolBitmap(symbol
, toolBitmapSize
);
188 palette
->AddTool(symbol
->GetToolId(), *bitmap
, wxNullBitmap
, true, 0, wxDefaultCoord
, NULL
, symbol
->GetName());
198 palette
->SetSelection(PALETTE_ARROW
);
199 m_diagramPalette
= palette
;