mirror of
https://github.com/macocianradu/javaGUItoolkit.git
synced 2026-03-18 13:40:04 +00:00
improved efficiency
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<Window Name="window" Visible="true" Size="640, 480">
|
||||
<!-- <Panel Name="MainPanel" BackgroundColor="#FFFFFF" Size="1.0, 1.0" Overlapping="false">-->
|
||||
<Button Name="button1" BackgroundColor="#990000" Size="0.5, 0.5" Label="button1">
|
||||
<Button Name="button4" BackgroundColor="#009999" Size="0.3, 0.3" Icon="square_white">
|
||||
<Button Name="button2" BackgroundColor="#000099" Size="50, 50" Label="button2"/>
|
||||
</Button>
|
||||
<Panel Name="MainPanel" BackgroundColor="#999999" Size="1.0, 1.0" Overlapping="true">
|
||||
<Button Name="button1" BackgroundColor="#990000" Size="0.5, 0.5" Location="0.0, 0.0" Label="button1">
|
||||
<Button Name="button4" BackgroundColor="#009999" Size="0.3, 0.3" Icon="square_white">
|
||||
<Button Name="button2" BackgroundColor="#000099" Size="50, 50" Label="button2"/>
|
||||
</Button>
|
||||
<Button Name="button6" BackgroundColor="#555555" Location="320, 0" Size="0.5, 0.5"/>
|
||||
<Button Name="button3" BackgroundColor="#009900" Size="100, 100" Location="300, 300" Icon="close_black"/>
|
||||
<!-- </Panel>-->
|
||||
</Button>
|
||||
<Button Name="button6" BackgroundColor="#555555" Location="0.5, 0.5" Size="0.5, 0.5"/>
|
||||
<Button Name="button3" BackgroundColor="#009900" Size="0.5, 0.5" Location="0.5, 0.0" Icon="close_black"/>
|
||||
<!-- <Button Name="button3" BackgroundColor="#123456" Size="0.5, 0.5" Location="0.5, 0.0" Icon="minimize_white"/>-->
|
||||
</Panel>
|
||||
</Window>
|
||||
@@ -12,7 +12,7 @@ public class Main {
|
||||
try{
|
||||
Window window = XAMLParser.parse("ui.xml");
|
||||
assert window != null;
|
||||
window.revalidate();
|
||||
window.repaint();
|
||||
Button button = (Button)window.findByName("button3");
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
@@ -24,11 +24,11 @@ public class Main {
|
||||
else {
|
||||
panel.setOverlapping(true);
|
||||
}
|
||||
window.revalidate();
|
||||
window.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
window.revalidate();
|
||||
window.repaint();
|
||||
System.out.println(Float.parseFloat("3"));
|
||||
long now;
|
||||
long prev = 0;
|
||||
|
||||
@@ -38,30 +38,30 @@ public class Button extends Visual {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
pressed = true;
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent mouseEvent) {
|
||||
pressed = false;
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent mouseEvent) {
|
||||
hovered = true;
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent mouseEvent) {
|
||||
hovered = false;
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent mouseEvent) {
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent mouseEvent) {
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ public class Visual {
|
||||
private Float relativeHeight;
|
||||
private Integer locationX;
|
||||
private Integer locationY;
|
||||
private Float relativeX;
|
||||
private Float relativeY;
|
||||
private Color backgroundColor;
|
||||
private Color foregroundColor;
|
||||
private Color fontColor;
|
||||
@@ -78,6 +80,8 @@ public class Visual {
|
||||
this.height = height;
|
||||
this.relativeWidth = -1.0f;
|
||||
this.relativeHeight = -1.0f;
|
||||
this.relativeX = -1.0f;
|
||||
this.relativeY = -1.0f;
|
||||
|
||||
this.locationX = 0;
|
||||
this.locationY = 0;
|
||||
@@ -107,6 +111,9 @@ public class Visual {
|
||||
if(v.relativeHeight > 0.0 || v.relativeWidth > 0.0) {
|
||||
v.setSize();
|
||||
}
|
||||
if(v.relativeX >= 0.0 || v.relativeY >= 0.0) {
|
||||
v.setLocation();
|
||||
}
|
||||
}
|
||||
this.dirty = true;
|
||||
this.notifyParent(SIZE_CHANGED);
|
||||
@@ -124,11 +131,30 @@ public class Visual {
|
||||
setSize();
|
||||
}
|
||||
|
||||
public void setLocation() {
|
||||
if(parent != null) {
|
||||
if(relativeX >= 0.0) {
|
||||
locationX = Math.round(relativeX * parent.width);
|
||||
}
|
||||
if(relativeY >= 0.0) {
|
||||
locationY = Math.round(relativeY * parent.height);
|
||||
}
|
||||
}
|
||||
|
||||
this.dirty = true;
|
||||
notifyParent(LOCATION_CHANGED);
|
||||
}
|
||||
|
||||
public void setLocation(Float x, Float y) {
|
||||
relativeX = x;
|
||||
relativeY = y;
|
||||
setLocation();
|
||||
}
|
||||
|
||||
public void setLocation(Integer x, Integer y) {
|
||||
this.locationX = x;
|
||||
this.locationY = y;
|
||||
this.dirty = true;
|
||||
notifyParent(LOCATION_CHANGED);
|
||||
setLocation();
|
||||
}
|
||||
|
||||
public void setLocationX(Integer x) {
|
||||
@@ -251,22 +277,20 @@ public class Visual {
|
||||
}
|
||||
}
|
||||
|
||||
private void repaint() {
|
||||
this.paint(imageBuffer);
|
||||
public void repaint() {
|
||||
if(!this.active){
|
||||
return;
|
||||
}
|
||||
if(this.dirty) {
|
||||
this.revalidate();
|
||||
return;
|
||||
}
|
||||
for(Visual v: children) {
|
||||
v.repaint();
|
||||
imageBuffer.getGraphics().drawImage(v.imageBuffer, v.locationX, v.locationY, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void revalidate() {
|
||||
if(!this.active){
|
||||
return;
|
||||
}
|
||||
private void revalidate() {
|
||||
clearImageBuffer();
|
||||
this.paint(imageBuffer);
|
||||
for (Visual v : children) {
|
||||
@@ -280,7 +304,7 @@ public class Visual {
|
||||
}
|
||||
Window window = (Window)this;
|
||||
window.setFrameImageBuffer(imageBuffer);
|
||||
window.repaint();
|
||||
window.revalidate();
|
||||
}
|
||||
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
@@ -449,7 +473,6 @@ public class Visual {
|
||||
|
||||
private void activate() {
|
||||
this.active = true;
|
||||
this.imageBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
for(Visual child: children) {
|
||||
child.activate();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ public class Window extends Visual {
|
||||
private TitleBar titleBar;
|
||||
private Panel mainPanel;
|
||||
private Panel contentPanel;
|
||||
private ResizeListener windowResizeListener;
|
||||
private Point2d oldSize;
|
||||
private Point2d oldLocation;
|
||||
|
||||
@@ -31,25 +30,7 @@ public class Window extends Visual {
|
||||
this.setUndecorated(true);
|
||||
this.addWindowStateListener(e -> {
|
||||
this.setSize(getWidth(), getHeight());
|
||||
revalidate();
|
||||
});
|
||||
Direction[] directions = {Direction.SOUTH, Direction.EAST, Direction.WEST};
|
||||
windowResizeListener = new ResizeListener(directions, new Point2d(getWidth(), getHeight()), new Point2d(getLocationX(), getLocationY()));
|
||||
this.addMouseListener(windowResizeListener);
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent mouseEvent) {
|
||||
setSize(windowResizeListener.size.x, windowResizeListener.size.y);
|
||||
setLocation(windowResizeListener.location.x, windowResizeListener.location.y);
|
||||
}
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent mouseEvent) {
|
||||
frame.setCursor(windowResizeListener.cursor);
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent mouseEvent) {
|
||||
frame.setCursor(windowResizeListener.cursor);
|
||||
}
|
||||
repaint();
|
||||
});
|
||||
this.mainPanel = new Panel();
|
||||
|
||||
@@ -77,9 +58,8 @@ public class Window extends Visual {
|
||||
else {
|
||||
contentPanel.setSize(width, height);
|
||||
}
|
||||
windowResizeListener.setSize(width, height);
|
||||
mainPanel.setSize(width, height);
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setFrameImageBuffer(BufferedImage imageBuffer){
|
||||
@@ -87,7 +67,7 @@ public class Window extends Visual {
|
||||
this.frame.repaint();
|
||||
}
|
||||
|
||||
public void repaint() {
|
||||
public void revalidate() {
|
||||
this.frame.repaint();
|
||||
}
|
||||
|
||||
@@ -171,7 +151,6 @@ public class Window extends Visual {
|
||||
|
||||
public void setLocation(int x, int y) {
|
||||
this.frame.setLocation(x, y);
|
||||
windowResizeListener.setLocation(x, y);
|
||||
}
|
||||
|
||||
public void setMainPanel(Panel panel) {
|
||||
|
||||
Reference in New Issue
Block a user