*/}}
Browse Source

More windows adaptation

YimingWu 1 year ago
parent
commit
10c7bc9316
7 changed files with 114 additions and 21 deletions
  1. 1 1
      la_5.h
  2. 1 3
      la_interface.h
  3. 71 15
      la_kernel.c
  4. 22 0
      resources/la_operators.c
  5. 11 1
      resources/la_properties.c
  6. 7 1
      resources/la_templates.c
  7. 1 0
      resources/la_translations.c

+ 1 - 1
la_5.h

@@ -50,8 +50,8 @@
 #ifdef __linux__
 #include <unistd.h>
 #include <dirent.h>
-#include <locale.h>
 #endif
 
+#include <locale.h>
 #include <sys/stat.h>
 #include <time.h>

+ 1 - 3
la_interface.h

@@ -46,12 +46,10 @@
 //#include <Windows.h>
 
 #define LA_VERSION_MAIN 5
-#define LA_VERSION_SUB 0
-#define LA_VERSION_MINOR 0
+#define LA_VERSION_SUB 1
 
 #define LA_ACTUATOR_CAPABILITY_MAIN 5
 #define LA_ACTUATOR_CAPABILITY_SUB 0
-#define LA_ACTUATOR_CAPABILITY_MINOR 0
 
 #define LA_NODE_MAIN_MODULE_NAME "LA_NODE_MAIN_MODULE"
 

+ 71 - 15
la_kernel.c

@@ -50,7 +50,11 @@ laOperator *DEB;
 
 laColumn *DEBUG_C;
 
+#ifdef _WIN32
+#define LA_GUI_WNDCLASS_NAME L"NUL4_GUI_CLASS"
+#else
 #define LA_GUI_WNDCLASS_NAME "NUL4_GUI_CLASS"
+#endif
 
 #ifdef __linux__
 typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
@@ -382,8 +386,13 @@ void laRenameWindow(laWindow* wnd, char* name){
 #ifdef __linux__
     XStoreName(MAIN.dpy, wnd->win, name);
 #endif
+#ifdef _WIN32
+    //wchar_t buf[128]; MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, 128);
+    SetWindowTextW(wnd->win, name);
+#endif
 }
 
+#ifdef __linux__
 const char* la_ConvertCursorID(int id){
     switch (id) {
     case LA_ARROW: return "arrow";
@@ -396,6 +405,21 @@ const char* la_ConvertCursorID(int id){
     }
     return "arrow";
 }
+#endif
+#ifdef _WIN32
+HCURSOR la_ConvertCursorID(int id){
+    switch (id){
+    case LA_ARROW: return LoadCursor(0,IDC_ARROW);
+    case LA_CROSS: return LoadCursor(0,IDC_CROSS);
+    case LA_LEFT_AND_RIGHT: return LoadCursor(0,IDC_SIZEWE);
+    case LA_UP_AND_DOWN: return LoadCursor(0, IDC_SIZENS);
+    case LA_MOVE: return LoadCursor(0, IDC_SIZEALL);
+    case LA_HAND: return LoadCursor(0, IDC_HAND);
+    case LA_CORNER: return LoadCursor(0, IDC_SIZENWSE);
+    }
+    return LoadCursor(0, IDC_ARROW);;
+}
+#endif
 
 void la_InitThreadEnviornment(){
     //pthread_spin_init(&MAIN.csNotifier, //pthread_PROCESS_PRIVATE);
@@ -608,15 +632,17 @@ int laGetReadyWith(int GLMajor, int GLMinor, int BufferSamples){
     MAIN.wmfullscroff=XInternAtom(MAIN.dpy,"_NET_WM_STATE_FULLSCREEN",0);
 #endif //linux
 #ifdef _WIN32
+    setlocale(LC_ALL, "zh_CN.utf8");
+
     MAIN.hinstance = GetModuleHandle(NULL);
 
     HINSTANCE* hInst = &MAIN.hinstance;
-    WNDCLASSEX wt;
-    wt.cbSize = sizeof(WNDCLASSEX);
+    WNDCLASSEXW wt;
+    wt.cbSize = sizeof(WNDCLASSEXW);
     wt.cbClsExtra = 0;
     wt.cbWndExtra = 0;
     wt.hbrBackground = 0;
-    wt.hCursor = LoadCursor(*hInst, IDC_ARROW);
+    wt.hCursor = LoadCursor(0, IDC_ARROW);
     wt.hIcon = LoadIcon(*hInst, IDI_WINLOGO);
     wt.hIconSm = LoadIcon(*hInst, IDI_WINLOGO);
     wt.hInstance = *hInst;
@@ -2125,6 +2151,9 @@ void laSetWindowCursor(int id){
     Cursor c = XcursorLibraryLoadCursor(MAIN.dpy, la_ConvertCursorID(id));
     XDefineCursor(MAIN.dpy, MAIN.CurrentWindow->win, c);
 #endif
+#ifdef _WIN32
+    SetCursor(la_ConvertCursorID(id));
+#endif
 };
 void la_AssignBlockPP(laBlock* b){
     b->PP.EndInstance = b;
@@ -2676,7 +2705,7 @@ void laDestroySinglePanel(laPanel *p, int immediate){
 
     la_DestroyUiList(&p->UI, 1, 1, 0);
     la_DestroyUiList(&p->TitleBar, 1, 1, 0);
-    la_DestroyUiList(p->MenuRefer, 0, 1, 1);
+    //la_DestroyUiList(p->MenuRefer, 0, 1, 1);
 
     if (p->Mode){
         p->AnimationMode = LA_PANEL_ANIMATION_DISSOVE; laRefreshWindow();
@@ -6516,6 +6545,9 @@ LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
     char mbuf[10] = { 0 }; uint32_t uchar=0;
     short wheelmark = 0;
     int  WheelDir = 0;
+    UINT32 pointerId; POINTER_INPUT_TYPE pointerType;
+    POINTER_PEN_INFO penInfo; POINTER_TOUCH_INFO touchInfo;
+    POINT point;
     if (!hwnd) return DefWindowProc(hwnd, message, wparam, lparam);
     switch (message) {
     case WM_PAINT:
@@ -6523,6 +6555,7 @@ LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
         break;
     case WM_MOUSEMOVE:
         la_SendMouseEvent(hwnd, LA_MOUSEMOVE, PARAM_2_FROM(lparam));
+        MAIN.IsPen = 0; MAIN.PointerIsEraser = 0;
         break;
 
     case WM_LBUTTONDOWN:
@@ -6559,8 +6592,32 @@ LRESULT CALLBACK LA_WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
         }
         break;
     case WM_SIZE:
+        if (wparam == SIZE_MINIMIZED) break;
         la_CommandResizeWindow(hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam));
         break;
+    case WM_POINTERUPDATE:
+        pointerId = GET_POINTERID_WPARAM(wparam);
+        pointerType = PT_POINTER;
+
+        if(!GetPointerType(pointerId, &pointerType)){
+            pointerType = PT_POINTER;
+            printf("is pointer\n");
+        }
+        if(pointerType == PT_PEN){
+            if(GetPointerPenInfo(pointerId, &penInfo)){
+                point.x = penInfo.pointerInfo.ptPixelLocation.x; point.y = penInfo.pointerInfo.ptPixelLocation.y;
+                ScreenToClient(hwnd, &point);
+                MAIN.IsPen = 1; MAIN.StylusPressure = (real)penInfo.pressure / 1024; MAIN.PointerIsEraser = 0;
+            }
+        }
+        else if (pointerType == PT_TOUCH){
+            if (GetPointerTouchInfo(pointerId, &touchInfo)) {
+                point.x = touchInfo.pointerInfo.ptPixelLocation.x; point.y = touchInfo.pointerInfo.ptPixelLocation.y;
+                ScreenToClient(hwnd, &point);
+                MAIN.IsPen = 1; MAIN.StylusPressure = (real)touchInfo.pressure / 1024; MAIN.PointerIsEraser = 1;
+            }
+        }
+        break;
 
     //case WM_SYSKEYDOWN:
     //    if (lparam & 0x40000000) break;
@@ -6759,6 +6816,9 @@ int laCopyToClipboard(unsigned char * text){
 #endif
 }
 int la_ProcessSysMessage(){
+    int SendDelay = 0, SendIdle = 0;
+    if (!MAIN.DelayTriggered && MAIN.TimeAccum - MAIN.DelayStart > MAIN.DelayTime) SendDelay = 1;
+    if (!MAIN.IdleTriggered && MAIN.TimeAccum - MAIN.IdleStart > MAIN.IdleTime) SendIdle = 1;
 #ifdef __linux__
     XEvent e;
     int type;
@@ -6768,10 +6828,6 @@ int la_ProcessSysMessage(){
     Status InputStatus = 0;
     laWindow* wnd ;
 
-    int SendDelay=0,SendIdle=0;
-    if(!MAIN.DelayTriggered && MAIN.TimeAccum-MAIN.DelayStart>MAIN.DelayTime) SendDelay=1;
-    if(!MAIN.IdleTriggered && MAIN.TimeAccum-MAIN.IdleStart>MAIN.IdleTime) SendIdle=1;
-
     while(XPending(MAIN.dpy)){
         XGenericEventCookie *cookie = &e.xcookie;
         XNextEvent(MAIN.dpy, &e);
@@ -6878,13 +6934,6 @@ int la_ProcessSysMessage(){
             break;
         }
     }
-
-    for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
-        if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
-        if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE);  MAIN.IdleTriggered=1; }
-    }
-
-    return 1;
 #endif //linux
 #ifdef _WIN32
     MSG msg; int Processed = 0;
@@ -6892,8 +6941,15 @@ int la_ProcessSysMessage(){
 
     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
         TranslateMessage(&msg); DispatchMessage(&msg);
+        SendIdle = 0; MAIN.IdleStart = MAIN.TimeAccum; MAIN.IdleTriggered = 0;
     };
 #endif
+
+    for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
+        if(SendDelay) { la_SendTimerEvent(w->win, LA_TIME_DELAY); MAIN.DelayTriggered=1; }
+        if(SendIdle) { la_SendTimerEvent(w->win, LA_TIME_IDLE);  MAIN.IdleTriggered=1; }
+    }
+    return 1;
 };
 
 void la_PrintOperatorStack(){

+ 22 - 0
resources/la_operators.c

@@ -1039,6 +1039,28 @@ int OPINV_Fullscreen(laOperator *a, laEvent *e){
         .data = {.l = {full, XInternAtom(MAIN.dpy, "_NET_WM_STATE_FULLSCREEN", True), None, 0, 1 }}
     };
     XSendEvent(MAIN.dpy, XRootWindow(MAIN.dpy, XDefaultScreen(MAIN.dpy)), False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent*) &msg);
+#endif
+#ifdef _WIN32
+    DWORD dwStyle = GetWindowLong(w->win, GWL_STYLE);
+    static WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) };
+    if (full){
+        MONITORINFO mi = { sizeof(mi) };
+        if (GetWindowPlacement(w->win, &g_wpPrev) &&
+            GetMonitorInfo(MonitorFromWindow(w->win,
+                MONITOR_DEFAULTTOPRIMARY), &mi)) {
+            SetWindowLong(w->win, GWL_STYLE,
+                dwStyle & ~WS_OVERLAPPEDWINDOW);
+            SetWindowPos(w->win, HWND_TOP,
+                mi.rcMonitor.left, mi.rcMonitor.top,
+                mi.rcMonitor.right - mi.rcMonitor.left,
+                mi.rcMonitor.bottom - mi.rcMonitor.top,
+                SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
+        }
+    }else{
+        SetWindowLong(w->win, GWL_STYLE,dwStyle|WS_OVERLAPPEDWINDOW);
+        SetWindowPlacement(w->win, &g_wpPrev);
+        SetWindowPos(w->win,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_FRAMECHANGED);
+    }
 #endif
     w->IsFullScreen=full;
     laRedrawCurrentWindow();

+ 11 - 1
resources/la_properties.c

@@ -321,6 +321,16 @@ void laset_PanelSnapDistance(laPanel *p, int index, int n){
         break;
     }
 }
+void laread_PanelSnapDistance(laPanel* p, int index, int n) {
+    int a;
+    if (!n) return;
+    switch (index) { //lrtb
+    case 0: p->SL = n; break;
+    case 1: p->SR = n; break;
+    case 2: p->ST = n; break;
+    case 3: p->SB = n; break;
+    }
+}
 void laset_PanelSnapEnable(laPanel *p, int index, int n){
     laWindow *w = MAIN.CurrentWindow;
     int a;
@@ -1210,7 +1220,7 @@ void la_RegisterInternalProps(){
                 laAddEnumItem(ep, "no", "No Snap", "Not Snapped to edge", 0);
                 laAddEnumItem(ep, "yes", "Snap", "Snapped to edge", U'🞉');
             } //don't swap order with the one below
-            laAddIntProperty(p, "snap", "Snap Distance", "Snapping Distance To Edges", 0,"Left,Right,Top,Bottom", "px", 0,0,1, 0,0,offsetof(laPanel, SL), 0,0,4, 0,laset_PanelSnapDistance, 0,0,0,0,0,0);
+            laAddIntProperty(p, "snap", "Snap Distance", "Snapping Distance To Edges", 0,"Left,Right,Top,Bottom", "px", 0,0,1, 0,0,offsetof(laPanel, SL), 0,0,4, 0,laset_PanelSnapDistance, 0,0,0, laread_PanelSnapDistance,0,0);
             laAddIntProperty(p, "show", "Show", "The Panel Is Shown Or Not", 0,0,0,0,0,1, 0,0,offsetof(laPanel, Show), 0,0,0,0,0,0,0,0,0,0,0);
             laAddIntProperty(p, "mode", "Mode", "Normal/Floating/Static/Modal etc.", 0,0,0,0,0,1, 0,0,offsetof(laPanel, Mode), 0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
             ep = laAddEnumProperty(p, "is_menu_panel", "Is Menu Panel", "Is Menu Panel", 0,0,0,0,0,offsetof(laPanel, IsMenuPanel), 0,0,0,0,0,0,0,0,0,0);{

+ 7 - 1
resources/la_templates.c

@@ -1310,6 +1310,9 @@ void laui_UserPreference(laUiList *uil, laPropPack *Base, laPropPack *OperatorIn
             laShowSeparator(muil,mc);
 
             laShowLabel(muil, mc, "Input device handling:", 0, 0);
+#ifdef _WIN32
+            laShowLabel(muil, mc, "Not yet implemened on Windows.", 0, 0);
+#endif
             laShowLabel(muil, mcl, "Input Mapping:", 0, 0)->Flags|=LA_TEXT_ALIGN_RIGHT;
             laShowItemFull(muil, mcr, 0, "LA_panel_activator",0,"panel_id=LAUI_input_mapper;text=Configure",0,0);
             laShowLabel(muil, mcl, "Pads/Joysticks:", 0, 0)->Flags|=LA_TEXT_ALIGN_RIGHT;
@@ -1318,6 +1321,9 @@ void laui_UserPreference(laUiList *uil, laPropPack *Base, laPropPack *OperatorIn
             laShowSeparator(muil,mc);
 
             laShowLabel(muil, mc, "Wacom Devices:", 0, 0);
+#ifdef _WIN32
+            laShowLabel(muil, mc, "Not yet implemened on Windows.", 0, 0);
+#endif
             laShowItem(muil, mcl, 0, "la.user_preferences.wacom_device_stylus");
             laShowItem(muil, mcl, 0, "la.user_preferences.wacom_device_eraser");
             laShowItemFull(muil, mcr, 0, "LA_refresh_controllers",0,"text=Refresh",0,0);
@@ -1389,7 +1395,7 @@ void laui_About(laUiList *uil, laPropPack *Base, laPropPack *OperatorInst, laCol
         g = laMakeGroup(u, tc, "LaGUI information", 0);
         gu = g->Page;{
             gc = laFirstColumn(gu);
-            sprintf(buf, "LaGUI.%d.%d.%d", LA_VERSION_MAIN, LA_VERSION_SUB, LA_VERSION_MINOR);
+            sprintf(buf, "LaGUI.%d.%d", LA_VERSION_MAIN, LA_VERSION_SUB);
             laShowLabel(gu, gc, buf, 0, 0)->Flags|=LA_TEXT_MONO;
             laShowLabel(gu, gc, LAGUI_GIT_BRANCH,0,0)->Flags|=LA_TEXT_MONO;
 #ifdef LAGUI_GIT_HASH

+ 1 - 0
resources/la_translations.c

@@ -19,6 +19,7 @@
 #include "la_5.h"
 
 static const char *entries[]={
+"Not yet implemened on Windows.","尚未在Windows上实现。",
 "Set Min","调成最小",
 "Set Max","调成最大",
 "Restore Default","恢复默认值",