コード例 #1
0
ファイル: Textbox.cpp プロジェクト: AdamGaik/kinf
void Textbox::draw()
{
    al_draw_filled_rectangle(AREA, al_map_rgba(255,255,255,1));

    [=]{ // Lambda rysująca text
        int length = (text == "" ? default_text : text).size();
        float x = area.x() + font_size;
        const float y = area.y() + font_size;
        for (int i = 0; i < text.size(); ++i) {
            if (x + al_get_text_width(font(font_size), (text == "" ? default_text : text).substr(0, i+1).c_str()) >= area.x2()) {
                length = i;
                break;
            }
        }
        string text_to_draw = (text == "" ? default_text : text).substr(0, length);
        if (text == "") {
            al_draw_text(font(font_size), Color(200,200,200), x, y, ALLEGRO_ALIGN_LEFT, text_to_draw.c_str());
            return;
        }
        pair<int,int> s;
        s.first = range(selection.first, 0, length);
        s.second = range(selection.second, 0, length);
        string t = text_to_draw.substr(0, s.first);
        al_draw_text(font(font_size), Color::black(), x, y, ALLEGRO_ALIGN_LEFT, t.c_str());
        x += al_get_text_width(font(font_size), t.c_str());
        t = text_to_draw.substr(s.first, s.second - s.first);
        al_draw_filled_rectangle(x, y, x+al_get_text_width(font(font_size), t.c_str()), y+font_size, color);
        al_draw_text(font(font_size), color.ifDark() ? Color::white() : Color::black(), x, y, ALLEGRO_ALIGN_LEFT, t.c_str());
        x += al_get_text_width(font(font_size), t.c_str());
        t = text_to_draw.substr(s.second);
        al_draw_text(font(font_size), Color::black(), x, y, ALLEGRO_ALIGN_LEFT, t.c_str());
    }();

    //al_draw_rectangle(area.x1()+font_size/2, area.y1()+font_size/2, area.x2()-font_size/2, area.y2()-font_size/2, Color::white(), font_size);
    al_draw_filled_rectangle(area.x2()-font_size, area.y1(), area.x2(), area.y2(), Color::white());

    al_draw_rectangle(AREA, Color::black(), 1);

    if (cs.getInvaded() || cs.getIsPressed() || active) {

        int x = 7;
        for (float i = 0; i < x; ++i) {
            al_draw_rectangle(area.x1()+i, area.y1()+i, area.x2()-i, area.y2()-i, Color(0, 0, 0, 255-255*((i*2)/x)), 1);
        }

        if (active) {

            al_draw_rectangle(AREA, color, 3);
            if (show_cursor) {
                al_draw_line(cursor_x(), area.y() + font_size, cursor_x(), area.y() + font_size*2, Color::black(), font_size/10);
            }
        }
    }
}
コード例 #2
0
ファイル: OGETA.cpp プロジェクト: AMDmi3/7kaa
// return 1 for selected
int GetA::detect_click()
{
	if( !enable_flag )
		return 0;

	if( !mouse_drag_flag )
	{
		int clickCount = mouse.any_click(x-font_ptr->max_font_width, y, x_limit, y+height()-1);
		if( clickCount == 1)
		{
			// set cursor_pos
			// scan from the last character, until the clicked x is
			// less than the character x
			for( cursor_pos = strlen(input_field); 
				cursor_pos > 0 && mouse.click_x() < cursor_x(cursor_pos);
				--cursor_pos );
			err_when( cursor_pos < 0 || cursor_pos > strlen(input_field));
			clear_select();
			mouse_drag_flag = 1;
			return 1;
		}
		else if( clickCount > 1 )
		{
			select_whole();
			return 1;
		}
	}
	else
	{
		if( !mouse.left_press )
		{
			mouse_drag_flag = 0;
		}
		for( cursor_pos = strlen(input_field); 
			cursor_pos > 0 && mouse.cur_x < cursor_x(cursor_pos);
			--cursor_pos );
		err_when( cursor_pos < 0 || cursor_pos > strlen(input_field));
		return 1;
	}
	return 0;
}