diff --git a/src/main/java/org/warp/picalculator/gui/DisplayManager.java b/src/main/java/org/warp/picalculator/gui/DisplayManager.java index d29d32bc..20f17723 100755 --- a/src/main/java/org/warp/picalculator/gui/DisplayManager.java +++ b/src/main/java/org/warp/picalculator/gui/DisplayManager.java @@ -40,7 +40,8 @@ public final class DisplayManager implements RenderingLoop { public String[] errorStackTrace; public final static int[] glyphsHeight; - public static Screen screen; + private static Screen screen; + public static Semaphore screenChange = new Semaphore(0); public static String displayDebugString; public static ObjectArrayList errorMessages; @@ -136,6 +137,7 @@ public final class DisplayManager implements RenderingLoop { try { screen.create(); DisplayManager.screen = screen; + screenChange.release(); if (screen.initialized == false) { screen.initialize(); } @@ -160,6 +162,7 @@ public final class DisplayManager implements RenderingLoop { try { screen.create(); DisplayManager.screen = screen; + screenChange.release(); if (screen.initialized == false) { screen.initialize(); } @@ -196,6 +199,7 @@ public final class DisplayManager implements RenderingLoop { DisplayManager.currentSession += 1; } DisplayManager.screen = DisplayManager.sessions[DisplayManager.currentSession]; + screenChange.release(); } } @@ -228,10 +232,11 @@ public final class DisplayManager implements RenderingLoop { DisplayManager.currentSession -= 1; } DisplayManager.screen = DisplayManager.sessions[DisplayManager.currentSession]; + screenChange.release(); } } - public Screen getScreen() { + public static Screen getScreen() { return DisplayManager.screen; } @@ -353,9 +358,10 @@ public final class DisplayManager implements RenderingLoop { renderer.glColor3i(255, 255, 255); if (error != null) { - Utils.getFont(false, false).use(engine); + BinaryFont fnt = Utils.getFont(false, false); + fnt.use(engine); renderer.glColor3i(129, 28, 22); - renderer.glDrawStringRight(Main.screenSize[0] - 2, Main.screenSize[1] - DisplayManager.glyphsHeight[1] - 2, "ANDREA CAVALLI'S CALCULATOR"); + renderer.glDrawStringRight(Main.screenSize[0] - 2, Main.screenSize[1] - (fnt.getCharacterHeight() + 2), Main.calculatorNameUPPER + " CALCULATOR"); renderer.glColor3i(149, 32, 26); renderer.glDrawStringCenter((Main.screenSize[0] / 2), 22, error); renderer.glColor3i(164, 34, 28); diff --git a/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockChar.java b/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockChar.java index 5b38892f..a59fdd93 100755 --- a/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockChar.java +++ b/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockChar.java @@ -40,7 +40,7 @@ public class BlockChar extends Block { @Override public void recomputeDimensions() { - width = BlockContainer.getDefaultCharWidth(small); + width = BlockContainer.getDefaultCharWidth(small)-1; height = BlockContainer.getDefaultCharHeight(small); line = height / 2; } diff --git a/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockVariable.java b/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockVariable.java index b4a29939..902e6022 100644 --- a/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockVariable.java +++ b/src/main/java/org/warp/picalculator/gui/expression/blocks/BlockVariable.java @@ -217,7 +217,6 @@ public class BlockVariable extends Block { @Override public void draw(GraphicEngine ge, Renderer r, Caret caret) { - BlockContainer.getDefaultFont(true).use(ge); r.glColor3f(1.0f, 1.0f, 1.0f); DisplayManager.guiSkin.use(ge); int popupX = location[0]; @@ -242,6 +241,7 @@ public class BlockVariable extends Block { r.glFillRect(popupX+2, popupY+5+height/2-7/2, 4, 7, 160, 21, 4, 7); r.glFillRect(popupX+width-2-4, popupY+5+height/2-7/2, 4, 7, 172, 21, 4, 7); r.glColor(color); + BlockContainer.getDefaultFont(true).use(ge); r.glDrawStringCenter(popupX+width/2, popupY+2+5, text); } diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java b/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java index 4e99a77f..e4ac1a63 100644 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java @@ -5,6 +5,7 @@ import java.awt.GraphicsEnvironment; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.ArrayList; +import java.util.concurrent.Semaphore; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; @@ -24,6 +25,7 @@ public class CPUEngine implements GraphicEngine { public final CPURenderer r = new CPURenderer(); public BufferedImage g = new BufferedImage(r.size[0], r.size[1], BufferedImage.TYPE_INT_RGB); public volatile boolean initialized = false; + public Semaphore exitSemaphore = new Semaphore(0); @Override public void setTitle(String title) { @@ -88,6 +90,7 @@ public class CPUEngine implements GraphicEngine { @Override public void destroy() { initialized = false; + exitSemaphore.release(); INSTANCE.setVisible(false); INSTANCE.dispose(); } @@ -123,7 +126,7 @@ public class CPUEngine implements GraphicEngine { @Deprecated() public void refresh() { - if (DisplayManager.screen == null || (DisplayManager.error != null && DisplayManager.error.length() > 0) || DisplayManager.screen == null || DisplayManager.screen.mustBeRefreshed()) { + if (DisplayManager.getScreen() == null || (DisplayManager.error != null && DisplayManager.error.length() > 0) || DisplayManager.getScreen() == null || DisplayManager.getScreen().mustBeRefreshed()) { INSTANCE.c.repaint(); } } @@ -175,11 +178,8 @@ public class CPUEngine implements GraphicEngine { @Override public void waitUntilExit() { try { - do { - Thread.sleep(500); - } while (initialized); - } catch (final InterruptedException e) { - + exitSemaphore.acquire(); + } catch (InterruptedException e) { } } diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java b/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java index e421d4a0..1ac46d27 100755 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java @@ -158,9 +158,9 @@ public class CPUFont implements BinaryFont { @Override public int getStringWidth(String text) { - final int w = (charW+1) * text.length(); + final int w = charW * text.length(); if (text.length() > 0 && w > 0) { - return w-1; + return w; } else { return 0; } diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPURenderer.java b/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPURenderer.java index 6c763702..a181cd9e 100644 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPURenderer.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/cpu/CPURenderer.java @@ -229,7 +229,7 @@ public class CPURenderer implements Renderer { int j; final int l = text.length; for (int i = 0; i < l; i++) { - cpos = (i * (currentFont.charW + 1)); + cpos = (i * (currentFont.charW)); final int charIndex = text[i]; for (int dy = 0; dy < currentFont.charH; dy++) { for (int dx = 0; dx < currentFont.charW; dx++) { diff --git a/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java b/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java index 5ab4675e..6f69f5c7 100755 --- a/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java +++ b/src/main/java/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java @@ -6,6 +6,7 @@ import java.util.Collections; import java.util.List; import java.util.Vector; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.Semaphore; import org.warp.picalculator.Main; import org.warp.picalculator.Utils; @@ -25,6 +26,7 @@ public class GPUEngine implements GraphicEngine { private GPURenderer r; int[] size = new int[] { Main.screenSize[0], Main.screenSize[1] }; private final CopyOnWriteArrayList registeredFonts = new CopyOnWriteArrayList(); + private Semaphore exitSemaphore = new Semaphore(0); @Override public int[] getSize() { @@ -94,6 +96,7 @@ public class GPUEngine implements GraphicEngine { public void destroy() { initialized = false; created = false; + exitSemaphore.release(); wnd.window.destroy(); } @@ -128,11 +131,8 @@ public class GPUEngine implements GraphicEngine { @Override public void waitUntilExit() { try { - do { - Thread.sleep(500); - } while (initialized | created); - } catch (final InterruptedException e) { - + exitSemaphore.acquire(); + } catch (InterruptedException e) { } } diff --git a/src/main/java/org/warp/picalculator/gui/screens/MathInputScreen.java b/src/main/java/org/warp/picalculator/gui/screens/MathInputScreen.java index 221d70a2..0ccd9986 100755 --- a/src/main/java/org/warp/picalculator/gui/screens/MathInputScreen.java +++ b/src/main/java/org/warp/picalculator/gui/screens/MathInputScreen.java @@ -618,10 +618,7 @@ public class MathInputScreen extends Screen { final ChooseVariableValueScreen cvs = new ChooseVariableValueScreen(this, new VariableValue((Variable) f, new Number(calc, 0))); DisplayManager.INSTANCE.setScreen(cvs); try { - while (DisplayManager.screen == cvs) { - Utils.out.println(1, Thread.currentThread().getName()); - Thread.sleep(200); - } + DisplayManager.screenChange.acquire(); } catch (final InterruptedException e) {} if (cvs.resultNumberValue == null) { cancelled = true; diff --git a/src/main/resources/font_32.rft b/src/main/resources/font_32.rft deleted file mode 100755 index fa9e6236..00000000 Binary files a/src/main/resources/font_32.rft and /dev/null differ diff --git a/src/main/resources/font_big.rft b/src/main/resources/font_big.rft index 2779f4db..44431625 100755 Binary files a/src/main/resources/font_big.rft and b/src/main/resources/font_big.rft differ diff --git a/src/main/resources/font_big_2x.rft b/src/main/resources/font_big_2x.rft index daaa6fa9..0b9e1ff3 100755 Binary files a/src/main/resources/font_big_2x.rft and b/src/main/resources/font_big_2x.rft differ diff --git a/src/main/resources/font_ex.rft b/src/main/resources/font_ex.rft index dfb6c85e..7e0e03b0 100755 Binary files a/src/main/resources/font_ex.rft and b/src/main/resources/font_ex.rft differ diff --git a/src/main/resources/font_small.rft b/src/main/resources/font_small.rft index ec1e2980..508ac551 100755 Binary files a/src/main/resources/font_small.rft and b/src/main/resources/font_small.rft differ diff --git a/src/main/resources/font_small_2x.rft b/src/main/resources/font_small_2x.rft index 66538376..55c45cf4 100755 Binary files a/src/main/resources/font_small_2x.rft and b/src/main/resources/font_small_2x.rft differ diff --git a/src/main/resources/font_square.rft b/src/main/resources/font_square.rft index d037f05a..17ecb485 100755 Binary files a/src/main/resources/font_square.rft and b/src/main/resources/font_square.rft differ