]> git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/meshtex/MainMenu.h
* added MeshTex plugin src to project (can't compile)
[xonotic/netradiant.git] / contrib / meshtex / MainMenu.h
1 /**
2  * @file MainMenu.h
3  * Declares the MainMenu class.
4  * @ingroup meshtex-ui
5  */
6
7 /*
8  * Copyright 2012 Joel Baxter
9  *
10  * This file is part of MeshTex.
11  *
12  * MeshTex is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * MeshTex is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with MeshTex.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26 #if !defined(INCLUDED_MAINMENU_H)
27 #define INCLUDED_MAINMENU_H
28
29 #include "GenericMainMenu.h"
30 #include "MeshVisitor.h"
31
32 /**
33  * Subclass of GenericMainMenu that constructs the commands for this plugin.
34  *
35  * @ingroup meshtex-ui
36  */
37 class MainMenu : public GenericMainMenu
38 {
39 private: // private types
40
41    /**
42     * Visitor for invoking a function on a MeshEntity when that function does
43     * not require any arguments other than the texture axes. These operations
44     * are triggered immediately on selecting a menu entry, rather than being
45     * triggered by applying some other dialog.
46     */
47    class PresetFuncVisitor : public MeshVisitor
48    {
49    public:
50       /**
51        * Function signature for a preset function.
52        */
53       typedef void(MeshEntity::*VisitorFunctor)(MeshEntity::TextureAxisSelection axes);
54    public:
55       PresetFuncVisitor(const VisitorFunctor& visitorFunctor,
56                         MeshEntity::TextureAxisSelection axes);
57    private:
58       bool Execute(MeshEntity& meshEntity) const;
59
60    private:
61       const VisitorFunctor _visitorFunctor;
62       const MeshEntity::TextureAxisSelection _axes;
63    };
64
65 public: // public methods
66
67    MainMenu(SmartPointer<GenericDialog>& setScaleDialog,
68             SmartPointer<GenericDialog>& getInfoDialog,
69             SmartPointer<GenericDialog>& genFuncDialog);
70    ~MainMenu();
71    void CommandMeshVisitor(const std::string& commandString);
72    void CommandHelp(const std::string& commandString);
73    void CommandAbout(const std::string& commandString);
74
75 private: // private methods
76
77    void AddMeshVisitorEntry(const char *commandLabel,
78                             const char *command,
79                             const SmartPointer<MeshVisitor>& visitor);
80
81 private: // private types
82
83    /**
84     * Type for a map between a string and a reference-counted visitor.
85     */
86    typedef std::map<std::string, SmartPointer<MeshVisitor> > VisitorMap;
87
88 private:
89
90    /**
91     * Associations between commands and visitors that implement them.
92     */
93    VisitorMap _visitorMap;
94
95    /**
96     * Callback for all of the commands that trigger CommandMeshVisitor. This is
97     * stored in a member var rather than a local var just because otherwise it
98     * would need to be passed around and clutter up an already ugly set of
99     * invocations.
100     */
101    const CommandCallbackMethod
102       <MainMenu, &MainMenu::CommandMeshVisitor> _commandMeshVisitor;
103 };
104
105 #endif // #if !defined(INCLUDED_MAINMENU_H)