| 1 | /* |
|---|
| 2 | ================================================================================= |
|---|
| 3 | This file is part of Cafu, the open-source game engine and graphics engine |
|---|
| 4 | for multiplayer, cross-platform, real-time 3D action. |
|---|
| 5 | Copyright (C) 2002-2012 Carsten Fuchs Software. |
|---|
| 6 | |
|---|
| 7 | Cafu is free software: you can redistribute it and/or modify it under the terms |
|---|
| 8 | of the GNU General Public License as published by the Free Software Foundation, |
|---|
| 9 | either version 3 of the License, or (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 12 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|---|
| 13 | PURPOSE. See the GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with Cafu. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | |
|---|
| 18 | For support and more information about Cafu, visit us at <http://www.cafu.de>. |
|---|
| 19 | ================================================================================= |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #ifndef CAFU_DIALOG_EDIT_SURFACE_PROPS_HPP_INCLUDED |
|---|
| 23 | #define CAFU_DIALOG_EDIT_SURFACE_PROPS_HPP_INCLUDED |
|---|
| 24 | |
|---|
| 25 | #include "SurfaceInfo.hpp" |
|---|
| 26 | #include "ObserverPattern.hpp" |
|---|
| 27 | #include "wx/wx.h" |
|---|
| 28 | #include "wx/spinctrl.h" |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | class EditorMaterialI; |
|---|
| 32 | class MapBezierPatchT; |
|---|
| 33 | class MapBrushT; |
|---|
| 34 | class MapDocumentT; |
|---|
| 35 | class MapElementT; |
|---|
| 36 | class MapFaceT; |
|---|
| 37 | class ViewWindow3DT; |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | class EditSurfacePropsDialogT : public wxPanel, public ObserverT |
|---|
| 41 | { |
|---|
| 42 | public: |
|---|
| 43 | |
|---|
| 44 | static const unsigned long ALL_FACES; // Needed to select all faces of a brush. |
|---|
| 45 | |
|---|
| 46 | /// The constructor. |
|---|
| 47 | EditSurfacePropsDialogT(wxWindow* Parent, MapDocumentT* MapDoc); |
|---|
| 48 | |
|---|
| 49 | // Implementation of the ObserverT interface. |
|---|
| 50 | void NotifySubjectDies(SubjectT* Subject); |
|---|
| 51 | |
|---|
| 52 | /// Overridden wxDialog::Show() function, because we also want to update the dialog on Show(true). |
|---|
| 53 | /// Note that this method is called *indirectly* by the wxAUI framework, when the related pane is shown or hidden! |
|---|
| 54 | bool Show(bool show=true); |
|---|
| 55 | |
|---|
| 56 | /// Clears the list of faces and patches that were selected for surface-editing. |
|---|
| 57 | void ClearSelection(); |
|---|
| 58 | |
|---|
| 59 | /// Called when the user left clicked on a face/patch in the 3D view in order to toggle (select) it. |
|---|
| 60 | /// FaceIndex==ALL_FACES will toggle all faces of a brush (if Object is a brush). |
|---|
| 61 | void ToggleClick(MapElementT* Object, unsigned long FaceIndex); |
|---|
| 62 | |
|---|
| 63 | /// Called when the user right clicked on a face/patch in the 3D view to apply a material. |
|---|
| 64 | /// FaceIndex==ALL_FACES will perform the apply click on all faces of a brush (if Object is a brush). |
|---|
| 65 | void ApplyClick(ViewWindow3DT& ViewWin3D, MapElementT* Object, unsigned long FaceIndex); |
|---|
| 66 | |
|---|
| 67 | /// Called when a material is picked by the eye dropper (left mouse button click in eyedropper mode). |
|---|
| 68 | void EyeDropperClick(MapElementT* Object, unsigned long FaceIndex); |
|---|
| 69 | |
|---|
| 70 | /// Returns true if the hide selection overlay checkbox is unchecked and false if it is checked. |
|---|
| 71 | bool WantSelectionOverlay() const { return !CheckBoxHideSelMask->IsChecked(); } |
|---|
| 72 | |
|---|
| 73 | /// Returns the number of currently selected faces. |
|---|
| 74 | unsigned long GetNrOfSelectedFaces() const { return m_SelectedFaces.Size(); } |
|---|
| 75 | |
|---|
| 76 | /// Returns the number of currently selected Bezier patches. |
|---|
| 77 | unsigned long GetNrOfSelectedPatches() const { return m_SelectedPatches.Size(); } |
|---|
| 78 | |
|---|
| 79 | /// Returns the current list of MRU materials (the first element is the selected material). |
|---|
| 80 | ArrayT<EditorMaterialI*> GetMRUMaterials() const; |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | private: |
|---|
| 84 | |
|---|
| 85 | enum RightMBClickModeT // For SetSurfaceInfo(). |
|---|
| 86 | { |
|---|
| 87 | ApplyNormal, |
|---|
| 88 | ApplyViewAligned, |
|---|
| 89 | ApplyEdgeAligned, |
|---|
| 90 | ApplyProjective |
|---|
| 91 | }; |
|---|
| 92 | |
|---|
| 93 | enum ApplySettingT // Determines which value is applied if ApplyNormal is called. |
|---|
| 94 | { |
|---|
| 95 | ApplyNone =0x00, |
|---|
| 96 | ApplyScaleX =0x01, |
|---|
| 97 | ApplyScaleY =0x02, |
|---|
| 98 | ApplyShiftX =0x04, |
|---|
| 99 | ApplyShiftY =0x08, |
|---|
| 100 | ApplyRotation=0x10, |
|---|
| 101 | ApplyMaterial=0x20, |
|---|
| 102 | ApplyAll =0xFF |
|---|
| 103 | }; |
|---|
| 104 | |
|---|
| 105 | /// A struct that describes a selected face. |
|---|
| 106 | struct SelectedFaceT |
|---|
| 107 | { |
|---|
| 108 | MapFaceT* Face; |
|---|
| 109 | MapBrushT* Brush; |
|---|
| 110 | unsigned long FaceIndex; |
|---|
| 111 | }; |
|---|
| 112 | |
|---|
| 113 | MapDocumentT* m_MapDoc; ///< Pointer to the currently active document, or NULL when no document active. |
|---|
| 114 | TexCoordGenModeT m_CurrentTexGenMode; ///< The texture coordinates generation mode for the currently (i.e. last) picked face/patch. |
|---|
| 115 | Vector3fT m_CurrentUAxis; ///< The u-axis of the currently (i.e. last) picked face/patch. |
|---|
| 116 | Vector3fT m_CurrentVAxis; ///< The v-axis of the currently (i.e. last) picked face/patch. |
|---|
| 117 | ArrayT<SelectedFaceT> m_SelectedFaces; ///< The list of selected faces. |
|---|
| 118 | ArrayT<MapBezierPatchT*> m_SelectedPatches; ///< The list of selected patches. |
|---|
| 119 | |
|---|
| 120 | /// Applies the dialogs data to a face/patch using a specific ApplyMode, that decides how the data is applied. |
|---|
| 121 | /// The ApplySetting is only used if ApplyMode is ApplyNormal to specify which data should be applied (e.g. only |
|---|
| 122 | /// scale values). The ApplySetting should never be set when calling an ApplyMode other than ApplyNormal. |
|---|
| 123 | void SetSurfaceInfo(const MapFaceT* Face, SurfaceInfoT& SI, EditorMaterialI** Material, const RightMBClickModeT ApplyMode, const ApplySettingT Setting, ViewWindow3DT* ViewWin3D=NULL) const; |
|---|
| 124 | void SetSurfaceInfo(const MapBezierPatchT* Patch, SurfaceInfoT& SI, EditorMaterialI** Material, const RightMBClickModeT ApplyMode, const ApplySettingT Setting, ViewWindow3DT* ViewWin3D=NULL) const; |
|---|
| 125 | |
|---|
| 126 | // Updates the face normal and material vector info in the dialog. |
|---|
| 127 | void UpdateVectorInfo(); |
|---|
| 128 | |
|---|
| 129 | // "Orientation" section controls. |
|---|
| 130 | wxSpinCtrlDouble* m_SpinCtrlScaleX; |
|---|
| 131 | wxSpinCtrlDouble* m_SpinCtrlScaleY; |
|---|
| 132 | wxSpinCtrlDouble* m_SpinCtrlShiftX; |
|---|
| 133 | wxSpinCtrlDouble* m_SpinCtrlShiftY; |
|---|
| 134 | wxSpinCtrlDouble* m_SpinCtrlRotation; |
|---|
| 135 | wxStaticText* m_TexGenModeInfo; |
|---|
| 136 | |
|---|
| 137 | // Face and Material Vector info text. |
|---|
| 138 | wxStaticText* MaterialXInfo; |
|---|
| 139 | wxStaticText* MaterialYInfo; |
|---|
| 140 | |
|---|
| 141 | // "Alignment" section controls. |
|---|
| 142 | wxCheckBox* CheckBoxAlignWrtWorld; |
|---|
| 143 | wxCheckBox* CheckBoxAlignWrtFace; |
|---|
| 144 | wxCheckBox* CheckBoxTreatMultipleAsOne; |
|---|
| 145 | |
|---|
| 146 | // "Material" section controls. |
|---|
| 147 | wxChoice* ChoiceCurrentMat; |
|---|
| 148 | wxStaticBitmap* m_BitmapCurrentMat; |
|---|
| 149 | wxStaticText* StaticTextCurrentMatSize; |
|---|
| 150 | |
|---|
| 151 | // "Tool Mode" section controls. |
|---|
| 152 | wxCheckBox* CheckBoxHideSelMask; |
|---|
| 153 | wxChoice* ChoiceRightMBMode; |
|---|
| 154 | |
|---|
| 155 | // "Material Orientation" section event handlers (one for all spin controls). |
|---|
| 156 | void OnSpinCtrlValueChanged(wxSpinDoubleEvent& Event); |
|---|
| 157 | |
|---|
| 158 | // "Alignment" section event handlers. |
|---|
| 159 | void OnButtonAlign (wxCommandEvent& Event); |
|---|
| 160 | void OnCheckBoxAlignWorld (wxCommandEvent& Event); |
|---|
| 161 | void OnCheckBoxAlignFace (wxCommandEvent& Event); |
|---|
| 162 | void OnCheckBoxTreatMultipleAsOne(wxCommandEvent& Event); |
|---|
| 163 | |
|---|
| 164 | // "Material" section event handlers. |
|---|
| 165 | void OnSelChangeCurrentMat(wxCommandEvent& Event); |
|---|
| 166 | void OnButtonBrowseMats (wxCommandEvent& Event); |
|---|
| 167 | void OnButtonReplaceMats (wxCommandEvent& Event); |
|---|
| 168 | |
|---|
| 169 | // "Tool Mode" section event handlers. |
|---|
| 170 | void OnCheckBoxHideSelMask (wxCommandEvent& Event); |
|---|
| 171 | void OnSelChangeRightMB (wxCommandEvent& Event); |
|---|
| 172 | void OnButtonApplyToAllSelected(wxCommandEvent& Event); |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | // IDs for the controls whose events we are interested in. |
|---|
| 176 | enum |
|---|
| 177 | { |
|---|
| 178 | ID_SPINCTRL_SCALE_X=wxID_HIGHEST+1, |
|---|
| 179 | ID_SPINCTRL_SCALE_Y, |
|---|
| 180 | ID_SPINCTRL_SHIFT_X, |
|---|
| 181 | ID_SPINCTRL_SHIFT_Y, |
|---|
| 182 | ID_SPINCTRL_ROTATION, |
|---|
| 183 | ID_BUTTON_ALIGN2FITFACE, |
|---|
| 184 | ID_BUTTON_ALIGN2TOP, |
|---|
| 185 | ID_BUTTON_ALIGN2LEFT, |
|---|
| 186 | ID_BUTTON_ALIGN2CENTER, |
|---|
| 187 | ID_BUTTON_ALIGN2RIGHT, |
|---|
| 188 | ID_BUTTON_ALIGN2BOTTOM, |
|---|
| 189 | ID_CHECKBOX_ALIGN_WRT_WORLD, |
|---|
| 190 | ID_CHECKBOX_ALIGN_WRT_FACE, |
|---|
| 191 | ID_CHECKBOX_TREAT_MULTIPLE_AS_ONE, |
|---|
| 192 | ID_CHOICE_CURRENT_MAT, |
|---|
| 193 | ID_BUTTON_BROWSE_MATS, |
|---|
| 194 | ID_BUTTON_REPLACE_MATS, |
|---|
| 195 | ID_CHECKBOX_HIDE_SEL_MASK, |
|---|
| 196 | ID_CHOICE_RIGHT_MB_MODE, |
|---|
| 197 | ID_BUTTON_APPLY_TO_ALL_SELECTED |
|---|
| 198 | }; |
|---|
| 199 | |
|---|
| 200 | DECLARE_EVENT_TABLE() |
|---|
| 201 | }; |
|---|
| 202 | |
|---|
| 203 | #endif |
|---|