简体   繁体   English

摇摆油漆程序-如何处理选择?

[英]Swing paint program - How to handle selection?

I'm trying to make a paint program using swing. 我正在尝试使用swing创建绘画程序。 I have several shapes that the user can draw, including ellipses, lines, and rectangles. 我有几种用户可以绘制的形状,包括椭圆,直线和矩形。 The shapes can drawn (using graphics2d) with various strokes (line thicknesses) and can be filled or unfilled. 可以使用各种笔划(线条粗细)绘制(使用graphics2d)形状,并且可以填充或不填充形状。

I'm trying to implement a feature such that the user can click a shape with the right mouse button and drag it to move it. 我正在尝试实现一项功能,以便用户可以用鼠标右键单击形状并将其拖动以移动它。

My current strategy is to poll the array of shapes is reverse order (meaning in case of multiple shapes the most recently added one is selected). 我当前的策略是按相反顺序轮询形状数组(这意味着在选择多个形状的情况下,将选择最近添加的形状)。

Each shape implementation has a method called isSelected(int x, int y) . 每个形状实现都有一个称为isSelected(int x, int y) I need to figure out how to determine whether a point falls on the shape. 我需要弄清楚如何确定一个点是否落在形状上。 One challenge is that an unfilled shape such as an oval should not be selected when clicked inside, but should be selected if it is filled. 一个挑战是,在内部单击时,不应选择未填充的形状(例如椭圆形),而在填充时应选择未填充的形状。 Also, selection should respond to the thickness of a stroke. 同样,选择应响应笔划的粗细。 That is, a line should be selectable by clicking out the outer area if it uses a thicker stroke, not just the exact center of the line. 也就是说,如果线条使用的是较粗的笔划,而不仅仅是线条的确切中心,则可以通过单击外部区域来选择线条。

How on earth can I go about implementing this? 我到底该如何实施呢?

I am storing an array of a custom type which implements a 2d shape from this API 我正在存储自定义类型的数组,该数组通过此API实现2D形状

Then you could use: 然后,您可以使用:

Depending on the information you have and what you want to check 根据您所拥有的信息以及您要检查的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM