Changeset 374 for cafu/trunk

Show
Ignore:
Timestamp:
09/10/11 10:57:11 (9 months ago)
Author:
Carsten
Message:

Gui Editor:
Updated the Gui Editor code for Choice windows,
lining out the design and style that the other windows should be adapted to as well.

Location:
cafu/trunk
Files:
2 added
15 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/GuiEditor/Commands/ModifyWindow.cpp

    r367 r374  
    2626#include "GuiSys/GuiMan.hpp" 
    2727#include "GuiSys/GuiImpl.hpp" 
    28 #include "GuiSys/WindowChoice.hpp" 
    2928#include "GuiSys/WindowModel.hpp" 
    3029#include "MaterialSystem/Renderer.hpp" 
    3130#include "MaterialSystem/MaterialManager.hpp" 
    3231#include "Fonts/FontTT.hpp" 
    33 #include "TextParser/TextParser.hpp" 
    3432 
    3533 
     
    138136        m_Window->Font=cf::GuiSys::GuiMan->GetFont(m_NewString); 
    139137    } 
    140     else if (m_PropertyName=="Choices") 
    141     { 
    142         cf::GuiSys::ChoiceT* ChoiceWindow=dynamic_cast<cf::GuiSys::ChoiceT*>(m_Window); 
    143         wxASSERT(ChoiceWindow!=NULL); 
    144  
    145         m_OldString=""; 
    146  
    147         ArrayT<std::string>& Choices=ChoiceWindow->GetChoices(); 
    148  
    149         for (unsigned long ChoiceNr=0; ChoiceNr<Choices.Size(); ChoiceNr++) 
    150             m_OldString+=Choices[ChoiceNr]+";"; 
    151  
    152         // Parse choice list and update the window choices. 
    153         TextParserT ChoiceParser(m_NewString.c_str(), ";", false); 
    154         Choices.Clear(); 
    155  
    156         try 
    157         { 
    158             while (!ChoiceParser.IsAtEOF()) 
    159             { 
    160                 Choices.PushBack(ChoiceParser.GetNextToken()); 
    161                 ChoiceParser.AssertAndSkipToken(";"); 
    162             } 
    163         } 
    164         catch (const TextParserT::ParseError&) 
    165         { 
    166             // Undo all changes made up to this point. 
    167             try 
    168             { 
    169                 TextParserT ChoiceParser(m_OldString.c_str(), ";", false); 
    170                 Choices.Clear(); 
    171  
    172                 while (!ChoiceParser.IsAtEOF()) 
    173                 { 
    174                     Choices.PushBack(ChoiceParser.GetNextToken()); 
    175                     ChoiceParser.AssertAndSkipToken(";"); 
    176                 } 
    177             } 
    178             catch (const TextParserT::ParseError&) 
    179             { 
    180                 wxASSERT(false); 
    181                 return false; 
    182             } 
    183  
    184             return false; 
    185         } 
    186     } 
    187138    else if (m_PropertyName=="Model") 
    188139    { 
     
    258209        m_Window->Font=cf::GuiSys::GuiMan->GetFont(m_OldString); 
    259210    } 
    260     else if (m_PropertyName=="Choices") 
    261     { 
    262         cf::GuiSys::ChoiceT* ChoiceWindow=dynamic_cast<cf::GuiSys::ChoiceT*>(m_Window); 
    263         wxASSERT(ChoiceWindow!=NULL); 
    264  
    265         ArrayT<std::string>& Choices=ChoiceWindow->GetChoices(); 
    266  
    267         // Parse choice list and update the window choices. 
    268         TextParserT ChoiceParser(m_OldString.c_str(), ";", false); 
    269         Choices.Clear(); 
    270  
    271         try 
    272         { 
    273             while (!ChoiceParser.IsAtEOF()) 
    274             { 
    275                 Choices.PushBack(ChoiceParser.GetNextToken()); 
    276                 ChoiceParser.AssertAndSkipToken(";"); 
    277             } 
    278         } 
    279         catch (const TextParserT::ParseError&) 
    280         { 
    281             wxASSERT(false); 
    282         } 
    283     } 
    284211    else if (m_PropertyName=="Model") 
    285212    { 
  • cafu/trunk/CaWE/GuiEditor/ObserverPattern.cpp

    r285 r374  
    138138 
    139139 
     140void SubjectT::UpdateAllObservers_Modified(const EditorWindowT* Win, const wxString& PropName) 
     141{ 
     142    for (unsigned long ObsNr=0; ObsNr<m_Observers.Size(); ObsNr++) 
     143        m_Observers[ObsNr]->Notify_WinChanged(this, Win, PropName); 
     144} 
     145 
     146 
    140147SubjectT::~SubjectT() 
    141148{ 
  • cafu/trunk/CaWE/GuiEditor/ObserverPattern.hpp

    r316 r374  
    4242namespace GuiEditor 
    4343{ 
     44    class EditorWindowT; 
    4445    class SubjectT; 
    4546    class UpdateBoxT; 
     
    9899        //@} 
    99100 
     101        /// Notifies the observer that a property of a window has changed. 
     102        /// @param Subject    The GUI document whose window has changed. 
     103        /// @param Win        The window whose property has changed. 
     104        /// @param PropName   The name of the property whose value has changed. 
     105        virtual void Notify_WinChanged(SubjectT* Subject, const EditorWindowT* Win, const wxString& PropName) { } 
     106 
    100107        /// This method is called whenever a subject is about the be destroyed (and become unavailable). 
    101         /// \param dyingSubject   The subject that is being destroyed. 
     108        /// @param dyingSubject   The subject that is being destroyed. 
    102109        virtual void NotifySubjectDies(SubjectT* dyingSubject)=0; 
    103110 
     
    135142        virtual void UpdateAllObservers_Modified(const ArrayT<cf::GuiSys::WindowT*>& Windows, WindowModDetailE Detail, const wxString& PropertyName); 
    136143        virtual void UpdateAllObservers_Modified(cf::GuiSys::WindowT* Window, WindowModDetailE Detail, const wxString& PropertyName); 
     144        virtual void UpdateAllObservers_Modified(const EditorWindowT* Win, const wxString& PropName); 
    137145 
    138146        /// The virtual destructor. 
  • cafu/trunk/CaWE/GuiEditor/RenderWindow.cpp

    r367 r374  
    101101 
    102102 
     103void RenderWindowT::Notify_WinChanged(SubjectT* Subject, const EditorWindowT* Win, const wxString& PropName) 
     104{ 
     105    Refresh(false); 
     106} 
     107 
     108 
    103109void RenderWindowT::NotifySubjectDies(SubjectT* dyingSubject) 
    104110{ 
  • cafu/trunk/CaWE/GuiEditor/RenderWindow.hpp

    r285 r374  
    4747        void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<cf::GuiSys::WindowT*>& Windows, WindowModDetailE Detail); 
    4848        void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<cf::GuiSys::WindowT*>& Windows, WindowModDetailE Detail, const wxString& PropertyName); 
     49        void Notify_WinChanged(SubjectT* Subject, const EditorWindowT* Win, const wxString& PropName); 
    4950        void NotifySubjectDies(SubjectT* dyingSubject); 
    5051 
  • cafu/trunk/CaWE/GuiEditor/WindowInspector.cpp

    r367 r374  
    7373void WindowInspectorT::NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<cf::GuiSys::WindowT*>& Windows, WindowModDetailE Detail) 
    7474{ 
    75     if (!m_SelectedWindow) return; 
    76  
    77     if (Detail==WMD_HIERARCHY) return; // The ordner doesn't affect the window inspector. 
    78  
    79     for (unsigned long WindowNr=0; WindowNr<Windows.Size(); WindowNr++) 
    80     { 
    81         if (m_SelectedWindow==Windows[WindowNr]) 
    82         { 
    83             if (Detail==WMD_GENERIC) 
    84             { 
    85                 RefreshPropGrid(); 
    86                 return; 
    87             } 
    88  
    89             if (Detail==WMD_TRANSFORMED) 
    90             { 
    91                 // Update all transformation related properties (position, size, rotation). 
    92                 wxPGProperty* Property=GetProperty("Position.X"); 
    93                 Property->SetValue(wxVariant(m_SelectedWindow->Rect[0])); 
    94  
    95                 Property=GetProperty("Position.Y"); 
    96                 Property->SetValue(wxVariant(m_SelectedWindow->Rect[1])); 
    97  
    98                 Property=GetProperty("Size.Width"); 
    99                 Property->SetValue(wxVariant(m_SelectedWindow->Rect[2])); 
    100  
    101                 Property=GetProperty("Size.Height"); 
    102                 Property->SetValue(wxVariant(m_SelectedWindow->Rect[3])); 
    103  
    104                 Property=GetProperty("Rotation"); 
    105                 Property->SetValue(wxVariant(m_SelectedWindow->RotAngle)); 
    106  
    107                 RefreshGrid(); 
    108  
    109                 return; 
    110             } 
    111  
    112             if (Detail==WMD_HOR_TEXT_ALIGN) 
    113             { 
    114                 wxPGProperty* Property=GetProperty("HorizontalAlign"); 
    115                 Property->SetValueFromInt(int(m_SelectedWindow->TextAlignHor)); 
    116  
    117                 RefreshGrid(); 
    118  
    119                 return; 
    120             } 
     75    if (m_IsRecursiveSelfNotify) return; 
     76    if (!m_SelectedWindow) return; 
     77    if (Windows.Find(m_SelectedWindow)==-1) return; 
     78 
     79    switch (Detail) 
     80    { 
     81        case WMD_HIERARCHY: 
     82        { 
     83            // The window hierarchy doesn't affect the window inspector. 
     84            break; 
     85        } 
     86 
     87        case WMD_GENERIC: 
     88        { 
     89            RefreshPropGrid(); 
     90            break; 
     91        } 
     92 
     93        case WMD_TRANSFORMED: 
     94        { 
     95            // Update all transformation related properties (position, size, rotation). 
     96            wxPGProperty* Property=GetProperty("Position.X"); 
     97            Property->SetValue(wxVariant(m_SelectedWindow->Rect[0])); 
     98 
     99            Property=GetProperty("Position.Y"); 
     100            Property->SetValue(wxVariant(m_SelectedWindow->Rect[1])); 
     101 
     102            Property=GetProperty("Size.Width"); 
     103            Property->SetValue(wxVariant(m_SelectedWindow->Rect[2])); 
     104 
     105            Property=GetProperty("Size.Height"); 
     106            Property->SetValue(wxVariant(m_SelectedWindow->Rect[3])); 
     107 
     108            Property=GetProperty("Rotation"); 
     109            Property->SetValue(wxVariant(m_SelectedWindow->RotAngle)); 
     110 
     111            RefreshGrid(); 
     112            break; 
     113        } 
     114 
     115        case WMD_HOR_TEXT_ALIGN: 
     116        { 
     117            wxPGProperty* Property=GetProperty("HorizontalAlign"); 
     118            Property->SetValueFromInt(int(m_SelectedWindow->TextAlignHor)); 
     119 
     120            RefreshGrid(); 
     121            break; 
    121122        } 
    122123    } 
     
    127128{ 
    128129    if (m_IsRecursiveSelfNotify) return; 
    129  
    130     if (!m_SelectedWindow) return; 
    131  
    132     for (unsigned long WindowNr=0; WindowNr<Windows.Size(); WindowNr++) 
    133     { 
    134         if (m_SelectedWindow==Windows[WindowNr]) 
    135         { 
    136             wxPGProperty* Property=GetProperty(PropertyName); 
    137             wxASSERT(Property); 
    138  
    139             GuiDocumentT::GetSibling(m_SelectedWindow)->UpdateProperty(Property); 
    140  
    141             RefreshGrid(); 
    142             return; 
    143         } 
    144     } 
     130    if (!m_SelectedWindow) return; 
     131    if (Windows.Find(m_SelectedWindow)==-1) return; 
     132 
     133    wxPGProperty* Property=GetProperty(PropertyName); 
     134    wxASSERT(Property); 
     135 
     136    GuiDocumentT::GetSibling(m_SelectedWindow)->UpdateProperty(Property); 
     137    RefreshGrid(); 
     138} 
     139 
     140 
     141void WindowInspectorT::Notify_WinChanged(SubjectT* Subject, const EditorWindowT* Win, const wxString& PropName) 
     142{ 
     143    if (m_IsRecursiveSelfNotify) return; 
     144    if (!m_SelectedWindow) return; 
     145    if (Win->GetDual()!=m_SelectedWindow) return; 
     146 
     147    wxPGProperty* Property=GetProperty(PropName); 
     148    wxASSERT(Property); 
     149 
     150    GuiDocumentT::GetSibling(m_SelectedWindow)->UpdateProperty(Property); 
     151    RefreshGrid(); 
    145152} 
    146153 
     
    196203    ClearSelection(); 
    197204 
     205    m_IsRecursiveSelfNotify=true; 
    198206    GuiDocumentT::GetSibling(m_SelectedWindow)->HandlePGChange(Event, m_Parent); 
    199 } 
     207    m_IsRecursiveSelfNotify=false; 
     208} 
  • cafu/trunk/CaWE/GuiEditor/WindowInspector.hpp

    r285 r374  
    4848        void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<cf::GuiSys::WindowT*>& Windows, WindowModDetailE Detail); 
    4949        void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<cf::GuiSys::WindowT*>& Windows, WindowModDetailE Detail, const wxString& PropertyName); 
     50        void Notify_WinChanged(SubjectT* Subject, const EditorWindowT* Win, const wxString& PropName); 
    5051        void NotifySubjectDies(SubjectT* dyingSubject); 
    5152 
     
    6061        bool                 m_IsRecursiveSelfNotify; 
    6162 
    62  
    6363        void OnPropertyGridChanged(wxPropertyGridEvent& Event); 
    6464 
  • cafu/trunk/CaWE/GuiEditor/WindowTree.cpp

    r367 r374  
    240240 
    241241 
     242void WindowTreeT::Notify_WinChanged(SubjectT* Subject, const EditorWindowT* Win, const wxString& PropName) 
     243{ 
     244} 
     245 
     246 
    242247void WindowTreeT::RefreshTree() 
    243248{ 
  • cafu/trunk/CaWE/GuiEditor/WindowTree.hpp

    r293 r374  
    6464        void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<cf::GuiSys::WindowT*>& Windows, WindowModDetailE Detail); 
    6565        void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<cf::GuiSys::WindowT*>& Windows, WindowModDetailE Detail, const wxString& PropertyName); 
     66        void Notify_WinChanged(SubjectT* Subject, const EditorWindowT* Win, const wxString& PropName); 
    6667        void NotifySubjectDies(SubjectT* dyingSubject); 
    6768 
  • cafu/trunk/CaWE/GuiEditor/Windows/EditorChoiceWindow.cpp

    r373 r374  
    2424#include "../GuiDocument.hpp" 
    2525#include "../Commands/ModifyWindow.hpp" 
     26#include "../Commands/SetStrings.hpp" 
    2627 
    2728#include "GuiSys/WindowChoice.hpp" 
     
    4546    EditorWindowT::FillInPG(PropMan); 
    4647 
    47     wxString ChoicesString; 
     48    wxString Str; 
    4849 
    4950    for (unsigned long ChoiceNr=0; ChoiceNr<m_Choice->GetChoices().Size(); ChoiceNr++) 
    50         ChoicesString+=m_Choice->GetChoices()[ChoiceNr]+";\n"; 
     51    { 
     52        if (ChoiceNr>0) Str+="\n"; 
     53        Str+=m_Choice->GetChoices()[ChoiceNr]; 
     54    } 
    5155 
    52     PropMan->Append(new wxLongStringProperty("Choices", wxPG_LABEL, ChoicesString)); 
     56    PropMan->Append(new wxLongStringProperty("Choices", wxPG_LABEL, Str)); 
    5357    PropMan->Append(new wxIntProperty("DefaultChoice", wxPG_LABEL, m_Choice->GetSelectedChoice())); 
    5458} 
     
    6367    if (PropName=="Choices") 
    6468    { 
    65         wxString ChoicesString; 
     69        wxString Str; 
    6670 
    6771        for (unsigned long ChoiceNr=0; ChoiceNr<m_Choice->GetChoices().Size(); ChoiceNr++) 
    68             ChoicesString+=m_Choice->GetChoices()[ChoiceNr]+";\n"; 
     72        { 
     73            if (ChoiceNr>0) Str+="\n"; 
     74            Str+=m_Choice->GetChoices()[ChoiceNr]; 
     75        } 
    6976 
    70         Property->SetValueFromString(ChoicesString); 
     77        Property->SetValueFromString(Str); 
    7178        return true; 
    7279    } 
     
    9198    if (PropName=="Choices") 
    9299    { 
    93         static cf::GuiSys::WindowT::MemberVarT DummyVar; 
     100        ArrayT<std::string> NewStrings; 
     101        wxStringTokenizer   Tokenizer(Prop->GetValueAsString(), "\r\n"); 
    94102 
    95         // Remove all newline characters from the string since they break the choices display. 
    96         wxString FormattedString=Prop->GetValueAsString(); 
    97         FormattedString.Replace("\\n", ""); 
    98         // Remove all trailing characters after the last delimiter (;). 
    99         FormattedString=FormattedString.Mid(0, FormattedString.Find(';', true)+1); 
     103        while (Tokenizer.HasMoreTokens()) 
     104            NewStrings.PushBack(std::string(Tokenizer.GetNextToken())); 
    100105 
    101         // Specially treated by command. 
    102         ChildFrame->SubmitCommand(new CommandModifyWindowT(m_GuiDoc, m_Choice, PropName, DummyVar, FormattedString)); 
     106        ChildFrame->SubmitCommand(new CommandSetStringsT(m_GuiDoc, this, PropName, m_Choice->m_Choices, NewStrings)); 
    103107        return true; 
    104108    } 
  • cafu/trunk/CaWE/GuiEditor/Windows/EditorWindow.hpp

    r367 r374  
    4848        /// The destructor. 
    4949        virtual ~EditorWindowT() { } 
     50 
     51        /// Returns the GuiSys "dual" or "sibling" of this window. 
     52        const cf::GuiSys::WindowT* GetDual() const { return m_Win; } 
    5053 
    5154        /// Returns the GuiDocumentT instance that this window lives in. 
  • cafu/trunk/CaWE/ModelEditor/ObserverPattern.hpp

    r341 r374  
    8888        virtual void Notify_AnimStateChanged(SubjectT* Subject) { } 
    8989 
    90         /// Notifies the observer that the listz of submodels has changed. 
     90        /// Notifies the observer that the list of submodels has changed. 
    9191        /// @param Subject   The model document with the model in which the list of submodels has changed. 
    9292        virtual void Notify_SubmodelsChanged(SubjectT* Subject) { } 
  • cafu/trunk/Games/DeathMatch/GUIs/MainMenu/MainMenu_init.cgui

    r51 r374  
    12581258    self:set("backColor", 0, 0, 0, 0); 
    12591259    self:set("font", "Fonts/Impact"); 
    1260     self:set("text", "Cafu is copyright © 2001-2010 Carsten Fuchs Software.\nAll rights reserved.                       http://www.cafu.de"); 
     1260    self:set("text", "Cafu is copyright © 2001-2011 Carsten Fuchs Software.\nAll rights reserved.                       http://www.cafu.de"); 
    12611261    self:set("textScale", 0.22); 
    12621262    self:set("textColor", 0.5, 0.5, 0.5, 1); 
  • cafu/trunk/Libs/GuiSys/Window.hpp

    r367 r374  
    117117 
    118118            /// Extra / extern / extension data that user code can derive from and assign to this window 
    119             /// in order to "configure" it with "callbacks" (e\.g\. the \c Render() method) and to have it 
     119            /// in order to "configure" it with "callbacks" (e.g.\ the \c Render() method) and to have it 
    120120            /// store additional user-specific data and functions. 
    121121            struct ExtDataT 
  • cafu/trunk/Libs/GuiSys/WindowChoice.hpp

    r373 r374  
    2626 
    2727 
     28namespace GuiEditor { class EditorChoiceWindowT; } 
     29 
     30 
    2831namespace cf 
    2932{ 
     
    3134    { 
    3235        /// A choice window. 
    33         /// This was initially intended to look-n-feel like a combobox under Windows, 
    34         /// but it turns out that for speed and ease of implementation, an entirely 
    35         /// different approach is more feasible (for now). 
     36        /// This was initially intended to look and feel like a "combobox" under Windows, 
     37        /// but for ease of implementation, the current approach works slightly different. 
    3638        class ChoiceT : public WindowT 
    3739        { 
    3840            public: 
    3941 
    40             /// Constructor for creating a listbox. 
    41             /// @param Params Choice creation parameters. 
     42            /// Constructor for creating a choice. 
     43            /// @param Params   Choice creation parameters. 
    4244            ChoiceT(const cf::GuiSys::WindowCreateParamsT& Params); 
    4345 
    44             /// The Copy Constructor. 
    45             /// @param Window Window to copy. 
    46             /// @param Recursive Whether to copy the whole window hierarchy of the window and its children. 
     46            /// The copy constructor. 
     47            /// @param Window      Window to copy. 
     48            /// @param Recursive   Whether to copy the whole window hierarchy of the window and its children. 
    4749            ChoiceT(const ChoiceT& Window, bool Recursive=false); 
    4850 
     
    5355 
    5456            /// Returns an array of the choices of this window. 
    55             ArrayT<std::string>& GetChoices() { return m_Choices; } 
     57            const ArrayT<std::string>& GetChoices() const { return m_Choices; } 
    5658 
     59            /// Returns the currently selected choice, -1 for none. 
    5760            int GetSelectedChoice() const { return m_SelectedChoice; } 
    5861 
     
    6972 
    7073            protected: 
     74 
     75            friend class GuiEditor::EditorChoiceWindowT; 
    7176 
    7277            void FillMemberVars();  ///< Helper method that fills the MemberVars array with entries for each class member.