bool InputField::Input(ALLEGRO_EVENT &ev, float &scalex, float &scaley) { int unichar = 0; detectingbutton->Input(ev, scalex, scaley); if(detectingbutton->is_button_clicked() == true && detectingbutton->is_mouse_in_it() == false && ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN && ev.mouse.button == 1) { detectingbutton->unclick(); } else if(detectingbutton->is_button_clicked() == true) { if(ev.type == ALLEGRO_EVENT_KEY_CHAR && (ev.keyboard.keycode == ALLEGRO_KEY_BACKSPACE || ev.keyboard.keycode == ALLEGRO_KEY_ENTER)) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_BACKSPACE : if(al_ustr_length(al_text) > 0) { al_ustr_remove_chr(al_text, al_ustr_length(al_text)-1); } break; case ALLEGRO_KEY_ENTER : detectingbutton->unclick(); break; } } else if(ev.type == ALLEGRO_EVENT_KEY_CHAR) { if(lenght_limit == true && (int)text.size() >= max_lenght) { return true; } unichar = ev.keyboard.unichar; if(unichar >= 32) { al_ustr_append_chr(al_text, unichar); } } } text = al_cstr_dup(al_text); text_width = al_get_text_width(font, text.c_str()) + 7; return true; }
/* Test al_ustr_new_from_buffer, al_cstr_dup. */ static void t39(void) { const char s1[] = "Корабът ми на въздушна възглавница\0е пълен със змиорки"; ALLEGRO_USTR *us; char *s2; us = al_ustr_new_from_buffer(s1, sizeof(s1) - 1); /* missing NUL term. */ s2 = al_cstr_dup(us); al_ustr_free(us); CHECK(0 == strcmp(s1, s2)); CHECK(0 == memcmp(s1, s2, sizeof(s1))); /* including NUL terminator */ al_free(s2); }