MCPcopy Create free account
hub / github.com/DISTRHO/DPF / onMouse

Function onMouse

examples/States/ExampleUIStates.cpp:227–293  ·  view source on GitHub ↗

Mouse press event. This UI will de/activate blocks when you click them and report it as a state change to the plugin. */

Source from the content-addressed store, hash-verified

225 This UI will de/activate blocks when you click them and report it as a state change to the plugin.
226 */
227 bool onMouse(const MouseEvent& ev) override
228 {
229 // Test for left-clicked + pressed first.
230 if (ev.button != 1 || ! ev.press)
231 return false;
232
233 const uint width = getWidth();
234 const uint height = getHeight();
235
236 Rectangle<double> r;
237
238 r.setWidth(width/3 - 6);
239 r.setHeight(height/3 - 6);
240
241 // handle left, center and right columns
242 for (int i=0; i<3; ++i)
243 {
244 r.setX(3 + i*width/3);
245
246 // top
247 r.setY(3);
248
249 if (r.contains(ev.pos))
250 {
251 // index that this block applies to
252 const uint32_t index = 0+i;
253
254 // invert block state
255 fParamGrid[index] = !fParamGrid[index];
256
257 // report change to host (and thus plugin)
258 setState(getStateKeyFromIndex(index), fParamGrid[index] ? "true" : "false");
259
260 // trigger repaint
261 repaint();
262 break;
263 }
264
265 // middle
266 r.setY(3 + height/3);
267
268 if (r.contains(ev.pos))
269 {
270 // same as before
271 const uint32_t index = 3+i;
272 fParamGrid[index] = !fParamGrid[index];
273 setState(getStateKeyFromIndex(index), fParamGrid[index] ? "true" : "false");
274 repaint();
275 break;
276 }
277
278 // bottom
279 r.setY(3 + height*2/3);
280
281 if (r.contains(ev.pos))
282 {
283 // same as before
284 const uint32_t index = 6+i;

Callers

nothing calls this directly

Calls 10

getStateKeyFromIndexFunction · 0.85
setXMethod · 0.80
setYMethod · 0.80
setStateFunction · 0.70
getWidthFunction · 0.50
getHeightFunction · 0.50
repaintFunction · 0.50
setWidthMethod · 0.45
setHeightMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected