menu.add(item);
bar.add(menu);
frame.setJMenuBar(bar);
final AWTCanvas canvas = ServiceLoader.load(ch.blackspirit.graphics.CanvasFactory.class).iterator().next()
.createAWTCanvas(true);
canvas.setGraphicsListener(new GraphicsListener() {
public void draw(View view, Graphics renderer) {
renderer.clear();
view.setCamera(-x, -y, 0);
renderer.clear();
for(int x = -2; x < 2; x++) {
for(int y = -2; y < 2; y++) {
renderer.translate(x * 44, y * image.getHeight());
renderer.drawImage(image, 44, image.getHeight(), 0, 0, 44, image.getHeight());
renderer.clearTransform();
}
}
}
public void sizeChanged(GraphicsContext context, View view) {
view.setSize(canvas.getWidth(), canvas.getHeight());
}
public void init(View view, Graphics renderer) {
view.setSize(canvas.getWidth(), canvas.getHeight());
}
});
// Integrate canvas into Swing frame
frame.getContentPane().add(canvas.getComponent());
frame.getContentPane().setPreferredSize(new Dimension(800,600));
frame.pack();
image = canvas.getImageFactory().createImage(
SwingDemo.class.getResource("/sprites/Crono - Walk (Left) 44x68.png"), true);
canvas.getComponent().addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent e) {
x += e.getX() - lastX;
y += e.getY() - lastY;
lastX = e.getX();
lastY = e.getY();
// Redraw the canvas
canvas.draw();
}
public void mouseMoved(MouseEvent e) {}
});
canvas.getComponent().addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
lastX = e.getX();
lastY = e.getY();
}