| 206 | } |
| 207 | |
| 208 | void imgui_instance::update_input(const polymer::app_input_event & e) |
| 209 | { |
| 210 | ImGui::SetCurrentContext(data.context); |
| 211 | |
| 212 | ImGuiIO & io = ImGui::GetIO(); |
| 213 | |
| 214 | if (e.type == app_input_event::Type::MOUSE) |
| 215 | { |
| 216 | if (e.action == GLFW_PRESS) |
| 217 | { |
| 218 | int button = clamp<int>(e.value[0], 0, 3); |
| 219 | data.MousePressed[button] = true; |
| 220 | } |
| 221 | io.MousePos = ImVec2(e.cursor.x, e.cursor.y); |
| 222 | } |
| 223 | |
| 224 | if (e.type == app_input_event::Type::CURSOR) |
| 225 | { |
| 226 | io.MousePos = ImVec2(e.cursor.x, e.cursor.y); |
| 227 | } |
| 228 | |
| 229 | if (e.type == app_input_event::Type::SCROLL) |
| 230 | { |
| 231 | data.MouseWheel += (float)e.value[1]; // Use fractional mouse wheel, 1.0 unit 5 lines. |
| 232 | } |
| 233 | |
| 234 | if (e.type == app_input_event::Type::KEY) |
| 235 | { |
| 236 | update_key_modifiers(io, e.mods); |
| 237 | ImGuiKey imgui_key = glfw_key_to_imgui_key(e.value[0]); |
| 238 | if (imgui_key != ImGuiKey_None) |
| 239 | { |
| 240 | io.AddKeyEvent(imgui_key, (e.action == GLFW_PRESS || e.action == GLFW_REPEAT)); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | if (e.type == app_input_event::Type::CHAR) |
| 245 | { |
| 246 | if (e.value[0] > 0 && e.value[0] < 0x10000) |
| 247 | { |
| 248 | io.AddInputCharacter((unsigned short) e.value[0]); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | } |
| 253 | |
| 254 | bool imgui_instance::create_fonts_texture() |
| 255 | { |