Ejemplo n.º 1
0
void dropdown_widget::handle_draw() const
{
	if(type_ == DROPDOWN_LIST) {
		graphics::draw_hollow_rect(
			rect(x()-1, y()-1, width()+2, height()+2).sdl_rect(), 
			has_focus() ? graphics::color_white() : graphics::color_grey());
	}
	graphics::draw_hollow_rect(
		rect(x()+width()-height(), y()-1, height()+1, height()+2).sdl_rect(), 
		has_focus() ? graphics::color_white() : graphics::color_grey());

	glPushMatrix();
	glTranslatef(GLfloat(x() & ~1), GLfloat(y() & ~1), 0.0);
	if(type_ == DROPDOWN_LIST) {
		label_->handle_draw();
	} else if(type_ == DROPDOWN_COMBOBOX) {
		editor_->handle_draw();
	}
	if(dropdown_image_) {
		dropdown_image_->handle_draw();
	}
	if(dropdown_menu_ && dropdown_menu_->visible()) {
		dropdown_menu_->handle_draw();
	}
	glPopMatrix();
}
Ejemplo n.º 2
0
	void paint(Painter& painter) override {
		const auto r = screen_rect();
		const auto& s = style();

		Rect target_rect { r.pos, { r.width(), s.font.line_height() }};
		const size_t visible_item_count = r.height() / s.font.line_height();

		auto selected = recent.find(selected_key);
		if( selected == std::end(recent) ) {
			selected = std::begin(recent);
		}

		auto range = recent.range_around(selected, visible_item_count);

		for(auto p = range.first; p != range.second; p++) {
			const auto& entry = *p;
			const auto is_selected_key = (selected_key == entry.key());
			draw(entry, target_rect, painter, s, (has_focus() && is_selected_key));
			target_rect.pos.y += target_rect.height();
		}

		painter.fill_rectangle(
			{ target_rect.left(), target_rect.top(), target_rect.width(), r.bottom() - target_rect.top() },
			style().background
		);
	}
Ejemplo n.º 3
0
void GUI::Checkbox::Draw() {
	SDL_Rect rect = {x+1,y+1,w-2,h-2};

	SDL_Colour black = ImgStuff::Colour(0,0,0);
	SDL_Colour white = ImgStuff::Colour(255,255,255);

	SDL_Colour bc = has_focus() ? ImgStuff::Colour(255,255,0) : white;
	SDL_Rect bt = {x,y,w,1}, bb = {x,y+h,w,1}, bl = {x,y,1,h}, br = {x+w,y,1,h};

	ImgStuff::draw_rect(bt, bc, 255);
	ImgStuff::draw_rect(bb, bc, 255);
	ImgStuff::draw_rect(bl, bc, 255);
	ImgStuff::draw_rect(br, bc, 255);

	ImgStuff::draw_rect(rect, black, 178);

	if(state) {
		TTF_Font *font = FontStuff::LoadFont("fonts/DejaVuSansMono.ttf", 18);
		int fh = TTF_FontHeight(font);
		int fw = FontStuff::TextWidth(font, "X");

		rect.x = x + (w - fw) / 2;
		rect.y = y + (h - fh) / 2;

		FontStuff::BlitText(screen, rect, font, white, "X");
	}
}
Ejemplo n.º 4
0
void Viewport::render(SDL_Renderer& ren, int x, int y, SDL_Rect* extent){
	SDL_Rect old_clip;
	SDL_Rect new_clip = {
		x ,//+ extent->x,
		y ,//+ extent->y,
		extent->w,
		extent->h
	};
	SDL_RenderGetClipRect(&ren, &old_clip);
	SDL_RenderSetClipRect(&ren, &new_clip);

	SDL_Rect target_extent = {
		camera_coords.x() + extent->x,
		camera_coords.y() + extent->y,
		extent->w,
		extent->h
	};
	this->wrappee->render(ren, x, y, &target_extent);
	this->render_viewport_children(ren, x, y, extent);

	SDL_Rect rect = {
		x - extent->x,
		y - extent->y,
		viewport_coord().w(),
		viewport_coord().h()
	};
	if(has_focus()){
		Util::render_rectangle(&ren, &rect, Util::colour_orange());
	} else{
		Util::render_rectangle(&ren, &rect, Util::colour_black());
	}
	SDL_RenderSetClipRect(&ren, &old_clip);
}
Ejemplo n.º 5
0
void GUI::TextBox::Draw() {
	SDL_Rect rect = {x, y, w, h};

	ensure_SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0, 0, 0));

	rect.x += 1;
	rect.y += 1;
	rect.w -= 1;
	rect.h -= 1;

	ensure_SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 255, 255, 255));

	TTF_Font *font = FontStuff::LoadFont("fonts/DejaVuSansMono.ttf", 14);
	int fh = TTF_FontHeight(font);

	rect.x = x + (h - fh) / 2;
	rect.y = y + (h - fh) / 2;

	FontStuff::BlitText(screen, rect, font, ImgStuff::Colour(0,0,0), text);

	if(has_focus()) {
		rect.x += FontStuff::TextWidth(font, text.substr(0, insert_offset));
		rect.w = FontStuff::TextWidth(font, insert_offset < text.length() ? text.substr(insert_offset, 1) : "A");
		rect.h = fh;

		ensure_SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0, 0, 0));

		if(insert_offset < text.length()) {
			FontStuff::BlitText(screen, rect, font, ImgStuff::Colour(255,255,255), text.substr(insert_offset, 1));
		}
	}
}
Ejemplo n.º 6
0
void Slider::_notification(int p_what) {


	switch(p_what) {

		case NOTIFICATION_MOUSE_ENTER: {

			mouse_inside=true;
			update();
		} break;
		case NOTIFICATION_MOUSE_EXIT: {

			mouse_inside=false;
			update();
		} break;
		case NOTIFICATION_DRAW: {
			RID ci = get_canvas_item();
			Size2i size = get_size();
			Ref<StyleBox> style = get_stylebox("slider");
			Ref<StyleBox> focus = get_stylebox("focus");
			Ref<Texture> grabber = get_icon(mouse_inside||has_focus()?"grabber_hilite":"grabber");
			Ref<Texture> tick = get_icon("tick");

			if (orientation==VERTICAL) {

				style->draw(ci,Rect2i(Point2i(),Size2i(style->get_minimum_size().width+style->get_center_size().width,size.height)));
				//if (mouse_inside||has_focus())
				//	focus->draw(ci,Rect2i(Point2i(),Size2i(style->get_minimum_size().width+style->get_center_size().width,size.height)));
				float areasize = size.height - grabber->get_size().height;
				if (ticks>1) {
					int tickarea = size.height - tick->get_height();
					for(int i=0;i<ticks;i++) {
					        if( ! ticks_on_borders && (i == 0 || i + 1 == ticks) ) continue;
						int ofs = i*tickarea/(ticks-1);
						tick->draw(ci,Point2(0,ofs));
					}

				}
				grabber->draw(ci,Point2i(size.width/2-grabber->get_size().width/2,size.height - get_unit_value()*areasize - grabber->get_size().height));
			} else {
				style->draw(ci,Rect2i(Point2i(),Size2i(size.width,style->get_minimum_size().height+style->get_center_size().height)));
				//if (mouse_inside||has_focus())
				//	focus->draw(ci,Rect2i(Point2i(),Size2i(size.width,style->get_minimum_size().height+style->get_center_size().height)));

				float areasize = size.width - grabber->get_size().width;
				if (ticks>1) {
					int tickarea = size.width - tick->get_width();
					for(int i=0;i<ticks;i++) {
					        if( (! ticks_on_borders) && ( (i == 0) || ((i + 1) == ticks)) ) continue;
						int ofs = i*tickarea/(ticks-1);
						tick->draw(ci,Point2(ofs,0));
					}

				}
				grabber->draw(ci,Point2i(get_unit_value()*areasize,size.height/2-grabber->get_size().height/2));
			}

		} break;
	}
}
Ejemplo n.º 7
0
void GUI::ImgButton::Draw() {
	SDL_Rect srect = {0, 0, image->w/2, image->h/2};
	SDL_Rect rect = {x, y, 0, 0};

	if(has_focus()) {
		srect.x = srect.w;
	}

	ensure_SDL_BlitSurface(image, NULL, screen, &rect);
}
Ejemplo n.º 8
0
int
Snes9xPreferences::get_focused_binding (void)
{
    for (int i = 0; b_links[i].button_name; i++)
    {
        if (has_focus (b_links[i].button_name))
            return i;
    }

    return -1;
}
Ejemplo n.º 9
0
bool Viewport::keyboard_keydown(SDL_Event& ev){
	if(has_focus()){
		const Uint8* keyboard = SDL_GetKeyboardState(NULL);		
		if(keyboard[SDL_SCANCODE_W]){ move_camera_px_y(-1); }
		if(keyboard[SDL_SCANCODE_D]){ move_camera_px_x(1); }
		if(keyboard[SDL_SCANCODE_S]){ move_camera_px_y(1); }
		if(keyboard[SDL_SCANCODE_A]){ move_camera_px_x(-1); }		
	}
	this->wrappee->keyboard_keydown(ev);
	return true;
}
Ejemplo n.º 10
0
void NumberField::paint(Painter& painter) {
    const auto text = to_string_dec_int(value_, length_, fill_char);

    const auto paint_style = has_focus() ? style().invert() : style();

    painter.draw_string(
        screen_pos(),
        paint_style,
        text
    );
}
Ejemplo n.º 11
0
void
Inputbox::draw(DrawingContext& gc)
{
  gc.draw_fillrect(rect, Color(255,255,255));
  gc.draw_rect(rect, has_focus() ? Color(255,128,0) : Color(0,0,0));
  
  gc.print_left(Fonts::verdana11, 
                Vector2i(rect.left + 5, 
                         rect.top + rect.get_height()/2 - Fonts::verdana11.get_height()/2),
                text);
}
Ejemplo n.º 12
0
void OptionsField::paint(Painter& painter) {
    const auto paint_style = has_focus() ? style().invert() : style();

    if( selected_index() < options.size() ) {
        const auto text = options[selected_index()].first;
        painter.draw_string(
            screen_pos(),
            paint_style,
            text
        );
    }
}
Ejemplo n.º 13
0
void Image::paint(Painter& painter) {
    if( bitmap_ ) {
        // Code also handles ImageButton behavior.
        const bool selected = (has_focus() || highlighted());
        painter.draw_bitmap(
            screen_pos(),
            *bitmap_,
            selected ? background_ : foreground_,
            selected ? foreground_ : background_
        );
    }
}
Ejemplo n.º 14
0
bool dropdown_widget::handle_event(const SDL_Event& event, bool claimed)
{
	SDL_Event ev = event;
	switch(ev.type) {
		case SDL_MOUSEMOTION: {
			ev.motion.x -= x() & ~1;
			ev.motion.y -= y() & ~1;
			break;
		}
		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP: {
			ev.button.x -= x() & ~1;
			ev.button.y -= y() & ~1;
			break;
		}
	}

	if(claimed) {
		return claimed;
	}

	if(type_ == DROPDOWN_COMBOBOX && editor_) {
		if(editor_->handle_event(ev, claimed)) {
			return true;
		}
	}

	if(dropdown_menu_ && dropdown_menu_->visible()) {
		if(dropdown_menu_->handle_event(ev, claimed)) {
			return true;
		}
	}

	if(has_focus() && dropdown_menu_) {
		if(event.type == SDL_KEYDOWN 
			&& (ev.key.keysym.sym == controls::get_keycode(controls::CONTROL_ATTACK) 
			|| ev.key.keysym.sym == controls::get_keycode(controls::CONTROL_JUMP))) {
			claimed = true;
			dropdown_menu_->set_visible(!dropdown_menu_->visible());
		}
	}

	if(event.type == SDL_MOUSEMOTION) {
		return handle_mousemotion(event.motion, claimed);
	} else if(event.type == SDL_MOUSEBUTTONDOWN) {
		return handle_mousedown(event.button, claimed);
	} else if(event.type == SDL_MOUSEBUTTONUP) {
		return handle_mouseup(event.button, claimed);
	}
	return claimed;
}
Ejemplo n.º 15
0
// ==========================================================================
// DO_EVENT
// ==========================================================================
void gm_tools_screen::do_event(boost::any const &ev)
{
    auto const *vk = boost::any_cast<terminalpp::virtual_key>(&ev);
    bool handled = false;
    
    if (vk)
    {
        if (vk->key == terminalpp::vk::ht)
        {
            focus_next();
            
            if (!has_focus())
            {
                focus_next();
            }
            
            handled = true;
        }
        else if (vk->key == terminalpp::vk::bt)
        {
            focus_previous();

            if (!has_focus())
            {
                focus_previous();
            }
            
            handled = true;
        }
    }
    
    if (!handled)
    {
        composite_component::do_event(ev);
    }
}
Ejemplo n.º 16
0
  virtual void OnPaint(Canvas &canvas) {
    canvas.SelectWhiteBrush();
    if (has_focus())
      canvas.SelectBlackPen();
    else
      canvas.SelectWhitePen();
    canvas.clear();

    unsigned text_height = canvas.CalcTextSize(_T("W")).cy;
    for (int i = num_events - 1, y = 4; i >= 0; --i, y += text_height) {
      const struct key_event &event = events[i];
      TCHAR buffer[64];
      _stprintf(buffer, _T("key %s = 0x%x"),
                event.down ? _T("down") : _T("up"), event.code);
      canvas.text(4, y, buffer);
    }
  }
Ejemplo n.º 17
0
void Button::paint(Painter& painter) {
    const auto r = screen_rect();

    const auto paint_style = (has_focus() || highlighted()) ? style().invert() : style();

    painter.draw_rectangle(r, style().foreground);

    painter.fill_rectangle(
    { r.left() + 1, r.top() + 1, r.width() - 2, r.height() - 2 },
    paint_style.background
    );

    const auto label_r = paint_style.font.size_of(text_);
    painter.draw_string(
    { r.left() + (r.width() - label_r.width()) / 2, r.top() + (r.height() - label_r.height()) / 2 },
    paint_style,
    text_
    );
}
Ejemplo n.º 18
0
void TtkLabel::handle_redraw_event(const TtkRect& redraw_rect)
{
	TtkGcInterface& gc = ws_env().gc();
	gc.set_clipping_rect(redraw_rect);

	TtkRect label_rect(rect());
	TtkRect text_rect(label_rect.tl_.x_ + 1,
			  label_rect.tl_.y_ + 1,
			  label_rect.br_.x_ - 1,
			  label_rect.br_.y_ - 1);
	gc.clear(label_rect);
	if (action_ || !action_) {	//for test
		gc.set_pen_color(kTtkColorBlue);
		if (has_focus())
			gc.draw_rect(label_rect);
		gc.draw_text(text_, text_rect, true);
	} else {
		gc.set_pen_color(kTtkColorBlack);
		gc.draw_text(text_, text_rect, false);
	}
}
Ejemplo n.º 19
0
void GUI::TextButton::Draw() {
	SDL_Rect rect = {x, y, w, h};

	ensure_SDL_BlitSurface(m_bgs, NULL, screen, &rect);

	if(m_borders) {
		Uint32 bcolour = has_focus() ? SDL_MapRGB(screen->format, 255, 255, 0) : SDL_MapRGB(screen->format, 255, 255, 255);
		SDL_Rect ra = {x,y,w,1}, rb = {x,y,1,h}, rc = {x,y+h,w,1}, rd = {x+w,y,1,h+1};

		ensure_SDL_FillRect(screen, &ra, bcolour);
		ensure_SDL_FillRect(screen, &rb, bcolour);
		ensure_SDL_FillRect(screen, &rc, bcolour);
		ensure_SDL_FillRect(screen, &rd, bcolour);
	}

	rect.w = 0;
	rect.h = 0;

	int hoff = (h - TTF_FontLineSkip(m_font)) / 2;
	int width = FontStuff::TextWidth(m_font, m_text);

	switch(m_align) {
		case LEFT:
			rect.x = x + hoff;
			rect.y = y + hoff;
			break;

		case CENTER:
			rect.x = x + (w - width) / 2;
			rect.y = y + hoff;
			break;

		case RIGHT:
			rect.x = (x + w) - (width + hoff);
			rect.y = y + hoff;
			break;
	}

	FontStuff::BlitText(screen, rect, m_font, m_fgc, m_text);
}
Ejemplo n.º 20
0
void
ButtonWindow::on_paint(Canvas &canvas)
{
  if (has_focus()) {
    Pen pen(Layout::Scale(1), COLOR_BLACK);
    canvas.select(pen);
    canvas.hollow_brush();
    canvas.rectangle(-1, -1, canvas.get_width(), canvas.get_height());
  }

  PixelRect rc = { 2, 2, canvas.get_width()-4, canvas.get_height()-4 };
  if (down) {
    rc.left += Layout::FastScale(1);
    rc.top += Layout::FastScale(1);
  }

  canvas.draw_button(get_client_rect(), down);

  canvas.set_text_color(is_enabled() ? COLOR_BLACK : COLOR_GRAY);
  canvas.background_transparent();
  canvas.formatted_text(&rc, text.c_str(), get_text_style());
}
Ejemplo n.º 21
0
void FrequencyField::paint(Painter& painter) {
	const auto mhz = to_string_dec_int(value_ / 1000000, 4);
	const auto hz100 = to_string_dec_int((value_ / 100) % 10000, 4, '0');

	const auto paint_style = has_focus() ? style().invert() : style();

	painter.draw_string(
		screen_pos(),
		paint_style,
		mhz
	);
	painter.draw_string(
		screen_pos() + Point { 4 * 8, 0 },
		paint_style,
		"."
	);
	painter.draw_string(
		screen_pos() + Point { 5 * 8, 0 },
		paint_style,
		hz100
	);
}
Ejemplo n.º 22
0
void ButtonArray::_notification(int p_what) {

    switch(p_what) {
    case NOTIFICATION_MOUSE_EXIT: {
        hover=-1;
        update();
    }
    break;
    case NOTIFICATION_READY: {
        MethodInfo mi;
        mi.name="mouse_sub_enter";

        add_user_signal(mi);

    }
    break;
    case NOTIFICATION_DRAW: {

        Size2 size=get_size();
        Size2 minsize=get_combined_minimum_size();
        Ref<StyleBox> style_normal = get_stylebox("normal");
        Ref<StyleBox> style_selected = get_stylebox("selected");
        Ref<StyleBox> style_focus = get_stylebox("focus");
        Ref<StyleBox> style_hover = get_stylebox("hover");
        Ref<Font> font_normal = get_font("font");
        Ref<Font> font_selected = get_font("font_selected");
        int icon_sep = get_constant("icon_separator");
        int button_sep = get_constant("button_separator");
        Color color_normal = get_color("font_color");
        Color color_selected = get_color("font_color_selected");

        int sep=button_sep;
        int ofs=0;
        int expand=0;

        switch(align) {
        case ALIGN_BEGIN: {

            ofs=0;
        }
        break;
        case ALIGN_CENTER: {

            ofs=Math::floor((size[orientation] - minsize[orientation])/2);
        }
        break;
        case ALIGN_END: {

            ofs=Math::floor((size[orientation] - minsize[orientation]));
        }
        break;
        case ALIGN_FILL: {

            if (buttons.size()>1)
                sep+=Math::floor((size[orientation]- minsize[orientation])/(buttons.size()-1.0));
            ofs=0;
        }
        break;
        case ALIGN_EXPAND_FILL: {

            ofs=0;
            expand=size[orientation] - minsize[orientation];
        }
        break;



        }

        int op_size = orientation==VERTICAL ? size.width : size.height;


        for(int i=0; i<buttons.size(); i++) {

            int ms = buttons[i]._ms_cache;
            int s=ms;
            if (expand>0) {
                s+=expand/buttons.size();
            }
            if(min_button_size != -1 && s < min_button_size) {
                s = min_button_size;
            }

            Rect2 r;
            r.pos[orientation]=ofs;
            r.pos[!orientation]=0;
            r.size[orientation]=s;
            r.size[!orientation]=op_size;

            Ref<Font> f;
            Color c;
            Point2 sbsize;
            Point2 sbofs;
            if (i==selected) {
                draw_style_box(style_selected,r);
                sbsize=style_selected->get_minimum_size();
                sbofs=style_selected->get_offset();
                f=font_selected;
                c=color_selected;
                if (has_focus())
                    draw_style_box(style_focus,r);
            } else {
                if (hover==i)
                    draw_style_box(style_hover,r);
                else if (!flat)
                    draw_style_box(style_normal,r);
                sbsize=style_normal->get_minimum_size();
                sbofs=style_normal->get_offset();
                f=font_normal;
                c=color_normal;
            }

            Size2 ssize = f->get_string_size(buttons[i].text);
            if (buttons[i].icon.is_valid()) {

                ssize.x+=buttons[i].icon->get_width();
            }
            Point2 text_ofs=((r.size-ssize-sbsize)/2.0+Point2(0,f->get_ascent())).floor()+sbofs;
            if (buttons[i].icon.is_valid()) {

                draw_texture(buttons[i].icon,r.pos+Point2(text_ofs.x,Math::floor((r.size.height-buttons[i].icon->get_height())/2.0)));
                text_ofs.x+=buttons[i].icon->get_width()+icon_sep;

            }
            draw_string(f,text_ofs+r.pos,buttons[i].text,c);
            buttons[i]._pos_cache=ofs;
            buttons[i]._size_cache=s;

            ofs+=s;
            ofs+=sep;
        }

    }
    break;
    }
}
Ejemplo n.º 23
0
void Slider::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_MOUSE_ENTER: {

			mouse_inside = true;
			update();
		} break;
		case NOTIFICATION_MOUSE_EXIT: {

			mouse_inside = false;
			update();
		} break;
		case NOTIFICATION_VISIBILITY_CHANGED: // fallthrough
		case NOTIFICATION_EXIT_TREE: {

			mouse_inside = false;
			grab.active = false;
		} break;
		case NOTIFICATION_DRAW: {
			RID ci = get_canvas_item();
			Size2i size = get_size();
			Ref<StyleBox> style = get_stylebox("slider");
			Ref<StyleBox> focus = get_stylebox("focus");
			Ref<StyleBox> grabber_area = get_stylebox("grabber_area");
			Ref<Texture> grabber = get_icon(editable ? ((mouse_inside || has_focus()) ? "grabber_highlight" : "grabber") : "grabber_disabled");
			Ref<Texture> tick = get_icon("tick");

			if (orientation == VERTICAL) {

				int widget_width = style->get_minimum_size().width + style->get_center_size().width;
				float areasize = size.height - grabber->get_size().height;
				style->draw(ci, Rect2i(Point2i(size.width / 2 - widget_width / 2, 0), Size2i(widget_width, size.height)));
				grabber_area->draw(ci, Rect2i(Point2i((size.width - widget_width) / 2, size.height - areasize * get_as_ratio() - grabber->get_size().height / 2), Size2i(widget_width, areasize * get_as_ratio() + grabber->get_size().width / 2)));
				/*
				if (mouse_inside||has_focus())
					focus->draw(ci,Rect2i(Point2i(),Size2i(style->get_minimum_size().width+style->get_center_size().width,size.height)));
				*/
				if (ticks > 1) {
					int tickarea = size.height - tick->get_height();
					for (int i = 0; i < ticks; i++) {
						if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) continue;
						int ofs = i * tickarea / (ticks - 1);
						tick->draw(ci, Point2i((size.width - widget_width) / 2, ofs));
					}
				}
				grabber->draw(ci, Point2i(size.width / 2 - grabber->get_size().width / 2, size.height - get_as_ratio() * areasize - grabber->get_size().height));
			} else {

				int widget_height = style->get_minimum_size().height + style->get_center_size().height;
				float areasize = size.width - grabber->get_size().width;

				style->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(size.width, widget_height)));
				grabber_area->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(areasize * get_as_ratio() + grabber->get_size().width / 2, widget_height)));
				/*
				if (mouse_inside||has_focus())
					focus->draw(ci,Rect2i(Point2i(),Size2i(size.width,style->get_minimum_size().height+style->get_center_size().height)));
				*/

				if (ticks > 1) {
					int tickarea = size.width - tick->get_width();
					for (int i = 0; i < ticks; i++) {
						if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) continue;
						int ofs = i * tickarea / (ticks - 1);
						tick->draw(ci, Point2i(ofs, (size.height - widget_height) / 2));
					}
				}
				grabber->draw(ci, Point2i(get_as_ratio() * areasize, size.height / 2 - grabber->get_size().height / 2));
			}

		} break;
	}
}
Ejemplo n.º 24
0
void Button::draw(const Point& p_pos,const Size& p_size,const Rect& p_exposed) {

	Painter *p=get_painter();

	/* Draw Outline */

	//if disabled...
	bool draw_displaced=false;

	DrawMode draw_mode=get_draw_mode();

	if (draw_mode==DRAW_HOVER) { //optative, otherwise draw normal

		if (stylebox( SB_BUTTON_HOVER ).mode!=StyleBox::MODE_NONE && (!is_toggle_mode() || (is_toggle_mode() && !is_pressed()))) {

			p->draw_stylebox( stylebox( SB_BUTTON_HOVER ) , Point() , p_size, p_exposed );

		} else
			draw_mode=is_pressed()?DRAW_PRESSED:DRAW_NORMAL;
	} ;

	if (draw_mode==DRAW_NORMAL) {

		p->draw_stylebox( stylebox( SB_BUTTON_NORMAL ) , Point() , p_size, p_exposed );

	}

	if (draw_mode==DRAW_PRESSED) {

		p->draw_stylebox( stylebox( SB_BUTTON_PRESSED ) , Point() , p_size, p_exposed );
		draw_displaced=true;

	}


	Rect area_rect=Rect( p_pos, p_size );

	area_rect.pos.x=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_LEFT );
	area_rect.pos.y=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_TOP );
	area_rect.size-=area_rect.pos;

	area_rect.size.x-=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_RIGHT );
	area_rect.size.y-=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_BOTTOM );

	area_rect.size.x-=constant( C_BUTTON_EXTRA_MARGIN )*2;
	area_rect.pos.x+=constant( C_BUTTON_EXTRA_MARGIN );
	area_rect.size.y-=constant( C_BUTTON_EXTRA_MARGIN )*2;
	area_rect.pos.y+=constant( C_BUTTON_EXTRA_MARGIN );

	area_rect.size.x-=constant( C_BUTTON_DISPLACEMENT );
	area_rect.size.y-=constant( C_BUTTON_DISPLACEMENT );
	if (draw_displaced)
		area_rect.pos+=Point( constant( C_BUTTON_DISPLACEMENT ), constant( C_BUTTON_DISPLACEMENT ) );


	if (constant(C_BUTTON_HAS_CHECKBOX)) {

		Size cbsize;

		if ( constant( C_BUTTON_CHECKBOX_SIZE )>0 ) {

			cbsize.width+=constant( C_BUTTON_CHECKBOX_SIZE );
			cbsize.height+=constant( C_BUTTON_CHECKBOX_SIZE );
		} else {

			cbsize=p->get_bitmap_size( bitmap( BITMAP_BUTTON_UNCHECKED ) );
		}

		Point check_pos=area_rect.pos;
		check_pos.y+=(area_rect.size.height-cbsize.height)/2;

		if ( constant( C_BUTTON_CHECKBOX_SIZE )>0 ) {

			p->draw_stylebox( stylebox( is_pressed() ? SB_BUTTON_CHECKED : SB_BUTTON_UNCHECKED ) , check_pos , cbsize);
		} else {

			p->draw_bitmap( bitmap( is_pressed() ? BITMAP_BUTTON_CHECKED : BITMAP_BUTTON_UNCHECKED ), check_pos );
		}

		area_rect.pos.x+=cbsize.x+constant( C_BUTTON_SEPARATION );
		area_rect.size.x-=cbsize.x+constant( C_BUTTON_SEPARATION );
	}

	if (get_icon() >=0 && p->is_bitmap_valid( get_icon() )) {

		Size icon_size=p->get_bitmap_size( get_icon() );

		Point icon_pos=area_rect.pos;
		icon_pos.y+=(area_rect.size.height-icon_size.height)/2;

		p->draw_bitmap( get_icon(), icon_pos );

		area_rect.pos.x+=icon_size.width;
		area_rect.size.x-=icon_size.width;
		if (label_text!="") {
			
			area_rect.pos.x+=constant( C_BUTTON_SEPARATION ); //separation for the label
			area_rect.size.x-=constant( C_BUTTON_SEPARATION ); //separation for the label
		}

	}

	if (shortcut!=0) {
	

		String s_str = Keyboard::get_code_name( shortcut );
		int w = p->get_font_string_width( font(FONT_BUTTON), s_str );
		
		Point shrc_ofs= area_rect.pos;
		
		shrc_ofs.y+=(area_rect.size.height-p->get_font_height( font( FONT_BUTTON ) ))/2+p->get_font_ascent( font( FONT_BUTTON ) );
		shrc_ofs.x = (area_rect.pos.x+area_rect.size.x)-w;
		
		p->draw_text( font( FONT_BUTTON ) ,  shrc_ofs, s_str, color(COLOR_BUTTON_SHORTCUT_FONT) );
		
		area_rect.size.x-=w;
		
	}

	Point label_ofs=area_rect.pos;
	if (constant(C_BUTTON_LABEL_ALIGN_CENTER)) {

		label_ofs.x+=(area_rect.size.width-p->get_font_string_width( font( FONT_BUTTON ) , label_text ))/2;
	}
	label_ofs.y+=(area_rect.size.height-p->get_font_height( font( FONT_BUTTON ) ))/2+p->get_font_ascent( font( FONT_BUTTON ) );


	
	p->draw_text( font( FONT_BUTTON ) ,  label_ofs, label_text, color(draw_mode==DRAW_HOVER?COLOR_BUTTON_FONT_HOVER:COLOR_BUTTON_FONT) );
	if (accel_char >= 0) {
		int width = 0;
		for (int i=0; i<accel_char; i++) {

			width += p->get_font_char_width(font( FONT_BUTTON ), label_text[i]);
		};
		p->draw_text( font( FONT_BUTTON ) ,  label_ofs + Point(width, 0), "_", color(COLOR_BUTTON_FONT) );
	};


	if (has_focus())
		p->draw_stylebox( stylebox( SB_BUTTON_FOCUS ) , Point() , p_size, p_exposed);

}
Ejemplo n.º 25
0
void TextureButton::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_DRAW: {
			DrawMode draw_mode = get_draw_mode();

			Ref<Texture> texdraw;

			switch (draw_mode) {
				case DRAW_NORMAL: {

					if (normal.is_valid())
						texdraw = normal;
				} break;
				case DRAW_PRESSED: {

					if (pressed.is_null()) {
						if (hover.is_null()) {
							if (normal.is_valid())
								texdraw = normal;
						} else
							texdraw = hover;

					} else
						texdraw = pressed;
				} break;
				case DRAW_HOVER: {

					if (hover.is_null()) {
						if (pressed.is_valid() && is_pressed())
							texdraw = pressed;
						else if (normal.is_valid())
							texdraw = normal;
					} else
						texdraw = hover;
				} break;
				case DRAW_DISABLED: {

					if (disabled.is_null()) {
						if (normal.is_valid())
							texdraw = normal;
					} else
						texdraw = disabled;
				} break;
			}

			if (texdraw.is_valid()) {
				Point2 ofs;
				Size2 size = texdraw->get_size();
				Rect2 tex_regin = Rect2(Point2(), texdraw->get_size());
				bool tile = false;
				if (expand) {
					switch (stretch_mode) {
						case STRETCH_KEEP:
							size = texdraw->get_size();
							break;
						case STRETCH_SCALE:
							size = get_size();
							break;
						case STRETCH_TILE:
							size = get_size();
							tile = true;
							break;
						case STRETCH_KEEP_CENTERED:
							ofs = (get_size() - texdraw->get_size()) / 2;
							size = texdraw->get_size();
							break;
						case STRETCH_KEEP_ASPECT_CENTERED:
						case STRETCH_KEEP_ASPECT: {
							Size2 _size = get_size();
							float tex_width = texdraw->get_width() * _size.height / texdraw->get_height();
							float tex_height = _size.height;

							if (tex_width > _size.width) {
								tex_width = _size.width;
								tex_height = texdraw->get_height() * tex_width / texdraw->get_width();
							}

							if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) {
								ofs.x = (_size.width - tex_width) / 2;
								ofs.y = (_size.height - tex_height) / 2;
							}
							size.width = tex_width;
							size.height = tex_height;
						} break;
						case STRETCH_KEEP_ASPECT_COVERED: {
							size = get_size();
							Size2 tex_size = texdraw->get_size();
							Size2 scaleSize(size.width / tex_size.width, size.height / tex_size.height);
							float scale = scaleSize.width > scaleSize.height ? scaleSize.width : scaleSize.height;
							Size2 scaledTexSize = tex_size * scale;
							Point2 ofs = ((scaledTexSize - size) / scale).abs() / 2.0f;
							tex_regin = Rect2(ofs, size / scale);
						} break;
					}
				}
				if (tile)
					draw_texture_rect(texdraw, Rect2(ofs, size), tile);
				else
					draw_texture_rect_region(texdraw, Rect2(ofs, size), tex_regin);
			}
			if (has_focus() && focused.is_valid()) {

				Rect2 drect(Point2(), get_size());
				draw_texture_rect(focused, drect, false);
			};
		} break;
	}
}
Ejemplo n.º 26
0
void Slider::_gui_input(Ref<InputEvent> p_event) {

	if (!editable) {
		return;
	}

	Ref<InputEventMouseButton> mb = p_event;

	if (mb.is_valid()) {
		if (mb->get_button_index() == BUTTON_LEFT) {

			if (mb->is_pressed()) {
				Ref<Texture> grabber = get_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber");
				grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x;

				double grab_width = (double)grabber->get_size().width;
				double grab_height = (double)grabber->get_size().height;
				double max = orientation == VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
				if (orientation == VERTICAL)
					set_as_ratio(1 - (((double)grab.pos - (grab_height / 2.0)) / max));
				else
					set_as_ratio(((double)grab.pos - (grab_width / 2.0)) / max);
				grab.active = true;
				grab.uvalue = get_as_ratio();
			} else {
				grab.active = false;
			}
		} else if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) {

			set_value(get_value() + get_step());
		} else if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN) {
			set_value(get_value() - get_step());
		}
	}

	Ref<InputEventMouseMotion> mm = p_event;

	if (mm.is_valid()) {
		if (grab.active) {

			Size2i size = get_size();
			Ref<Texture> grabber = get_icon("grabber");
			float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos;
			if (orientation == VERTICAL)
				motion = -motion;
			float areasize = orientation == VERTICAL ? size.height - grabber->get_size().height : size.width - grabber->get_size().width;
			if (areasize <= 0)
				return;
			float umotion = motion / float(areasize);
			set_as_ratio(grab.uvalue + umotion);
		}
	}

	if (!mm.is_valid() && !mb.is_valid()) {

		if (p_event->is_action("ui_left") && p_event->is_pressed()) {

			if (orientation != HORIZONTAL)
				return;
			set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
			accept_event();
		} else if (p_event->is_action("ui_right") && p_event->is_pressed()) {

			if (orientation != HORIZONTAL)
				return;
			set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
			accept_event();
		} else if (p_event->is_action("ui_up") && p_event->is_pressed()) {

			if (orientation != VERTICAL)
				return;

			set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
			accept_event();
		} else if (p_event->is_action("ui_down") && p_event->is_pressed()) {

			if (orientation != VERTICAL)
				return;
			set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
			accept_event();

		} else {

			Ref<InputEventKey> k = p_event;

			if (!k.is_valid() || !k->is_pressed())
				return;

			switch (k->get_scancode()) {

				case KEY_HOME: {

					set_value(get_min());
					accept_event();
				} break;
				case KEY_END: {

					set_value(get_max());
					accept_event();

				} break;
			}
		}
	}
}
Ejemplo n.º 27
0
void
WndSymbolButton::on_paint(Canvas &canvas)
{
  /* background and selector */
  canvas.clear(background_brush);

  // Get button RECT and shrink it to make room for the selector/focus
  RECT rc = get_client_rect();

  // Draw button to the background
  canvas.draw_button(rc, is_down());

  // Draw focus rectangle
  if (has_focus()) {
    RECT focus_rc = rc;
    InflateRect(&focus_rc, -3, -3);
    canvas.draw_focus(focus_rc);
  }

  // If button has text on it
  tstring caption = get_text();
  if (caption.empty())
    return;

  // If button is pressed, offset the text for 3D effect
  if (is_down())
    OffsetRect(&rc, 1, 1);

  canvas.null_pen();
  canvas.black_brush();

  const char ch = (char)caption[0];

  // Draw arrow symbols instead of < and >
  if (ch == '<' || ch == '>') {
    int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

    static RasterPoint Arrow[4];
    Arrow[0].x = (rc.left + rc.right) / 2 + (ch == '<' ? size : -size);
    Arrow[0].y = (rc.top + rc.bottom) / 2 + size;
    Arrow[1].x = (rc.left + rc.right) / 2 + (ch == '<' ? -size : size);
    Arrow[1].y = (rc.top + rc.bottom) / 2;
    Arrow[2].x = (rc.left + rc.right) / 2 + (ch == '<' ? size : -size);
    Arrow[2].y = (rc.top + rc.bottom) / 2 - size;
    Arrow[3].x = Arrow[0].x;
    Arrow[3].y = Arrow[0].y;

    canvas.polygon(Arrow, 4);
  }

  // Draw arrow symbols instead of v and ^
  if (ch == '^' || ch == 'v') {
    int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

    RasterPoint Arrow[3];
    Arrow[0].x = (rc.left + rc.right) / 2 +
                 size;
    Arrow[0].y = (rc.top + rc.bottom) / 2 +
                 (ch == '^' ? size : -size);
    Arrow[1].x = (rc.left + rc.right) / 2;
    Arrow[1].y = (rc.top + rc.bottom) / 2 +
                 (ch == '^' ? -size : size);
    Arrow[2].x = (rc.left + rc.right) / 2 - size;
    Arrow[2].y = (rc.top + rc.bottom) / 2 +
                 (ch == '^' ? size : -size);

    canvas.polygon(Arrow, 3);
  }

  // Draw symbols instead of + and -
  if (ch == '+' || ch == '-') {
    int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

    canvas.rectangle((rc.left + rc.right) / 2 - size,
                     (rc.top + rc.bottom) / 2 - size / 3,
                     (rc.left + rc.right) / 2 + size,
                     (rc.top + rc.bottom) / 2 + size / 3);

    if (ch == '+')
      canvas.rectangle((rc.left + rc.right) / 2 - size / 3,
                       (rc.top + rc.bottom) / 2 - size,
                       (rc.left + rc.right) / 2 + size / 3,
                       (rc.top + rc.bottom) / 2 + size);
  }

  // Draw Fly bitmap
  if (caption == _T("Fly")) {
    Bitmap launcher1_bitmap(IDB_LAUNCHER1);
    if (is_down())
      canvas.stretch(launcher1_bitmap);
    else {
      canvas.clear_white();
      canvas.stretch_transparent(launcher1_bitmap, Color::BLUE);
    }
  }

  // Draw Simulator bitmap
  if (caption == _T("Simulator")) {
    Bitmap launcher2_bitmap(IDB_LAUNCHER2);
    if (is_down())
      canvas.stretch(launcher2_bitmap);
    else {
      canvas.clear_white();
      canvas.stretch_transparent(launcher2_bitmap, Color::BLUE);
    }
  }

}
Ejemplo n.º 28
0
void ColorRampEdit::_notification(int p_what) {

	if (p_what==NOTIFICATION_ENTER_TREE) {
		if (!picker->is_connected("color_changed",this,"_color_changed")) {
			picker->connect("color_changed",this,"_color_changed");
		}
	}
	if (p_what==NOTIFICATION_DRAW) {

		int w = get_size().x;
		int h = get_size().y;

		if (w == 0 || h == 0)
			return; //Safety check. We have division by 'h'. And in any case there is nothing to draw with such size

		int total_w = get_size().width-get_size().height-3;

		//Draw checker pattern for ramp
		_draw_checker(0,0, total_w, h);

		//Draw color ramp
		ColorRamp::Point prev;
		prev.offset=0;
		if(points.size() == 0)
			prev.color=Color(0,0,0); //Draw black rectangle if we have no points
		else
			prev.color = points[0].color;  //Extend color of first point to the beginning.

		for(int i=-1;i<points.size();i++) {

			ColorRamp::Point next;
			//If there is no next point
			if (i+1 == points.size()) {
				if(points.size() == 0)
					next.color=Color(0,0,0); //Draw black rectangle if we have no points
				else
					next.color=points[i].color; //Extend color of last point to the end.
				next.offset=1;
			} else {
				next=points[i+1];
			}

			if (prev.offset==next.offset) {
				prev=next;
				continue;
			}

			Vector<Vector2> points;
			Vector<Color> colors;
			points.push_back(Vector2(prev.offset*total_w,h));
			points.push_back(Vector2(prev.offset*total_w,0));
			points.push_back(Vector2(next.offset*total_w,0));
			points.push_back(Vector2(next.offset*total_w,h));
			colors.push_back(prev.color);
			colors.push_back(prev.color);
			colors.push_back(next.color);
			colors.push_back(next.color);
			draw_primitive(points,colors,Vector<Point2>());
			prev=next;
		}

		//Draw point markers
		for(int i=0;i<points.size();i++) {

			Color col = i==grabbed?Color(1,0.0,0.0,0.9):points[i].color.contrasted();
			col.a = 0.9;

			draw_line(Vector2(points[i].offset*total_w,0),Vector2(points[i].offset*total_w,h/2),col);
			draw_rect(Rect2(points[i].offset*total_w-POINT_WIDTH/2, h/2, POINT_WIDTH, h/2), Color(0.6, 0.6, 0.6, i==grabbed?0.9:0.4));
			draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w-POINT_WIDTH/2,h-1),col);
			draw_line(Vector2(points[i].offset*total_w+POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h-1),col);
			draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h/2),col);
			draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h-1),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h-1),col);

		}


		//Draw "button" for color selector
		_draw_checker(total_w+3,0, h, h);
		if (grabbed!=-1) {
			//Draw with selection color
			draw_rect(Rect2(total_w+3,0,h,h),points[grabbed].color);
		} else {
			//if no color selected draw grey color with 'X' on top.
			draw_rect(Rect2(total_w+3,0,h,h), Color(0.5, 0.5, 0.5, 1));
			draw_line(Vector2(total_w+3,0),Vector2(total_w+3+h,h),Color(1,1,1,0.6));
			draw_line(Vector2(total_w+3,h),Vector2(total_w+3+h,0),Color(1,1,1,0.6));
		}

		//Draw borders around color ramp if in focus
		if (has_focus()) {

			draw_line(Vector2(-1,-1),Vector2(total_w+1,-1),Color(1,1,1,0.6));
			draw_line(Vector2(total_w+1,-1),Vector2(total_w+1,h+1),Color(1,1,1,0.6));
			draw_line(Vector2(total_w+1,h+1),Vector2(-1,h+1),Color(1,1,1,0.6));
			draw_line(Vector2(-1,-1),Vector2(-1,h+1),Color(1,1,1,0.6));
		}

	}
}
Ejemplo n.º 29
0
void RichTextLabel::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_RESIZED: {

			main->first_invalid_line=0; //invalidate ALL
			update();

		} break;
		case NOTIFICATION_ENTER_TREE: {

			set_bbcode(bbcode);
			main->first_invalid_line=0; //invalidate ALL
			update();

		} break;
		case NOTIFICATION_THEME_CHANGED: {

			if (is_inside_tree() && use_bbcode) {
				parse_bbcode(bbcode);
				//first_invalid_line=0; //invalidate ALL
				//update();
			}

		} break;
		case NOTIFICATION_DRAW: {

			_validate_line_caches(main);
			_update_scroll();


			RID ci=get_canvas_item();
			Size2 size = get_size();

			VisualServer::get_singleton()->canvas_item_set_clip(ci,true);

			if (has_focus()) {
				VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci,true);
				draw_style_box(get_stylebox("focus"),Rect2(Point2(),size));
				VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci,false);
			}

			int ofs = vscroll->get_val();

			//todo, change to binary search

			int from_line = 0;
			int total_chars = 0;
			while (from_line<main->lines.size()) {

				if (main->lines[from_line].height_accum_cache>=ofs)
					break;
				from_line++;
				total_chars+=main->lines[from_line].char_count;
			}

			if (from_line>=main->lines.size())
				break; //nothing to draw

			int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs;
			Ref<Font> base_font=get_font("normal_font");
			Color base_color=get_color("default_color");

			while (y<size.height && from_line<main->lines.size()) {

				_process_line(main,Point2(),y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color,Point2i(),NULL,NULL,NULL,total_chars);
				total_chars+=main->lines[from_line].char_count;
				from_line++;
			}
		}
	}
}
Ejemplo n.º 30
0
void SimpleTextfield::update(sf::Time& time_passed){
    if (has_focus())
        _rect_shape.setOutlineThickness(2);
    else
        _rect_shape.setOutlineThickness(0);
}