DEADSOFTWARE

gl: implement touch screen controls
[d2df-sdl.git] / src / game / renders / opengl / r_render.pas
index 9fa586aee5beb8782268231b0d02be8bc1996352..80783b6d7f82784d21db3a21ab4e1b90d29e7719 100644 (file)
@@ -93,6 +93,9 @@ implementation
     {$IFDEF ENABLE_SYSTEM}
       g_system,
     {$ENDIF}
+    {$IFDEF ENABLE_TOUCH}
+      r_touch,
+    {$ENDIF}
     {$IFDEF ENABLE_HOLMES}
       r_holmes,
     {$ENDIF}
@@ -286,12 +289,14 @@ implementation
   end;
 
   procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
-    var s: AnsiString;
+    var s: AnsiString; oldy: Integer;
   begin
     r_Common_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
 
     if p <> nil then
     begin
+      oldy := y;
+      if h < 239 then y := y - 32; (* hack: hide nickname on 640x400 *)
       r_Render_DrawHUD(x + w - 196 + 2, y, p);
       if p.Spectator then
       begin
@@ -301,6 +306,7 @@ implementation
         if p.NoRespawn then
           r_Common_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
       end;
+      y := oldy;
     end;
 
     if gShowPing and g_Game_IsClient then
@@ -392,7 +398,7 @@ implementation
   end;
 
   procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
-    var l, t, r, b, xx, yy: Integer;
+    var l, t, r, b, xx, yy, cx, cy: Integer;
   begin
     r_Draw_GetRect(l, t, r, b);
     r_Draw_SetRect(x, y, x + w, y + h);
@@ -400,32 +406,32 @@ implementation
     r_Common_GetCameraPos(p, true, xx, yy);
     if p <> nil then
     begin
+      r_Map_Draw(x, y, w, h, xx, yy, p, cx, cy);
       {$IFDEF ENABLE_HOLMES}
         if p = gPlayer1 then
         begin
-          r_Holmes_plrViewPos(x, y);
-          r_Holmes_plrViewSize(w, h);
+          r_Holmes_plrViewPos(cx, cy);
+          r_Holmes_plrViewSize(h, w);
         end;
       {$ENDIF}
-      r_Map_Draw(x, y, w, h, xx, yy, p);
       r_Render_DrawStatsView(x, y, w, h, p);
       if p.Spectator and p.NoRespawn then
         r_Common_DrawText(_lc[I_PLAYER_SPECT4], x div 2 + w div 2, y div 2 + h div 2, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
     end
     else
     begin
-      r_Map_Draw(x, y, w, h, xx, yy, nil);
+      r_Map_Draw(x, y, w, h, xx, yy, nil, cx, cy);
     end;
 
     r_Draw_SetRect(l, t, r, b);
   end;
 
   procedure r_Render_DrawMapView (x, y, w, h, camx, camy: Integer);
-    var l, t, r, b: Integer;
+    var l, t, r, b, cx, cy: Integer;
   begin
     r_Draw_GetRect(l, t, r, b);
     r_Draw_SetRect(x, y, x + w, y + h);
-    r_Map_Draw(x, y, w, h, camx, camy, nil);
+    r_Map_Draw(x, y, w, h, camx, camy, nil, cx, cy);
     r_Draw_SetRect(l, t, r, b);
   end;
 
@@ -1056,7 +1062,7 @@ implementation
       FPSTime := time;
     end;
 
-    r_Draw_Setup(gScreenWidth, gScreenHeight);
+    r_Draw_Setup(gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight);
 
     glClearColor(0.0, 0.0, 0.0, 0.0);
     glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
@@ -1237,7 +1243,9 @@ implementation
       r_Holmes_DrawUI;
     {$ENDIF}
 
-    // TODO draw touch screen controls
+    {$IFDEF ENABLE_TOUCH}
+      r_Touch_Draw;
+    {$ENDIF}
 
     sys_Repaint;
   end;
@@ -1248,8 +1256,8 @@ implementation
     gWinSizeY := h;
     gRC_Width := w;
     gRC_Height := h;
-    gScreenWidth := w;
-    gScreenHeight := h;
+    gScreenWidth := Round(w / r_pixel_scale);
+    gScreenHeight := Round(h / r_pixel_scale);
   end;
 
   procedure r_Render_Apply;
@@ -1286,8 +1294,7 @@ implementation
 {$IFDEF ENABLE_TOUCH}
   procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
   begin
-    // TODO implement touchscreen
-    founded := False;
+    r_Touch_GetKeyRect(key, x, y, w, h, founded)
   end;
 {$ENDIF}