]> git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/meshtex/PluginModule.cpp
Merge branch 'master' into master-merge
[xonotic/netradiant.git] / contrib / meshtex / PluginModule.cpp
1 /**
2  * @file PluginModule.cpp
3  * Implements the PluginModule class.
4  * @ingroup generic-plugin
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 #include "PluginModule.h"
27 #include "GenericPluginUI.h"
28
29
30 /**
31  * Plugin function table.
32  */
33 _QERPluginTable PluginModule::_pluginAPI;
34
35 /**
36  * Default constructor. Initialize the function table.
37  */
38 PluginModule::PluginModule()
39 {
40    _pluginAPI.m_pfnQERPlug_Init = &QERPluginInit;
41    _pluginAPI.m_pfnQERPlug_GetName = &QERPluginGetName;
42    _pluginAPI.m_pfnQERPlug_GetCommandList = &QERPluginGetCommandList;
43    _pluginAPI.m_pfnQERPlug_GetCommandTitleList = &QERPluginGetCommandTitleList;
44    _pluginAPI.m_pfnQERPlug_Dispatch = &QERPluginDispatch;
45 }
46
47 /**
48  * Destructor.
49  */
50 PluginModule::~PluginModule()
51 {
52 }
53
54 /**
55  * Fetch a pointer to the function table.
56  */
57 _QERPluginTable *
58 PluginModule::getTable()
59 {
60    return &_pluginAPI;
61 }
62
63 /**
64  * Initialize plugin.
65  *
66  * @param hApp        Dummy arg; ignored.
67  * @param pMainWidget Main window widget.
68  *
69  * @return The plugin name.
70  */
71 const char *
72 PluginModule::QERPluginInit(void *hApp,
73                             void *pMainWidget)
74 {
75    // Inform the UI of the main app window.
76    UIInstance().SetWindow((GtkWidget *)pMainWidget);
77    // Return the plugin name.
78    return PLUGIN_NAME;
79 }
80
81 /**
82  * Get the plugin's name.
83  *
84  * @return The plugin name.
85  */
86 const char *
87 PluginModule::QERPluginGetName()
88 {
89    // Return the plugin name.
90    return PLUGIN_NAME;
91 }
92
93 /**
94  * Get the command list for the plugin menu, as a semicolon-separated string
95  * of tokens representing each command.
96  *
97  * @return The command list string.
98  */
99 const char *
100 PluginModule::QERPluginGetCommandList()
101 {
102    // Bail out if the plugin menu doesn't exist.
103    if (UIInstance().MainMenu() == NULL)
104    {
105       return "";
106    }
107    // Get the command list from the menu.
108    return UIInstance().MainMenu()->GetCommandList().c_str();
109 }
110
111 /**
112  * Get the command label list for the plugin menu, as a semicolon-separated
113  * string of labels to appear in the menu.
114  *
115  * @return The command label list string.
116  */
117 const char *
118 PluginModule::QERPluginGetCommandTitleList()
119 {
120    // Bail out if the plugin menu doesn't exist.
121    if (UIInstance().MainMenu() == NULL)
122    {
123       return "";
124    }
125    // Get the command label list from the menu.
126    return UIInstance().MainMenu()->GetCommandLabelList().c_str();
127 }
128
129 /**
130  * Invoke a plugin command.
131  *
132  * @param command      The command token.
133  * @param vMin         3-element float vector definining min corner of
134  *                     selection.
135  * @param vMax         3-element float vector definining max corner of
136  *                     selection.
137  * @param bSingleBrush Dummy arg; ignored.
138  */
139 void
140 PluginModule::QERPluginDispatch(const char *command,
141                                 float *vMin,
142                                 float *vMax,
143                                 bool bSingleBrush)
144 {
145    // Bail out if the plugin menu doesn't exist.
146    if (UIInstance().MainMenu() == NULL)
147    {
148       // XXX This shouldn't happen; might as well drop an ASSERT or error
149       // message in here. First make sure there's no odd Radiant-exiting
150       // corner case race that could trigger it though.
151       return;
152    }
153    // Send the command dispatch to the menu.
154    // XXX For my particular use case I don't need vMin or vMax, but for
155    // generality's sake those values should be passed along here, and then I
156    // can drop them when the flow gets to MeshTex-specific code... that will
157    // require changes for several types/signatures though.
158    UIInstance().MainMenu()->Dispatch(command);
159 }