WindowManagerProvider::WindowManagerProvider(DisplayWindow window) : window(window), canvas(window.get_gc()), site(0), focus(0), mouse_capture(0), scale(1.0f), mouse_enabled(true), enabled(false) { slots.connect(window.sig_resize(), this, &WindowManagerProvider::on_displaywindow_resize); InputContext ic = window.get_ic(); slots.connect(ic.get_mouse().sig_key_up(), this, &WindowManagerProvider::on_mouse_input_received); slots.connect(ic.get_mouse().sig_key_down(), this, &WindowManagerProvider::on_mouse_input_received); slots.connect(ic.get_mouse().sig_key_dblclk(), this, &WindowManagerProvider::on_mouse_input_received); slots.connect(ic.get_mouse().sig_pointer_move(), this, &WindowManagerProvider::on_mouse_input_received); slots.connect(ic.get_keyboard().sig_key_up(), this, &WindowManagerProvider::on_input_received); slots.connect(ic.get_keyboard().sig_key_down(), this, &WindowManagerProvider::on_input_received); for (int i = 0; i < ic.get_tablet_count(); ++i) { slots.connect(ic.get_tablet(i).sig_axis_move(), this, &WindowManagerProvider::on_mouse_input_received); slots.connect(ic.get_tablet(i).sig_key_down(), this, &WindowManagerProvider::on_mouse_input_received); slots.connect(ic.get_tablet(i).sig_key_dblclk(), this, &WindowManagerProvider::on_mouse_input_received); slots.connect(ic.get_tablet(i).sig_key_up(), this, &WindowManagerProvider::on_mouse_input_received); slots.connect(ic.get_tablet(i).sig_proximity_change(), this, &WindowManagerProvider::on_mouse_input_received); } #ifdef WIN32 DataBuffer ani_file = File::read_bytes("Resources/Engine/Cursors/NormalSelect.ani"); int desired_width = 32; int desired_height = 32; cursor = (HCURSOR)CreateIconFromResourceEx((PBYTE) ani_file.get_data(), ani_file.get_size(), FALSE, 0x00030000, desired_width, desired_height, LR_DEFAULTCOLOR); if (cursor == 0) throw Exception("CreateIconFromResourceEx failed!"); #endif }
int HSV::start(const std::vector<std::string> &args) { DisplayWindow window("ClanLib HSV Example", 1024, 768); Slot slot = window.sig_window_close().connect(this, &HSV::on_close); Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &HSV::on_input_up); Canvas canvas(window); InputContext ic = window.get_ic(); ProgramObject program = create_shader_program(canvas); Texture texture = create_texture(canvas); clan::Font font(canvas, "tahoma", 24); ubyte64 last_time = System::get_time(); float hue_offset = 0.0; while (!quit) { ubyte64 current_time = System::get_time(); float time_delta_ms = static_cast<float> (current_time - last_time); last_time = current_time; if (ic.get_keyboard().get_keycode(keycode_left)) hue_offset += 0.0005f * time_delta_ms; else if (ic.get_keyboard().get_keycode(keycode_right)) hue_offset -= 0.0005f * time_delta_ms; if (hue_offset < -1.0f) hue_offset += 1.0f; if (hue_offset > 1.0f) hue_offset -= 1.0f; render_texture(canvas, program, texture, hue_offset); font.draw_text(canvas, 32, 700, "Use cursor keys left and right"); window.flip(); KeepAlive::process(10); } return 0; }
GUIWindowManagerProvider_Direct::GUIWindowManagerProvider_Direct(DisplayWindow &display_window, Canvas &canvas) : site(0), activated_window(0), capture_mouse_window(NULL), display_window(display_window), window_canvas(canvas) { slots.connect(display_window.sig_window_close(), this, &GUIWindowManagerProvider_Direct::on_displaywindow_window_close); InputContext ic = display_window.get_ic(); slots.connect(ic.get_mouse().sig_key_up(), this, &GUIWindowManagerProvider_Direct::on_input_mouse_up); slots.connect(ic.get_mouse().sig_key_down(), this, &GUIWindowManagerProvider_Direct::on_input_mouse_down); slots.connect(ic.get_mouse().sig_key_dblclk(), this, &GUIWindowManagerProvider_Direct::on_input_mouse_down); slots.connect(ic.get_mouse().sig_pointer_move(), this, &GUIWindowManagerProvider_Direct::on_input_mouse_move); slots.connect(ic.get_keyboard().sig_key_up(), this, &GUIWindowManagerProvider_Direct::on_input); slots.connect(ic.get_keyboard().sig_key_down(), this, &GUIWindowManagerProvider_Direct::on_input); for (int tc = 0; tc < ic.get_tablet_count(); ++tc) { slots.connect(ic.get_tablet(tc).sig_axis_move(), this, &GUIWindowManagerProvider_Direct::on_input_mouse_move); slots.connect(ic.get_tablet(tc).sig_key_dblclk(), this, &GUIWindowManagerProvider_Direct::on_input_mouse_down); slots.connect(ic.get_tablet(tc).sig_key_down(), this, &GUIWindowManagerProvider_Direct::on_input_mouse_down); slots.connect(ic.get_tablet(tc).sig_key_up(), this, &GUIWindowManagerProvider_Direct::on_input); } }
int HSV::start(const std::vector<std::string> &args) { clan::SlotContainer cc; DisplayWindow window("ClanLib HSV Sprite", 1024, 768); cc.connect(window.sig_window_close(), clan::bind_member(this, &HSV::on_close)); cc.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &HSV::on_input_up)); Canvas canvas(window); InputContext ic = window.get_ic(); clan::Font font(canvas, "Tahoma", -11); HSVSpriteBatch sprite_batcher(canvas); HSVSprite car1(canvas, &sprite_batcher, "../../Game/SpritesRTS/Gfx/spaceshoot_body_moving1.png"); HSVSprite car2(canvas, &sprite_batcher, "Resources/ferrari_maranello.png"); HSVSprite *cars[] = { &car1, &car2 }; ubyte64 last_fps_update = System::get_time(); ubyte64 last_time = last_fps_update; int fps = 0; std::string fps_text; float hue_offset = 0.0; while (!quit) { ubyte64 current_time = System::get_time(); float time_delta_ms = static_cast<float> (current_time - last_time); last_time = current_time; if (ic.get_keyboard().get_keycode(keycode_left)) hue_offset += 0.0005f * time_delta_ms; else if (ic.get_keyboard().get_keycode(keycode_right)) hue_offset -= 0.0005f * time_delta_ms; if (hue_offset < -1.0f) hue_offset += 1.0f; if (hue_offset > 1.0f) hue_offset -= 1.0f; canvas.clear(Colorf::darkslategrey); float car_hue = hue_offset; for (int y = 0; y < 10; y++) { for (int x = 0; x < 7; x++) { cars[(x+y)%2]->draw(canvas, 60+x*128, 60+y*64, car_hue); car_hue += 0.02f; if (car_hue < -1.0f) car_hue += 1.0f; if (car_hue > 1.0f) car_hue -= 1.0f; } } fps++; if (System::get_time() - last_fps_update > 2000) { fps_text = string_format("%1 fps", fps/2.0f); last_fps_update = System::get_time(); fps = 0; } Size fps_size = font.get_text_size(canvas, fps_text); font.draw_text(canvas, canvas.get_width()-10-fps_size.width, 16, fps_text); font.draw_text(canvas, 32, 730, "Use cursor keys left and right"); window.flip(0); KeepAlive::process(); } return 0; }
void GUIWindowManagerProvider_System::create_window( GUITopLevelWindow *handle, GUITopLevelWindow *owner, GUIComponent *component, GUITopLevelDescription description) { description.set_update_supported(true); GUITopLevelWindowSystem *owner_window = 0; if (owner) { owner_window = window_map[owner]; description.set_owner_window(owner_window->window); } GUITopLevelWindowSystem *top_level_window; #ifdef WIN32 // Cached windows do not work on Linux if (description.get_using_gui_window_cache()) { used_cached_windows++; if (used_cached_windows <= cached_windows.size()) { top_level_window = cached_windows[used_cached_windows-1]; top_level_window->slots = SlotContainer(); cache_window_handles[handle] = top_level_window->window.get_hwnd(); } else { top_level_window = new GUITopLevelWindowSystem; top_level_window->window = DisplayWindow(description); top_level_window->canvas = Canvas(top_level_window->window); cached_windows.push_back(top_level_window); cache_window_handles[handle] = top_level_window->window.get_hwnd(); } } else #endif { top_level_window = new GUITopLevelWindowSystem; top_level_window->window = DisplayWindow(description); top_level_window->canvas = Canvas(top_level_window->window); } top_level_window->canvas.set_map_mode(map_2d_upper_left); top_level_window->slots.connect(top_level_window->window.sig_lost_focus(), this, &GUIWindowManagerProvider_System::on_displaywindow_lost_focus, handle); top_level_window->slots.connect(top_level_window->window.sig_got_focus(), this, &GUIWindowManagerProvider_System::on_displaywindow_got_focus, handle); top_level_window->slots.connect(top_level_window->window.sig_resize(), this, &GUIWindowManagerProvider_System::on_displaywindow_resize, handle); top_level_window->slots.connect(top_level_window->window.sig_paint(), this, &GUIWindowManagerProvider_System::on_displaywindow_paint, handle); top_level_window->slots.connect(top_level_window->window.sig_window_close(), this, &GUIWindowManagerProvider_System::on_displaywindow_window_close, handle); top_level_window->slots.connect(top_level_window->window.sig_window_destroy(), this, &GUIWindowManagerProvider_System::on_displaywindow_window_destroy, handle); InputContext ic = top_level_window->window.get_ic(); top_level_window->slots.connect(ic.get_mouse().sig_key_up(), this, &GUIWindowManagerProvider_System::on_input, handle); top_level_window->slots.connect(ic.get_mouse().sig_key_down(), this, &GUIWindowManagerProvider_System::on_input, handle); top_level_window->slots.connect(ic.get_mouse().sig_key_dblclk(), this, &GUIWindowManagerProvider_System::on_input, handle); top_level_window->slots.connect(ic.get_mouse().sig_pointer_move(), this, &GUIWindowManagerProvider_System::on_input, handle); top_level_window->slots.connect(ic.get_keyboard().sig_key_up(), this, &GUIWindowManagerProvider_System::on_input, handle); top_level_window->slots.connect(ic.get_keyboard().sig_key_down(), this, &GUIWindowManagerProvider_System::on_input, handle); for (int i = 0; i < ic.get_tablet_count(); ++i) { top_level_window->slots.connect(ic.get_tablet(i).sig_axis_move(), this, &GUIWindowManagerProvider_System::on_input, handle); top_level_window->slots.connect(ic.get_tablet(i).sig_key_down(), this, &GUIWindowManagerProvider_System::on_input, handle); top_level_window->slots.connect(ic.get_tablet(i).sig_key_dblclk(), this, &GUIWindowManagerProvider_System::on_input, handle); top_level_window->slots.connect(ic.get_tablet(i).sig_key_up(), this, &GUIWindowManagerProvider_System::on_input, handle); top_level_window->slots.connect(ic.get_tablet(i).sig_proximity_change(), this, &GUIWindowManagerProvider_System::on_input, handle); } window_map[handle] = top_level_window; sig_toplevel_window_created.invoke(top_level_window->window); }