Example #1
0
void WidgetEdit::increment_edit_pos()
{
    this->edit_pos++;
    size_t n = UTF8GetPos(reinterpret_cast<uint8_t *>(this->label.buffer + this->edit_buffer_pos), 1);
    char c = this->label.buffer[this->edit_buffer_pos + n];
    this->label.buffer[this->edit_buffer_pos + n] = 0;
    gdi::TextMetrics tm(this->font, this->label.buffer + this->edit_buffer_pos);
    this->h_text = tm.height;
    this->cursor_px_pos += tm.width;
    this->label.buffer[this->edit_buffer_pos + n] = c;
    this->edit_buffer_pos += n;

    if (this->label.shift_text(this->cursor_px_pos)) {
        this->drawall = true;
    }
}
Example #2
0
WidgetEdit::WidgetEdit(
    gdi::GraphicApi & drawable,
    Widget & parent, NotifyApi* notifier, const char * text,
    int group_id, BGRColor fgcolor, BGRColor bgcolor, BGRColor focus_color,
    Font const & font, std::size_t edit_position, int xtext, int ytext)
: Widget(drawable, parent, notifier, group_id)
, label(drawable, *this, nullptr, text, 0, fgcolor, bgcolor, font, xtext, ytext)
, w_text(0)
, h_text(0)
, cursor_color(0x888888)
, focus_color(focus_color)
, drawall(false)
, draw_border_focus(true)
, font(font)
{
    if (text) {
        this->buffer_size = strlen(text);
        this->num_chars = UTF8Len(byte_ptr_cast(this->label.buffer));
        this->edit_pos = std::min(this->num_chars, edit_position);
        this->edit_buffer_pos = UTF8GetPos(reinterpret_cast<uint8_t *>(this->label.buffer), this->edit_pos);
        this->cursor_px_pos = 0;
        char c = this->label.buffer[this->edit_buffer_pos];
        this->label.buffer[this->edit_buffer_pos] = 0;
        gdi::TextMetrics tm1(this->font, this->label.buffer);
        this->w_text = tm1.width;
        this->cursor_px_pos = this->w_text;
        this->label.buffer[this->edit_buffer_pos] = c;
        // TODO: tm.height unused ?
        gdi::TextMetrics tm2(this->font, &this->label.buffer[this->edit_buffer_pos]);
        this->w_text += tm2.width;
    } else {
        this->buffer_size = 0;
        this->num_chars = 0;
        this->edit_buffer_pos = 0;
        this->edit_pos = 0;
        this->cursor_px_pos = 0;
    }

    // TODO: tm.width unused ?
    gdi::TextMetrics tm(this->font, "Édp");
    this->h_text = tm.height;
    this->h_text -= 1;

    this->pointer_flag = Pointer::POINTER_EDIT;
}
Example #3
0
    virtual void rdp_input_mouse(int device_flags, int x, int y, Keymap2* keymap)
    {
        if (device_flags == (MOUSE_FLAG_BUTTON1|MOUSE_FLAG_DOWN)) {
            Rect old_cursor_rect = this->get_cursor_rect();
            size_t e = this->edit_pos;
            if (x <= this->dx() + this->masked_text.x_text + this->w_char/2) {
                this->edit_pos = 0;
                this->edit_buffer_pos = 0;
            }
            else if (x >= int(this->dx() + this->masked_text.x_text + this->w_char * this->num_chars)) {
                if (this->edit_pos < this->num_chars) {
                    this->edit_pos = this->num_chars;
                    this->edit_buffer_pos = this->buffer_size;
                }
            }
            else {

                 //      dx
                 // <---------->
                 //           x
                 // <------------------->
                 //     -x_text
                 //     <------>             screen
                 // +-------------------------------------------------------------
                 // |                        editbox
                 // |           +--------------------------------+
                 // |   {.......|.......X................}       |
                 // |           +--------------------------------+
                 // |   <--------------->
                 // |   (x - dx - x_text)
                 // |

                this->edit_pos = std::min<size_t>((x - this->dx() - this->masked_text.x_text - this->w_char/2) / this->w_char, this->num_chars-1);
                this->edit_buffer_pos = UTF8GetPos(reinterpret_cast<uint8_t*>(&this->label.buffer[0]), this->edit_pos);
            }
            if (e != this->edit_pos) {
                this->update_draw_cursor(old_cursor_rect);
            }
        } else {
            Widget2::rdp_input_mouse(device_flags, x, y, keymap);
        }
    }