1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "BorderPanel.h"
21 
22 #include "View/ViewConstants.h"
23 
24 #include <wx/dcclient.h>
25 
26 namespace TrenchBroom {
27     namespace View {
IMPLEMENT_DYNAMIC_CLASS(BorderPanel,wxPanel)28         IMPLEMENT_DYNAMIC_CLASS(BorderPanel, wxPanel)
29 
30         BorderPanel::BorderPanel() :
31         wxPanel(),
32         m_borders(0),
33         m_thickness(1) {}
34 
BorderPanel(wxWindow * parent,const int borders,const int thickness)35         BorderPanel::BorderPanel(wxWindow* parent, const int borders, const int thickness) :
36         wxPanel(),
37         m_borders(0),
38         m_thickness(1) {
39             Create(parent, borders, thickness);
40         }
41 
~BorderPanel()42         BorderPanel::~BorderPanel() {}
43 
Create(wxWindow * parent,int borders,int thickness)44         void BorderPanel::Create(wxWindow* parent, int borders, int thickness) {
45             wxPanel::Create(parent);
46             m_borders = borders;
47             m_thickness = thickness;
48             Bind(wxEVT_PAINT, &BorderPanel::OnPaint, this);
49         }
50 
OnPaint(wxPaintEvent & event)51         void BorderPanel::OnPaint(wxPaintEvent& event) {
52             if (IsBeingDeleted()) return;
53 
54             wxPaintDC dc(this);
55             dc.SetPen(wxPen(Colors::borderColor()));
56 
57             wxRect rect = GetClientRect();
58             if ((m_borders & wxLEFT) != 0)
59                 dc.DrawLine(rect.GetLeft(), rect.GetTop(), rect.GetLeft(), rect.GetBottom());
60             if ((m_borders & wxTOP) != 0)
61                 dc.DrawLine(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetTop());
62             if ((m_borders & wxRIGHT) != 0)
63                 dc.DrawLine(rect.GetRight(), rect.GetTop(), rect.GetRight(), rect.GetBottom());
64             if ((m_borders & wxBOTTOM) != 0)
65                 dc.DrawLine(rect.GetLeft(), rect.GetBottom(), rect.GetRight(), rect.GetBottom());
66             event.Skip();
67         }
68 
DoGetBestSize() const69         wxSize BorderPanel::DoGetBestSize() const {
70             wxSize size = wxPanel::DoGetBestSize();
71             if ((m_borders & wxLEFT) != 0)
72                 size.x += m_thickness;
73             if ((m_borders & wxTOP) != 0)
74                 size.y += m_thickness;
75             if ((m_borders & wxRIGHT) != 0)
76                 size.x += m_thickness;
77             if ((m_borders & wxBOTTOM) != 0)
78                 size.y += m_thickness;
79             return size;
80         }
81     }
82 }
83