Преглед изворни кода

Add support for window parenting

Daniele Bartolini пре 12 година
родитељ
комит
71b0765295

+ 19 - 9
engine/Device.cpp

@@ -63,6 +63,7 @@ Device::Device() :
 	m_preferred_window_width(1000),
 	m_preferred_window_width(1000),
 	m_preferred_window_height(625),
 	m_preferred_window_height(625),
 	m_preferred_window_fullscreen(0),
 	m_preferred_window_fullscreen(0),
+	m_parent_window_handle(0),
 	m_preferred_mode(MODE_RELEASE),
 	m_preferred_mode(MODE_RELEASE),
 
 
 	m_quit_after_init(0),
 	m_quit_after_init(0),
@@ -424,7 +425,7 @@ void Device::create_input_manager()
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void Device::create_window()
 void Device::create_window()
 {
 {
-	m_window = CE_NEW(m_allocator, OsWindow)(m_preferred_window_width, m_preferred_window_height);
+	m_window = CE_NEW(m_allocator, OsWindow)(m_preferred_window_width, m_preferred_window_height, m_parent_window_handle);
 
 
 	CE_ASSERT(m_window != NULL, "Unable to create the window");
 	CE_ASSERT(m_window != NULL, "Unable to create the window");
 
 
@@ -481,6 +482,7 @@ void Device::parse_command_line(int argc, char** argv)
 		{ "width",            AOA_REQUIRED_ARGUMENT, NULL,        'w' },
 		{ "width",            AOA_REQUIRED_ARGUMENT, NULL,        'w' },
 		{ "height",           AOA_REQUIRED_ARGUMENT, NULL,        'h' },
 		{ "height",           AOA_REQUIRED_ARGUMENT, NULL,        'h' },
 		{ "fullscreen",       AOA_NO_ARGUMENT,       &m_preferred_window_fullscreen, 1 },
 		{ "fullscreen",       AOA_NO_ARGUMENT,       &m_preferred_window_fullscreen, 1 },
+		{ "parent-window",    AOA_REQUIRED_ARGUMENT, NULL,        'p' },
 		{ "dev",              AOA_NO_ARGUMENT,       &m_preferred_mode, MODE_DEVELOPMENT },
 		{ "dev",              AOA_NO_ARGUMENT,       &m_preferred_mode, MODE_DEVELOPMENT },
 		{ "quit-after-init",  AOA_NO_ARGUMENT,       &m_quit_after_init, 1 },
 		{ "quit-after-init",  AOA_NO_ARGUMENT,       &m_quit_after_init, 1 },
 		{ NULL, 0, NULL, 0 }
 		{ NULL, 0, NULL, 0 }
@@ -516,6 +518,12 @@ void Device::parse_command_line(int argc, char** argv)
 				m_preferred_window_height = atoi(args.optarg());
 				m_preferred_window_height = atoi(args.optarg());
 				break;
 				break;
 			}
 			}
+			// Parent window
+			case 'p':
+			{
+				m_parent_window_handle = string::parse_uint(args.optarg());
+				break;
+			}
 			case 'i':
 			case 'i':
 			case '?':
 			case '?':
 			default:
 			default:
@@ -558,14 +566,16 @@ void Device::print_help_message()
 	"All of the following options take precedence over\n"
 	"All of the following options take precedence over\n"
 	"environment variables and configuration files.\n\n"
 	"environment variables and configuration files.\n\n"
 
 
-	"  --help                Show this help.\n"
-	"  --root-path <path>    Use <path> as the filesystem root path.\n"
-	"  --width <width>       Set the <width> of the render window.\n"
-	"  --height <width>      Set the <height> of the render window.\n"
-	"  --fullscreen          Start in fullscreen.\n"
-	"  --dev                 Run the engine in development mode\n"
-	"  --quit-after-init     Quit the engine immediately after the\n"
-	"                        initialization. Used only for debugging.\n");
+	"  --help                     Show this help.\n"
+	"  --root-path <path>         Use <path> as the filesystem root path.\n"
+	"  --width <width>            Set the <width> of the main window.\n"
+	"  --height <width>           Set the <height> of the main window.\n"
+	"  --fullscreen               Start in fullscreen.\n"
+	"  --parent-window <handle>   Set the parent window <handle> of the main window.\n"
+	"                             Used only by tools.\n"
+	"  --dev                      Run the engine in development mode\n"
+	"  --quit-after-init          Quit the engine immediately after the initialization.\n"
+	"                             Used only for debugging.\n");
 }
 }
 
 
 Device g_device;
 Device g_device;

+ 1 - 0
engine/Device.h

@@ -139,6 +139,7 @@ private:
 	int32_t					m_preferred_window_width;
 	int32_t					m_preferred_window_width;
 	int32_t					m_preferred_window_height;
 	int32_t					m_preferred_window_height;
 	int32_t					m_preferred_window_fullscreen;
 	int32_t					m_preferred_window_fullscreen;
+	uint32_t				m_parent_window_handle;
 	int32_t					m_preferred_mode;
 	int32_t					m_preferred_mode;
 	char					m_preferred_root_path[MAX_PATH_LENGTH];
 	char					m_preferred_root_path[MAX_PATH_LENGTH];
 
 

+ 1 - 1
engine/os/android/OsWindow.cpp

@@ -36,7 +36,7 @@ namespace crown
 static ANativeWindow* window = NULL;
 static ANativeWindow* window = NULL;
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-OsWindow::OsWindow(uint32_t width, uint32_t height) :
+OsWindow::OsWindow(uint32_t width, uint32_t height, uint32_t /*parent*/) :
 	m_window(NULL),
 	m_window(NULL),
 	m_width(0),
 	m_width(0),
 	m_height(0),
 	m_height(0),

+ 1 - 1
engine/os/android/OsWindow.h

@@ -36,7 +36,7 @@ class OsWindow
 {
 {
 public:
 public:
 
 
-					OsWindow(uint32_t width, uint32_t height);
+					OsWindow(uint32_t width, uint32_t height, uint32_t parent);
 					~OsWindow();
 					~OsWindow();
 
 
 	void			show();
 	void			show();

+ 12 - 3
engine/os/linux/OsWindow.cpp

@@ -91,9 +91,10 @@ static Key x11_translate_key(int32_t x11_key)
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-OsWindow::OsWindow(uint32_t width, uint32_t height) :
+OsWindow::OsWindow(uint32_t width, uint32_t height, uint32_t parent) :
 	m_x11_display(NULL),
 	m_x11_display(NULL),
 	m_x11_window(None),
 	m_x11_window(None),
+	m_x11_parent_window(None),
 	m_x(0),
 	m_x(0),
 	m_y(0),
 	m_y(0),
 	m_width(width),
 	m_width(width),
@@ -108,10 +109,18 @@ OsWindow::OsWindow(uint32_t width, uint32_t height) :
 	CE_ASSERT(m_x11_display != NULL, "Unable to open X11 display");
 	CE_ASSERT(m_x11_display != NULL, "Unable to open X11 display");
 
 
 	int screen = DefaultScreen(m_x11_display);
 	int screen = DefaultScreen(m_x11_display);
-	Window root_window = RootWindow(m_x11_display, screen);
 	int depth = DefaultDepth(m_x11_display, screen);
 	int depth = DefaultDepth(m_x11_display, screen);
 	Visual* visual = DefaultVisual(m_x11_display, screen);
 	Visual* visual = DefaultVisual(m_x11_display, screen);
 
 
+	if (parent != 0)
+	{
+		m_x11_parent_window = (Window) parent;
+	}
+	else
+	{
+		m_x11_parent_window = RootWindow(m_x11_display, screen);
+	}
+
 	// We want to track keyboard and mouse events
 	// We want to track keyboard and mouse events
 	XSetWindowAttributes win_attribs;
 	XSetWindowAttributes win_attribs;
 	win_attribs.background_pixmap = 0;
 	win_attribs.background_pixmap = 0;
@@ -121,7 +130,7 @@ OsWindow::OsWindow(uint32_t width, uint32_t height) :
 
 
 	m_x11_window = XCreateWindow(
 	m_x11_window = XCreateWindow(
 				   m_x11_display,
 				   m_x11_display,
-				   root_window,
+				   m_x11_parent_window,
 				   0, 0,
 				   0, 0,
 				   width, height,
 				   width, height,
 				   0,
 				   0,

+ 5 - 1
engine/os/linux/OsWindow.h

@@ -39,7 +39,10 @@ class OsWindow
 {
 {
 public:
 public:
 
 
-					OsWindow(uint32_t width, uint32_t height);
+	/// Creates the window with the given @a width and @a height.
+	/// When @a parent is != 0, it is interpreted as the OS-specific
+	/// handle of the parent window.
+					OsWindow(uint32_t width, uint32_t height, uint32_t parent);
 					~OsWindow();
 					~OsWindow();
 
 
 	void			show();
 	void			show();
@@ -66,6 +69,7 @@ private:
 
 
 	Display*		m_x11_display;
 	Display*		m_x11_display;
 	Window			m_x11_window;
 	Window			m_x11_window;
+	Window			m_x11_parent_window;
 
 
 	uint32_t		m_x;
 	uint32_t		m_x;
 	uint32_t		m_y;
 	uint32_t		m_y;

+ 1 - 1
engine/os/win/OsWindow.cpp

@@ -91,7 +91,7 @@ static Key translate_key(int32_t winKey)
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-OsWindow::OsWindow(uint32_t width, uint32_t height) :
+OsWindow::OsWindow(uint32_t width, uint32_t height, uint32_t /*window*/) :
 	m_window_handle(NULL),
 	m_window_handle(NULL),
 	m_x(0),
 	m_x(0),
 	m_y(0),
 	m_y(0),

+ 1 - 1
engine/os/win/OsWindow.h

@@ -36,7 +36,7 @@ class OsWindow
 {
 {
 public:
 public:
 
 
-					OsWindow(uint32_t width, uint32_t height);
+					OsWindow(uint32_t width, uint32_t height, uint32_t window);
 					~OsWindow();
 					~OsWindow();
 
 
 	void			show();
 	void			show();