-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbSIRDlet.java
168 lines (143 loc) · 4.64 KB
/
AbSIRDlet.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//
// AbSIRDlet - A real-time SIRDS drawing applet
//
// Written by Lewey Geselowitz
// http://www.leweyg.com
//
import java.awt.event.*;
import java.awt.image.*;
import java.applet.*;
import java.util.*;
import java.awt.*;
import java.net.*;
public class AbSIRDlet implements SIRDSlet
{
private SIRDSAppletManager mManager;
private ZSprite mZBuffer;
private ZDraw mDrawArea;
private int mWidth, mHeight;
private boolean mUseSIRD = true;
private int mCurMX, mCurMY, mCurrentZ;
private int mLastMX, mLastMY;
private int mDrawRadius;
private final int mPalWidth = 40;
private SceneManager mScene;
private void DrawPallette()
{
int y;
int ny;
for (int i=0; i<ZDraw.MAXZ; i++)
{
y = (i*mWidth)/ZDraw.MAXZ;
ny= ((i+1)*mWidth)/ZDraw.MAXZ;
mZBuffer.fillRect(mWidth-mPalWidth, y,
mPalWidth, ny-y, i);
}
}
public void start(Object manager, int option){
mDrawRadius = 10;
mCurrentZ = 10;
mManager=(SIRDSAppletManager)manager;
mScene=mManager.getSceneManager();
mManager.setShowFloaterCursor(true);
mManager.setAllowSaving(true);
mManager.setAllowLoading(true);
mWidth = mManager.getSize().width;
mHeight = mManager.getSize().height;
mZBuffer = new ZSprite(mScene.width, mScene.height);
mScene.addPrimitive(mZBuffer);
mDrawArea = new ZDraw(mZBuffer.data, mWidth-mPalWidth-ZDraw.SIRDW,
mHeight, ZDraw.SIRDW, mZBuffer.stride );
DrawPallette();
Floater f=mScene.setFloaterText("position","Position: ",0xffddddcc);
f.z=2;
int lineHeight=f.h;
f=mScene.setFloaterText("xpos","x: ?",0xffddddcc);
f.y=lineHeight;
f=mScene.setFloaterText("ypos","y: ?",0xffddddcc);
f.y=2*lineHeight;
f=mScene.setFloaterText("zpos","z: ?",0xffddddcc);
f.y=3*lineHeight;
f=mScene.setFloaterText("pen","pen-size: "+mDrawRadius,0xffddddcc);
f.y=4*lineHeight;
mScene.floaters.setFloater("apenmouse",new Floater(2*mDrawRadius,2*mDrawRadius));
updatePenInformation();
//f.ignoreHeightmap=false;
}
public void stop(){
mManager.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
public void paintFrame(){
}
public void calculateFrame(long timeMS){
if (mManager.isMousePressed(MouseEvent.BUTTON1)){
if (mManager.isMousePressedChanged(MouseEvent.BUTTON1)){
mDrawArea.mIgnoreZ=mManager.isKeyPressed(KeyEvent.VK_CONTROL);
mDrawArea.fillCircle( mManager.getMouseX()-ZDraw.SIRDW, mManager.getMouseY(), mDrawRadius, mCurrentZ );
if (mManager.getMouseX() + mPalWidth > mWidth)
{
mCurrentZ = (mManager.getMouseY() * ZDraw.MAXZ) / mHeight;
}
} else {
mDrawArea.mIgnoreZ=mManager.isKeyPressed(KeyEvent.VK_CONTROL);
mDrawArea.DrawLine( mManager.getMouseX()-ZDraw.SIRDW, mManager.getMouseY(),
mLastMX-ZDraw.SIRDW, mLastMY, mDrawRadius, mCurrentZ);
}
}
mLastMX = mManager.getMouseX();
mLastMY = mManager.getMouseY();
if (mCurMX!=mLastMX || mCurMY!=mLastMY){
mCurMX=mLastMX;
mCurMY=mLastMY;
drawInformation();
}
if (mManager.isKeyPressed(KeyEvent.VK_A)){
mCurrentZ+=1+ZDraw.MAXZ/50;
if (mCurrentZ>ZDraw.MAXZ) mCurrentZ=ZDraw.MAXZ;
} else if (mManager.isKeyPressed(KeyEvent.VK_S)){
mCurrentZ-=1+ZDraw.MAXZ/50;
if (mCurrentZ<0) mCurrentZ=0;
} else if (mManager.isKeyPressed(KeyEvent.VK_D)){
mDrawRadius+=1;
updatePenInformation();
} else if (mManager.isKeyPressed(KeyEvent.VK_F)){
mDrawRadius-=1;
updatePenInformation();
}
drawInformation();
}
private void updatePenInformation(){
mScene.setFloaterText("pen","pen-size: "+mDrawRadius,0xffddddcc);
Floater f=(Floater)mScene.floaters.getFloater("apenmouse");
if (2*mDrawRadius>=mZBuffer.SIRDW) return;
if (f.w<2*mDrawRadius || f.h<2*mDrawRadius) f.setSize(2*mDrawRadius,2*mDrawRadius);
f.clear();
f.fillCircle(f.w/2,f.h/2, mDrawRadius,0x88ee8800);
f.fillCircle(f.w/2+1,f.h/2, 2,0xff000000);
}
private void drawInformation(){
mScene.setFloaterText("xpos","x: "+mCurMX,0xffddddcc);
mScene.setFloaterText("ypos", "y: "+mCurMY,0xffddddcc);
mScene.setFloaterText("zpos","z: "+ mCurrentZ,0xffddddcc);
mManager.setFloaterCursorZ(mCurrentZ+3);
Floater mf=(Floater) mScene.floaters.getFloater("apenmouse");
mf.x=mCurMX-mf.w/2;
mf.y=mCurMY-mf.h/2;
mf.z=mCurrentZ;
}
public String getName(){
return Translations.getInstance().AbSIRDS();
}
public String getDescription(){
return Translations.getInstance().AbSIRDSDesc();
}
public String getKeys(){
return Translations.getInstance().AbSIRDSKeys();
}
public String[] getPossibleOptions(){
return new String[0];
}
public int getDefaultOption(){
return 0;
}
}