void Edit::on_enter() { #ifdef __windows__ if(Keyboard::is_pressed(0x0D)) #endif #ifdef __gnu_linux__ if(Keyboard::is_pressed(0xff0d)) #endif { if(is_multilined()) // a multilined editor { if(get_text().length() >= get_character_limit()) // if text length has reached character_limit { // double the height of the edit set_height(get_height() * 2); // GOOD! // add to the character_limit (new character_limit) set_character_limit(get_character_limit() + get_character_limit()); // ??? // newline??? set_text(get_text() + "\n"); // reset cursor x position set_cursor_x(0); // set cursor y position int char_height = 12; set_cursor_y(get_cursor_y() + char_height); } } } }
///////////// // TEXT-RELATED ///////////// void Edit::set_text(const std::string& text) { std::string string0 (text); if(string0.length() > get_character_limit()) { string0 = string0.erase(string0.length() - string0.length() + get_character_limit()); } get_label()->set_string(string0); int char_width = 10; // estimated glyph width set_cursor_x(cursor_x + (get_width() / char_width)); // set cursor at end of string }
void Edit::on_backspace() { #ifdef __windows__ if(Keyboard::is_pressed(0x08)) #endif #ifdef __gnu_linux__ if(Keyboard::is_pressed(0xff08)) #endif { // erase last character in string if(get_text().length()!=0) set_text(get_text().erase(get_text().length() - 1)); // move cursor back int char_width = 10; set_cursor_x(get_cursor_x() - char_width); } }
/** * Prints a character to the screen, is used * by kprintf and kputs * * @param c Character to print **/ void kputch(unsigned char c) { unsigned short *where; unsigned att = get_attribute() << 8; if(c == 0x08) { /// ! SELBER SCHREIBEN ! if(get_cursor_x() != 0) set_cursor_x(get_cursor_x() - 1); } // else if(c == 0x09) { int newx; /// ! SELBER SCHREIBEN ! newx = (get_cursor_x() + 8) & ~(8 - 1); set_cursor_x(newx); } // Carriage return? Set the cursor to the beginning of the current line else if(c == '\r') { /// ! SELBER SCHREIBEN ! set_cursor_x(0); } // Linefeed? Set the cursor to the next line else if(c == '\n') { /// ! SELBER SCHREIBEN ! set_cursor_x(0); set_cursor_y(get_cursor_y() + 1); } else if(c >= ' ') { /// ! SELBER SCHREIBEN ! //FIXME: get_textmemptr() doesn't work here (whyever...) where = (unsigned short*)0xB8000 + (get_cursor_y() * 80 + get_cursor_x()); *where = c | att; set_cursor_x(get_cursor_x() + 1); } /// ! SELBER SCHREIBEN ! // More than 80 lines? Scroll the screen if(get_cursor_x() >= 80) { set_cursor_x(0); set_cursor_y(get_cursor_y() + 1); } /// ! SELBER SCHREIBEN ! // Scroll the screen and move the cursor scroll_screen(); move_cursor(); }
void Edit::set_cursor_position(double x, double y) { set_cursor_x(x); set_cursor_y(y); }