/* TextureEditorPanel::onPatchPositionXChanged * Called when the patch x position spin control is changed *******************************************************************/ void TextureEditorPanel::onPatchPositionXChanged(wxCommandEvent& e) { // If anything other than 1 patch is selected, do nothing (shouldn't happen anyway) if (list_patches->GetSelectedItemCount() != 1) return; // Get selected patch CTPatch* patch = tex_current->getPatch(list_patches->selectedItems()[0]); if (!patch) return; // Set patch x offset patch->setOffsetX(spin_patch_left->GetValue()); // Update UI tex_canvas->redraw(true); tex_modified = true; }
/* TextureEditorPanel::onTexCanvasKeyDown * Called when a key is pressed within the texture canvas *******************************************************************/ void TextureEditorPanel::onTexCanvasKeyDown(wxKeyEvent& e) { // Check if keypress matches any keybinds wxArrayString binds = KeyBind::getBinds(KeyBind::asKeyPress(e.GetKeyCode(), e.GetModifiers())); // Check for alt key if (e.GetKeyCode() == WXK_ALT) alt_press = true; // Go through matching binds int x_movement = 0; int y_movement = 0; bool handled = false; for (unsigned a = 0; a < binds.size(); a++) { string name = binds[a]; // Move patch left if (name == "txed_patch_left") x_movement = -1; else if (name == "txed_patch_left8") x_movement = -8; // Move patch up else if (name == "txed_patch_up") y_movement = -1; else if (name == "txed_patch_up8") y_movement = -8; // Move patch right else if (name == "txed_patch_right") x_movement = 1; else if (name == "txed_patch_right8") x_movement = 8; // Move patch down else if (name == "txed_patch_down") y_movement = 1; else if (name == "txed_patch_down8") y_movement = 8; // Add patch else if (name == "txed_patch_add") { hack_nodrag = true; addPatch(); handled = true; } // Delete patch else if (name == "txed_patch_delete") { removePatch(); handled = true; } // Replace patch else if (name == "txed_patch_replace") { hack_nodrag = true; replacePatch(); handled = true; } // Duplicate patch else if (name == "txed_patch_duplicate") { duplicatePatch(); handled = true; } // Bring patch forward else if (name == "txed_patch_forward") { patchForward(); handled = true; } // Send patch back else if (name == "txed_patch_back") { patchBack(); handled = true; } } // Move patches if needed if (x_movement != 0 || y_movement != 0) { // Do patch duplicate if alt is pressed if (e.GetModifiers() == wxMOD_ALT && alt_press) { duplicatePatch(0, 0); alt_press = false; } wxArrayInt selected_patches = list_patches->selectedItems(); for (size_t a = 0; a < selected_patches.size(); a++) { CTPatch* patch = tex_current->getPatch(selected_patches[a]); if (!patch) continue; int16_t cx = patch->xOffset(); int16_t cy = patch->yOffset(); patch->setOffsetX(cx + x_movement); patch->setOffsetY(cy + y_movement); tex_modified = true; } tex_canvas->redraw(true); handled = true; } if (!e.AltDown()) alt_press = false; if (!handled) e.Skip(); }
/* TextureEditorPanel::onTexCanvasMouseEvent * Called on any mouse event within the texture canvas *******************************************************************/ void TextureEditorPanel::onTexCanvasMouseEvent(wxMouseEvent& e) { // Get mouse position relative to texture point2_t pos = tex_canvas->screenToTexPosition(e.GetX(), e.GetY()); // Get patch that the mouse is over (if any) int patch = tex_canvas->patchAt(pos.x, pos.y); // LEFT DOUBLE CLICK if (e.ButtonDClick(wxMOUSE_BTN_LEFT)) { replacePatch(); } // LEFT MOUSE DOWN else if (e.LeftDown()) { // If not dragging if (e.ShiftDown()) { // Shift is down, add to selection if (patch >= 0) list_patches->selectItem(patch); } else if (e.ControlDown()) { // Control is down, remove from selection if (patch >= 0) list_patches->deSelectItem(patch); } else { // Clear selection only if patch clicked was not already selected if (!tex_canvas->patchSelected(patch)) list_patches->clearSelection(); // Select patch if (patch >= 0) list_patches->selectItem(patch); } } // LEFT MOUSE UP else if (e.LeftUp()) { // Hide texture grid tex_canvas->showGrid(false); // If mouse up over an already-selected patch, and shift/ctrl aren't down, // select only that patch (this mimics 'normal' drag-and-drop/selection behaviour) if (!e.ShiftDown() && !e.ControlDown() && tex_canvas->patchSelected(patch) && !tex_canvas->isDragging()) { list_patches->clearSelection(); list_patches->selectItem(patch); } // Redraw texture canvas tex_canvas->redraw(false); updateTextureControls(); } // RIGHT MOUSE UP else if (e.RightUp()) { // Create context menu wxMenu popup; theApp->getAction("txed_patch_add")->addToMenu(&popup, true); theApp->getAction("txed_patch_remove")->addToMenu(&popup, true); theApp->getAction("txed_patch_replace")->addToMenu(&popup, true); theApp->getAction("txed_patch_back")->addToMenu(&popup, true); theApp->getAction("txed_patch_forward")->addToMenu(&popup, true); theApp->getAction("txed_patch_duplicate")->addToMenu(&popup, true); hack_nodrag = true; PopupMenu(&popup); } // MOUSE DRAGGING else if (e.Dragging()) { // Drag selected patches if left button is down and any patch is selected if (hack_nodrag) hack_nodrag = false; else if (e.LeftIsDown()) { if (list_patches->GetSelectedItemCount() > 0) { // Get drag amount according to texture point2_t tex_cur = tex_canvas->screenToTexPosition(e.GetX(), e.GetY()); point2_t tex_prev = tex_canvas->screenToTexPosition(tex_canvas->getMousePrevPos().x, tex_canvas->getMousePrevPos().y); point2_t diff = tex_cur - tex_prev; // Move any selected patches wxArrayInt selected_patches = list_patches->selectedItems(); for (size_t a = 0; a < selected_patches.size(); a++) { CTPatch* patch = tex_current->getPatch(selected_patches[a]); if (!patch) continue; int16_t cx = patch->xOffset(); int16_t cy = patch->yOffset(); patch->setOffsetX(cx + diff.x); patch->setOffsetY(cy + diff.y); tex_modified = true; } // Refresh texture canvas tex_canvas->showGrid(true); tex_canvas->redraw(false); } else if (tex_current && tex_current->isExtended() && tex_canvas->getViewType() > 0) { // Get drag amount according to texture point2_t tex_cur = tex_canvas->screenToTexPosition(e.GetX(), e.GetY()); point2_t tex_prev = tex_canvas->screenToTexPosition(tex_canvas->getMousePrevPos().x, tex_canvas->getMousePrevPos().y); point2_t diff = tex_cur - tex_prev; // Modify offsets tex_current->setOffsetX(tex_current->getOffsetX() - diff.x); tex_current->setOffsetY(tex_current->getOffsetY() - diff.y); tex_modified = true; // Refresh texture canvas tex_canvas->redraw(false); } } } e.Skip(); }