tornavis/intern/ghost/GHOST_IWindow.hh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

371 lines
12 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
2011-02-25 12:28:33 +01:00
/** \file
* \ingroup GHOST
* Declaration of GHOST_IWindow interface class.
2002-10-12 13:37:38 +02:00
*/
#pragma once
2002-10-12 13:37:38 +02:00
#include "GHOST_Rect.hh"
2002-10-12 13:37:38 +02:00
#include "GHOST_Types.h"
#include <stdlib.h>
#include <string>
2002-10-12 13:37:38 +02:00
class GHOST_IContext;
2002-10-12 13:37:38 +02:00
/**
* Interface for GHOST windows.
*
* You can create a window with the system's GHOST_ISystem::createWindow
* method.
* \see GHOST_ISystem#createWindow
*
* There are two coordinate systems:
2014-08-16 02:51:07 +02:00
*
* - The screen coordinate system. The origin of the screen is located in the
2021-09-27 13:01:48 +02:00
* upper left corner of the screen.
2014-08-16 02:51:07 +02:00
* - The client rectangle coordinate system. The client rectangle of a window
* is the area that is drawable by the application (excluding title bars etc.).
2002-10-12 13:37:38 +02:00
*/
class GHOST_IWindow {
public:
/**
* Destructor.
*/
virtual ~GHOST_IWindow() {}
2002-10-12 13:37:38 +02:00
/**
* Returns indication as to whether the window is valid.
* \return The validity of the window.
2002-10-12 13:37:38 +02:00
*/
2012-05-19 11:23:08 +02:00
virtual bool getValid() const = 0;
/**
* Returns the associated OS object/handle
* \return The associated OS object/handle
*/
2012-05-19 11:23:08 +02:00
virtual void *getOSWindow() const = 0;
2002-10-12 13:37:38 +02:00
/**
* Returns the type of drawing context used in this window.
* \return The current type of drawing context.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TDrawingContextType getDrawingContextType() = 0;
2002-10-12 13:37:38 +02:00
/**
* Tries to install a rendering context in this window.
* \param type: The type of rendering context installed.
* \return Indication as to whether installation has succeeded.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) = 0;
/**
* Returns the drawing context used in this window.
* \return The current drawing context.
*/
virtual GHOST_IContext *getDrawingContext() = 0;
2002-10-12 13:37:38 +02:00
/**
* Sets the title displayed in the title bar.
* \param title: The title to display in the title bar.
2002-10-12 13:37:38 +02:00
*/
virtual void setTitle(const char *title) = 0;
2002-10-12 13:37:38 +02:00
/**
* Returns the title displayed in the title bar.
* \param title: The title displayed in the title bar.
2002-10-12 13:37:38 +02:00
*/
virtual std::string getTitle() const = 0;
/**
* Sets the file name represented by this window.
* \param filepath: The file directory.
*/
virtual GHOST_TSuccess setPath(const char *filepath) = 0;
2002-10-12 13:37:38 +02:00
/**
* Returns the window rectangle dimensions.
* These are screen coordinates.
* \param bounds: The bounding rectangle of the window.
2002-10-12 13:37:38 +02:00
*/
2012-05-19 11:23:08 +02:00
virtual void getWindowBounds(GHOST_Rect &bounds) const = 0;
2002-10-12 13:37:38 +02:00
/**
* Returns the client rectangle dimensions.
* The left and top members of the rectangle are always zero.
* \param bounds: The bounding rectangle of the client area of the window.
2002-10-12 13:37:38 +02:00
*/
2012-05-19 11:23:08 +02:00
virtual void getClientBounds(GHOST_Rect &bounds) const = 0;
2002-10-12 13:37:38 +02:00
/**
* Resizes client rectangle width.
* \param width: The new width of the client area of the window.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess setClientWidth(uint32_t width) = 0;
2002-10-12 13:37:38 +02:00
/**
* Resizes client rectangle height.
* \param height: The new height of the client area of the window.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess setClientHeight(uint32_t height) = 0;
2002-10-12 13:37:38 +02:00
/**
* Resizes client rectangle.
* \param width: The new width of the client area of the window.
* \param height: The new height of the client area of the window.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess setClientSize(uint32_t width, uint32_t height) = 0;
2002-10-12 13:37:38 +02:00
/**
* Converts a point in screen coordinates to client rectangle coordinates
* \param inX: The x-coordinate on the screen.
* \param inY: The y-coordinate on the screen.
* \param outX: The x-coordinate in the client rectangle.
* \param outY: The y-coordinate in the client rectangle.
2002-10-12 13:37:38 +02:00
*/
virtual void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const = 0;
2002-10-12 13:37:38 +02:00
/**
* Converts a point in client rectangle coordinates to screen coordinates.
* \param inX: The x-coordinate in the client rectangle.
* \param inY: The y-coordinate in the client rectangle.
* \param outX: The x-coordinate on the screen.
* \param outY: The y-coordinate on the screen.
2002-10-12 13:37:38 +02:00
*/
virtual void clientToScreen(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const = 0;
/**
* Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
*/
virtual void setAcceptDragOperation(bool canAccept) = 0;
/**
* Returns acceptance of the dropped object
* Usually called by the "object dropped" event handling function
*/
virtual bool canAcceptDragOperation() const = 0;
2002-10-12 13:37:38 +02:00
/**
* Returns the state of the window (normal, minimized, maximized).
* \return The state of the window.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TWindowState getState() const = 0;
2002-10-12 13:37:38 +02:00
/**
* Sets the state of the window (normal, minimized, maximized).
* \param state: The state of the window.
* \return Indication of success.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess setState(GHOST_TWindowState state) = 0;
/**
* Sets the window "modified" status, indicating unsaved changes
* \param isUnsavedChanges: Unsaved changes or not.
* \return Indication of success.
*/
virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges) = 0;
/**
* Gets the window "modified" status, indicating unsaved changes
* \return True if there are unsaved changes
*/
virtual bool getModifiedState() = 0;
2002-10-12 13:37:38 +02:00
/**
* Sets the order of the window (bottom, top).
* \param order: The order of the window.
* \return Indication of success.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order) = 0;
2002-10-12 13:37:38 +02:00
/**
* Swaps front and back buffers of a window.
* \return A boolean success indicator.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess swapBuffers() = 0;
/**
* Sets the swap interval for #swapBuffers.
* \param interval: The swap interval to use.
* \return A boolean success indicator.
*/
virtual GHOST_TSuccess setSwapInterval(int interval) = 0;
/**
* Gets the current swap interval for #swapBuffers.
* \param intervalOut: pointer to location to return swap interval.
* (left untouched if there is an error)
* \return A boolean success indicator of if swap interval was successfully read.
*/
virtual GHOST_TSuccess getSwapInterval(int &intervalOut) = 0;
2002-10-12 13:37:38 +02:00
/**
* Activates the drawing context of this window.
* \return A boolean success indicator.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess activateDrawingContext() = 0;
/**
* Gets the OpenGL frame-buffer associated with the window's contents.
* \return The name of an OpenGL frame-buffer object.
*/
virtual unsigned int getDefaultFramebuffer() = 0;
Vulkan: Rewrite GHOST_ContextVK This is a rewrite of GHOST_ContextVK to align with Metal backend as described in #111389 - solution 3 with the adaptation that GHOST is still responsible for presenting the swap chain image and a post callback is still needed in case the swapchain is recreated. This PR also includes some smaller improvements in stability. Technical documentation: https://developer.blender.org/docs/eevee_and_viewport/gpu/vulkan/swap_chain/ * Renderpasses and framebuffers are not owned anymore by GHOST_ContextVK * VKFramebuffer doesn't contain a swap chain image. * Swapchain images can only be used as a blit destination or present source. Not as an attachment. * GHOST_ContextVK::swapBuffers would call a callback with the image the GPU module needs to blit the results to. * Clearing of depth/stencil attachments when no depth write state is set. * Enable VK_KHR_maintenance4 to relax the stage interface mapping. * Removes most vulkan validation warnings/errors. * Detection of frame buffer changes that needs to be applied before performing a command requiring render pass (draw/clear attachment) **Benefits** * Late retrieval of a swap chain image results in better overall performance as Blender doesn't need to wait until the image is presented on the screen. * Easier API and clearer state (transitions) * More control over Image layouts and command buffer states. (Better alignment with Vulkan API) Pull Request: https://projects.blender.org/blender/blender/pulls/111473
2023-08-29 15:05:08 +02:00
#ifdef WITH_VULKAN_BACKEND
virtual GHOST_TSuccess getVulkanSwapChainFormat(
GHOST_VulkanSwapChainData *r_swap_chain_data) = 0;
#endif
2002-10-12 13:37:38 +02:00
/**
* Invalidates the contents of this window.
* \return Indication of success.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess invalidate() = 0;
2002-10-12 13:37:38 +02:00
/**
* Returns the window user data.
* \return The window user data.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TUserDataPtr getUserData() const = 0;
2002-10-12 13:37:38 +02:00
/**
* Changes the window user data.
* \param userData: The window user data.
2002-10-12 13:37:38 +02:00
*/
virtual void setUserData(const GHOST_TUserDataPtr userData) = 0;
UI: Register File Browser as Child/Dialog-Window for the OS For many users, this will make the File Browser window behave more like what they would expect. It addresses the issue of the File Browser becoming hidden behind the main window by clicking anywhere in the latter. It communicates the interruptive, but temporary nature of the operation a bit better. Further, on tiling window managers the File Browser now opens as floating by default, like in other applications. Note that this also makes sure the File Browser is always opened as separate window, so it doesn't re-use the Preferences, or any other temporary window anymore. This seems to have been a common annoyance. More concretely, this makes the File Browser window behave as follows: * Stays on top of its parent Blender window, but not on top of non-Blender windows. * Minimizes with its parent window * Can be moved independently * Doesn't add an own item in task bars * Doesn't block other Blender windows (we may want to have this though) * Opens as floating window for tiling window managers (e.g. i3wm/Sway) Further notes: * When opening a file browser from the Preference window (or any temporary window), the main window, as the file browsers parent is moved on top of the Preferences, which makes it seem like the Preferences were closed. This is the general issue of bad secondary window handling as window activation changes. I made it so that the window is moved back once the file browser is closed. This behavior is confusing and would be nice to avoid. It's a separate issue though. * On most window managers on Linux the temporary window can not be minimized and maximized, they disable that for dialog windows. * On Windows and macOS, only minimizing is disabled, as there is no decent way yet to restore a window if it's not shown in the taskbar. Reviewed By: Brecht van Lommel, Campbell Barton, William Reynish Edits and macOS implementation by Brecht. Differential Revision: https://developer.blender.org/D5810 Part of T69652.
2019-10-03 16:59:49 +02:00
virtual bool isDialog() const = 0;
/***************************************************************************************
2012-07-01 00:49:33 +02:00
* Progress bar functionality
***************************************************************************************/
/**
2012-05-19 11:23:08 +02:00
* Sets the progress bar value displayed in the window/application icon
* \param progress: The progress percentage (0.0 to 1.0).
*/
virtual GHOST_TSuccess setProgressBar(float progress) = 0;
/**
* Hides the progress bar in the icon
*/
virtual GHOST_TSuccess endProgressBar() = 0;
2002-10-12 13:37:38 +02:00
/***************************************************************************************
2012-07-01 00:49:33 +02:00
* Cursor management functionality
***************************************************************************************/
2002-10-12 13:37:38 +02:00
/**
* Returns the current cursor shape.
* \return The current cursor shape.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TStandardCursor getCursorShape() const = 0;
2002-10-12 13:37:38 +02:00
/**
* Set the shape of the cursor.
* \param cursorShape: The new cursor shape type id.
2015-07-01 08:30:26 +02:00
* \return Indication of success.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursorShape) = 0;
virtual GHOST_TSuccess getCursorGrabBounds(GHOST_Rect &bounds) const = 0;
virtual void getCursorGrabState(GHOST_TGrabCursorMode &mode,
GHOST_TAxisFlag &axis_flag,
GHOST_Rect &bounds,
bool &use_software_cursor) = 0;
virtual bool getCursorGrabUseSoftwareDisplay() = 0;
/**
* Test if the standard cursor shape is supported by current platform.
* \return Indication of success.
*/
virtual GHOST_TSuccess hasCursorShape(GHOST_TStandardCursor cursorShape) = 0;
2002-10-12 13:37:38 +02:00
/**
* Set the shape of the cursor to a custom cursor.
* \param bitmap: The bitmap data for the cursor.
* \param mask: The mask data for the cursor.
* \param hotX: The X coordinate of the cursor hot-spot.
* \param hotY: The Y coordinate of the cursor hot-spot.
* \return Indication of success.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess setCustomCursorShape(uint8_t *bitmap,
uint8_t *mask,
2012-05-19 11:23:08 +02:00
int sizex,
int sizey,
int hotX,
int hotY,
bool canInvertColor) = 0;
virtual GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap) = 0;
2002-10-12 13:37:38 +02:00
/**
* Returns the visibility state of the cursor.
* \return The visibility state of the cursor.
2002-10-12 13:37:38 +02:00
*/
virtual bool getCursorVisibility() const = 0;
2002-10-12 13:37:38 +02:00
/**
* Shows or hides the cursor.
* \param visible: The new visibility state of the cursor.
* \return Indication of success.
2002-10-12 13:37:38 +02:00
*/
virtual GHOST_TSuccess setCursorVisibility(bool visible) = 0;
/**
* Grabs the cursor for a modal operation.
* \param grab: The new grab state of the cursor.
* \return Indication of success.
*/
virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode /*mode*/,
GHOST_TAxisFlag /*wrap_axis*/,
GHOST_Rect * /*bounds*/,
int32_t /*mouse_ungrab_xy*/[2])
{
return GHOST_kSuccess;
}
/** */
virtual GHOST_TSuccess beginFullScreen() const = 0;
virtual GHOST_TSuccess endFullScreen() const = 0;
virtual float getNativePixelSize() = 0;
/**
* Returns the recommended DPI for this window.
* \return The recommended DPI for this window.
*/
virtual uint16_t getDPIHint() = 0;
#ifdef WITH_INPUT_IME
/**
* Enable IME attached to the given window, i.e. allows user-input
* events to be dispatched to the IME.
* \param x: Requested x-coordinate of the rectangle.
* \param y: Requested y-coordinate of the rectangle.
* \param w: Requested width of the rectangle.
* \param h: Requested height of the rectangle.
* \param complete: Whether or not to complete the ongoing composition.
* - true: Start a new composition
* - false: Move the IME windows to the given position without finishing it.
*/
virtual void beginIME(int32_t x, int32_t y, int32_t w, int32_t h, bool completed) = 0;
/**
* Disable the IME attached to the given window, i.e. prohibits any user-input
* events from being dispatched to the IME.
*/
virtual void endIME() = 0;
#endif /* WITH_INPUT_IME */
2018-06-04 18:47:57 +02:00
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_IWindow")
#endif
2002-10-12 13:37:38 +02:00
};