/* CTextureCanvas::onMouseEvent * Called when and mouse event is generated (movement/clicking/etc) *******************************************************************/ void CTextureCanvas::onMouseEvent(wxMouseEvent& e) { bool refresh = false; // MOUSE MOVEMENT if (e.Moving() || e.Dragging()) { dragging = false; // Pan if middle button is down if (e.MiddleIsDown()) { offset = offset + point2_t(e.GetPosition().x - mouse_prev.x, e.GetPosition().y - mouse_prev.y); refresh = true; dragging = true; } else if (e.LeftIsDown()) dragging = true; // Check if patch hilight changes point2_t pos = screenToTexPosition(e.GetX(), e.GetY()); int patch = patchAt(pos.x, pos.y); if (hilight_patch != patch) { hilight_patch = patch; refresh = true; } } // LEFT BUTTON UP else if (e.LeftUp()) { // If we were dragging, generate end drag event if (dragging) { dragging = false; updateTexturePreview(); refresh = true; wxCommandEvent evt(EVT_DRAG_END, GetId()); evt.SetInt(wxMOUSE_BTN_LEFT); ProcessWindowEvent(evt); } } // LEAVING if (e.Leaving()) { // Set no hilighted patch hilight_patch = -1; refresh = true; } // Refresh is needed if (refresh) Refresh(); // Update 'previous' mouse coordinates mouse_prev.set(e.GetPosition().x, e.GetPosition().y); }
/* GfxCanvas::onMouseMovement * Called when the mouse pointer is moved within the canvas *******************************************************************/ void GfxCanvas::onMouseMovement(wxMouseEvent& e) { bool refresh = false; // Check if the mouse is over the image int x = e.GetPosition().x; int y = e.GetPosition().y - 2; bool on_image = onImage(x, y); cursor_pos = imageCoords(x, y); if (on_image && editing_mode) { if (cursor_pos != prev_pos) generateBrushShadow(); prev_pos = cursor_pos; } if (on_image != image_hilight) { image_hilight = on_image; refresh = true; // Update cursor if drag allowed if (on_image) { if (editing_mode) SetCursor(wxCursor(wxCURSOR_PENCIL)); else if (allow_drag) SetCursor(wxCursor(wxCURSOR_SIZING)); } else if (allow_drag && !e.LeftIsDown()) SetCursor(wxNullCursor); } // Drag if (e.LeftIsDown()) { if (editing_mode) { brushCanvas(x, y); } else { drag_pos.set(e.GetPosition().x, e.GetPosition().y); refresh = true; } } else if (e.MiddleIsDown()) { offset = offset + point2_t(e.GetPosition().x - mouse_prev.x, e.GetPosition().y - mouse_prev.y); refresh = true; } // Right mouse down if (e.RightIsDown() && on_image) pickColour(x, y); if (refresh) Refresh(); mouse_prev.set(e.GetPosition().x, e.GetPosition().y); }
/* ModifyOffsetsDialog::getOffset * Returns the offsets that have been entered *******************************************************************/ point2_t ModifyOffsetsDialog::getOffset() { long x = 0; long y = 0; entry_xoff->GetValue().ToLong(&x); entry_yoff->GetValue().ToLong(&y); return point2_t(x, y); }
/* CTextureCanvas::screenToTexPosition * Convert from [x,y] from the top left of the canvas to coordinates * relative to the top left of the texture *******************************************************************/ point2_t CTextureCanvas::screenToTexPosition(int x, int y) { // Check a texture is open if (!texture) return point2_t(0, 0); // Get texture scale double scalex = 1; double scaley = 1; if (tex_scale) { scalex = texture->getScaleX(); if (scalex == 0) scalex = 1; scaley = texture->getScaleY(); if (scaley == 0) scaley = 1; } // Get top-left of texture in screen coordinates (ie relative to the top-left of the canvas) int left = GetSize().x * 0.5 + offset.x; int top = GetSize().y * 0.5 + offset.y; // Adjust for view type double yscale = (tx_arc ? scale * 1.2 : scale); if (view_type == 0) { // None (centered) left -= ((double)texture->getWidth() / scalex) * 0.5 * scale; top -= ((double)texture->getHeight() / scaley) * 0.5 * yscale; } if (view_type >= 1) { // Sprite left -= ((double)texture->getOffsetX() / scalex) * scale; top -= ((double)texture->getOffsetY() / scaley) * yscale; } if (view_type == 2) { // HUD left -= 160 * scale; top -= 100 * yscale; } return point2_t(double(x - left) / scale * scalex, double(y - top) / yscale * scaley); }
/* GfxCanvas::imageCoords * Returns the image coordinates at [x,y] in screen coordinates, or * [-1, -1] if not on the image *******************************************************************/ point2_t GfxCanvas::imageCoords(int x, int y) { // Determine top-left coordinates of image in screen coords double left = GetSize().x * 0.5 + offset.x; double top = GetSize().y * 0.5 + offset.y; double yscale = scale * (gfx_arc ? 1.2 : 1); if (view_type == GFXVIEW_DEFAULT || view_type == GFXVIEW_TILED) { left = offset.x; top = offset.y; } else if (view_type == GFXVIEW_CENTERED) { left -= (double)image->getWidth() * 0.5 * scale; top -= (double)image->getHeight() * 0.5 * yscale; } else if (view_type == GFXVIEW_SPRITE) { left -= image->offset().x * scale; top -= image->offset().y * yscale; } else if (view_type == GFXVIEW_HUD) { left -= 160 * scale; top -= 100 * scale * (gfx_arc ? 1.2 : 1); left -= image->offset().x * scale; top -= image->offset().y * yscale; } // Determine bottom-right coordinates of image in screen coords double right = left + image->getWidth() * scale; double bottom = top + image->getHeight() * yscale; // Check if the pointer is within the image if (x >= left && x <= right && y >= top && y <= bottom) { // Determine where in the image it is double w = right - left; double h = bottom - top; double xpos = double(x - left) / w; double ypos = double(y - top) / h; return point2_t(xpos * image->getWidth(), ypos * image->getHeight()); } else return POINT_OUTSIDE; }
/* CTextureCanvas::screenToTexPosition * Convert from [x,y] from the top left of the texture to * coordinates relative to the top left of the canvas *******************************************************************/ point2_t CTextureCanvas::texToScreenPosition(int x, int y) { // Get texture scale double tscalex = 1; double tscaley = 1; if (tex_scale) { tscalex = texture->getScaleX(); if (tscalex == 0) tscalex = 1; tscaley = texture->getScaleY(); if (tscaley == 0) tscaley = 1; } tscalex = 1.0 / tscalex; tscaley = 1.0 / tscaley; // Get top/left double yscale = (tx_arc ? scale * 1.2 : scale); double halfx = (texture->getWidth() * 0.5 * scale * tscalex); double halfy = (texture->getHeight() * 0.5 * yscale * tscaley); double left = offset.x + (GetSize().x * 0.5) - halfx; double top = -offset.y + (GetSize().y * 0.5) - halfy; // Adjust for view types if (view_type >= 1) { // Sprite left -= (texture->getOffsetX() * scale * tscalex) - halfx; top += (texture->getOffsetY() * yscale * tscaley) - halfy; } if (view_type == 2) { // HUD left -= (160 * scale); top += (100 * yscale); } return point2_t(left, top); }
point2_t ModifyOffsetsDialog::calculateOffsets(int xoff, int yoff, int width, int height) { int type = getAlignType(); point2_t offset = getOffset(); int x = xoff; int y = yoff; if (type >= 0) { // Monster if (type == 0) { x = width * 0.5; y = height - 4; } // Monster (GL-friendly) else if (type == 1) { x = width * 0.5; y = height; } // Projectile else if (type == 2) { x = width * 0.5; y = height * 0.5; } // Weapon (Fullscreen) else if (type == 3) { x = -160 + (width * 0.5); y = -200 + height; } // Weapon (Doom status bar) else if (type == 4) { x = -160 + (width * 0.5); y = -200 + 32 + height; } // Weapon (Heretic status bar) else if (type == 5) { x = -160 + (width * 0.5); y = -200 + 42 + height; } // Weapon (Hexen status bar) else if (type == 6) { x = -160 + (width * 0.5); y = -200 + 38 + height; } } else { // Relative offset if (relativeOffset()) { if (xOffChange()) x = xoff + offset.x; if (yOffChange()) y = yoff + offset.y; } // Set offset else { if (xOffChange()) x = offset.x; if (yOffChange()) y = offset.y; } } return point2_t(x, y); }