瀏覽代碼

add platform functions for querying monitor information

jp9000 12 年之前
父節點
當前提交
f27dfb6809
共有 4 個文件被更改,包括 41 次插入0 次删除
  1. 6 0
      obs/platform-nix.cpp
  2. 6 0
      obs/platform-osx.cpp
  3. 20 0
      obs/platform-windows.cpp
  4. 9 0
      obs/platform.hpp

+ 6 - 0
obs/platform-nix.cpp

@@ -23,3 +23,9 @@ bool GetDataFilePath(const char *data, string &output)
 	// TODO
 	return false;
 }
+
+void GetMonitors(vector<MonitorInfo> &monitors)
+{
+	monitors.clear();
+	// TODO
+}

+ 6 - 0
obs/platform-osx.cpp

@@ -27,3 +27,9 @@ bool GetDataFilePath(const char *data, string &output)
 	output = str.str();
 	return !access(output.c_str(), R_OK);
 }
+
+void GetMonitors(vector<MonitorInfo> &monitors)
+{
+	monitors.clear();
+	// TODO
+}

+ 20 - 0
obs/platform-windows.cpp

@@ -30,3 +30,23 @@ bool GetDataFilePath(const char *data, string &output)
 	output = str.str();
 	return os_file_exists(output.c_str());
 }
+
+static BOOL CALLBACK OBSMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor,
+		LPRECT rect, LPARAM param)
+{
+	vector<MonitorInfo> &monitors = *(vector<MonitorInfo> *)param;
+
+	MonitorInfo monitor;
+	monitor.x  = rect->left;
+	monitor.y  = rect->top;
+	monitor.cx = rect->right - rect->left;
+	monitor.cy = rect->bottom - rect->top;
+	monitors.push_back(monitor);
+	return true;
+}
+
+void GetMonitors(vector<MonitorInfo> &monitors)
+{
+	monitors.clear();
+	EnumDisplayMonitors(NULL, NULL, OBSMonitorEnumProc, (LPARAM)&monitors);
+}

+ 9 - 0
obs/platform.hpp

@@ -17,8 +17,17 @@
 
 #pragma once
 
+#include <util/c99defs.h>
+
 #include <string>
+#include <vector>
 using namespace std;
 
+struct MonitorInfo {
+	int32_t  x, y;
+	uint32_t cx, cy;
+};
+
 /* Gets the path of obs-studio specific data files (such as locale) */
 bool GetDataFilePath(const char *data, string &path);
+void GetMonitors(vector<MonitorInfo> &monitors);