TopLevelWidgetPrivateData.cpp (4825B)
1 /* 2 * DISTRHO Plugin Framework (DPF) 3 * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com> 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any purpose with 6 * or without fee is hereby granted, provided that the above copyright notice and this 7 * permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD 10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN 11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include "TopLevelWidgetPrivateData.hpp" 18 #include "WidgetPrivateData.hpp" 19 #include "WindowPrivateData.hpp" 20 #include "pugl.hpp" 21 22 START_NAMESPACE_DGL 23 24 // ----------------------------------------------------------------------- 25 26 TopLevelWidget::PrivateData::PrivateData(TopLevelWidget* const s, Window& w) 27 : self(s), 28 selfw(s), 29 window(w) 30 { 31 /* if window already has a top-level-widget, make the new one match the first one in size 32 * this is needed because window creation and resize is a synchronous operation in some systems. 33 * as such, there's a chance the non-1st top-level-widgets would never get a valid size. 34 */ 35 if (!window.pData->topLevelWidgets.empty()) 36 { 37 TopLevelWidget* const first = window.pData->topLevelWidgets.front(); 38 39 selfw->pData->size = first->getSize(); 40 } 41 42 window.pData->topLevelWidgets.push_back(self); 43 } 44 45 TopLevelWidget::PrivateData::~PrivateData() 46 { 47 window.pData->topLevelWidgets.remove(self); 48 } 49 50 bool TopLevelWidget::PrivateData::keyboardEvent(const KeyboardEvent& ev) 51 { 52 // ignore event if we are not visible 53 if (! selfw->pData->visible) 54 return false; 55 56 // propagate event to all subwidgets recursively 57 return selfw->pData->giveKeyboardEventForSubWidgets(ev); 58 } 59 60 bool TopLevelWidget::PrivateData::characterInputEvent(const CharacterInputEvent& ev) 61 { 62 // ignore event if we are not visible 63 if (! selfw->pData->visible) 64 return false; 65 66 // propagate event to all subwidgets recursively 67 return selfw->pData->giveCharacterInputEventForSubWidgets(ev); 68 } 69 70 bool TopLevelWidget::PrivateData::mouseEvent(const MouseEvent& ev) 71 { 72 // ignore event if we are not visible 73 if (! selfw->pData->visible) 74 return false; 75 76 MouseEvent rev = ev; 77 78 if (window.pData->autoScaling) 79 { 80 const double autoScaleFactor = window.pData->autoScaleFactor; 81 82 rev.pos.setX(ev.pos.getX() / autoScaleFactor); 83 rev.pos.setY(ev.pos.getY() / autoScaleFactor); 84 rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor); 85 rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor); 86 } 87 88 // propagate event to all subwidgets recursively 89 return selfw->pData->giveMouseEventForSubWidgets(rev); 90 } 91 92 bool TopLevelWidget::PrivateData::motionEvent(const MotionEvent& ev) 93 { 94 // ignore event if we are not visible 95 if (! selfw->pData->visible) 96 return false; 97 98 MotionEvent rev = ev; 99 100 if (window.pData->autoScaling) 101 { 102 const double autoScaleFactor = window.pData->autoScaleFactor; 103 104 rev.pos.setX(ev.pos.getX() / autoScaleFactor); 105 rev.pos.setY(ev.pos.getY() / autoScaleFactor); 106 rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor); 107 rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor); 108 } 109 110 // propagate event to all subwidgets recursively 111 return selfw->pData->giveMotionEventForSubWidgets(rev); 112 } 113 114 bool TopLevelWidget::PrivateData::scrollEvent(const ScrollEvent& ev) 115 { 116 // ignore event if we are not visible 117 if (! selfw->pData->visible) 118 return false; 119 120 ScrollEvent rev = ev; 121 122 if (window.pData->autoScaling) 123 { 124 const double autoScaleFactor = window.pData->autoScaleFactor; 125 126 rev.pos.setX(ev.pos.getX() / autoScaleFactor); 127 rev.pos.setY(ev.pos.getY() / autoScaleFactor); 128 rev.absolutePos.setX(ev.absolutePos.getX() / autoScaleFactor); 129 rev.absolutePos.setY(ev.absolutePos.getY() / autoScaleFactor); 130 rev.delta.setX(ev.delta.getX() / autoScaleFactor); 131 rev.delta.setY(ev.delta.getY() / autoScaleFactor); 132 } 133 134 // propagate event to all subwidgets recursively 135 return selfw->pData->giveScrollEventForSubWidgets(rev); 136 } 137 138 void TopLevelWidget::PrivateData::fallbackOnResize(const uint width, const uint height) 139 { 140 puglFallbackOnResize(window.pData->view, width, height); 141 } 142 143 // ----------------------------------------------------------------------- 144 145 END_NAMESPACE_DGL