void EntitiesEditor::onInput(const InputState &state) { auto mouse_pos = state.mousePos() - clippedRect().min; computeCursor(mouse_pos, mouse_pos, state.isKeyPressed(InputKey::lshift)); if(state.isKeyDown('s')) { m_mode = Mode::selecting; sendEvent(this, Event::button_clicked, m_mode); } if(state.isKeyDown('p')) { m_mode = Mode::placing; sendEvent(this, Event::button_clicked, m_mode); } if(m_proto) { int inc = 0; if(state.isKeyDown(InputKey::left)) inc = -1; if(state.isKeyDown(InputKey::right)) inc = 1; int dir_count = m_proto->sprite().dirCount(0); if(inc && dir_count) m_proto_angle = (m_proto_angle + inc + dir_count) % dir_count; m_proto->setDirAngle(constant::pi * 2.0f * (float)m_proto_angle / float(dir_count)); } if(state.isKeyPressed(InputKey::del)) { for(int i = 0; i < (int)m_selected_ids.size(); i++) m_entity_map.remove(m_selected_ids[i]); m_selected_ids.clear(); } m_view.update(state); }
void XEditBox::mouseLPressEvent(X_Event *event) { cursor_addr=computeCursor(event->motion->x); //插入光标 }
bool EntitiesEditor::onMouseDrag(const InputState &state, int2 start, int2 current, int key, int is_final) { bool shift_pressed = state.isKeyPressed(InputKey::lshift); if(key == 0 && !state.isKeyPressed(InputKey::lctrl)) { computeCursor(start, current, shift_pressed); m_is_selecting = !is_final; if(m_mode == Mode::selecting && is_final && is_final != -1) { findVisible(m_selected_ids, m_selection); computeCursor(current, current, shift_pressed); } else if(m_mode == Mode::placing) { if(m_proto->typeId() == EntityId::trigger) { Trigger *trigger = static_cast<Trigger*>(m_proto.get()); if(m_trigger_mode == 0) { m_trigger_box = m_view.computeCursor(start, current, int3(1, 1, 1), m_cursor_pos.y, 0); if(state.isMouseButtonDown(InputButton::right)) { m_trigger_mode = 1; m_trigger_offset = current; } } IBox new_box = m_trigger_box; if(m_trigger_mode == 1) { int offset = screenToWorld(int2(0, m_trigger_offset.y - current.y)).y; if(offset < 0) new_box.min.y += offset; else new_box.max.y += offset; } trigger->setBox((FBox)new_box); m_cursor_pos = trigger->pos(); if(is_final > 0) { m_entity_map.add(PEntity(m_proto->clone())); } if(is_final) { m_trigger_mode = 0; trigger->setBox(FBox(0, 0, 0, 1, 1, 1) + trigger->pos()); } } else if(is_final > 0) m_entity_map.add(PEntity(m_proto->clone())); } return true; } else if(key == 1 && m_mode == Mode::selecting) { if(!m_is_moving) { m_is_moving_vertically = state.isKeyPressed(InputKey::lshift); m_is_moving = true; } if(m_is_moving_vertically) m_move_offset = int3(0, screenToWorld(int2(0, start.y - current.y)).y, 0); else m_move_offset = asXZY(screenToWorld(current - start), 0); if(is_final) m_is_moving = false; if(is_final > 0) { for(int n = 0; n < (int)m_selected_ids.size(); n++) { auto &object = m_entity_map[m_selected_ids[n]]; object.ptr->setPos(object.ptr->pos() + float3(m_move_offset)); m_entity_map.update(m_selected_ids[n]); } } return true; } return false; }