kba / lanterna

Automatically exported from code.google.com/p/lanterna
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Ability to Eliminate Window Shadow #105

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Some terminals don't support colors and thus the window shadow is simply wasted 
space.  I fixed this by creating a "No Shadow Theme", with some minor changes 
to GUIScreen and Theme classes.  

Example Use:
   GUIScreen gui = TerminalFacade.createGUIScreen();
   DefaultBackgroundRenderer render = 
      new DefaultBackgroundRenderer();      
   gui.setTheme(new NoShadowTheme()); // <--- 
   gui.setBackgroundRenderer(render);
   gui.getScreen().startScreen();

================================================
Patch
================================================

diff --git a/Lanterna-Test/src/NoShadowTheme.java 
b/Lanterna-Test/src/NoShadowTheme.java
new file mode 100644
index 0000000..d6e3aa8
--- /dev/null
+++ b/Lanterna-Test/src/NoShadowTheme.java
@@ -0,0 +1,11 @@
+import com.googlecode.lanterna.gui.Theme;
+
+
+public class NoShadowTheme extends Theme {
+
+   public NoShadowTheme() {
+       super();
+       setDefinition(Category.SHADOW, null);
+   }
+
+}
diff --git a/Lanterna-Test/src/com/googlecode/lanterna/gui/GUIScreen.java 
b/Lanterna-Test/src/com/googlecode/lanterna/gui/GUIScreen.java
index d7c547b..9f78474 100644
--- a/Lanterna-Test/src/com/googlecode/lanterna/gui/GUIScreen.java
+++ b/Lanterna-Test/src/com/googlecode/lanterna/gui/GUIScreen.java
@@ -181,8 +181,8 @@
                     new TerminalSize(preferredSize.getColumns(), preferredSize.getRows()));

             //First draw the shadow
-            Definition shadowDef = 
guiTheme.getDefinition(Theme.Category.SHADOW);
-            if (shadowDef != null) {
+            if (guiTheme.hasDefinition(Theme.Category.SHADOW)) {
+               Definition shadowDef = 
guiTheme.getDefinition(Theme.Category.SHADOW);
                textGraphics.applyTheme(shadowDef);
                textGraphics.fillRectangle(
                        ' ',
diff --git a/Lanterna-Test/src/com/googlecode/lanterna/gui/Theme.java 
b/Lanterna-Test/src/com/googlecode/lanterna/gui/Theme.java
index d3c7f8a..6275946 100644
--- a/Lanterna-Test/src/com/googlecode/lanterna/gui/Theme.java
+++ b/Lanterna-Test/src/com/googlecode/lanterna/gui/Theme.java
@@ -80,12 +80,16 @@
     }

     public Theme.Definition getDefinition(Category category) {
-        if (styles.containsKey(category) && styles.get(category) != null) {
+        if (hasDefinition(category)) {
             return styles.get(category);
         }

         return getDefault();
     }
+    
+    public boolean hasDefinition (Category category) {
+       return (styles.containsKey(category) && styles.get(category) != null);
+    }

     protected void setDefinition(Category category, Definition def) {
         if (def == null) {

Original issue reported on code.google.com by kitz...@gmail.com on 12 May 2014 at 12:48

GoogleCodeExporter commented 9 years ago
Oops.  Patch for GUIScreen is incorrect.  This is better...

@@ -19,6 +19,7 @@

 package com.googlecode.lanterna.gui;

+import com.googlecode.lanterna.gui.Theme.Definition;
 import com.googlecode.lanterna.gui.listener.WindowAdapter;
 import com.googlecode.lanterna.input.Key;
 import com.googlecode.lanterna.screen.Screen;
@@ -180,11 +181,17 @@
                     new TerminalSize(preferredSize.getColumns(), preferredSize.getRows()));

             //First draw the shadow
-            
textGraphics.applyTheme(guiTheme.getDefinition(Theme.Category.SHADOW));
-            textGraphics.fillRectangle(' ', new 
TerminalPosition(topLeft.getColumn() + 2, topLeft.getRow() + 1),
-                    new TerminalSize(subGraphics.getWidth(), 
subGraphics.getHeight()));
-
-            //Then draw the window
+            if (guiTheme.hasDefinition(Theme.Category.SHADOW)) {
+               Definition shadowDef = 
guiTheme.getDefinition(Theme.Category.SHADOW);
+               textGraphics.applyTheme(shadowDef);
+               textGraphics.fillRectangle(
+                       ' ',
+                       new TerminalPosition(topLeft.getColumn() + 2, topLeft
+                               .getRow() + 1),
+                       new TerminalSize(subGraphics.getWidth(), subGraphics
+                               .getHeight()));
+           }
+           //Then draw the window
             windowPlacement.getWindow().repaint(subGraphics);
         }

Original comment by kitz...@gmail.com on 12 May 2014 at 1:07

GoogleCodeExporter commented 9 years ago
Well, the theme system in 2.x is pretty useless as it is, I think we can just 
add a new property to either GUISystem or Window, to set if the shadow should 
be rendered or not.

For 3.x, I hope to have come up with a better solution altogether.

Original comment by mab...@gmail.com on 8 Jun 2014 at 12:58

GoogleCodeExporter commented 9 years ago
I've added Window.setDrawShadow(..) on the release/2.1 branch. Please give it a 
try if you can.

Original comment by mab...@gmail.com on 9 Jun 2014 at 1:17