Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 220 → Rev 221

/DUBwise/trunk/j2me/src/DUBwiseCanvas.java
13,15 → 13,7
import javax.microedition.media.control.*;
 
 
//#if fileapi=="on"
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.io.file.*;
 
import java.io.*;
import java.util.*;
//#endif
 
public class DUBwiseCanvas
extends Canvas
implements Runnable,org.ligi.ufo.DUBwiseDefinitions , DUBwiseUIDefinitions
28,23 → 20,7
{
 
//#if fileapi=="on"
public final static int MAX_FILELIST_LENGTH=100;
public final static int MAX_PATH_DEPTH=10;
 
byte act_path_depth=0;
String[] act_path_arr;
 
 
public String act_path()
{
String res="";
for (int i=0;i<act_path_depth;i++)
res+=act_path_arr[i];
return res;
}
 
String[] file_list;
int file_list_length=0;
DUBwiseFileAccess file_access;
//#endif
 
String act_input_str=" ";
65,8 → 41,6
int heading_offset=0;
int act_wp;
 
 
//#if bluetooth=="on"
private BTSearcher bt_scanner;
//#endif
108,7 → 82,8
public int[] graph_sources={0,1,2,3};
public String[] graph_names={"nick int","roll int","nick acc","roll acc"};
public int[][] graph_data;
 
public int graph_offset=0;
public int lcd_char_width=0;
public int lcd_char_height=0;
 
295,7 → 270,7
 
}
paint_lcd(g,true);
paint_lcd(g);
}
 
public void menu_keypress(int keyCode)
323,19 → 298,19
 
public boolean cam_condition()
{
return (mk.stick_data.stick[5]>100);
return (mk.stick_data.stick[settings.remote_cam_stick]>100);
}
 
// int lcd_top=25;
 
public void paint_lcd(Graphics g,boolean bottomup)
public void paint_lcd(Graphics g)
{
 
int y;
 
// int lcd_top= (state==STATEID_EDIT_PARAMS?0:25);
int lcd_top= 25;
max_lines=(canvas_height-lcd_top)/lcd_char_height;
//int lcd_top= 25;
max_lines=(canvas_height-25/*lcd_top*/)/lcd_char_height;
 
int spacer_left_right=(canvas_width-(20*(lcd_img.getWidth()/222)))/2;
// for(int i=0;i<lcd_lines.length;i++)
349,10 → 324,11
for(int i=0;i<display_lines;i++)
for (int pos=0;pos<20;pos++)
{
if (bottomup)
/*if (!bottomup)
y=i*lcd_char_height;
else*/
y=canvas_height-(display_lines-i)*lcd_char_height;
else
y=i*lcd_char_height;
 
g.setClip((lcd_img.getWidth()/222)*pos+spacer_left_right,y,(lcd_img.getWidth()/222),lcd_img.getHeight());
g.drawImage(lcd_img,spacer_left_right+(lcd_img.getWidth()/222)*pos-((pos<lcd_lines[i+lcd_off].length()?lcd_lines[i+lcd_off].charAt(pos):' ')-' ')*(lcd_img.getWidth()/222),y,g.TOP | g.LEFT);
359,7 → 335,7
}
}
 
public void load_images()
public void load_skin_images()
{
try
{
371,39 → 347,37
{
case SKINID_DARK:
lcd_img=Image.createImage("/lcd_green.png");
if (settings.do_scrollbg) bg_img=Image.createImage("/starfield.jpg"); break;
 
if (settings.do_scrollbg) bg_img=Image.createImage("/starfield.jpg");
break;
case SKINID_LIGHT:
lcd_img=Image.createImage("/lcd_blue.png");
if (settings.do_scrollbg) bg_img=Image.createImage("/clouds.jpg");
break;
}
lcd_char_width=lcd_img.getWidth()/222;
lcd_char_height=lcd_img.getHeight();
}
 
catch (Exception e)
{
debug.err(e.toString());
}
 
// bt_img=Image.createImage("/bt.png");
}
public void load_global_images()
{
try
{
symbols_img=Image.createImage("/symbols.png");
// load_img=Image.createImage("/load.png");
 
lcd_char_width=lcd_img.getWidth()/222;
lcd_char_height=lcd_img.getHeight();
 
 
if (bg_img!=null)
/* if (bg_img!=null)
graph_data=new int[GRAPH_COUNT][bg_img.getWidth()];
else
graph_data=new int[GRAPH_COUNT][this.getWidth()*2];
*/
 
for (int c=0;c<graph_data[0].length;c++)
for (int d=0;d<GRAPH_COUNT;d++)
graph_data[d][c]=-1;
 
try {
err_img=null;
err_img=Image.createImage("/preflight.jpg");
}
catch (Exception e) { }
 
}
catch (Exception e)
413,12 → 387,12
}
 
// construct
public DUBwiseCanvas(DUBwise _root)
{
 
//#if fileapi=="on"
file_list= new String[MAX_FILELIST_LENGTH];
act_path_arr=new String[MAX_PATH_DEPTH];
file_access=new DUBwiseFileAccess(this);
//#endif
 
root=_root;
427,6 → 401,7
helper = new DUBwiseHelper();
settings = new DUBwiseSettings(this);
settings.load();
load_global_images();
debug = new DUBwiseDebug(this);
 
//#if bluetooth=="on"
434,37 → 409,30
//#endif
 
 
 
//#if voice_mode!="no_voice"
status_voice=new MKStatusVoice(mk,this);
//#endif
// load_images();
 
if (settings.connection_url!="")
connect_mk(settings.connection_url,settings.connection_name);
mk.gps_position.act_speed_format=settings.speed_format;
mk.gps_position.act_gps_format= settings.gps_format;
 
 
chg_state(STATEID_MAINMENU);
 
new Thread(this).start();
 
if (settings.connection_url!="")
connect_mk(settings.connection_url,settings.connection_name);
}
 
 
 
/****************************** Thread ******************/
// ticking runnable Section
public void run()
{
 
 
while(true)
{
try {
496,6 → 464,13
switch(state)
{
 
case STATEID_GRAPH:
graph_offset--;
if (graph_offset==-graph_data[0].length)
graph_offset=0;
break;
 
case STATEID_CAMMODE:
try
506,6 → 481,7
debug.log("get snap\n");
cam_raw = mVideoControl.getSnapshot(null);
try { Thread.sleep(4000); }
catch (Exception e)
{
512,11 → 488,12
debug.log("Problem Sleeping ");
}
cam_img = Image.createImage(cam_raw, 0, cam_raw.length);
}
else
{
if (cam_img==null)
cam_img = Image.createImage(cam_raw, 0, cam_raw.length);
;;
}
}
catch ( Exception e)
632,12 → 609,22
root.quit();
}
 
try {
 
//rescan=false;
bg_offset--;
if (bg_offset==-graph_data[0].length)
bg_offset=0;
 
if (bg_img!=null)
{
bg_offset--;
if (bg_offset==-bg_img.getWidth())
bg_offset=0;
}
 
 
 
//#if devicecontrol=="on"
 
try {
if (settings.keep_lighton) com.nokia.mid.ui.DeviceControl.setLights(0,100);
//#endif
}
747,7 → 734,7
 
 
//draw background
if ((!settings.do_scrollbg) || (state==STATEID_EDIT_PARAMS))
if (!settings.do_scrollbg)
{
g.setColor(0xdedfff);
g.fillRect(0,0,canvas_width,symbols_img.getHeight());
879,7 → 866,7
g.setClip(err_img_left,err_img_top,err_img.getWidth()/2,err_img.getHeight());
g.drawImage(err_img,err_img_left-err_img.getWidth()/2,err_img_top, g.TOP | g.LEFT);
}
paint_lcd(g,true);
paint_lcd(g);
 
break;
 
995,13 → 982,13
 
if (cam_img!=null)
g.drawImage(cam_img,0,0,g.TOP | g.LEFT);
g.drawString("condition: " + cam_condition() ,0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
g.drawString("width " + cam_img.getWidth(),0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
g.drawString("height " + cam_img.getHeight(),0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
break;
g.drawString("condition: " + cam_condition() ,0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
g.drawString("width " + cam_img.getWidth(),0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
g.drawString("height " + cam_img.getHeight(),0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
break;
 
case STATEID_STICKVIEW:
 
1065,7 → 1052,7
//#if fileapi=="on"
case STATEID_FILEOPEN:
y_off+=spacer;
g.drawString("act_path" + act_path() ,0,y_off,Graphics.TOP | Graphics.LEFT);
g.drawString("act_path" + file_access.act_path() ,0,y_off,Graphics.TOP | Graphics.LEFT);
paint_menu(g);
break;
//#endif
1072,17 → 1059,17
case STATEID_STRINGINPUT:
case STATEID_ABOUT:
case STATEID_IPINPUT:
paint_lcd(g,true);
paint_lcd(g);
break;
 
case STATEID_READ_PARAMS:
paint_lcd(g,true);
paint_lcd(g);
break;
 
 
//#if bluetooth=="on"
case STATEID_SCANNING:
paint_lcd(g,true);
paint_lcd(g);
break;
//#endif
case STATEID_RAWDEBUG:
1241,7 → 1228,7
 
g.setColor(graph_colors[gr]);
try {
graph_data[gr][-bg_offset]=mk.debug_data.analog[graph_sources[gr]];
graph_data[gr][-graph_offset]=mk.debug_data.analog[graph_sources[gr]];
}
catch (Exception e)
{
1253,7 → 1240,7
 
for ( int x=0;x<canvas_width;x++)
{
int p= (((-bg_offset+x-canvas_width-5)));
int p= (((-graph_offset+x-canvas_width-5)));
if (p<1)
p+=graph_data[0].length;
p%=(graph_data[0].length-1);
1334,6 → 1321,7
Player mPlayer;
VideoControl mVideoControl;
Image cam_img;
Image last_cam_img;
int cam_img_seq=0;
byte[] cam_raw;
 
1382,11 → 1370,27
{
settings_editor = null;
params_editor = null;
err_img=null;
graph_data=null;
 
 
if (next_state!=state)act_menu_select=0;
// prepare next state
switch(next_state)
{
case STATEID_NC_ERRORS:
lcd_lines=new String[1];
lcd_lines[0]=""+mk.error_str;
try
{
err_img=Image.createImage("/preflight.jpg");
}
catch (Exception e)
{
debug.log("problem loading error image");
}
break;
case STATEID_EDIT_PARAMS:
params_editor = new MKParamsEditor(this,mk.params,STATEID_HANDLE_PARAMS);
break;
1407,64 → 1411,7
 
//#if fileapi=="on"
case STATEID_FILEOPEN:
if (act_path_depth==0)
{
Enumeration drives = FileSystemRegistry.listRoots();
int tmp_i=0;
while(drives.hasMoreElements())
{
file_list[tmp_i]= (String) drives.nextElement();
tmp_i++;
if (MAX_FILELIST_LENGTH<tmp_i)
break;
}
menu_items=new String[tmp_i];
lcd_lines=new String[tmp_i];
file_list_length=tmp_i;
for(tmp_i=0;tmp_i<file_list_length;tmp_i++)
menu_items[tmp_i]=file_list[tmp_i];
 
}
else
{
 
try {
FileConnection fc = (FileConnection) Connector.open("file:///"+act_path());
Enumeration filelist = fc.list("*", true);
int tmp_i=0;
while(filelist.hasMoreElements()) {
file_list[tmp_i] = (String) filelist.nextElement();
tmp_i++;
/* fc = (FileConnection)
Connector.open("file:///CFCard/" + fileName);
if(fc.isDirectory()) {
System.out.println("\tDirectory Name: " + fileName);
} else {
System.out.println
("\tFile Name: " + fileName +
"\tSize: "+fc.fileSize());
}*/
}
menu_items=new String[tmp_i+1];
lcd_lines=new String[tmp_i+1];
file_list_length=tmp_i+1;
menu_items[0]="..";
for(tmp_i=1;tmp_i<file_list_length;tmp_i++)
menu_items[tmp_i]=file_list[tmp_i-1];
 
 
fc.close();
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
}
}
 
 
file_access.trigger();
break;
//#endif
 
1485,11 → 1432,6
break;
 
 
case STATEID_NC_ERRORS:
lcd_lines=new String[1];
lcd_lines[0]=""+mk.error_str;
break;
 
case STATEID_ABOUT:
lcd_lines=credits;
lcd_lines[1]=" ufo-lib: " + mk.lib_version_str();
1498,14 → 1440,11
case STATEID_CONN_DETAILS:
setup_menu(conn_details_menu_items,conn_details_menu_actions);
break;
 
 
 
case STATEID_TRAFFIC:
setup_menu(onlyback_menu_items,back_to_conndetails_actions);
break;
case STATEID_CAMMODE:
mk.user_intent=USER_INTENT_RCDATA;
if (mVideoControl==null)
try
{
1627,6 → 1566,13
 
 
case STATEID_GRAPH:
graph_data=new int[GRAPH_COUNT][this.getWidth()*2];
for (int c=0;c<graph_data[0].length;c++)
for (int d=0;d<GRAPH_COUNT;d++)
graph_data[d][c]=-1;
mk.user_intent=USER_INTENT_GRAPH;
break;
 
1763,7 → 1709,7
debug.process_key(keyCode);
if (((keyCode==KEY_STAR) || (keyCode==113) ))//&&(state!= STATEID_STRINGINPUT))
if ((keyCode==KEY_STAR) || (keyCode==settings.key_back) )//&&(state!= STATEID_STRINGINPUT))
{
if (state==STATEID_EDIT_PARAMS)
{
1780,7 → 1726,7
}
 
 
if ((keyCode==KEY_POUND)&&(state!=STATEID_KEYCONTROL))
if (((keyCode==KEY_POUND)||(keyCode==settings.key_fullscreen))&&(state!=STATEID_KEYCONTROL))
{
settings.toggle_fullscreen();
 
2080,24 → 2026,7
case STATEID_FILEOPEN:
if ( getGameAction (keyCode)==FIRE )
{
if ((act_menu_select==0)&&(act_path_depth!=0))
{
act_path_depth--;
//act_path=act_path.substring(0,act_path.substring(0,act_path.length()-2).indexOf('/') );
 
//act_path=last_path;
}
else
{
//last_path=act_path;
if (act_path_depth==0)
act_path_arr[act_path_depth++]=file_list[act_menu_select];
else
act_path_arr[act_path_depth++]=file_list[act_menu_select-1];
}
act_menu_select=0;
chg_state(STATEID_FILEOPEN);
file_access.fire();
}
else
menu_keypress(keyCode);