mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-10-12 01:45:18 +02:00
Pausieren der ZM implementiert
This commit is contained in:
@@ -81,6 +81,9 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
|
|||||||
// Aktueller Zustand der Zeichenmaschine.
|
// Aktueller Zustand der Zeichenmaschine.
|
||||||
private Options.AppState state = Options.AppState.INITIALIZING;
|
private Options.AppState state = Options.AppState.INITIALIZING;
|
||||||
private boolean running = false;
|
private boolean running = false;
|
||||||
|
private boolean pause_pending = false;
|
||||||
|
|
||||||
|
private boolean stop_after_update = false, run_once = true;
|
||||||
|
|
||||||
// Aktuelle Frames pro Sekunde der Zeichenmaschine.
|
// Aktuelle Frames pro Sekunde der Zeichenmaschine.
|
||||||
private int framesPerSecond;
|
private int framesPerSecond;
|
||||||
@@ -278,6 +281,9 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
|
|||||||
* im Zeichenfenster an.
|
* im Zeichenfenster an.
|
||||||
*/
|
*/
|
||||||
public final void redraw() {
|
public final void redraw() {
|
||||||
|
if( state == Options.AppState.PAUSED ) {
|
||||||
|
draw();
|
||||||
|
}
|
||||||
canvas.render();
|
canvas.render();
|
||||||
// canvas.invalidate();
|
// canvas.invalidate();
|
||||||
// frame.repaint();
|
// frame.repaint();
|
||||||
@@ -285,6 +291,36 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
|
|||||||
// show();
|
// show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pausiert die Ausführung von {@link #update(double)} und {@link #draw()}
|
||||||
|
* nach dem nächsten vollständigen Frame.
|
||||||
|
* <p>
|
||||||
|
* Die Zeichenmaschine wechselt in den Zustand {@link Options.AppState#PAUSED},
|
||||||
|
* sobald der aktuelle Frame beendet wurde.
|
||||||
|
*/
|
||||||
|
public final void pause() {
|
||||||
|
pause_pending = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt die Ausführung der Zeichenmaschine fort, nachdem diese mit
|
||||||
|
* {@link #pause()} pausiert wurde.
|
||||||
|
*/
|
||||||
|
public final void resume() {
|
||||||
|
pause_pending = false;
|
||||||
|
if( state == Options.AppState.PAUSED ) {
|
||||||
|
state = Options.AppState.RUNNING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prüft, ob die Zeichenmaschine gerade pausiert ist.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public final boolean isPaused() {
|
||||||
|
return state == Options.AppState.PAUSED;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stoppt den Zeichenthread. Nachdem der aktuelle Frame gezeichnet wurde
|
* Stoppt den Zeichenthread. Nachdem der aktuelle Frame gezeichnet wurde
|
||||||
* wird {@link #teardown()} aufgerufen. Das Programm wird nicht beendet und
|
* wird {@link #teardown()} aufgerufen. Das Programm wird nicht beendet und
|
||||||
|
|||||||
Reference in New Issue
Block a user