Esempio n. 1
0
void Horizontal_paned_view::Render(const Widget& widget) const
{
	const Horizontal_paned& horizontal_paned = dynamic_cast<const Horizontal_paned&>(widget);
	Widget* left = horizontal_paned.Get_left();
	Widget* right = horizontal_paned.Get_right();
	Widget_view* view;
	int clip_x, clip_y, clip_w, clip_h;
	al_get_clipping_rectangle(&clip_x, &clip_y, &clip_w, &clip_h);
	if(left)
	{
		Vector2 p = left->Get_position();
		Vector2 s = left->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		left->Render();
	}
	if(right)
	{
		Vector2 p = right->Get_position();
		Vector2 s = right->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		right->Render();
	}
	al_set_clipping_rectangle(clip_x, clip_y, clip_w, clip_h);

	Vector2 p = widget.Get_position();
	Vector2 s = widget.Get_size();
	float pane = p.x+horizontal_paned.Get_pane_position();
	ALLEGRO_COLOR bg_color = al_map_rgb_f(0.7, 0.7, 0.7);
	ALLEGRO_COLOR edge_color = al_map_rgb_f(0.3, 0.3, 0.3);
	al_draw_filled_rectangle(pane, p.y+1, pane+6, p.y+s.y, bg_color);
	al_draw_rectangle(pane, p.y+1, pane+6, p.y+s.y, edge_color, 0);
	al_draw_line(pane+2, p.y+s.y/2-10, pane+2, p.y+s.y/2+10, edge_color, 0);
	al_draw_line(pane+4, p.y+s.y/2-10, pane+4, p.y+s.y/2+10, edge_color, 0);
}
Esempio n. 2
0
void Vertical_paned_view::Render(const Widget& widget) const
{
	const Vertical_paned& vertical_paned = dynamic_cast<const Vertical_paned&>(widget);
	Widget* top = vertical_paned.Get_top();
	Widget* bottom = vertical_paned.Get_bottom();
	Widget_view* view;
	int clip_x, clip_y, clip_w, clip_h;
	al_get_clipping_rectangle(&clip_x, &clip_y, &clip_w, &clip_h);
	if(top)
	{
		Vector2 p = top->Get_position();
		Vector2 s = top->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		top->Render();
	}
	if(bottom)
	{
		Vector2 p = bottom->Get_position();
		Vector2 s = bottom->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		bottom->Render();
	}
	al_set_clipping_rectangle(clip_x, clip_y, clip_w, clip_h);

	Vector2 p = widget.Get_position();
	Vector2 s = widget.Get_size();
	float pane = p.y+vertical_paned.Get_pane_position()+1;
	ALLEGRO_COLOR bg_color = al_map_rgb_f(0.7, 0.7, 0.7);
	ALLEGRO_COLOR edge_color = al_map_rgb_f(0.3, 0.3, 0.3);
	al_draw_filled_rectangle(p.x, pane, p.x+s.x-1, pane+6, bg_color);
	al_draw_rectangle(p.x, pane, p.x+s.x-1, pane+6, edge_color, 0);
	al_draw_line(p.x+s.x/2-10, pane+2, p.x+s.x/2+10, pane+2, edge_color, 0);
	al_draw_line(p.x+s.x/2-10, pane+4, p.x+s.x/2+10, pane+4, edge_color, 0);
}
Esempio n. 3
0
void Widget::Render ()
{
    SDL_Rect absolutePosition = GetAbsolutePosition();

    if ( m_cachedSurfaceID != INVALID_SURFACE_ID )
        g_graphics->Blit ( m_cachedSurfaceID, NULL, g_graphics->GetScreen(), &absolutePosition ); // FLAG
    for ( size_t i = 0; i < m_widgets.size(); i++ )
    {
        Widget *widget = m_widgets[i];
        CrbReleaseAssert ( widget );
        widget->Update();
        if ( widget->m_expired )
        {
            m_widgets.remove ( i-- );
            delete widget;
            continue;
        }
        widget->Render();
    }
}
Esempio n. 4
0
int main(int argc, char **argv)
{
	al_init();
	al_install_mouse();
	al_install_keyboard();
	al_init_image_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	al_init_primitives_addon();
	
	al_set_new_display_flags(ALLEGRO_WINDOWED|ALLEGRO_RESIZABLE);
	ALLEGRO_DISPLAY *display = al_create_display(640, 480);
	ALLEGRO_DISPLAY *tooldisplay = al_create_display(200, 480);
    al_set_window_position(tooldisplay, 10, 0);
    al_set_window_position(display, 220, 0);
    
	ALLEGRO_DISPLAY *current_display = tooldisplay;
	ALLEGRO_TIMER* timer = al_create_timer(1);

	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	al_register_event_source(event_queue, (ALLEGRO_EVENT_SOURCE *)display);
	al_register_event_source(event_queue, (ALLEGRO_EVENT_SOURCE *)tooldisplay);
	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_mouse_event_source());
	al_register_event_source(event_queue, al_get_timer_event_source(timer));

	ALLEGRO_FONT* font = al_load_font("data/DejaVuSans.ttf", 12, 0);
	if(!font)
		font = al_load_font("examples/data/DejaVuSans.ttf", 12, 0);

	Layout layout;

	Layout_controller layout_controller;
	layout_controller.Set_layout(&layout);

	Tree* widget_tree = layout_controller.Get_skin().Clone<Tree>("tree");
	widget_tree->Set_text("Desktop");
	widget_tree->Select();

	Widget* root_widget = layout_controller.Get_skin().Clone<Desktop>("desktop");
	root_widget->Set_position(Vector2(0, 0));
	root_widget->Set_size(Vector2(640, 480));

	layout_controller.Set_tree(widget_tree, root_widget);
	layout_controller.Set_root(root_widget);
	layout_controller.Set_root_tree(widget_tree);
	layout_controller.Select_tree(widget_tree);

	layout.Set_skin(&layout_controller.Get_skin());
	layout.Add_widget("root", root_widget, NULL);


	Editor_controller editor_controller;
	editor_controller.Set_layout_display(display);
	editor_controller.Set_layout_controller(layout_controller);
	editor_controller.Load(layout_controller.Get_skin());

	//FPS
	Label* fps_label = layout_controller.Get_skin().Clone<Label>("label");
	fps_label->Set_text("FPS: 100");

	//Main vbox
	Vertical_box* toolvbox = layout_controller.Get_skin().Clone<Vertical_box>("vertical box");
	toolvbox->Add(editor_controller.Get_root());
	toolvbox->Add(fps_label);

	Slider_box* slider_box = layout_controller.Get_skin().Clone<Slider_box>("slider box");
	slider_box->Set_child(toolvbox);

	Desktop* desktop = layout_controller.Get_skin().Clone<Desktop>("desktop");
	desktop->Set_child(slider_box);
	desktop->Set_position(Vector2(0, 0));
	desktop->Set_size(Vector2(200, 480));

	Widget* toolroot = desktop;

	al_start_timer(timer);
	bool quit = false;
	while (!quit)
	{
		ALLEGRO_EVENT event;
		al_wait_for_event(event_queue, &event);
		if (ALLEGRO_EVENT_KEY_DOWN == event.type)
		{
			if (ALLEGRO_KEY_ESCAPE == event.keyboard.keycode)
			{
				quit=true;
			}
		}
		if (ALLEGRO_EVENT_DISPLAY_CLOSE == event.type)
		{
			quit=true;
		}
		if (ALLEGRO_EVENT_DISPLAY_RESIZE == event.type)
		{
			al_acknowledge_resize(event.display.source);
			if(event.display.source == display)
				layout_controller.Get_root()->Set_size(Vector2(event.display.width-20, event.display.height-20));
		}
		if (ALLEGRO_EVENT_DISPLAY_SWITCH_IN == event.type)
		{
			current_display = event.display.source;
		}
		
		if(current_display == tooldisplay)
		{
			toolroot->Handle_event(event);
		}
		if(current_display == display)
		{
			layout_controller.Get_root()->Handle_event(event);
		}
		
		if(ALLEGRO_EVENT_TIMER == event.type) {
			double dt = al_get_timer_speed(timer);
			editor_controller.Update();
			layout_controller.Get_skin().Update(dt);

			al_set_target_backbuffer(display);
			layout_controller.Get_root()->Render();
			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));

			al_set_target_backbuffer(tooldisplay);
			toolroot->Render();

			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));

			double fps = 1 / dt;
			std::stringstream ss;
			ss<<fps;
			std::string fps_string;
			ss>>fps_string;
			fps_label->Set_text((std::string("FPS: ")+fps_string).c_str());

			if(dt < 1 && event.timer.count < al_get_timer_count(timer) - 4)
			{
				dt = dt * 1.1;
				al_set_timer_speed(timer, dt);
				//print("Tick too fast, setting speed to " .. timer_speed);
			}
			if(event.timer.count == al_get_timer_count(timer))
			{
				dt = dt * 0.9;
				al_set_timer_speed(timer, dt);
				//print("Tick too fast, setting speed to " .. timer_speed);
			}

			al_rest(0.001);
		}
	}