-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginModule.cpp
159 lines (147 loc) · 4.14 KB
/
PluginModule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* @file PluginModule.cpp
* Implements the PluginModule class.
* @ingroup generic-plugin
*/
/*
* Copyright 2012 Joel Baxter
*
* This file is part of MeshTex.
*
* MeshTex is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MeshTex is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MeshTex. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PluginModule.h"
#include "GenericPluginUI.h"
/**
* Plugin function table.
*/
_QERPluginTable PluginModule::_pluginAPI;
/**
* Default constructor. Initialize the function table.
*/
PluginModule::PluginModule()
{
_pluginAPI.m_pfnQERPlug_Init = &QERPluginInit;
_pluginAPI.m_pfnQERPlug_GetName = &QERPluginGetName;
_pluginAPI.m_pfnQERPlug_GetCommandList = &QERPluginGetCommandList;
_pluginAPI.m_pfnQERPlug_GetCommandTitleList = &QERPluginGetCommandTitleList;
_pluginAPI.m_pfnQERPlug_Dispatch = &QERPluginDispatch;
}
/**
* Destructor.
*/
PluginModule::~PluginModule()
{
}
/**
* Fetch a pointer to the function table.
*/
_QERPluginTable *
PluginModule::getTable()
{
return &_pluginAPI;
}
/**
* Initialize plugin.
*
* @param hApp Dummy arg; ignored.
* @param pMainWidget Main window widget.
*
* @return The plugin name.
*/
const char *
PluginModule::QERPluginInit(void *hApp,
void *pMainWidget)
{
// Inform the UI of the main app window.
UIInstance().SetWindow((GtkWidget *)pMainWidget);
// Return the plugin name.
return PLUGIN_NAME;
}
/**
* Get the plugin's name.
*
* @return The plugin name.
*/
const char *
PluginModule::QERPluginGetName()
{
// Return the plugin name.
return PLUGIN_NAME;
}
/**
* Get the command list for the plugin menu, as a semicolon-separated string
* of tokens representing each command.
*
* @return The command list string.
*/
const char *
PluginModule::QERPluginGetCommandList()
{
// Bail out if the plugin menu doesn't exist.
if (UIInstance().MainMenu() == NULL)
{
return "";
}
// Get the command list from the menu.
return UIInstance().MainMenu()->GetCommandList().c_str();
}
/**
* Get the command label list for the plugin menu, as a semicolon-separated
* string of labels to appear in the menu.
*
* @return The command label list string.
*/
const char *
PluginModule::QERPluginGetCommandTitleList()
{
// Bail out if the plugin menu doesn't exist.
if (UIInstance().MainMenu() == NULL)
{
return "";
}
// Get the command label list from the menu.
return UIInstance().MainMenu()->GetCommandLabelList().c_str();
}
/**
* Invoke a plugin command.
*
* @param command The command token.
* @param vMin 3-element float vector definining min corner of
* selection.
* @param vMax 3-element float vector definining max corner of
* selection.
* @param bSingleBrush Dummy arg; ignored.
*/
void
PluginModule::QERPluginDispatch(const char *command,
float *vMin,
float *vMax,
bool bSingleBrush)
{
// Bail out if the plugin menu doesn't exist.
if (UIInstance().MainMenu() == NULL)
{
// XXX This shouldn't happen; might as well drop an ASSERT or error
// message in here. First make sure there's no odd Radiant-exiting
// corner case race that could trigger it though.
return;
}
// Send the command dispatch to the menu.
// XXX For my particular use case I don't need vMin or vMax, but for
// generality's sake those values should be passed along here, and then I
// can drop them when the flow gets to MeshTex-specific code... that will
// require changes for several types/signatures though.
UIInstance().MainMenu()->Dispatch(command);
}