summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/modules/asura-core/graphics/binding/_color.cpp83
-rw-r--r--source/modules/asura-core/graphics/color.h12
-rw-r--r--source/modules/asura-core/graphics/image.h14
-rw-r--r--source/tests/win32/01_menu_bar.cpp95
-rw-r--r--source/tests/win32/02_multi_window.cpp104
-rw-r--r--source/tests/win32/03_sub_menu.cpp146
-rw-r--r--source/tests/win32/config.h10
7 files changed, 451 insertions, 13 deletions
diff --git a/source/modules/asura-core/graphics/binding/_color.cpp b/source/modules/asura-core/graphics/binding/_color.cpp
index 11e80a1..f06622c 100644
--- a/source/modules/asura-core/graphics/binding/_color.cpp
+++ b/source/modules/asura-core/graphics/binding/_color.cpp
@@ -1,6 +1,7 @@
#include "../color.h"
using namespace std;
+using namespace Luax;
namespace AsuraEngine
{
@@ -13,7 +14,15 @@ namespace AsuraEngine
{ "ToColor32", _ToColor32 },
{ "SetColor", _SetColor },
{ "GetColor", _GetColor },
- { "Multiply", _Multiply }
+ { "GetR", _GetR },
+ { "GetG", _GetG },
+ { "GetB", _GetB },
+ { "GetA", _GetA },
+ { "__eq", ___eq },
+ { "__add", ___add },
+ { "__sub", ___sub },
+ { "__mul", ___mul },
+ { "__div", ___div }
);
}
@@ -27,6 +36,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Color);
+ return 0;
}
// color:SetColor()
@@ -34,6 +44,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Color);
+ return 0;
}
// color:GetColor()
@@ -41,13 +52,79 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Color);
+ return 0;
}
- // color:Multiply()
- LUAX_IMPL_METHOD(Color, _Multiply)
+ // color:GetR()
+ LUAX_IMPL_METHOD(Color, _GetR)
{
LUAX_PREPARE(L, Color);
+ return 0;
+ }
+
+ // color:GetG()
+ LUAX_IMPL_METHOD(Color, _GetG)
+ {
+ LUAX_PREPARE(L, Color);
+
+ return 0;
+ }
+
+ // color:GetB()
+ LUAX_IMPL_METHOD(Color, _GetB)
+ {
+ LUAX_PREPARE(L, Color);
+
+ return 0;
+ }
+
+ // color:GetA()
+ LUAX_IMPL_METHOD(Color, _GetA)
+ {
+ LUAX_PREPARE(L, Color);
+
+ return 0;
+ }
+
+ // color:__eq()
+ LUAX_IMPL_METHOD(Color, ___eq)
+ {
+ LUAX_PREPARE(L, Color);
+
+ return 0;
+ }
+
+ // color:__add()
+ LUAX_IMPL_METHOD(Color, ___add)
+ {
+ LUAX_PREPARE(L, Color);
+
+ return 0;
+ }
+
+ // color:__sub()
+ LUAX_IMPL_METHOD(Color, ___sub)
+ {
+ LUAX_PREPARE(L, Color);
+
+ return 0;
+ }
+
+ // color:__mul()
+ LUAX_IMPL_METHOD(Color, ___mul)
+ {
+ LUAX_PREPARE(L, Color);
+
+ return 0;
+ }
+
+ // color:__div()
+ LUAX_IMPL_METHOD(Color, ___div)
+ {
+ LUAX_PREPARE(L, Color);
+
+ return 0;
}
}
diff --git a/source/modules/asura-core/graphics/color.h b/source/modules/asura-core/graphics/color.h
index c4945ca..e875846 100644
--- a/source/modules/asura-core/graphics/color.h
+++ b/source/modules/asura-core/graphics/color.h
@@ -53,11 +53,13 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_GetA);
// Ԫ
- LUAX_DECL_METHOD(__eq); // __eq
- LUAX_DECL_METHOD(__add); // __add
- LUAX_DECL_METHOD(__sub); // __sub
- LUAX_DECL_METHOD(__mul); // __mul
- LUAX_DECL_METHOD(__div); // __div
+ LUAX_DECL_METHOD(___eq); // __eq
+ LUAX_DECL_METHOD(___add); // __add
+ LUAX_DECL_METHOD(___sub); // __sub
+ LUAX_DECL_METHOD(___mul); // __mul
+ LUAX_DECL_METHOD(___div); // __div
+
+ //----------------------------------------------------------------------------//
};
diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h
index 2424ebb..30df8c0 100644
--- a/source/modules/asura-core/graphics/image.h
+++ b/source/modules/asura-core/graphics/image.h
@@ -56,11 +56,7 @@ namespace AsuraEngine
private:
- ///
- /// һͼƬһݵá
- ///
- ImageData* mImageData;
- Luax::LuaxMemberRef mImageDataRef;
+ //----------------------------------------------------------------------------//
LUAX_DECL_METHOD(_New);
LUAX_DECL_METHOD(_Refresh);
@@ -70,6 +66,14 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_GetPixel);
LUAX_DECL_METHOD(_Render);
+ //----------------------------------------------------------------------------//
+
+ ///
+ /// һͼƬһݵá
+ ///
+ ImageData* mImageData;
+ Luax::LuaxMemberRef mImageDataRef;
+
};
}
diff --git a/source/tests/win32/01_menu_bar.cpp b/source/tests/win32/01_menu_bar.cpp
new file mode 100644
index 0000000..95c95e4
--- /dev/null
+++ b/source/tests/win32/01_menu_bar.cpp
@@ -0,0 +1,95 @@
+#include "config.h"
+
+#if _run_app == _menu_bar
+
+#include <windows.h>
+
+#include <windows.h>
+
+LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
+void AddMenus(HWND);
+
+#define IDM_FILE_NEW 1
+#define IDM_FILE_OPEN 2
+#define IDM_FILE_QUIT 3
+
+int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
+ PWSTR lpCmdLine, int nCmdShow) {
+
+ MSG msg;
+ WNDCLASSW wc = { 0 };
+ wc.lpszClassName = L"Simple menu";
+ wc.hInstance = hInstance;
+ wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
+ wc.lpfnWndProc = WndProc;
+ wc.hCursor = LoadCursor(0, IDC_ARROW);
+
+ RegisterClassW(&wc);
+ CreateWindowW(wc.lpszClassName, L"Simple menu",
+ WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+ 100, 100, 350, 250, 0, 0, hInstance, 0);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ return (int)msg.wParam;
+}
+
+LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
+ WPARAM wParam, LPARAM lParam) {
+
+ switch (msg) {
+
+ case WM_CREATE:
+
+ AddMenus(hwnd);
+ break;
+
+ case WM_COMMAND:
+
+ switch (LOWORD(wParam)) {
+
+ case IDM_FILE_NEW:
+ case IDM_FILE_OPEN:
+
+ MessageBeep(MB_ICONINFORMATION);
+ break;
+
+ case IDM_FILE_QUIT:
+
+ SendMessage(hwnd, WM_CLOSE, 0, 0);
+ break;
+ }
+
+ break;
+
+ case WM_DESTROY:
+
+ PostQuitMessage(0);
+ break;
+ }
+
+ return DefWindowProcW(hwnd, msg, wParam, lParam);
+}
+
+void AddMenus(HWND hwnd) {
+
+ HMENU hMenubar;
+ HMENU hMenu;
+
+ hMenubar = CreateMenu();
+ hMenu = CreateMenu();
+
+ AppendMenuW(hMenu, MF_STRING, IDM_FILE_NEW, L"&New");
+ AppendMenuW(hMenu, MF_STRING, IDM_FILE_OPEN, L"&Open");
+ AppendMenuW(hMenu, MF_SEPARATOR, 0, NULL);
+ AppendMenuW(hMenu, MF_STRING, IDM_FILE_QUIT, L"&Quit");
+
+ AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L"&File");
+ SetMenu(hwnd, hMenubar);
+}
+
+#endif // _run_app == _menu_bar \ No newline at end of file
diff --git a/source/tests/win32/02_multi_window.cpp b/source/tests/win32/02_multi_window.cpp
new file mode 100644
index 0000000..99a943f
--- /dev/null
+++ b/source/tests/win32/02_multi_window.cpp
@@ -0,0 +1,104 @@
+#include "config.h"
+
+#if _run_app == _multi_window
+
+#include <windows.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+#define MAX_LOADSTRING 100
+HINSTANCE hInstance;
+HWND hWnd, hWnd2;
+
+struct WindowData {
+ HWND window;
+ HDC deviceContext;
+ HGLRC renderContext;
+};
+
+LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+ static PAINTSTRUCT ps;
+ int pf;
+ PIXELFORMATDESCRIPTOR pfd;
+ HDC deviceContext;
+ HGLRC renderContext;
+ struct WindowData * windowData = (struct WindowData *) GetWindowLongPtr(hWnd, 0);
+ switch (uMsg) {
+ case WM_NCCREATE:
+ deviceContext = GetDC(hWnd);
+ renderContext = wglCreateContext(deviceContext);
+
+ memset(&pfd, 0, sizeof(pfd));
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = 32;
+
+ pf = ChoosePixelFormat(deviceContext, &pfd);
+ SetPixelFormat(deviceContext, pf, &pfd);
+ DescribePixelFormat(deviceContext, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+ ReleaseDC(hWnd, deviceContext);
+ renderContext = wglCreateContext(deviceContext);
+ wglMakeCurrent(deviceContext, renderContext);
+
+ windowData = (struct WindowData *) malloc(sizeof(struct WindowData));
+ windowData->window = hWnd;
+ windowData->deviceContext = deviceContext;
+ windowData->renderContext = renderContext;
+ SetWindowLongPtr(hWnd, 0, (LONG)windowData);
+ return TRUE;
+ case WM_ACTIVATE:
+ wglMakeCurrent(windowData->deviceContext, windowData->renderContext);
+ break;
+ case WM_PAINT:
+ wglMakeCurrent(windowData->deviceContext, windowData->renderContext);
+ glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glVertex2i(0, 1); glVertex2i(-1, -1); glVertex2i(1, -1); glEnd(); glFlush();
+ wglMakeCurrent(NULL, NULL);
+ BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps);
+ return 0;
+ case WM_SIZE:
+ glViewport(0, 0, LOWORD(lParam), HIWORD(lParam)); PostMessage(hWnd, WM_PAINT, 0, 0); return 0;
+ case WM_CHAR:
+ if (wParam == 27) { PostQuitMessage(0); break; }
+ else { return 0; }
+ case WM_DESTROY:
+ ReleaseDC(hWnd, windowData->deviceContext);
+ wglDeleteContext(windowData->renderContext);
+ return 0;
+ case WM_CLOSE:
+ PostQuitMessage(0); return 0;
+ }
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
+
+
+int WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) {
+ MSG msg;
+ WNDCLASS wc;
+ int pf;
+ PIXELFORMATDESCRIPTOR pfd;
+ hInstance = GetModuleHandle(NULL);
+
+ wc.style = CS_OWNDC;
+ wc.lpfnWndProc = (WNDPROC)WindowProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = sizeof(struct WindowData *);
+ wc.hInstance = hInstance;
+ wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = NULL;
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = "OpenGL2";
+
+ RegisterClass(&wc);
+ hWnd = CreateWindowEx(WS_EX_WINDOWEDGE,"OpenGL2", "Hi there", WS_VSCROLL|WS_TILEDWINDOW, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);
+ //hWnd2 = CreateWindow("OpenGL2", "Hi there", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 110, 110, 640, 480, NULL, NULL, hInstance, NULL);
+ ShowWindow(hWnd, nCmdShow);
+ //ShowWindow(hWnd2, nCmdShow);
+ while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); }
+ wglMakeCurrent(NULL, NULL);
+ DestroyWindow(hWnd);
+ return msg.wParam;
+}
+
+#endif // _run_app == _multi_window \ No newline at end of file
diff --git a/source/tests/win32/03_sub_menu.cpp b/source/tests/win32/03_sub_menu.cpp
new file mode 100644
index 0000000..848c82e
--- /dev/null
+++ b/source/tests/win32/03_sub_menu.cpp
@@ -0,0 +1,146 @@
+#include "config.h"
+#if _run_app == _sub_menu
+
+#include <windows.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
+void AddMenus(HWND);
+
+#define IDM_FILE_NEW 1
+#define IDM_FILE_IMPORT 2
+
+#define IDM_IMPORT_MAIL 11
+
+#define IDM_ASSET 20
+
+
+int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
+ PWSTR lpCmdLine, int nCmdShow) {
+
+ MSG msg;
+ WNDCLASSW wc = { 0 };
+ wc.lpszClassName = L"Submenu";
+ wc.hInstance = hInstance;
+ wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
+ wc.lpfnWndProc = WndProc;
+ wc.hCursor = LoadCursor(0, IDC_ARROW);
+
+ RegisterClassW(&wc);
+ CreateWindowW(wc.lpszClassName, L"The Incredible Asura",
+ WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+ 100, 100, 350, 250, 0, 0, hInstance, 0);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+
+ ::Sleep(1);
+ }
+
+ return (int)msg.wParam;
+}
+HDC hdc;
+HGLRC glc;
+static PAINTSTRUCT ps;
+HBRUSH hBrush;
+HBRUSH hOldBrush;
+HPEN hPen;
+HPEN hOldPen;
+PIXELFORMATDESCRIPTOR pfd;
+int pf;
+
+LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
+ WPARAM wParam, LPARAM lParam) {
+
+ switch (msg) {
+
+ case WM_CREATE:
+ AddMenus(hwnd);
+
+ hdc = GetDC(hwnd);
+ glc = wglCreateContext(hdc);
+
+ memset(&pfd, 0, sizeof(pfd));
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = 32;
+
+ pf = ChoosePixelFormat(hdc, &pfd);
+ SetPixelFormat(hdc, pf, &pfd);
+ DescribePixelFormat(hdc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+ ReleaseDC(hwnd, hdc);
+ glc = wglCreateContext(hdc);
+ wglMakeCurrent(hdc, glc);
+
+ break;
+
+ case WM_COMMAND:
+
+ switch (LOWORD(wParam)) {
+
+ case IDM_FILE_NEW:
+ MessageBoxW(NULL, L"New file selected",
+ L"Information", MB_OK);
+ break;
+
+ case IDM_IMPORT_MAIL:
+ MessageBoxW(NULL, L"Import mail selected",
+ L"Information", MB_OK);
+ }
+
+ break;
+
+ case WM_DESTROY:
+
+ PostQuitMessage(0);
+ break;
+
+ case WM_PAINT:
+
+ //hdc = BeginPaint(hwnd, &ps);
+ //hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
+ //hOldPen = (HPEN)SelectObject(hdc, hPen);
+ //hBrush = CreateSolidBrush(RGB(0, 0, 255));
+ //hOldBrush = (HBRUSH)SelectObject(hdc, hBrush);
+ //Rectangle(hdc, 100, 100, 200, 170);
+ //EndPaint(hwnd, &ps);
+ hdc = GetDC(hwnd);
+ glc = wglCreateContext(hdc);
+ wglMakeCurrent(hdc, glc);
+ glClearColor(0.16, 0.16, 0.16, 1);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glColor4f(0.219, 0.219, 0.219, 1);
+ glRectf(-0.5f, -0.5f, 0.5f, 0.5f); //ƾ
+ glFlush(); //ִOpenGLָбеָ
+ wglMakeCurrent(NULL, NULL);
+ BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps);
+ break;
+ }
+
+ return DefWindowProcW(hwnd, msg, wParam, lParam);
+}
+
+void AddMenus(HWND hwnd) {
+
+ HMENU hMenubar = CreateMenu();
+ HMENU hMenu = CreateMenu();
+ HMENU hSubMenu = CreatePopupMenu();
+ HMENU asserMenu = CreateMenu();
+
+ AppendMenuW(hMenu, MF_STRING, IDM_FILE_NEW, L"&New");
+
+ AppendMenuW(asserMenu, MF_STRING, IDM_ASSET, L"Import &mail &assets");
+ AppendMenuW(hSubMenu, MF_STRING | MF_POPUP, (UINT_PTR)asserMenu, L"Import &mail");
+ AppendMenuW(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, L"&Import");
+
+ AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L"&File");
+
+ SetMenu(hwnd, hMenubar);
+}
+
+#endif // _run_app == _sub_menu \ No newline at end of file
diff --git a/source/tests/win32/config.h b/source/tests/win32/config.h
new file mode 100644
index 0000000..cf7341a
--- /dev/null
+++ b/source/tests/win32/config.h
@@ -0,0 +1,10 @@
+#ifndef __Config_H__
+#define __Config_H__
+
+#define _multi_window 1
+#define _menu_bar 2
+#define _sub_menu 3
+
+#define _run_app _sub_menu
+
+#endif \ No newline at end of file