Create an app without awt panels, make GUI using Nifty or anything else, use viewports or custom rendering pipeline to have multiple ‘windows’.
For GUI there is an option to make something that is almost-awt, based on Picture objects which handles mouse events, with window+controls hierarchy etc. You just need to write some smart code and optimize the texture’s loading process - to fill the existing image instead of creating new one.
Here is an example:
public class GuiBaseWindow extends Picture implements GuiInterface
{
protected static final int TITLE_TOP = 60;
public static final float HEIGHT_HD = 1080f;
private boolean _visible;
private boolean _normalPaint;
private Texture2D _texture;
protected BufferedImage _image;
protected final int _width;
protected final int _height;
protected float _scale;
protected final int _group;
protected final int _zOrder;
private final boolean _paintStdBack;
protected ArrayList<GuiInterface> _children;
private GuiInterface _underMouse;
//protected GuiInterface _focusedChild;
//Trzeba tu zrobic funkcje repaint, paint component(g), liste komponentów i ogolnie ogarnąć jak w AWT
public GuiBaseWindow(AssetManager manager, String name, int width, int height, int group, int z)
{
this(manager, name, width, height, group, z, false);
}
public GuiBaseWindow(AssetManager manager, String name, int width, int height, int group, int z, boolean painted)
{
this(manager, name, width, height, group, z, painted, BufferedImage.TYPE_INT_ARGB, Format.RGBA8);
}
public GuiBaseWindow(AssetManager manager, String name, int width, int height, int group, int z,
boolean painted, int imageType, Format imageFormat)
{
super(name);
_children = new ArrayList<GuiInterface>();
setWidth(width);
setHeight(height);
setLocalTranslation(0, 0, (float)z);
_paintStdBack = painted;
_width = width;
_height = height;
_group = group;
_zOrder = z;
_image = new BufferedImage(width, height, imageType); //BufferedImage.TYPE_INT_ARGB);
_texture = new Texture2D(width, height, imageFormat);
setTexture(manager, _texture, true);
//applyImage();
_visible = true;
_normalPaint = true;
}
protected BufferedImage getMainImage()
{
return _image;
}
public boolean isVisible()
{
return _visible;
}
public void setVisible(boolean val)
{
if (val == _visible) return;
_visible = val;
if (val) repaint();
if (val) setCullHint(CullHint.Inherit);
else setCullHint(CullHint.Always);
}
//public void onFocus(GuiInterface child)
//{
//if (_focusedChild != child)
//{
// if (_focusedChild != null) _focusedChild.setFocused(false);
//
// _focusedChild = child;
// _focusedChild.setFocused(true);
// repaint();
//}
//}
//@Override
//public void setPosition(float x, float y)
//{
// super.setPosition(x, y);
// setTransformRefresh();
//}
public void setFocused(boolean value)
{
if (value == false) return;
//if (_focusedChild != null)
//{
// _focusedChild.setFocused(false);
// _focusedChild = null;
// repaint();
//}
}
public boolean isFocused()
{
return false; // Okno zawsze to zwraca
}
public void setParent(GuiInterface parent)
{
//Okna nie maja parenta
}
public void addChild(GuiInterface child)
{
_children.add(child);
child.setParent(this);
}
public int getGroup()
{
return _group;
}
public float getScale()
{
return _scale;
}
public int getZOrder()
{
return _zOrder;
}
protected void setNormalPaint(boolean val)
{
_normalPaint = val;
}
public void repaint()
{
if (!_normalPaint)
{
if (_visible) repaint(null);
Image fimg = Util.load(_image, true, _texture.getImage()); //_awtLoader.load(_image, true);
//Image fimg = _awtLoader.load(_image, true);
_texture.setImage(fimg);
return;
}
Graphics2D g = (Graphics2D)_image.getGraphics();
Util.activateAntiAliasing(g);
//prepareTextDraw(g);
//czyszczenie
if (_paintStdBack)
{
//g.setColor(Color.GRAY);
//g.fillRect(0, 0, _width, _height);
g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, _width, _height);
g.setComposite(AlphaComposite.SrcOver);
//BufferedImage img = ImageFactory.getInstance().BIMG_GUI_CHRCARD;
//g.drawImage(img, 0, 0, _width, _height,
// 0, 48, img.getWidth(), img.getHeight(), null);
int border = 23;
BufferedImage til = ImageFactory.getInstance().BIMG_WND_TILEABLE;
for (int y = border; y <= _height - border; y += til.getHeight())
{
int h = til.getHeight();
if (y + h > _height - border) h = _height - border - y;
for (int x = border; x < _width - border; x += til.getWidth())
{
int r = til.getWidth();
if (x + r > _width - border) r = _width - border - x;
g.drawImage(til, x, y, x + r, y + h, 0, 0, r, h, null);
}
}
BufferedImage img1 = ImageFactory.getInstance().BIMG_WND_FRAME_T;
BufferedImage img2 = ImageFactory.getInstance().BIMG_WND_FRAME_B;
for (int x = border; x < _width - border; x += img1.getWidth())
{
int r = img1.getWidth();
if (x + r > _width - border) r = _width - border - x;
g.drawImage(img1, x, 0, x + r, img1.getHeight(), 0, 0, r, img1.getHeight(), null);
g.drawImage(img2, x, _height - img2.getHeight(), x + r, _height,
0, 0, r, img2.getHeight(), null);
}
img1 = ImageFactory.getInstance().BIMG_WND_FRAME_L;
img2 = ImageFactory.getInstance().BIMG_WND_FRAME_R;
for (int y = border; y < _height - border; y += img1.getHeight())
{
int r = img1.getHeight();
if (y + r > _height - border) r = _height - border - y;
g.drawImage(img1, 0, y, img1.getWidth(), y + r, 0, 0, img1.getWidth(), r, null);
g.drawImage(img2, _width - img2.getWidth(), y, _width, y + r,
0, 0, img2.getWidth(), r, null);
}
img1 = ImageFactory.getInstance().BIMG_WND_CORNER_LT;
g.drawImage(img1, 0, 0, null);
img1 = ImageFactory.getInstance().BIMG_WND_CORNER_RT;
g.drawImage(img1, _width - img1.getWidth(), 0, null);
img1 = ImageFactory.getInstance().BIMG_WND_CORNER_LB;
g.drawImage(img1, 0, _height - img1.getHeight(), null);
img1 = ImageFactory.getInstance().BIMG_WND_CORNER_RB;
g.drawImage(img1, _width - img1.getWidth(), _height - img1.getHeight(), null);
}
else
{
g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, _width, _height);
g.setComposite(AlphaComposite.SrcOver);
}
if (_visible) repaint(g);
g.dispose();
Image fimg = Util.load(_image, true, _texture.getImage()); //_awtLoader.load(_image, true);
//Image fimg = _awtLoader.load(_image, true);
_texture.setImage(fimg);
}
public void repaint(Graphics2D g)
{
paintComponent(g);
//GuiInterface foc = null;
if (g == null) return;
for (GuiInterface gui : _children)
{
//if (gui == _focusedChild) continue; //Na koncu!
if (gui.isFocused()) continue;
Graphics co = g.create(gui.getPosX(), gui.getPosY(),
gui.getBaseWidth(), gui.getBaseHeight());
gui.repaint((Graphics2D)co);
co.dispose();
}
for (GuiInterface gui : _children)
{
//if (gui == _focusedChild) continue; //Na koncu!
if (!gui.isFocused()) continue;
Graphics co = g.create(gui.getPosX(), gui.getPosY(),
gui.getBaseWidth(), gui.getBaseHeight());
gui.repaint((Graphics2D)co);
co.dispose();
}
//if (_focusedChild != null)
//{
// Graphics co = g.create(_focusedChild.getPosX(), _focusedChild.getPosY(),
// _focusedChild.getWidth(), _focusedChild.getHeight());
// _focusedChild.repaint((Graphics2D)co);
// co.dispose();
//}
}
public void paintComponent(Graphics2D g)
{
}
public boolean isActiveArea(float parX, float parY)
{
if (!_visible) return false;
Vector3f pos = getLocalTranslation();
if (parX < pos.x) return false;
if (parY < pos.y) return false;
if (parX > pos.x + getLocalScale().x) return false;
if (parY > pos.y + getLocalScale().y) return false;
//TODO: test pixeli, czy klik na transparentnym
return true;
}
public boolean isAcceptDrag(int locX, int locY)
{
return false;
}
public void mouseExit()
{
if (_underMouse != null) _underMouse.mouseExit();
_underMouse = null;
}
public void mouseEnter()
{
if (_underMouse != null) _underMouse.mouseExit();
_underMouse = null;
}
public boolean mouseMove(int locX, int locY)
{
if (!_visible) return false;
GuiInterface mostUp = null;
for (GuiInterface gui : _children)
{
if (locX < gui.getPosX()) continue;
if (locY < gui.getPosY()) continue;
if (locX > gui.getPosX() + gui.getBaseWidth()) continue;
if (locY > gui.getPosY() + gui.getBaseHeight()) continue;
if (mostUp == null) mostUp = gui;
//if (mostUp == _focusedChild) break;
if (mostUp.isFocused()) break;
}
if (mostUp != _underMouse)
{
if (_underMouse != null) _underMouse.mouseExit();
_underMouse = mostUp;
if (_underMouse != null)
{
GuiManager.getInstance().setHint(null);
_underMouse.mouseEnter();
}
}
// To prawdopodobnie psuło
//if (mostUp == null)
//{
// if (_focusedChild != null)
// {
// _focusedChild.setFocused(false);
// _focusedChild = null;
// }
// return;
//}
if (mostUp != null)
{
return mostUp.mouseMove(locX - mostUp.getPosX(), locY - mostUp.getPosY());
}
return false;
}
public boolean mouseUp(int locX, int locY, int mb)
{
if (!_visible) return false;
GuiInterface mostUp = null;
for (GuiInterface gui : _children)
{
if (locX < gui.getPosX()) continue;
if (locY < gui.getPosY()) continue;
if (locX > gui.getPosX() + gui.getBaseWidth()) continue;
if (locY > gui.getPosY() + gui.getBaseHeight()) continue;
//if (mostUp == null)
mostUp = gui;
//if (mostUp == _focusedChild) break;
if (mostUp.isFocused()) break;
}
//if (mb == GuiManager.MB_LEFT)
{
for (GuiInterface gui : _children)
{
if (gui == mostUp) continue;
gui.setFocused(false);
}
}
if (mostUp == null) return false;
//{
// if (_focusedChild != null)
// {
// _focusedChild.setFocused(false);
// _focusedChild = null;
// }
// return false;
//}
return mostUp.mouseUp(locX - mostUp.getPosX(), locY - mostUp.getPosY(), mb);
}
public int getBaseWidth()
{
return _width;
}
public int getBaseHeight()
{
return _height;
}
public int getPosX()
{
return (int) getLocalTranslation().x;
}
public int getPosY()
{
return (int) getLocalTranslation().y;
}
/**
* Perform scale and positioning operations.
* @param w width
* @param h height
*/
public void screenSizeChanged(int w, int h)
{
_scale = h / HEIGHT_HD;
setWidth(_width * _scale);
setHeight(_height * _scale);
Vector3f pos = getLocalTranslation();
if (pos.x + _width > w) pos.x = w - _width;
//if (pos.y + _height > h) pos.y = h - _height;
if (pos.y > h) pos.y = h;
}
public void applyState(int guiState, boolean isGameScene)
{
for (GuiInterface g : _children)
{
g.applyState(guiState, isGameScene);
}
}
// Przerobiony AWT Loader
}