support repeat. Swap up&down. Also some cleanup

This commit is contained in:
Stefan `Sec` Zehl 2011-08-02 23:34:47 +02:00
parent 691fa7d09b
commit e25e591287
1 changed files with 53 additions and 44 deletions

View File

@ -1,8 +1,9 @@
#include <string.h>
#include "basic/basic.h" #include "basic/basic.h"
#include "lcd/render.h" #include "lcd/render.h"
#include "lcd/display.h" #include "lcd/display.h"
#include "lcd/allfonts.h" #include "lcd/print.h"
#define CHARWIDTH 12 #define CHARWIDTH 12
#define CHARSPACE 0x20 #define CHARSPACE 0x20
@ -23,56 +24,65 @@ void inputInit(char p[],char s[], uint8_t l, uint8_t as, uint8_t ae) {
s_input.pos = 0; s_input.pos = 0;
s_input.dcursor = 0; s_input.dcursor = 0;
s_input.done = false; s_input.done = false;
s[l-1]=0;
for(int i=strlen(s);i<(l-1);i++)
s[i]=0;
} }
void inputMove() { void inputMove() {
char *cur = s_input.line+s_input.pos+s_input.dcursor; char *cur = s_input.line+s_input.pos+s_input.dcursor;
char key = getInput(); switch(getInputWaitRepeat()){
if (key == BTN_LEFT) { case BTN_LEFT:
if (s_input.dcursor >0) { if (s_input.dcursor >0) {
s_input.dcursor --; s_input.dcursor --;
} else if (s_input.pos > 0) { } else if (s_input.pos > 0) {
s_input.pos --; s_input.pos --;
} }
} else if (key == BTN_RIGHT) { break;
if (s_input.dcursor <RESX/CHARWIDTH-1 && s_input.pos + s_input.dcursor < s_input.maxlength) { case BTN_RIGHT:
if (*cur == 0) { if (s_input.dcursor <RESX/CHARWIDTH-1 && s_input.pos + s_input.dcursor < s_input.maxlength) {
*cur = CHARSPACE; if (*cur == 0) {
} *cur = CHARSPACE;
s_input.dcursor ++; }
} else if (s_input.pos + RESX/CHARWIDTH < s_input.maxlength) { s_input.dcursor ++;
s_input.pos++; } else if (s_input.pos + RESX/CHARWIDTH < s_input.maxlength) {
if (*cur == 0) { s_input.pos++;
*cur = CHARSPACE; if (*cur == 0) {
} *cur = CHARSPACE;
} }
} else if (key == BTN_DOWN) { }
if (*cur <= s_input.asciistart) { break;
*cur = s_input.asciiend; case BTN_UP:
} else if (*cur > s_input.asciiend) { if (*cur <= s_input.asciistart) {
*cur = s_input.asciiend; *cur = s_input.asciiend;
} else { } else if (*cur > s_input.asciiend) {
*cur = *cur - 1; *cur = s_input.asciiend;
} } else {
} else if (key == BTN_UP) { *cur = *cur - 1;
if (*cur >= s_input.asciiend) { }
*cur = s_input.asciistart; break;
} else if (*cur < s_input.asciistart) { case BTN_DOWN:
*cur = s_input.asciistart; if (*cur >= s_input.asciiend) {
} else { *cur = s_input.asciistart;
*cur = *cur + 1; } else if (*cur < s_input.asciistart) {
} *cur = s_input.asciistart;
} else if (key == (BTN_ENTER)) { } else {
s_input.done = true; *cur = *cur + 1;
} }
break;
case BTN_ENTER:
s_input.done = true;
// getInputWaitRelease();
break;
}
} }
void inputDraw() { void inputDraw() {
lcdFill(0); char tmp[2]= {0,0};
lcdClear();
DoString(0,0,s_input.prompt); DoString(0,0,s_input.prompt);
for (int dx = 0; dx<= RESX/CHARWIDTH && s_input.pos+dx<s_input.maxlength; dx++){ for (int dx = 0; dx<= RESX/CHARWIDTH && s_input.pos+dx<s_input.maxlength; dx++){
char tmp[1];
tmp[0] = s_input.line[s_input.pos+dx]; tmp[0] = s_input.line[s_input.pos+dx];
DoString(dx*CHARWIDTH, 30,tmp); DoString(dx*CHARWIDTH, 30,tmp);
} }
@ -93,13 +103,12 @@ void inputClean() {
} }
void input(char prompt[], char line[], uint8_t asciistart, uint8_t asciiend, uint8_t maxlength){ void input(char prompt[], char line[], uint8_t asciistart, uint8_t asciiend, uint8_t maxlength){
font=&Font_7x8; setSystemFont();
inputInit(prompt, line, maxlength, asciistart, asciiend); inputInit(prompt, line, maxlength, asciistart, asciiend);
lcdFill(0);
while (!s_input.done) { while (!s_input.done) {
inputDraw();
lcdDisplay(); lcdDisplay();
inputMove(); inputMove();
inputDraw();
} }
inputClean(); inputClean();
return; return;