Refactoring.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 13 Jul 2018 23:05:19 +0000 (02:05 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 13 Jul 2018 23:05:19 +0000 (02:05 +0300)
src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java

index 87f0dd3..feda7df 100755 (executable)
@@ -31,12 +31,23 @@ public class ViewPanel extends JPanel implements ComponentListener {
     private Timer canvasUpdateTimer;
     private ViewUpdateTimerTask canvasUpdateTimerTask;
     private RenderingContext renderingContext = null;
+
+    /**
+     * UI component that mouse is currently hovering over.
+     */
     private MouseInteractionController currentMouseOverComponent;
+
+    /**
+     * Currently target FPS for this view. It can be changed at runtime. Also when nothing
+     * changes in the view, then frames are not really repainted.
+     */
+    private int targetFPS = 30;
+
     /**
-     * Currently target FPS for this view. It might change at runtime.
+     * Set to true if it is known than next frame reeds to be painted. Flag is cleared
+     * immediately after frame got updated.
      */
-    private int targetFramerate = 30;
-    private boolean repaintDuringNextViewUpdate = true;
+    private boolean viewRepaintNeeded = true;
 
     public ViewPanel() {
         viewRenderListeners.add(context.getAvatar());
@@ -47,7 +58,7 @@ public class ViewPanel extends JPanel implements ComponentListener {
 
         initializePanelLayout();
 
-        setFrameRate(targetFramerate);
+        setFrameRate(targetFPS);
 
         addComponentListener(this);
     }
@@ -68,12 +79,12 @@ public class ViewPanel extends JPanel implements ComponentListener {
 
     @Override
     public void componentResized(final ComponentEvent e) {
-        repaintDuringNextViewUpdate = true;
+        viewRepaintNeeded = true;
     }
 
     @Override
     public void componentShown(final ComponentEvent e) {
-        repaintDuringNextViewUpdate = true;
+        viewRepaintNeeded = true;
     }
 
     public ViewContext getContext() {
@@ -110,21 +121,21 @@ public class ViewPanel extends JPanel implements ComponentListener {
                 if (currentMouseOverComponent == null) {
                     currentMouseOverComponent = renderingContext.clickedItem;
                     currentMouseOverComponent.mouseEntered();
-                    repaintDuringNextViewUpdate = true;
+                    viewRepaintNeeded = true;
                 } else if (currentMouseOverComponent != renderingContext.clickedItem) {
                     currentMouseOverComponent.mouseExited();
                     currentMouseOverComponent = renderingContext.clickedItem;
                     currentMouseOverComponent.mouseEntered();
-                    repaintDuringNextViewUpdate = true;
+                    viewRepaintNeeded = true;
                 }
             } else {
                 // mouse click
                 renderingContext.clickedItem.mouseClicked();
-                repaintDuringNextViewUpdate = true;
+                viewRepaintNeeded = true;
             }
         } else if (currentMouseOverComponent != null) {
             currentMouseOverComponent.mouseExited();
-            repaintDuringNextViewUpdate = true;
+            viewRepaintNeeded = true;
             currentMouseOverComponent = null;
         }
     }
@@ -166,7 +177,7 @@ public class ViewPanel extends JPanel implements ComponentListener {
      * repainted on first opportunity.
      */
     public void repaintDuringNextViewUpdate() {
-        repaintDuringNextViewUpdate = true;
+        viewRepaintNeeded = true;
     }
 
     public void setFrameRate(final int frameRate) {
@@ -178,7 +189,7 @@ public class ViewPanel extends JPanel implements ComponentListener {
             canvasUpdateTimer = null;
         }
 
-        targetFramerate = frameRate;
+        targetFPS = frameRate;
 
         if (frameRate > 0) {
             canvasUpdateTimer = new Timer();
@@ -237,8 +248,8 @@ public class ViewPanel extends JPanel implements ComponentListener {
         if ((getWidth() <= 0) || (getHeight() <= 0))
             return;
 
-        if (repaintDuringNextViewUpdate) {
-            repaintDuringNextViewUpdate = false;
+        if (viewRepaintNeeded) {
+            viewRepaintNeeded = false;
             reRenderFrame = true;
         }