mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 16:20:49 +01:00
Add the trig menu.
Change-Id: Ifbe2518cb3a089dace82d56031987fbc7a2e6181
This commit is contained in:
@@ -34,6 +34,85 @@ static void print_prompt(char* text, int index) {
|
||||
KDDrawChar(text[index], KDPointMake(index * font_size.width, SCREEN_HEIGHT - (PROMPT_HEIGHT / 2)), true);
|
||||
}
|
||||
|
||||
static void clear_trig_menu() {
|
||||
{
|
||||
KDRect r;
|
||||
r.x = SCREEN_WIDTH / 4 - 1;
|
||||
r.y = SCREEN_HEIGHT / 4 - 1;
|
||||
r.width = SCREEN_WIDTH / 2 + 2;
|
||||
r.height = SCREEN_HEIGHT / 2 + 2;
|
||||
KDFillRect(r, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
static void print_trig_menu() {
|
||||
{
|
||||
KDRect r;
|
||||
r.x = SCREEN_WIDTH / 4 - 1;
|
||||
r.y = SCREEN_HEIGHT / 4 - 1;
|
||||
r.width = SCREEN_WIDTH / 2 + 2;
|
||||
r.height = SCREEN_HEIGHT / 2 + 2;
|
||||
KDFillRect(r, 0xFF);
|
||||
}
|
||||
{
|
||||
KDRect r;
|
||||
r.x = SCREEN_WIDTH / 4;
|
||||
r.y = SCREEN_HEIGHT / 4;
|
||||
r.width = SCREEN_WIDTH / 2;
|
||||
r.height = SCREEN_HEIGHT / 2;
|
||||
KDFillRect(r, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
static int get_trig_input(char* input) {
|
||||
int pos = 0;
|
||||
const char* kTexts[] = {
|
||||
"sine",
|
||||
"cosine",
|
||||
"tangent",
|
||||
"cancel"
|
||||
};
|
||||
const char* kOutputs[] = {
|
||||
"sin( )",
|
||||
"cos( )",
|
||||
"tan( )",
|
||||
};
|
||||
const KDPoint orig = KDPointMake(SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4);
|
||||
while (true) {
|
||||
print_trig_menu();
|
||||
|
||||
uint16_t vert_acc = 0;
|
||||
for (int i(0); i<4; i++) {
|
||||
KDSize text_size = KDStringSize(kTexts[i]);
|
||||
KDDrawString(kTexts[i],
|
||||
KDPointMake(orig.x, orig.y + vert_acc + text_size.height / 2),
|
||||
i==pos);
|
||||
vert_acc += text_size.height;
|
||||
}
|
||||
|
||||
ion_event_t event = ion_get_event();
|
||||
if (event == UP_ARROW) {
|
||||
pos--;
|
||||
if (pos < 0) {
|
||||
pos = 0;
|
||||
}
|
||||
} else if (event == DOWN_ARROW) {
|
||||
pos++;
|
||||
if (pos >= 4) {
|
||||
pos = 3;
|
||||
}
|
||||
} else if (event == '=') {
|
||||
clear_trig_menu();
|
||||
if (pos == 3) {
|
||||
return 0;
|
||||
} else {
|
||||
memcpy(input, kOutputs[pos], (size_t) strlen(kOutputs[pos]));
|
||||
return strlen(kOutputs[pos]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char* get_text() {
|
||||
char input[255] = {0};
|
||||
int index = 0;
|
||||
@@ -60,10 +139,20 @@ char* get_text() {
|
||||
input[index++] = (char) event;
|
||||
// We are at the end of the line.
|
||||
if (index > max) {
|
||||
max++;
|
||||
max=index;
|
||||
input[max] = ' ';
|
||||
input[max+1] = '\0';
|
||||
}
|
||||
} else if (event == TRIG_MENU) {
|
||||
int tmp = get_trig_input(&input[index]);
|
||||
index+=tmp;
|
||||
if (index > max) {
|
||||
max=index;
|
||||
input[max] = ' ';
|
||||
input[max+1] = '\0';
|
||||
}
|
||||
// we want to be inside the parenthese if there are some.
|
||||
index -= (tmp > 2) ? 2 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user