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

try to have non-feedback menus but not quite there

YimingWu пре 3 месеци
родитељ
комит
64c9485d2b
7 измењених фајлова са 156 додато и 26 уклоњено
  1. 7 0
      la_interface.h
  2. 79 17
      la_kernel.c
  3. 24 0
      la_util.c
  4. 1 1
      resources/la_operators.c
  5. 30 8
      resources/la_templates.c
  6. 1 0
      resources/la_widgets.c
  7. 14 0
      resources/la_widgets_viewers.c

+ 7 - 0
la_interface.h

@@ -130,6 +130,7 @@
 #define LA_KEY_NUMDOT    (LA_KEY_EXTRA+15)
 #define LA_KEY_NUMENTER  (LA_KEY_EXTRA+16)
 
+#define LA_KEY_PANNING   (1<<26)
 #define LA_SIGNAL_EVENT  (1<<31)
 
 #ifdef _WIN32
@@ -194,6 +195,10 @@
 #define LA_MOUSE_WHEEL_UP (LA_MOUSE_EVENT | LA_STATE_UP | LA_KEY_MOUSE_SCROLL)
 #define LA_KEY_DOWN (LA_KEYBOARD_EVENT | LA_STATE_DOWN)
 #define LA_KEY_UP (LA_KEYBOARD_EVENT | LA_STATE_UP)
+#define LA_PANNING_LEFT (LA_KEYBOARD_EVENT | LA_KEY_PANNING | LA_KEY_ARRLEFT)
+#define LA_PANNING_RIGHT (LA_KEYBOARD_EVENT | LA_KEY_PANNING | LA_KEY_ARRRIGHT)
+#define LA_PANNING_UP (LA_KEYBOARD_EVENT | LA_KEY_PANNING | LA_KEY_ARRUP)
+#define LA_PANNING_DOWN (LA_KEYBOARD_EVENT | LA_KEY_PANNING | LA_KEY_ARRDOWN)
 
 #define LA_LEFT_DOWN (LA_KEYBOARD_EVENT | LA_KEY_ARRLEFT | LA_STATE_DOWN)
 #define LA_RIGHT_DOWN (LA_KEYBOARD_EVENT | LA_KEY_ARRRIGHT | LA_STATE_DOWN)
@@ -1357,6 +1362,7 @@ STRUCTURE(laPanel){
     char LaterDestroy;
     char CloseWhenMovedOut;
     int Mode;
+    int NoConfirm;
 
     int LiveEditing;
     laUiItem *EditingUi;
@@ -2513,6 +2519,7 @@ laUiItem *laOnConditionThat(laUiList *uil, laColumn *c, laUiConditionNode *Expre
 laUiItem *laOnConditionToggle(laUiList *uil, laColumn *col, laUiDefineFunc define, int Remove, laPropPack *ExtraBase, laPropPack *ExtraThis, laWidget* Widget);
 laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner);
 laUiItem *laElse(laUiList *uil, laUiItem *Beginner);
+laUiList* laMakeMenuPageEx(laUiList* uil, laColumn* c, const char* Title, int flags);
 laUiList *laMakeMenuPage(laUiList *uil, laColumn *c, const char *Title);
 laUiItem *laShowSeparator(laUiList *uil, laColumn *widest);
 void laFixHeight(laUiList *uil, short Rows);

+ 79 - 17
la_kernel.c

@@ -60,6 +60,8 @@
 #include <android_native_app_glue.h>
 #include <android/window.h>
 #include <android/asset_manager.h>
+#include <android/input.h>
+#include <android/keycodes.h> 
 
 FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
               fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
@@ -5223,7 +5225,7 @@ laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
 
     return ui;
 }
-laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
+laUiList* laMakeMenuPageEx(laUiList* uil, laColumn* c, const char* Title, int flags) {
     laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
     laUiList* muil = memAcquireSimple(sizeof(laUiList));
 
@@ -5231,12 +5233,16 @@ laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
     strSafeSet(&ui->Display, Title);
     ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
     ui->C = c;
+    ui->Flags|=flags;
     lstAppendItem(&uil->UiItems, ui);
 
     lstAppendItem(&ui->Subs, muil);
 
     return muil;
 }
+laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
+    return laMakeMenuPageEx(uil,c,Title,0);
+}
 laUiItem *laShowSeparator(laUiList *uil, laColumn *widest){
     laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
 
@@ -8264,6 +8270,7 @@ static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
     case APP_CMD_STOP: break;
     case APP_CMD_DESTROY: break;
     case APP_CMD_CONFIG_CHANGED:
+    case APP_CMD_WINDOW_RESIZED:
         MAIN.AppWidth=ANativeWindow_getWidth(MAIN.app->window);
         MAIN.AppHeight=ANativeWindow_getHeight(MAIN.app->window);
         
@@ -8272,6 +8279,19 @@ static void la_AndroidCommandCallback(struct android_app *app, int32_t cmd){
         //print_cur_config(MAIN.app);
 
         // Check screen orientation here!
+        if (MAIN.egl_dpy != EGL_NO_DISPLAY) {
+            eglMakeCurrent(MAIN.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+            if (MAIN.egl_surf != EGL_NO_SURFACE) {
+                eglDestroySurface(MAIN.egl_dpy, MAIN.egl_surf);
+                MAIN.egl_surf = EGL_NO_SURFACE;
+            }
+            EGLint displayFormat = 0;
+            eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &displayFormat);
+            ANativeWindow_setBuffersGeometry(app->window,MAIN.AppWidth,MAIN.AppHeight,
+                displayFormat);
+            MAIN.egl_surf = eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, app->window, NULL);
+            eglMakeCurrent(MAIN.egl_dpy, MAIN.egl_surf, MAIN.egl_surf, MAIN.glc);
+        }
         break;
     default: break;
     }
@@ -8493,28 +8513,70 @@ static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *eve
 
     }
     elif(type == AINPUT_EVENT_TYPE_MOTION){
-        int pcount = AMotionEvent_getPointerCount(event); int x,y;
-        if(pcount){
-            real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
-            x=rx; y=ry;
-        }
+        static real zoom_offset=1; static real temp_distance=0;
+        real zoom; int gesture_handled=0;
+        int pcount = AMotionEvent_getPointerCount(event); int x,y; static real cx=0,cy=0;
         int32_t action = AMotionEvent_getAction(event);
         unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
         int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
 
-        if (flags == AMOTION_EVENT_ACTION_DOWN){
-            la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
-            la_SendMouseEvent(0,LA_L_MOUSE_DOWN,x,y);
-        }
-        else if (flags == AMOTION_EVENT_ACTION_UP){
-            la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
-        }
-        else if (flags == AMOTION_EVENT_ACTION_MOVE){
-            la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
+        if(pcount){
+            real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
+            x=rx; y=ry;
+            if(pcount>=2 && (flags!=AMOTION_EVENT_ACTION_UP) && (flags!=AMOTION_EVENT_ACTION_CANCEL)
+                && (flags!=AMOTION_EVENT_ACTION_POINTER_UP)){
+                real x2=AMotionEvent_getX(event, 1), y2=AMotionEvent_getY(event, 1);
+                real ctx=(x+x2)/2, cty=(y+y2)/2;
+                real distance = tnsDistIdv2(x2,y2,rx,ry);
+                if(temp_distance){ zoom_offset*=(distance/temp_distance); }
+                temp_distance = distance;
+
+                while(zoom_offset > 1.1){ zoom_offset-=0.1; 
+                    la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
+                    la_SendMouseEvent(0, LA_MOUSEUP|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
+                }
+                while(zoom_offset < (1.0/1.1)){ zoom_offset+=(0.1/1.1); 
+                    la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
+                    la_SendMouseEvent(0, LA_MOUSEDOWN|LA_KEY_MOUSE_SCROLL, x,y); gesture_handled=1;
+                }
+                if(cx || cy){
+                    if(!gesture_handled){
+                        real dist = tnsDistIdv2(ctx,cty,cx,cy);
+                        while(dist > LA_RH){
+                            int udlr = fabs(cty-cy) > fabs(ctx-cx);
+                            int direction = udlr?(cty>cy?LA_KEY_ARRUP:LA_KEY_ARRDOWN):
+                                                 (ctx>cx?LA_KEY_ARRLEFT:LA_KEY_ARRRIGHT);
+                            real fac = (real)(LA_RH)/dist;
+                            cx=tnsLinearItp(cx,ctx,fac); cy=tnsLinearItp(cy,cty,fac);
+                            la_SendMouseEvent(0, LA_L_MOUSE_UP, x,y);
+                            la_SendKeyboardEvent(0, LA_KEY_DOWN, direction|LA_KEYBOARD_EVENT|LA_KEY_PANNING);
+                            gesture_handled=1;
+                            dist = tnsDistIdv2(ctx,cty,cx,cy);
+                        }
+                    }
+                }else{
+                    cx=ctx; cy=cty;
+                }
+            }else{
+                temp_distance = 0; cx=0; cy=0;
+            }
         }
-        else if (flags == AMOTION_EVENT_ACTION_CANCEL){
-            la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
+        if(!gesture_handled){
+            if (flags == AMOTION_EVENT_ACTION_DOWN){
+                la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
+                la_SendMouseEvent(0,LA_L_MOUSE_DOWN,x,y);
+            }
+            else if (flags == AMOTION_EVENT_ACTION_UP){
+                la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
+            }
+            else if (flags == AMOTION_EVENT_ACTION_MOVE){
+                la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
+            }
+            else if (flags == AMOTION_EVENT_ACTION_CANCEL){
+                la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
+            }
         }
+        
     }
 
     //static float r=0;

+ 24 - 0
la_util.c

@@ -2448,6 +2448,30 @@ void laOpenInternetLink(char *url){
 #endif
 #ifdef _WIN32
     strSafePrint(&s, "start %s", url);
+#endif
+#ifdef LAGUI_ANDROID
+    JNIEnv *env = NULL;
+    JavaVM *vm = MAIN.app->activity->vm;
+    (*vm)->AttachCurrentThread(vm, &env, NULL);
+
+    jstring urlString = (*env)->NewStringUTF(env, url);
+    jclass uriClass = (*env)->FindClass(env, "android/net/Uri");
+    jmethodID uriParse = (*env)->GetStaticMethodID(env, uriClass, "parse", "(Ljava/lang/String;)Landroid/net/Uri;");
+    jobject uri = (*env)->CallStaticObjectMethod(env, uriClass, uriParse, urlString);
+
+    jclass intentClass = (*env)->FindClass(env, "android/content/Intent");
+    jfieldID actionViewId = (*env)->GetStaticFieldID(env, intentClass, "ACTION_VIEW", "Ljava/lang/String;");
+    jobject actionView = (*env)->GetStaticObjectField(env, intentClass, actionViewId);
+    jmethodID newIntent = (*env)->GetMethodID(env, intentClass, "<init>", "(Ljava/lang/String;Landroid/net/Uri;)V");
+    jobject intent = (*env)->AllocObject(env, intentClass);
+
+    (*env)->CallVoidMethod(env, intent, newIntent, actionView, uri);
+    jclass activityClass = (*env)->FindClass(env, "android/app/Activity");
+    jmethodID startActivity = (*env)->GetMethodID(env, activityClass, "startActivity", "(Landroid/content/Intent;)V");
+    (*env)->CallVoidMethod(env, MAIN.app->activity->clazz, startActivity, intent);
+
+    (*vm)->DetachCurrentThread(vm);
+    return;
 #endif
     system(s->Ptr);
     strSafeDestroy(&s);

+ 1 - 1
resources/la_operators.c

@@ -2144,7 +2144,7 @@ int OPMOD_MenuPanel(laOperator *a, laEvent *e){
 
     lstClearPointer(&Locals);
 
-    if (a->ConfirmData){
+    if (a->ConfirmData && (!p->NoConfirm)){
         laConfirmInt(a, a->ConfirmData->IData, a->ConfirmData->Mode);
         la_StopUiOperatorService(p);
         laDestroySinglePanel(p,0);

+ 30 - 8
resources/la_templates.c

@@ -541,9 +541,9 @@ void laui_DefaultMenuExtras(laUiList *uil, laPropPack *pp, laPropPack *actinst,
 }
 
 void laui_DefaultMenuBarActual(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context){
-    laUiList *muil;
-    laColumn *c,*mc;
-    laUiItem* bb;
+    laUiList *muil,*backuil;
+    laColumn *c,*mc,*backc;
+    laUiItem* bb,*mbb;
 
     c = laFirstColumn(uil);
     laUiItem* row=laBeginRow(uil,c,0,0);
@@ -555,10 +555,19 @@ void laui_DefaultMenuBarActual(laUiList *uil, laPropPack *pp, laPropPack *actins
     }laElse(uil,bb);{
         laShowItem(uil, c, 0, "LA_new_panel")->Flags=LA_UI_FLAGS_ICON;
 
+#ifdef LAGUI_ANDROID
+        backc=c; backuil=uil;
+        uil=laMakeMenuPageEx(uil,c,"Menu",/*LA_UI_FLAGS_NO_CONFIRM*/0); c=laFirstColumn(uil);
+        mbb=laBeginRow(uil,c,0,0);
+#endif
+
         if(MAIN.MenuButtons){ MAIN.MenuButtons(uil,0,0,0,0); }
 
+#ifdef LAGUI_ANDROID
+        laEndRow(uil,mbb); mbb=laBeginRow(uil,c,0,0);
+#else
         laShowSeparator(uil,c);
-
+#endif
         laUiItem* mui=laOnConditionThat(uil,c,laPropExpression(0,"la.windows.maximized_ui"));{
             laShowItemFull(uil,c,0,"LA_canvas_ui_maximize", 0, "icon=🡰;restore=true;text=Restore Layout", 0, 0);
         }laElse(uil,mui);{
@@ -574,17 +583,21 @@ void laui_DefaultMenuBarActual(laUiList *uil, laPropPack *pp, laPropPack *actins
         }laEndCondition(uil,mui);
 
         laUiItem* uc=laOnConditionThat(uil,c,laPropExpression(0,"la.user_preferences.enable_color_management"));{
+#ifdef LAGUI_ANDROID
+        laEndRow(uil,mbb); mbb=laBeginRow(uil,c,0,0);
+#else
                 laShowSeparator(uil,c);
-                laShowItemFull(uil,c,0,"la.user_preferences.auto_switch_color_space",0,"icon=A",0,0)->Flags|=LA_UI_FLAGS_ICON|LA_UI_FLAGS_CYCLE|LA_UI_FLAGS_HIGHLIGHT;
+#endif
+                laShowItemFull(uil,c,0,"la.user_preferences.auto_switch_color_space",0,"icon=A",0,0)->Flags|=LA_UI_FLAGS_ICON|LA_UI_FLAGS_CYCLE|LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_NO_CONFIRM;
                 laUiItem* uc1=laOnConditionThat(uil,c,laPropExpression(0,"la.user_preferences.auto_switch_color_space"));{
                     laShowItem(uil,c,0,"la.windows.output_color_space")->Flags|=LA_UI_FLAGS_PLAIN;
                 }laElse(uil,uc1);{
                     laShowItem(uil,c,0,"la.windows.output_color_space");
                 }laEndCondition(uil, uc1);
-                laShowItemFull(uil,c,0,"la.windows.output_show_overflow",0,"text=🟩;",0,0);
-                laShowItemFull(uil,c,0,"la.windows.use_composing",0,"text=☀",0,0);
+                laShowItemFull(uil,c,0,"la.windows.output_show_overflow",0,"text=🟩;",0,0)->Flags|=LA_UI_FLAGS_NO_CONFIRM;
+                laShowItemFull(uil,c,0,"la.windows.use_composing",0,"text=☀",0,0)->Flags|=LA_UI_FLAGS_NO_CONFIRM;
                 laUiItem* cmp=laOnConditionThat(uil,c,laPropExpression(0,"la.windows.use_composing"));{
-                    muil = laMakeMenuPage(uil, c, "⯆");{ mc = laFirstColumn(muil);
+                    muil = laMakeMenuPageEx(uil, c, "⯆",LA_UI_FLAGS_NO_CONFIRM);{ mc = laFirstColumn(muil);
                         laUiItem*b,*ui;
                         b=laBeginRow(muil,mc,0,0); laShowLabel(muil,mc,"γ",0,0);
                         ui=laShowItemFull(muil, mc, 0, "la.windows.composing_gamma",0,"text=Gamma",0,0); ui->Expand=1;
@@ -594,8 +607,14 @@ void laui_DefaultMenuBarActual(laUiList *uil, laPropPack *pp, laPropPack *actins
                         laShowItem(muil,mc,&ui->PP,"restore")->Flags|=LA_UI_FLAGS_NO_CONFIRM|LA_UI_FLAGS_ICON; laEndRow(muil,b);
                     }
                 }laEndCondition(uil, cmp);
+
         }laEndCondition(uil, uc);
 
+#ifdef LAGUI_ANDROID
+        laEndRow(uil,mbb);
+        c=backc; uil=backuil;
+#endif
+
         if(MAIN.MenuExtras){ laShowSeparator(uil,c); MAIN.MenuExtras(uil,0,0,0,0); }
 
         laUiItem* b1=laOnConditionThat(uil,c,laPropExpression(0,"la.windows.panels_hidden"));
@@ -605,11 +624,14 @@ void laui_DefaultMenuBarActual(laUiList *uil, laPropPack *pp, laPropPack *actins
                 laShowItemFull(muil, mc, 0, "la.windows.panels_hidden", 0,0, laui_IdentifierOnly,0);
             }
         laEndCondition(uil, b1);
+
+#ifndef LAGUI_ANDROID
         b1=laOnConditionThat(uil,c,laPropExpression(0,"la.windows.is_fullscreen"));{
             laShowItemFull(uil,c,0,"LA_fullscreen",0,"restore=true;text=Restore;icon=🡷",0,0)->Flags|=LA_UI_FLAGS_EXIT_WHEN_TRIGGERED;
         }laElse(uil,b1);{
             laShowItemFull(uil,c,0,"LA_fullscreen",0,0,0,0)->Flags|=LA_UI_FLAGS_EXIT_WHEN_TRIGGERED;
         }laEndCondition(uil, b1);
+#endif
 
     }laEndCondition(uil,bb);
 

+ 1 - 0
resources/la_widgets.c

@@ -2881,6 +2881,7 @@ int OPMOD_MenuItem(laOperator *a, laEvent *e){
         laLocalToWindow(a, a->ToPanel, &GX, &GY);
         ui->State = LA_UI_ACTIVE;
         p = laEnableMenuPanel(a->ToPanel, a, ui->Subs.pFirst, &ui->PP, GX, GX + 300, GY, MAIN.CurrentWindow->CH-LA_2RH, 0, e);
+        p->NoConfirm = (ui->Flags&LA_UI_FLAGS_NO_CONFIRM)!=0;
         laShowPanelWithDropDownEffect(p);
         laRedrawCurrentPanel();
         return LA_RUNNING;

+ 14 - 0
resources/la_widgets_viewers.c

@@ -1015,6 +1015,16 @@ int OPINV_3DOr2DViewAdjust(laOperator *a, laEvent *e){
     a->CustomData = ex;
     ex->LastX = e->x; ex->LastY = e->y;
 
+    if(a->Type->Modal == OPMOD_CanvasMove && a->This->EndInstance){
+        laCanvasExtra* cex=a->This->EndInstance;
+        char* str=strGetArgumentString(a->ExtraInstructionsP,"pan");
+        if(strSame(str,"left")){ cex->PanX -= (LA_RH) * cex->ZoomX; }
+        elif(strSame(str,"right")){ cex->PanX += (LA_RH) * cex->ZoomX; }
+        elif(strSame(str,"up")){ cex->PanY += (LA_RH) * cex->ZoomY; }
+        elif(strSame(str,"down")){ cex->PanY -= (LA_RH) * cex->ZoomY; }
+        return LA_FINISHED;
+    }
+
     return LA_RUNNING;
 }
 int OPEXT_3DOr2DViewAdjust(laOperator *a, int Mark){
@@ -1143,6 +1153,10 @@ void la_RegisterUiTypesViewerWidgets(){
     laAssignNewKey(km, 0, "LA_2d_view_zoom", LA_KM_SEL_UI_EXTRA, 0, LA_MOUSE_WHEEL_DOWN, 0, "direction=out");
     laAssignNewKey(km, 0, "LA_2d_view_zoom", LA_KM_SEL_UI_EXTRA, 0, LA_MOUSE_WHEEL_UP, 0, "direction=in");
     laAssignNewKey(km, 0, "LA_2d_view_move", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT, LA_L_MOUSE_DOWN, 0, 0);
+    laAssignNewKey(km, 0, "LA_2d_view_move", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, LA_PANNING_LEFT, "pan=left");
+    laAssignNewKey(km, 0, "LA_2d_view_move", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, LA_PANNING_RIGHT, "pan=right");
+    laAssignNewKey(km, 0, "LA_2d_view_move", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, LA_PANNING_UP, "pan=up");
+    laAssignNewKey(km, 0, "LA_2d_view_move", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, LA_PANNING_DOWN, "pan=down");
     laAssignNewKey(km, 0, "LA_2d_view_click", LA_KM_SEL_UI_EXTRA, 0, LA_L_MOUSE_DOWN, 0, 0);