Debian Codegraph @

radiant/ui/materials/editor/MapExpressionEntry.h

raw
1 #pragma once
2
3 #include "i18n.h"
4 #include <wx/panel.h>
5 #include <wx/textctrl.h>
6 #include <wx/button.h>
7 #include <wx/sizer.h>
8
9 #include "ui/common/ImageFileSelector.h"
10
11 namespace ui
12 {
13
14 class MapExpressionEntry :
15 public wxPanel
16 {
17 private:
18 wxTextCtrl* _textEntry;
19 wxButton* _browseButton;
20 wxWindow* _windowToPlaceDialogsOn;
21
22 public:
23 // Create a map expression entry box featuring a browse/select button
24 // The windowToPlaceDialogsOn argument will be used to position the modal dialog (if set)
25 MapExpressionEntry(wxWindow* parent, wxWindow* windowToPlaceDialogsOn = nullptr) :
26 wxPanel(parent, wxID_ANY),
27 _windowToPlaceDialogsOn(windowToPlaceDialogsOn)
28 {
29 SetSizer(new wxBoxSizer(wxHORIZONTAL));
30
31 _textEntry = new wxTextCtrl(this, wxID_ANY);
32
33 _browseButton = new wxButton(this, wxID_ANY, "...");
34 _browseButton->SetMaxSize(wxSize(40, -1));
35 _browseButton->Bind(wxEVT_BUTTON, &MapExpressionEntry::onBrowseButtonClick, this);
36 _browseButton->SetToolTip(_("Select an Image File"));
37
38 GetSizer()->Add(_textEntry, 1, wxRIGHT|wxALIGN_CENTER_VERTICAL, 6);
39 GetSizer()->Add(_browseButton, 0, wxALIGN_CENTER_VERTICAL, 0);
40 }
41
42 wxTextCtrl* GetTextCtrl()
43 {
44 return _textEntry;
45 }
46
47 wxString GetValue()
48 {
49 return _textEntry->GetValue();
50 }
51
52 void SetValue(const wxString& value)
53 {
54 _textEntry->SetValue(value);
55 }
56
57 private:
58 bool isLookingForCubeMap()
59 {
60 return GetValue().StartsWith("env/");
61 }
62
63 void onBrowseButtonClick(wxCommandEvent& ev)
64 {
65 auto selector = new ImageFileSelector(this, _textEntry);
66
67 selector->SetVisibleTextureTypes(isLookingForCubeMap() ?
68 ImageFileSelector::TextureType::CubeMap : ImageFileSelector::TextureType::Map);
69
70 if (_windowToPlaceDialogsOn != nullptr)
71 {
72 selector->SetPosition(_windowToPlaceDialogsOn->GetScreenPosition());
73 selector->SetSize(_windowToPlaceDialogsOn->GetSize());
74 }
75
76 selector->ShowModal(_textEntry->GetValue().ToStdString());
77 selector->Destroy();
78 }
79 };
80
81 }