Commit 69fc57ed authored by D-AIRY's avatar D-AIRY

xWindow system

parent 27af5fec
......@@ -102,7 +102,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;SX_DLL;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);SX_LIB_NAME="xWnd"</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;SX_DLL;_DEBUG;XWINDOW_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);SX_LIB_NAME="xWnd"</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<TreatSpecificWarningsAsErrors>4316</TreatSpecificWarningsAsErrors>
......@@ -122,7 +122,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN64;_CRT_SECURE_NO_WARNINGS;SX_DLL;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);SX_LIB_NAME="xWnd"</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN64;_CRT_SECURE_NO_WARNINGS;SX_DLL;_DEBUG;XWINDOW_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);SX_LIB_NAME="xWnd"</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<TreatSpecificWarningsAsErrors>4316</TreatSpecificWarningsAsErrors>
......@@ -144,7 +144,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;_USRDLL;SX_DLL;%(PreprocessorDefinitions);SX_LIB_NAME="xWnd"</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;XWINDOW_EXPORTS;_WINDOWS;_USRDLL;SX_DLL;%(PreprocessorDefinitions);SX_LIB_NAME="xWnd"</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<TreatSpecificWarningsAsErrors>4316</TreatSpecificWarningsAsErrors>
</ClCompile>
......@@ -165,7 +165,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN64;_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;_USRDLL;SX_DLL;%(PreprocessorDefinitions);SX_LIB_NAME="xWnd"</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN64;_CRT_SECURE_NO_WARNINGS;NDEBUG;XWINDOW_EXPORTS;_WINDOWS;_USRDLL;SX_DLL;%(PreprocessorDefinitions);SX_LIB_NAME="xWnd"</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<TreatSpecificWarningsAsErrors>4316</TreatSpecificWarningsAsErrors>
</ClCompile>
......@@ -179,9 +179,14 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\..\source\xWindow\xWindow.h" />
<ClInclude Include="..\..\..\source\xWindow\IXWindowSystem.h" />
<ClInclude Include="..\..\..\source\xWindow\Window.h" />
<ClInclude Include="..\..\..\source\xWindow\WindowSystem.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\source\xWindow\dllmain.cpp" />
<ClCompile Include="..\..\..\source\xWindow\Window.cpp" />
<ClCompile Include="..\..\..\source\xWindow\WindowSystem.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -15,10 +15,23 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\source\xWindow\xWindow.h">
<ClInclude Include="..\..\..\source\xWindow\IXWindowSystem.h" />
<ClInclude Include="..\..\..\source\xWindow\WindowSystem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\xWindow\Window.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\source\xWindow\dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\source\xWindow\WindowSystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\source\xWindow\Window.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
/***********************************************************
Copyright Vitaliy Buturlin, Evgeny Danilovich, 2017, 2018
Copyright © Vitaliy Buturlin, Evgeny Danilovich, 2017, 2018
See the license in LICENSE
***********************************************************/
......@@ -9,8 +9,50 @@ See the license in LICENSE
#include <SkyXEngine.h>
//#include <common/string_func.h>
#if 0
#include <xWindow/IXWindowSystem.h>
#ifdef _DEBUG
# pragma comment(lib, "xWindow_d.lib")
#else
# pragma comment(lib, "xWindow.lib")
#endif
class CWindowCallback: public IXWindowCallback
{
public:
INT_PTR XMETHODCALLTYPE onMessage(UINT msg, WPARAM wParam, LPARAM lParam, IXWindow *pWindow)
{
return(pWindow->runDefaultCallback(msg, wParam, lParam));
}
};
#endif
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
#if 0
IXWindowSystem *pWindowSystem = XWindowInit();
XWINDOW_DESC wdesc;
wdesc.iPosX = XCW_USEDEFAULT;
wdesc.iPosY = XCW_USEDEFAULT;
wdesc.iSizeX = 800;
wdesc.iSizeY = 600;
wdesc.szTitle = "xWindow";
wdesc.flags = XWF_BUTTON_CLOSE | XWF_BUTTON_MINIMIZE | XWF_NORESIZE;
CWindowCallback cb;
IXWindow *pWindow = pWindowSystem->createWindow(&wdesc, &cb);
while(pWindowSystem->processMessages())
{
Sleep(10);
}
mem_release(pWindow);
mem_release(pWindowSystem);
return(0);
#endif
//MessageBox(0, 0, 0, 0);
SkyXEngine_PreviewCreate();
SkyXEngine_Init(0, 0, lpCmdLine);
......
#ifndef __XWINDOW_H
#define __XWINDOW_H
#ifndef __IXWINDOWSYSTEM_H
#define __IXWINDOWSYSTEM_H
#include <gdefines.h>
#if defined(_WINDOWS)
# if defined(XWINDOW_EXPORTS)
# define XWAPI __declspec(dllexport)
# else
# define XWAPI __declspec(dllimport)
# endif
#else
# define XWAPI
#endif
#define C extern "C"
enum XWINDOW_FLAG
{
XWF_DEFAULT = 0x0000,
XWF_NOBORDER = 0x0001,
XWF_BUTTON_CLOSE = 0x0002,
XWF_BUTTON_MINMAX = 0x0004,
XWF_TRANSPARENT = 0x0008,
XWF_NORESIZE = 0x0010
XWF_BUTTON_MINIMIZE = 0x0004,
XWF_BUTTON_MAXIMIZE = 0x0008,
XWF_TRANSPARENT = 0x0010,
XWF_NORESIZE = 0x0020
};
DEFINE_ENUM_FLAG_OPERATORS(XWINDOW_FLAG);
......@@ -18,10 +30,10 @@ DEFINE_ENUM_FLAG_OPERATORS(XWINDOW_FLAG);
struct XWINDOW_DESC
{
UINT uSizeX;
UINT uSizeY;
UINT uPosX = XCW_USEDEFAULT;
UINT uPosY = XCW_USEDEFAULT;
int iSizeX;
int iSizeY;
int iPosX = XCW_USEDEFAULT;
int iPosY = XCW_USEDEFAULT;
XWINDOW_FLAG flags = XWF_DEFAULT;
const char *szTitle;
};
......@@ -32,7 +44,7 @@ class IXWindow: public IXUnknown
{
public:
//!
virtual XWINDOW_OS_HANDLE* XMETHODCALLTYPE getOSHandle() = 0;
virtual XWINDOW_OS_HANDLE XMETHODCALLTYPE getOSHandle() = 0;
//! Скрывает окно (остается в таскбаре)
virtual void XMETHODCALLTYPE hide() = 0;
......@@ -44,7 +56,7 @@ public:
virtual void XMETHODCALLTYPE show() = 0;
//! Видимо ли окно (открыто и не свернуто)
virtual void XMETHODCALLTYPE isVisible() = 0;
virtual bool XMETHODCALLTYPE isVisible() = 0;
//!
virtual void XMETHODCALLTYPE setTitle(const char *szTitle) = 0;
......@@ -64,6 +76,7 @@ public:
class IXWindowSystem: public IXUnknown
{
public:
//!
virtual IXWindow* XMETHODCALLTYPE createWindow(const XWINDOW_DESC *pWindowDesc, IXWindowCallback *pCallback = NULL, IXWindow *pParent = NULL) = 0;
......@@ -71,4 +84,6 @@ class IXWindowSystem: public IXUnknown
virtual bool XMETHODCALLTYPE processMessages(UINT uMaxMessages = 0) = 0;
};
C XWAPI IXWindowSystem* XWindowInit();
#endif
#include "Window.h"
#if defined(_WINDOWS)
#include <dwmapi.h>
#pragma comment(lib, "Dwmapi.lib")
#endif
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
CWindow *pWindow = (CWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if(pWindow)
{
switch(msg)
{
case WM_DESTROY:
case WM_CLOSE:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_KEYUP:
case WM_CHAR:
case WM_ACTIVATE:
case WM_SIZE:
case WM_COMMAND:
case WM_KILLFOCUS:
case WM_XBUTTONDBLCLK:
case WM_XBUTTONDOWN:
case WM_XBUTTONUP:
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONDBLCLK:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MBUTTONDBLCLK:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_MOUSEWHEEL:
case WM_INPUT:
case WM_SETCURSOR:
case WM_MOUSEMOVE:
return(pWindow->runCallback(msg, wParam, lParam));
}
}
return(DefWindowProc(hWnd, msg, wParam, lParam));
}
CWindow::CWindow(HINSTANCE hInst, UINT uId, const XWINDOW_DESC *pWindowDesc, IXWindowCallback *pCallback, IXWindow *pParent):
m_hInst(hInst),
m_uId(uId),
m_pCallback(pCallback)
{
assert(pCallback);
m_windowDesc = *pWindowDesc;
#if defined(_WINDOWS)
UINT style = CS_HREDRAW | CS_VREDRAW;
if(!(pWindowDesc->flags & XWF_BUTTON_CLOSE))
{
style |= CS_NOCLOSE;
}
char szClassName[64];
sprintf_s(szClassName, "XWindowClass_%u", uId);
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = style;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szClassName;
wcex.hIconSm = NULL;
//wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
if(!RegisterClassEx(&wcex))
{
LibReport(REPORT_MSG_LEVEL_FATAL, "Unable to register window class!\n");
}
//#############################################################################
RECT rc = {0, 0, pWindowDesc->iSizeX, pWindowDesc->iSizeY};
DWORD wndStyle = 0;
if(pWindowDesc->flags & XWF_BUTTON_MINIMIZE)
{
wndStyle |= WS_MINIMIZEBOX | WS_SYSMENU;
}
if(pWindowDesc->flags & XWF_BUTTON_MAXIMIZE)
{
wndStyle |= WS_MAXIMIZEBOX | WS_SYSMENU;
}
if(pWindowDesc->flags & XWF_BUTTON_CLOSE)
{
wndStyle |= WS_SYSMENU;
}
if(pWindowDesc->flags & XWF_NOBORDER)
{
wndStyle &= ~(WS_SYSMENU | WS_CAPTION | WS_SIZEBOX | WS_MAXIMIZE | WS_MINIMIZE | WS_THICKFRAME);
}
AdjustWindowRect(&rc, wndStyle, false);
int iPosX = pWindowDesc->iPosX;
int iPosY = pWindowDesc->iPosY;
if(iPosX == XCW_USEDEFAULT)
{
iPosX = CW_USEDEFAULT;
}
if(iPosY == XCW_USEDEFAULT)
{
iPosY = CW_USEDEFAULT;
}
m_hWnd = CreateWindowA(szClassName, pWindowDesc->szTitle, wndStyle, iPosX, iPosY, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, wcex.hInstance, NULL);
if(!m_hWnd)
{
LibReport(REPORT_MSG_LEVEL_FATAL, "Unable to create window!\n");
}
if(pWindowDesc->flags & XWF_TRANSPARENT)
{
DWM_BLURBEHIND dwmBlur = {0};
dwmBlur.dwFlags = DWM_BB_ENABLE;
dwmBlur.fEnable = TRUE;
DwmEnableBlurBehindWindow(m_hWnd, &dwmBlur);
}
SetWindowLongPtr(m_hWnd, GWLP_USERDATA, (LONG)this);
ShowWindow(m_hWnd, SW_NORMAL);
if(pWindowDesc->flags & XWF_NOBORDER)
{
LONG lStyle = GetWindowLong(m_hWnd, GWL_STYLE);
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
SetWindowLong(m_hWnd, GWL_STYLE, lStyle);
}
#endif
}
CWindow::~CWindow()
{
#if defined(_WINDOWS)
char szClassName[64];
sprintf_s(szClassName, "XWindowClass_%u", m_uId);
UnregisterClassA(szClassName, m_hInst);
DestroyWindow(m_hWnd);
#endif
}
XWINDOW_OS_HANDLE XMETHODCALLTYPE CWindow::getOSHandle()
{
return(m_hWnd);
}
void XMETHODCALLTYPE CWindow::hide()
{
ShowWindow(m_hWnd, SW_MINIMIZE);
}
void XMETHODCALLTYPE CWindow::close()
{
ShowWindow(m_hWnd, SW_HIDE);
}
void XMETHODCALLTYPE CWindow::show()
{
ShowWindow(m_hWnd, SW_SHOW);
}
bool XMETHODCALLTYPE CWindow::isVisible()
{
return(!!IsWindowVisible(m_hWnd));
}
void XMETHODCALLTYPE CWindow::setTitle(const char *szTitle)
{
SetWindowTextA(m_hWnd, szTitle);
}
void XMETHODCALLTYPE CWindow::update(const XWINDOW_DESC *pWindowDesc)
{
SetClassLong(m_hWnd, GCL_STYLE, GetClassLong(m_hWnd, GCL_STYLE) | CS_NOCLOSE);
}
INT_PTR XMETHODCALLTYPE CWindow::runDefaultCallback(UINT msg, WPARAM wParam, LPARAM lParam)
{
return(DefWindowProcA(m_hWnd, msg, wParam, lParam));
}
INT_PTR CWindow::runCallback(UINT msg, WPARAM wParam, LPARAM lParam)
{
if(m_pCallback)
{
return(m_pCallback->onMessage(msg, wParam, lParam, this));
}
return(runDefaultCallback(msg, wParam, lParam));
}
#ifndef __WINDOW_H
#define __WINDOW_H
#include "IXWindowSystem.h"
class CWindow: public IXWindow
{
public:
CWindow(HINSTANCE hInst, UINT uId, const XWINDOW_DESC *pWindowDesc, IXWindowCallback *pCallback = NULL, IXWindow *pParent = NULL);
~CWindow();
XWINDOW_OS_HANDLE XMETHODCALLTYPE getOSHandle() override;
void XMETHODCALLTYPE hide() override;
void XMETHODCALLTYPE close() override;
void XMETHODCALLTYPE show() override;
bool XMETHODCALLTYPE isVisible() override;
void XMETHODCALLTYPE setTitle(const char *szTitle) override;
void XMETHODCALLTYPE update(const XWINDOW_DESC *pWindowDesc) override;
INT_PTR XMETHODCALLTYPE runDefaultCallback(UINT msg, WPARAM wParam, LPARAM lParam) override;
INT_PTR runCallback(UINT msg, WPARAM wParam, LPARAM lParam);
protected:
HWND m_hWnd = NULL;
HINSTANCE m_hInst;
XWINDOW_DESC m_windowDesc;
UINT m_uId;
IXWindowCallback *m_pCallback;
};
#endif
#include "WindowSystem.h"
#include "Window.h"
#if defined(_GTK_WINDOWS)
# include <gtk/gtk.h>
#endif
IXWindow* XMETHODCALLTYPE CWindowSystem::createWindow(const XWINDOW_DESC *pWindowDesc, IXWindowCallback *pCallback, IXWindow *pParent)
{
HINSTANCE hInst = GetModuleHandle(NULL);
return(new CWindow(hInst, m_uNextWindowId++, pWindowDesc, pCallback, pParent));
}
bool XMETHODCALLTYPE CWindowSystem::processMessages(UINT uMaxMessages)
{
UINT uProcessed = 0;
#if defined(_WINDOWS)
MSG msg = {0};
while((!uMaxMessages || (uProcessed++ < uMaxMessages)) && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
return(false);
}
/*
if(g_hAccelTable && TranslateAccelerator(GetParent((HWND)SGCore_GetHWND()), g_hAccelTable, &msg))
{
continue;
}
*/
TranslateMessage(&msg);
DispatchMessage(&msg);
}
#else
while((!uMaxMessages || (uProcessed++ < uMaxMessages)) && gtk_events_pending())
{
if(gtk_main_iteration())
{
return(false);
}
}
#endif
return(true);
}
C XWAPI IXWindowSystem* XWindowInit()
{
return(new CWindowSystem());
}
#ifndef __WINDOWSYSTEM_H
#define __WINDOWSYSTEM_H
#include "IXWindowSystem.h"
class CWindowSystem: public IXWindowSystem
{
public:
IXWindow* XMETHODCALLTYPE createWindow(const XWINDOW_DESC *pWindowDesc, IXWindowCallback *pCallback = NULL, IXWindow *pParent = NULL) override;
bool XMETHODCALLTYPE processMessages(UINT uMaxMessages = 0) override;
protected:
UINT m_uNextWindowId = 0;
};
#endif
// dllmain.cpp : Defines the entry point for the DLL application.
#if defined(_WINDOWS)
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment