Subversion Repositories Projects

Rev

Rev 82 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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