-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterface.java
101 lines (87 loc) · 3.21 KB
/
Interface.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Main;
import static Main.MetaBalls.gl;
import com.sun.opengl.util.Animator;
import com.sun.opengl.util.GLUT;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.swing.JFrame;
/**
*
* @author Íèêèòà Ðóñåöêèé
*/
public class Interface extends JFrame {
static Listener myListener;
static GLCanvas canvas;
static Animator animator;
public Interface() {
init();
}
private void init() {
setSize(800, 800);
setTitle("Metaballs 2D");
setVisible(true);
setResizable(false);
setLocationRelativeTo(null);
myListener = new Listener();
canvas = new GLCanvas();
canvas.addKeyListener(myListener);
canvas.addMouseListener(myListener);
canvas.addMouseWheelListener(myListener);
canvas.addGLEventListener(new MetaBalls());
canvas.setBounds(0, 0, getWidth(), getHeight() - 30);
animator = new Animator(canvas);
add(canvas);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
animator.start();
}
public void drawText(GLAutoDrawable drawable, GLUT glut) {
gl.glColor4f(1f, 1f, 1f, 0.6f);
gl.glWindowPos2i(20, 20);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, "Press F1 for help");
gl.glWindowPos2i(drawable.getWidth() - 180, drawable.getHeight() - 20);
int space = 0;
String typeCalcName = "";
switch (Data.type) {
case 0:
typeCalcName = "Blocks";
space = 100;
break;
case 1:
typeCalcName = "Marching Squares";
space = 180;
break;
case 2:
typeCalcName = "Interpolated";
space = 140;
break;
}
gl.glColor4f(1f, 1f, 1f, 0.6f);
gl.glWindowPos2i(drawable.getWidth() - 200, drawable.getHeight() - 25);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, "Grid Dimension: " + Data.gridStep);
gl.glWindowPos2i(drawable.getWidth() - 130, drawable.getHeight() - 45);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, "Speed: " + Data.speedCoef);
gl.glWindowPos2i(drawable.getWidth() - 110, drawable.getHeight() - 65);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, "Size: " + Data.circleSize);
gl.glWindowPos2i(drawable.getWidth() - 139, drawable.getHeight() - 85);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, "Number: " + Data.circleCount);
gl.glWindowPos2i(drawable.getWidth() - space, 20);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, typeCalcName);
}
}