Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
206 | ligi | 1 | /*************************************************************** |
2 | * |
||
3 | * Code for on Device Debugging of DUBwise |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
6 | * Mailto: LiGi @at@ LiGi DOTT de |
||
7 | * |
||
8 | ***************************************************************/ |
||
9 | |||
10 | import javax.microedition.lcdui.*; |
||
11 | |||
12 | |||
13 | public class DUBwiseDebug |
||
14 | extends Canvas |
||
15 | { |
||
16 | |||
17 | |||
18 | public boolean showing=false; |
||
19 | public boolean paused=false; |
||
20 | |||
21 | public String debug_msg=""; |
||
22 | |||
23 | private byte[] debug_screen_sequence={KEY_POUND,KEY_NUM4,KEY_NUM2}; |
||
24 | private byte debug_screen_sequence_pos=0; |
||
25 | |||
26 | |||
27 | public final static int DEBUG_HISTORY_LENGTH=100; |
||
28 | |||
29 | |||
30 | public String[] debug_msgs; |
||
31 | |||
32 | public int debug_pos=0; |
||
33 | public int debug_paused_pos=0; |
||
34 | |||
35 | |||
36 | int y_off=0; |
||
37 | |||
38 | |||
39 | public DUBwiseCanvas canvas; |
||
40 | |||
41 | public DUBwiseDebug(DUBwiseCanvas canvas_) |
||
42 | { |
||
43 | canvas=canvas_; |
||
44 | |||
45 | debug_msgs=new String[DEBUG_HISTORY_LENGTH]; |
||
46 | for (int tmp_i=0;tmp_i<DEBUG_HISTORY_LENGTH;tmp_i++) |
||
47 | debug_msgs[tmp_i]=""; |
||
48 | } |
||
49 | |||
50 | public void log(String str) |
||
51 | { |
||
52 | if (debug_pos==DEBUG_HISTORY_LENGTH) |
||
53 | debug_pos=0; |
||
54 | |||
55 | debug_msgs[debug_pos]=str; |
||
56 | debug_pos++; |
||
57 | // debug_msgs[debug_pos]=str; |
||
58 | } |
||
59 | |||
60 | |||
61 | public void err(String str) |
||
62 | { |
||
63 | if (debug_pos==DEBUG_HISTORY_LENGTH) |
||
64 | debug_pos=0; |
||
65 | |||
66 | debug_msgs[debug_pos]=str; |
||
67 | debug_pos++; |
||
68 | showing=false; |
||
69 | paused=true; |
||
70 | // debug_msgs[debug_pos]=str; |
||
71 | } |
||
72 | |||
73 | public void paint (Graphics g) |
||
74 | { |
||
75 | |||
76 | Font debug_font= Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); |
||
77 | |||
78 | g.setFont(debug_font); |
||
79 | |||
80 | g.setColor(0x0000FF); |
||
81 | g.fillRect(0,0,canvas.getWidth(),canvas.getHeight()); |
||
82 | g.setColor(0xFFFFFF); |
||
83 | |||
84 | y_off=0; |
||
85 | if (!paused) debug_paused_pos=debug_pos; |
||
86 | for (int tmp_pos=debug_paused_pos;((tmp_pos>0)&&(y_off<canvas.getHeight()));tmp_pos--) |
||
87 | { |
||
88 | debug_msg=debug_msgs[tmp_pos]; |
||
89 | String tmp_str=""; |
||
90 | |||
91 | for(int tmp_i=0;tmp_i<debug_msg.length();tmp_i++) |
||
92 | { |
||
93 | if ((debug_msg.charAt(tmp_i)=='\r')||(debug_msg.charAt(tmp_i)=='\n')) |
||
94 | { |
||
95 | g.drawString(tmp_str,5,y_off,Graphics.TOP | Graphics.LEFT); |
||
96 | y_off+=debug_font.getHeight(); |
||
97 | tmp_str=""; |
||
98 | } |
||
99 | else |
||
100 | tmp_str+=debug_msg.charAt(tmp_i); |
||
101 | } |
||
102 | g.drawString(tmp_pos+" "+tmp_str,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
103 | y_off+=debug_font.getHeight(); |
||
104 | } |
||
105 | |||
106 | } |
||
107 | |||
108 | public void process_key(int keyCode) |
||
109 | { |
||
110 | |||
111 | |||
112 | if (!showing) |
||
113 | { |
||
114 | if (keyCode==debug_screen_sequence[debug_screen_sequence_pos]) |
||
115 | { |
||
116 | debug_screen_sequence_pos++; |
||
117 | if(debug_screen_sequence_pos==debug_screen_sequence.length) |
||
118 | { |
||
119 | showing=true; |
||
120 | debug_screen_sequence_pos=0; |
||
121 | } |
||
122 | } |
||
123 | else |
||
124 | debug_screen_sequence_pos=0; |
||
125 | } |
||
126 | else |
||
127 | { |
||
128 | if (keyCode==KEY_STAR) |
||
129 | showing=false; |
||
130 | |||
131 | if (keyCode==KEY_NUM0) |
||
132 | paused=!paused; |
||
133 | |||
134 | |||
135 | switch (getGameAction (keyCode)) |
||
136 | { |
||
137 | case UP: |
||
138 | debug_paused_pos++; |
||
139 | break; |
||
140 | |||
141 | case DOWN: |
||
142 | debug_paused_pos--; |
||
143 | break; |
||
144 | |||
145 | } |
||
146 | |||
147 | |||
148 | } |
||
149 | |||
150 | |||
151 | } |
||
152 | |||
153 | |||
154 | |||
155 | } |