Example #1
0
int dGetLineBox (char * s,int max,int width,int x,int y)
{
	int		pos = strlen(s);
	int		refresh = 1;
	uint	key;
	char	c;
	
	while(1)
	{
		if (refresh)
		{
			dAreaClear(x,y,x+width*6+2,y+10,2);

			if (pos<width-1)
			{
				PrintXY (x+1,y+2,(uchar*)s,0);
				PrintXY (x+1+pos*6,y+2,(uchar*)"_",0);
			}
			else
			{
				PrintXY (x+1,y+2,(uchar*)(s+pos-width+1),0);
				PrintXY (x+1+(width-1)*6,y+2,(uchar*)"_",0);
			}
			refresh = 0;
		}

		GetKey(&key);

		if ((c=dGetKeyChar(key))!=0)
		{
			if (pos>=max) continue;

			s[pos++] = c;s[pos] = '\0';
			refresh = 1;
		}
		else
		{
			if (key==KEY_CTRL_DEL)
			{
				if (pos<=0) continue;
				s[--pos] = '\0';
				refresh  = 1;
			}
			else if (key==KEY_CTRL_AC)
			{
				*s		= 0;
				pos		= 0;
				refresh	= 1;
			}
			else if (key==KEY_CTRL_EXE) return 1;
			else if (key==KEY_CTRL_EXIT) return 0;
			
		}
		
	}
}
Example #2
0
int dGetLine (char * s,int max) // This function is depended on dConsole
                                                                // And this function is not allowed to abolish
{
        int             pos = strlen(s);
        int             refresh = 1;
        int             x,y,l,width;
        int    key;
        char    c;


        l = strlen (line_buf[line_index]);

        if (l>=LINE_COL_MAX)
        {
                dConsolePut("\n");
                l = 0;
        }
        else
                dConsoleRedraw();

        x = l + 1;
        y = line_count;
        width = LINE_COL_MAX - l;
        
        //LCD_CursorEn(1);

        while (1)
        {
                if (refresh)
                {
                        int i;
                        for (i=x;i<=LINE_COL_MAX;++i)
                        {
                                locate(i,y-line_start);print((uchar*)" ");
                        }
                        if (pos<width-1)
                        {
                                locate(x,y-line_start);            print((uchar*)s);
                                locate(x+pos,y-line_start);        printCursor();
                        }
                        else
                        {
                                locate(x,y-line_start);            print((uchar*)s+pos-width+1);
                                locate(x+width-1,y-line_start);    printCursor(); //cursor
                        }
                        refresh = 0;
                }
                //int keyflag = GetSetupSetting( (unsigned int)0x14);
                key=GetKey();

                if (key==KEY_CHAR_PLUS) {
                  if ((int)strlen(s)>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last+");
                    pos=pos+5; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"+", pos);
                    pos=pos+1; refresh = 1;
                  }
                } else if (key==KEY_CHAR_MINUS) {
                  if ((int)strlen(s)>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last-");
                    pos=pos+5; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"-", pos);
                    pos=pos+1; refresh = 1;
                  }
                } else if (key==KEY_CHAR_MULT) {
                  if ((int)strlen(s)>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last*");
                    pos=pos+5; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"*", pos);
                    pos=pos+1; refresh = 1;
                  }
                } else if (key==KEY_CHAR_DIV) {
                  if ((int)strlen(s)>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last/");
                    pos=pos+5; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"/", pos);
                    pos=pos+1; refresh = 1;
                  }
                } else if (key==KEY_CHAR_POW) {
                  if ((int)strlen(s)>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last^");
                    pos=pos+5; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"^", pos);
                    pos=pos+1; refresh = 1;
                  }
                } else if (key==KEY_CHAR_SQUARE) {
                  if ((int)strlen(s)+1>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last^2");
                    pos=pos+6; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"^2", pos);
                    pos=pos+2; refresh = 1;
                  }
                } else if (key==KEY_CHAR_ROOT) {
                  if ((int)strlen(s)+4>=max) continue;
                  append(s, (char*)"sqrt(", pos);
                  pos=pos+5; refresh = 1;
                }else if (key==KEY_CHAR_H) {
                    if ((int)strlen(s)+4>=max) continue;
                    append(s, (char*)"h", pos);
                    pos=pos+1; refresh = 1;
                  } else if (key==KEY_CHAR_CUBEROOT) {
                  if ((int)strlen(s)+5>=max) continue;
                  append(s, (char*)"^(1/3)", pos); // example: to get cubic root of 27, do 27^(1/3)
                  pos=pos+6; refresh = 1;
                } else if (key==KEY_CHAR_POWROOT) {
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"^(1/", pos); // example: to get cubic root of 27, do 27^(1/3)
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_LN) { // the log() function in eigenmath is the natural log (Casio's ln)
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"log(", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_EXPN) { // the exp() function in eigenmath is the natural expnonent (Casio's e^x)
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"exp(", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_SIN) {
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"sin(", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_ASIN) {
                  if ((int)strlen(s)+6>=max) continue;
                  append(s, (char*)"arcsin(", pos);
                  pos=pos+7; refresh = 1;
                } else if (key==KEY_CHAR_COS) {
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"cos(", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_ACOS) {
                  if ((int)strlen(s)+6>=max) continue;
                  append(s, (char*)"arccos(", pos);
                  pos=pos+7; refresh = 1;
                } else if (key==KEY_CHAR_TAN) {
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"tan(", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_ATAN) {
                  if ((int)strlen(s)+6>=max) continue;
                  append(s, (char*)"arctan(", pos);
                  pos=pos+7; refresh = 1;
                } else if (key==KEY_CHAR_FRAC) {
                  if ((int)strlen(s)>=max) continue;
                  append(s, (char*)"/", pos);
                  pos=pos+1; refresh = 1;
                } else if (key==KEY_CTRL_FD) {
                  if ((int)strlen(s)+4>=max) continue;
                  append(s, (char*)"float", pos); // no ( at the end because this is often used to manipulate the last result
                  pos=pos+5; refresh = 1;
                } else if (key==KEY_CHAR_FACT) {
                  if ((int)strlen(s)>=max) continue;
                  append(s, (char*)"!", pos); 
                  pos=pos+1; refresh = 1;
                } else if (key==KEY_CHAR_IMGNRY) {
                  if ((int)strlen(s)>=max) continue;
                  append(s, (char*)"i", pos);
                  pos=pos+1; refresh = 1;
                } else if (key==KEY_CHAR_PI) {
                  if ((int)strlen(s)+1>=max) continue;
                  append(s, (char*)"pi", pos);
                  pos=pos+2; refresh = 1;
                } else if (key==KEY_CHAR_EXP) {
                  if ((int)strlen(s)+4>=max) continue;
                  append(s, (char*)"*10^(", pos);
                  pos=pos+5; refresh = 1;
                } else if (key==KEY_CHAR_PMINUS) {
                  if ((int)strlen(s)+1>=max) continue;
                  append(s, (char*)"(-", pos);
                  pos=pos+2; refresh = 1;
                } else if (key==KEY_CHAR_ANS) {
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"last", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_ENG) {
                  if ((int)strlen(s)+7>=max) continue;
                  append(s, (char*)"selftest", pos);
                  pos=pos+8; refresh = 1;
                } else if (key==KEY_CTRL_MODE) {
                  // open functions catalog
                  /*char text[20] = "";
                  if(showCatalog(text)) {
                    int len = strlen(text);
                    if(pos+len>max) continue;
                    else {
                      append(s, text, pos);
                      pos=pos+len; refresh = 1;
                    }
                  }*/
                  //LCD_CursorEn(0);
                  LCD_SelectFont((u8 *)Font_Ascii_5X7E_Menu);
                  Mode_main();
                  LCD_Clear(0);
                  LCD_SelectFont((u8 *)Font_Ascii_5X7E);
                  dConsoleRedraw();
                  //LCD_CursorEn(1);
                  refresh = 1;
                } else if (key==KEY_CTRL_SETUP) {
                  //LCD_CursorEn(0);
                  LCD_SelectFont((u8 *)Font_Ascii_5X7E_Menu);
                  Setup_main();
                  LCD_Clear(0);
                  LCD_SelectFont((u8 *)Font_Ascii_5X7E);
                  dConsoleRedraw();
                  //LCD_CursorEn(1);
                  refresh = 1;
                } else if (key==KEY_CTRL_UP) {
                  // go up in command history
                  //do_up_arrow();
                  //line_start--;
                  //dConsoleRedraw();
                  //pos=strlen(s);
                  refresh = 1;
                  if (line_start>0)
                    line_start--;
                  dConsoleRedraw();
                } else if (key==KEY_CTRL_DOWN) {
                  // go down in command history
                  //do_down_arrow();
                  //line_start++;
                  //dConsoleRedraw();
                  //pos=strlen(s);
                  refresh = 1;
		  if (line_start<LINE_ROW_MAX-4)
                    line_start++;
                  dConsoleRedraw();
                } else if (key==KEY_CTRL_LEFT) {
                  // move cursor left
                  if(pos<=0) continue;
                  pos--;
                  refresh = 1;
                } else if (key==KEY_CTRL_RIGHT) {
                  // move cursor right
                  if(pos>=(int)strlen(s)) continue;
                  pos++;
                  refresh = 1;
                } else if ((c=dGetKeyChar(key))!=0) {
                        if ((int)strlen(s)>=max) continue;
                        char ns[2] = "";
                        ns[0] = c; ns[1]='\0';
                        append(s, ns, pos);
                        pos++;
                        refresh = 1;
                }
                else if (key==KEY_CTRL_DEL)
                {
                        if (pos<=0) continue;
                        pos--;
                        int i = pos;
                        do {
                                s[i] = s[i+1];
                                i++;
                        } while (s[i] != '\0');
                        refresh = 1;
                }
                else if (key==KEY_CTRL_AC)
                {
                        *s              = 0;
                        pos             = 0;
                        refresh = 1;
                }
                else if (key==KEY_CTRL_EXE) 
                {
                  //LCD_CursorEn(0);
                  return 1;
                }
        }
        return 0;
}
Example #3
0
int dGetLine (char * s,int max)	// This function is depended on dConsole
								// And this function is not allowed to abolish
{
	int		pos = strlen(s);
	int		refresh = 1;
	int		x,y,l,width;
	uint	key;
	char	c;
	
	
	l = strlen (line_buf[line_index]);
	
	if (l>=LINE_COL_MAX)
	{
		dConsolePut("\n");
		l = 0;
	}
	else
		dConsoleRedraw();

	x = l + 1;
	y = line_count;
	width = LINE_COL_MAX - l;

	while (1)
	{
		if (refresh)
		{
			int i;
			for (i=x;i<=LINE_COL_MAX;++i)
			{
				locate(i,y);Print((uchar*)" ");
			}
			if (pos<width-1)
			{
				locate(x,y);		Print((uchar*)s);
				locate(x+pos,y);	Print((uchar*)"_");
			}
			else
			{
				locate(x,y);			Print((uchar*)s+pos-width+1);
				locate(x+width-1,y);	Print((uchar*)"_");
			}
			refresh = 0;
		}
		GetKey(&key);
		if ((c=dGetKeyChar(key))!=0)
		{
			if (pos>=max) continue;

			s[pos++] = c;s[pos] = '\0';
			refresh = 1;
		}
		else
		{
			if (key==KEY_CTRL_DEL)
			{
				if (pos<=0) continue;
				s[--pos] = '\0';
				refresh  = 1;
			}
			else if (key==KEY_CTRL_AC)
			{
				*s		= 0;
				pos		= 0;
				refresh	= 1;
			}
			else if (key==KEY_CTRL_EXE) return 1;
			
		}
	}
	return 0;
}