cleaned all trailing white space from source files.
[sdk] / ecere / src / gui / drivers / AndroidInterface.ec
index 600f92b..5b467f1 100644 (file)
@@ -32,7 +32,7 @@ import "Condition"
 #endif
 
 // *** NATIVE APP GLUE ********
-enum LooperID : byte { main = 1, input = 2, user = 3 };
+enum LooperID { main = 1, input = 2, user = 3 };
 enum AppCommand : byte
 {
    error = 0, inputChanged, initWindow, termWindow, windowResized, windowRedrawNeeded,
@@ -547,6 +547,7 @@ static char * androidArgv[1];
 
 static int desktopW, desktopH;
 static char * clipBoardData;
+static int mouseX, mouseY;
 
 class AndroidInterface : Interface
 {
@@ -570,12 +571,13 @@ class AndroidInterface : Interface
    bool ProcessInput(bool processAll)
    {
       bool eventAvailable = false;
-      if(androidActivity.ident >= 0)
+
+      if(androidActivity.ident < 0)
+         androidActivity.ident = (LooperID)ALooper_pollAll(0, null, &androidActivity.events, (void**)&androidActivity.source);
+      while(androidActivity.ident >= 0)
       {
          AndroidPollSource source = androidActivity.source;
-         //PrintLn("androidActivity.ident >= 0");
-         // Process this event.
-         androidActivity.ident = 0;
+
          androidActivity.source = null;
          if(source)
             source.process(source.userData);
@@ -592,25 +594,37 @@ class AndroidInterface : Interface
             }
          }
          */
-         // eventAvailable = true;
+         if(gotInit && androidActivity.window)
+         {
+            int w = ANativeWindow_getWidth(androidActivity.window);
+            int h = ANativeWindow_getHeight(androidActivity.window);
+            if(desktopW != w || desktopH != h)
+            {
+               guiApp.SetDesktopPosition(0, 0, w, h, true);
+               desktopW = w;
+               desktopH = h;
+               guiApp.desktop.Update(null);
+            }
+         }
+
+         eventAvailable = true;
          if(androidActivity.destroyRequested)
          {
             guiApp.desktop.Destroy(0);
             eventAvailable = true;
+            androidActivity.ident = (LooperID)-1;
          }
+         else if(processAll)
+            androidActivity.ident = (LooperID)ALooper_pollAll(0, null, &androidActivity.events, (void**)&androidActivity.source);
+         else
+            androidActivity.ident = (LooperID)-1;
       }
-
-      if(androidActivity.animating)
-         guiApp.desktop.Update(null);
-
-      if(!eventAvailable)
-         return false;
-      return true;
+      return eventAvailable;
    }
 
    void Wait()
    {
-      androidActivity.ident = (LooperID)ALooper_pollAll(androidActivity.animating ? 0 : -1, null, &androidActivity.events, (void**)&androidActivity.source);
+      androidActivity.ident = (LooperID)ALooper_pollAll((int)(1000/18.2f), null, &androidActivity.events, (void**)&androidActivity.source);
       // guiApp.WaitEvent();
    }
 
@@ -742,11 +756,15 @@ class AndroidInterface : Interface
       int rootWindow, childWindow;
       int mx, my;
       unsigned int state;
+
+      *x = mouseX;
+      *y = mouseY;
    }
 
    void SetMousePosition(int x, int y)
    {
-
+      mouseX = x;
+      mouseY = y;
    }
 
    void SetMouseRange(Window window, Box box)
@@ -776,7 +794,7 @@ class AndroidInterface : Interface
       if(window && window.windowData)
       {
       }
-   }  
+   }
 
    void ClearClipboard()
    {
@@ -790,7 +808,7 @@ class AndroidInterface : Interface
    {
       bool result = false;
       if((clipBoard.text = new0 byte[size]))
-         result = true;   
+         result = true;
       return result;
    }
 
@@ -862,7 +880,7 @@ class AndroidInterface : Interface
    void SetTimerResolution(uint hertz)
    {
       // timerDelay = hertz ? (1000000 / hertz) : MAXINT;
-   }  
+   }
 
    bool SetIcon(Window window, BitmapResource resource)
    {
@@ -887,6 +905,17 @@ struct SavedState
 
 static AndroidActivity androidActivity;
 
+default const char * AndroidInterface_GetLibLocation()
+{
+   if(androidActivity)
+   {
+      static char loc[MAX_LOCATION];
+      sprintf(loc, "/data/data/com.ecere.%s/lib/lib", androidActivity.moduleName);
+      return loc;
+   }
+   return null;
+}
+
 static bool gotInit;
 
 default float AMotionEvent_getAxisValue(const AInputEvent* motion_event,
@@ -1039,7 +1068,6 @@ class AndroidActivity : AndroidAppGlue
    const ASensor* accelerometerSensor;
    ASensorEventQueue* sensorEventQueue;
    */
-   bool animating;
    SavedState state;
 
    int onInputEvent(AInputEvent* event)
@@ -1071,7 +1099,7 @@ class AndroidActivity : AndroidAppGlue
          //PrintLn("Got a motion input event: ", action);
          /*
          if(action == 8) //AMOTION_EVENT_ACTION_SCROLL)
-            axis = AMotionEvent_getAxisValue(event, 9, index); //AMOTION_EVENT_AXIS_VSCROLL); 
+            axis = AMotionEvent_getAxisValue(event, 9, index); //AMOTION_EVENT_AXIS_VSCROLL);
          */
 
          AInputQueue_finishEvent(inputQueue, event, 1);
@@ -1083,12 +1111,15 @@ class AndroidActivity : AndroidAppGlue
                break;
                */
             case AMOTION_EVENT_ACTION_DOWN:
+               mouseX = x, mouseY = y;
                window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown, x, y, &keyFlags, false, true);
                break;
             case AMOTION_EVENT_ACTION_UP:
+               mouseX = x, mouseY = y;
                window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp, x, y, &keyFlags, false, true);
                break;
             case AMOTION_EVENT_ACTION_MOVE:
+               mouseX = x, mouseY = y;
                window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &keyFlags, false, true);
                break;
             case AMOTION_EVENT_ACTION_CANCEL: break;
@@ -1096,8 +1127,6 @@ class AndroidActivity : AndroidAppGlue
             case AMOTION_EVENT_ACTION_POINTER_DOWN: break;
             case AMOTION_EVENT_ACTION_POINTER_UP: break;
          }
-
-         animating = true;
          return 1;
       }
       else if(type == AINPUT_EVENT_TYPE_KEY)
@@ -1174,11 +1203,10 @@ class AndroidActivity : AndroidAppGlue
             }
             break;
          case termWindow:
-            animating = false;
             guiApp.desktop.UnloadGraphics(false);
             break;
          case gainedFocus:
-            androidActivity.animating = true;
+            guiApp.desktop.Update(null);
             guiApp.SetAppFocus(true);
             /*
             if(accelerometerSensor)
@@ -1193,10 +1221,13 @@ class AndroidActivity : AndroidAppGlue
             if(accelerometerSensor)
                ASensorEventQueue_disableSensor(sensorEventQueue, accelerometerSensor);
             */
-            animating = false;
             guiApp.SetAppFocus(false);
             guiApp.desktop.Update(null);
             break;
+         case configChanged:
+            if(window)
+               guiApp.desktop.UpdateDisplay();
+            break;
       }
    }
 
@@ -1214,7 +1245,7 @@ class AndroidActivity : AndroidAppGlue
 
       {
          Module app;
-          
+
          // Evolve the Application class into a GuiApplication
          eInstance_Evolve((Instance *)&__androidCurrentModule, class(GuiApplication));
 
@@ -1247,7 +1278,7 @@ class AndroidActivity : AndroidAppGlue
             }
 
             // Call Main()
-            __androidCurrentModule._vTbl[12](__androidCurrentModule);
+            ((void (*)(void *))(void *)__androidCurrentModule._vTbl[12])(__androidCurrentModule);
          }
 
          if(!destroyRequested)