Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_BoundsTracker.cpp
- This file was added.
| /* | |||||
| * This program 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. | |||||
| * | |||||
| * This program 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 this program; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * The Original Code is Copyright (C) 2019 Blender Foundation. | |||||
| * All rights reserved. | |||||
| */ | |||||
| /** \file \ingroup GHOST | |||||
| * | |||||
| * Definition of GHOST_BoundsTracker class. | |||||
| */ | |||||
brecht: What is a "bounds tracker"? Can you document this? Or can this just be part of `GHOST_Window`… | |||||
Done Inline Actionsthe bounds tracker code is only used for X11 and SDL. It could be put into GHOST_Window. I have added some more comments to that code. sobakasu: the bounds tracker code is only used for X11 and SDL. It could be put into GHOST_Window. I have… | |||||
| #include "GHOST_BoundsTracker.h" | |||||
| #include <cstdlib> | |||||
| #define MAX_WM_TRANSFORM 50 | |||||
| GHOST_BoundsTracker:: | |||||
| GHOST_BoundsTracker(void) | |||||
| { | |||||
| } | |||||
| /* Set bounds used in a create window operation */ | |||||
| void | |||||
| GHOST_BoundsTracker:: | |||||
| setCreateBounds( | |||||
| GHOST_TInt32 left, | |||||
| GHOST_TInt32 top, | |||||
| GHOST_TUns32 width, | |||||
| GHOST_TUns32 height) | |||||
| { | |||||
| m_rect_create.set(left, top, left + width, top + height); | |||||
| } | |||||
| /* Compute the transformation on client bounds made by the window manager. | |||||
| * This method should be called after the window has been created on window resize/move events. | |||||
| */ | |||||
| void | |||||
| GHOST_BoundsTracker:: | |||||
| updateWmTransform(GHOST_Rect client_bounds) | |||||
| { | |||||
| if (!m_found_transform) { | |||||
| // determine the transformation made by the window manager | |||||
| m_transform_x = client_bounds.m_l - m_rect_create.m_l; | |||||
| m_transform_y = client_bounds.m_t - m_rect_create.m_t; | |||||
| // expect the window manager to only adjust the size slightly | |||||
| // to add a title bar and borders etc. If the transformation is | |||||
| // too large, ignore it. | |||||
| if (abs(m_transform_x) < MAX_WM_TRANSFORM && | |||||
| abs(m_transform_y) < MAX_WM_TRANSFORM) { | |||||
| m_found_transform = true; | |||||
| } | |||||
| else { | |||||
| m_transform_x = m_transform_y = 0; | |||||
| } | |||||
| //printf("update wm transform: (%d,%d)\n", m_transform_x, m_transform_y); | |||||
| } | |||||
| } | |||||
| /* Convert the given client bounds to window bounds. The resulting bounds can be used to | |||||
| * create a window with the same size and position as the current window. | |||||
| */ | |||||
| void | |||||
| GHOST_BoundsTracker:: | |||||
| clientToWindowBounds(GHOST_Rect &bounds) const | |||||
| { | |||||
| // unapply transformations made by window manager so that future calls | |||||
| // to createWindow create the same geometry. | |||||
| if (m_found_transform) { | |||||
| bounds.m_l -= m_transform_x; | |||||
| bounds.m_t -= m_transform_y; | |||||
| bounds.m_r -= m_transform_x; | |||||
| bounds.m_b -= m_transform_y; | |||||
| } | |||||
| } | |||||
What is a "bounds tracker"? Can you document this? Or can this just be part of GHOST_Window instead of a separate class?