Revision: 2345
http://vexi.svn.sourceforge.net/vexi/?rev=2345&view=rev
Author: clrg
Date: 2007-09-27 10:05:10 -0700 (Thu, 27 Sep 2007)
Log Message:
-----------
Improve initial rendering - eliminates non-root-color flicker
Modified Paths:
--------------
trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java
Modified: trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java 2007-09-27 15:46:56 UTC
(rev 2344)
+++ trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java 2007-09-27 17:05:10 UTC
(rev 2345)
@@ -7,6 +7,7 @@
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Canvas;
+import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dialog;
@@ -311,14 +312,14 @@
g.fillRect(_x1, _y1, _x2 - _x1, _y2 - _y1);
}
}
- public void drawLine(int x1, int y1, int x2, int y2, int color)
{
- // TODO Auto-generated method stub
- throw new Error("FIXME: not yet implemented");
- }
- public void fillTriangle(int x1, int y1, int x2, int y2, int
x3, int y3, int color) {
- // TODO Auto-generated method stub
- throw new Error("FIXME: not yet implemented");
- }
+ public void drawLine(int x1, int y1, int x2, int y2, int color) {
+ // TODO Auto-generated method stub
+ throw new Error("FIXME: not yet implemented");
+ }
+ public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int
y3, int color) {
+ // TODO Auto-generated method stub
+ throw new Error("FIXME: not yet implemented");
+ }
}
@@ -354,23 +355,25 @@
public void setInvisible(boolean b) { window.setVisible(!b); }
public void setIcon(Picture i)
{
- if (frame == null) return;
- //frame.setIconImage(image);
+ if (frame == null) return;
+ //frame.setIconImage(image);
// BROKEN - setting the icon
// ... problem setting icon causes java to hang if from
AWTPicture's image
// ImageIcon(..).getImage() seems to work however.
// frame.setIconImage(((AWTPicture)i).i);
}
public void _setSize(int width, int height) {
- discoverInsets();
- window.setSize(width + (leftInset + rightInset), height +
(topInset + bottomInset));
+ discoverInsets();
+ //System.err.println("_setSize: "+width+", "+height
+ // +" ("+leftInset+", "+rightInset+", "+topInset+",
"+bottomInset+")");
+ window.setSize(width + (leftInset + rightInset), height +
(topInset + bottomInset));
}
protected void _setMinimized(boolean b) {
- Log.warn(this, "JDK 1.1 platforms cannot minimize or unminimize
windows");
+ Log.warn(this, "JDK 1.1 platforms cannot minimize or unminimize
windows");
}
protected void _setMaximized(boolean b) {
if (!b) {
- Log.warn(this, "JDK 1.1 platforms cannot unmaximize windows");
+ Log.warn(this, "JDK 1.1 platforms cannot unmaximize windows");
return;
}
window.setLocation(new Point(0, 0));
@@ -399,7 +402,7 @@
}
public InputMethodRequests getInputMethodRequests() {
// REMARK - makes us a passive client FOOTNOTE1
- return null;
+ return null;
}
}
@@ -416,8 +419,8 @@
refreshFromBackbuffer(r.x - leftInset, r.y - topInset,
r.width, r.height);
}
public InputMethodRequests getInputMethodRequests() {
- // REMARK - makes us a passive client FOOTNOTE1
- return null;
+ // REMARK - makes us a passive client FOOTNOTE1
+ return null;
}
}
@@ -431,71 +434,68 @@
bottomInset = i.bottom;
rightInset = i.right;
// respect the size of the root box
- window.setSize(pendingWidth + (leftInset + rightInset),
pendingHeight + (topInset + bottomInset));
+ window.setSize(pendingWidth + (leftInset + rightInset),
pendingHeight + (topInset + bottomInset));
}
/** sets the maximum size of the frame */
public void setMaximumSize(int maxw, int maxh) {
-
+
}
/** note that the minimum size is handled by getMinimumSize in
InnerFrame/InnerWindow */
public void setMinimumSize(int minx, int miny, boolean resizable) {
- if (frame != null) frame.setResizable(resizable);
- // FEATURE: Java 1.5
- //window.setMinimumSize(new
Dimension(root.minwidth+leftInset+rightInset,
root.minheight+topInset+bottomInset));
+ if (frame != null) frame.setResizable(resizable);
+ // FEATURE: Java 1.5
+ //window.setMinimumSize(new
Dimension(root.minwidth+leftInset+rightInset,
root.minheight+topInset+bottomInset));
}
- private int oldfill = 0x0;
+ private int rootfill = 0x0;
+ private Color rootcolor = null;
+ private final void setBackgroundColor() {
+ rootfill = root.fillcolor;
+ rootcolor = (rootfill & 0xFF000000) == 0 ? Color.white :
+ new Color((rootfill >> 16) & 0xff, (rootfill >> 8) & 0xff,
(rootfill) & 0xff);
+ window.setBackground(rootcolor);
+ }
+
public void render() {
// useful optimisation;
- if (oldfill != root.fillcolor) {
- oldfill = root.fillcolor;
- window.setBackground((root.fillcolor & 0xFF000000) == 0 ?
- java.awt.Color.white :
- new java.awt.Color((root.fillcolor >> 16)
& 0xff,
- (root.fillcolor >> 8) & 0xff,
- (root.fillcolor) & 0xff));
- }
+ if (rootfill != root.fillcolor) setBackgroundColor();
super.render();
}
AWTSurface(Box root, boolean framed) {
super(root);
- /*
- // fill the backbuffer with the root colour to prevent early
flicker
- // NOTE: is this really necessary?
- AWTPixelBuffer buf = (AWTPixelBuffer)backbuffer;
- buf.g.setColor(new java.awt.Color((root.fillcolor >> 16) & 0xff,
- (root.fillcolor >> 8) & 0xff,
- (root.fillcolor) & 0xff));
- buf.g.fillRect(0, 0, pendingWidth, pendingHeight);
- */
+
try {
if (framed) window = frame = new InnerFrame();
else window = new InnerWindow();
- setLocation();
- setSize(pendingWidth, pendingHeight);
-
// this is here to catch HeadlessException on jdk1.4
} catch (java.lang.UnsupportedOperationException e) {
Log.error(this, "Exception thrown in AWTSurface$InnerFrame()
-- this should never happen");
Log.error(this, e);
}
- if(frame!=null)
- frame.setIconImage(new
ImageIcon(Main.class.getResource("builtin/vexi-icon.png")).getImage());
+ // set the default icon image to the vexi logo
+ if (frame != null)
+ frame.setIconImage(new
ImageIcon(Main.class.getResource("builtin/vexi-icon.png")).getImage());
+
+
// Theoretically pack causes the insets to be calculated.
//
// AWT Bug - (Linux X11 at least)
// The insets calculated are not always exact. It seems
// that only a guess is returned.
- //
- //window.pack();
- //insets = window.getInsets();
+ window.pack();
+ setLocation();
+ setSize(pendingWidth, pendingHeight); // setSize handles the insets
- // Not setting size before showing the frame
- //setSize(root.maxwidth, root.maxheight);
+ // initialise the backbuffer and window with the root colour
+ // REMARK - this is for nicer initial rendering
+ setBackgroundColor();
+ AWTPixelBuffer buf = (AWTPixelBuffer)backbuffer;
+ buf.g.setColor(rootcolor);
+ buf.g.fillRect(0, 0, pendingWidth, pendingHeight);
window.addMouseListener(this);
window.addKeyListener(this);
@@ -564,44 +564,46 @@
public void componentMoved(ComponentEvent e) {
PosChange(window.getLocation().x, window.getLocation().y); }
public void componentResized(ComponentEvent e) {
- // Insets first known exactly on first componentResized
event
- // Before being set visible (AWT on top of XWindows at
least)
- // after pack it seems AWT guesses what the insets will
be
- // Take every time in case they change(?!)
+ // Insets first known exactly on first componentResized event
+ // Before being set visible (AWT on top of XWindows at least)
+ // after pack it seems AWT guesses what the insets will be
+ // Take every time in case they change(?!)
discoverInsets();
+ //System.err.println("componentResized: "+window.getWidth()+",
"+window.getHeight()
+ // +" ("+leftInset+", "+rightInset+", "+topInset+",
"+bottomInset+")");
componentResized(window.getWidth() - leftInset - rightInset,
window.getHeight() - topInset - bottomInset);
}
public void componentResized(int newwidth, int newheight) {
- // First we fill the expanded part of the buffer before
- // an old (dirty) copy of that buffer part gets painted
- AWTPixelBuffer buf = (AWTPixelBuffer)backbuffer;
- buf.g.setColor(new java.awt.Color((root.fillcolor >> 16) & 0xff,
+ // First we fill the expanded part of the buffer before
+ // an old (dirty) copy of that buffer part gets painted
+ AWTPixelBuffer buf = (AWTPixelBuffer)backbuffer;
+ buf.g.setColor(new java.awt.Color((root.fillcolor >> 16) & 0xff,
(root.fillcolor >> 8) & 0xff,
(root.fillcolor) & 0xff));
- if (pendingWidth < newwidth) {
- buf.g.fillRect(pendingWidth, 0, newwidth, newheight);
- dirty(pendingWidth, 0, newwidth-pendingWidth,
newheight);
- }
- if (pendingHeight < newheight) {
- buf.g.fillRect(0, pendingHeight, newwidth, newheight);
- dirty(0, pendingHeight, newwidth,
newheight-pendingHeight);
- }
- SizeChange(newwidth, newheight);
+ if (pendingWidth < newwidth) {
+ buf.g.fillRect(pendingWidth, 0, newwidth, newheight);
+ dirty(pendingWidth, 0, newwidth-pendingWidth, newheight);
+ }
+ if (pendingHeight < newheight) {
+ buf.g.fillRect(0, pendingHeight, newwidth, newheight);
+ dirty(0, pendingHeight, newwidth, newheight-pendingHeight);
+ }
+ SizeChange(newwidth, newheight);
}
public void keyTyped(KeyEvent k) {
- // REMARK - we are a so called 'passive Input Method' client.
- // We receive composed text (e.g. asian characters) as key
events
- // where we want to convert them into a keypressed/keyreleased
- // Vexi event. Unfortunately we need a way to distinguish
between
- // events due to inputMethods (which we want) and those from the
- // keyboard which are already handled via
keyPressed/keyReleased.
+ // REMARK - we are a so called 'passive Input Method' client.
+ // We receive composed text (e.g. asian characters) as key events
+ // where we want to convert them into a keypressed/keyreleased
+ // Vexi event. Unfortunately we need a way to distinguish between
+ // events due to inputMethods (which we want) and those from the
+ // keyboard which are already handled via keyPressed/keyReleased.
// HACK Simplest is to just except non-ascii chars.
- int unicode = (int)k.getKeyChar();
- if(255>= unicode) return;
- KeyPressed(""+k.getKeyChar());
- KeyReleased(""+k.getKeyChar());
+ int unicode = (int)k.getKeyChar();
+ if(255>= unicode) return;
+ KeyPressed(""+k.getKeyChar());
+ KeyReleased(""+k.getKeyChar());
}
public void keyPressed(KeyEvent k) { KeyPressed(translateKey(k)); }
public void keyReleased(KeyEvent k) { KeyReleased(translateKey(k)); }
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn