Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35258 > unrolled thread
| Started by | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| First post | 2016-08-11 23:14 +0200 |
| Last post | 2016-08-11 17:40 -0400 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
Making a cross-hair visible Cecil Westerhof <Cecil@decebal.nl> - 2016-08-11 23:14 +0200
Re: Making a cross-hair visible Arne Vajhøj <arne@vajhoej.dk> - 2016-08-11 17:34 -0400
Re: Making a cross-hair visible Silvio <silvio@internet.com> - 2016-08-11 23:36 +0200
Re: Making a cross-hair visible Cecil Westerhof <Cecil@decebal.nl> - 2016-08-12 00:20 +0200
Re: Making a cross-hair visible Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-11 17:40 -0400
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2016-08-11 23:14 +0200 |
| Subject | Making a cross-hair visible |
| Message-ID | <87a8gjm2it.fsf@Equus.decebal.nl> |
I am dabbling with Swing to do some GUI stuff. This is relatively new
for me. At the moment I draw a rectangle for cropping an image. The
position is selected by clicking on the centre from where I think the
rectangle should be placed. This can be a little of, so I have to
fine-tune it. For this I draw a little cross in the centre. Problem is
that I paint it in black and when the centre is black, I will not see
it. And with every colour I choose I can have this problem. Is there a
smart way to make the cross always visible?
I was thinking about a timer function which would alternate the colour
of the cross between black and white, but was wondering if there is a
better way.
At the moment my code is:
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
int centerX = x + cropWidth / 2;
int centerY = y + cropHeight / 2;
super.paintComponent(g);
g2.setStroke(stroke);
g.setColor(rectColor);
g.drawImage(image, 0, 0, imageWidth, imageHeight, null);
g.drawRect(x, y, cropWidth, cropHeight);
g.drawLine(centerX - crossLength, centerY, centerX + crossLength, centerY);
g.drawLine(centerX, centerY - crossLength, centerX, centerY + crossLength);
}
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2016-08-11 17:34 -0400 |
| Message-ID | <noir15$vmv$1@gioia.aioe.org> |
| In reply to | #35258 |
On 8/11/2016 5:14 PM, Cecil Westerhof wrote: > I am dabbling with Swing to do some GUI stuff. This is relatively new > for me. At the moment I draw a rectangle for cropping an image. The > position is selected by clicking on the centre from where I think the > rectangle should be placed. This can be a little of, so I have to > fine-tune it. For this I draw a little cross in the centre. Problem is > that I paint it in black and when the centre is black, I will not see > it. And with every colour I choose I can have this problem. Is there a > smart way to make the cross always visible? White circle with black cross in? Arne
[toc] | [prev] | [next] | [standalone]
| From | Silvio <silvio@internet.com> |
|---|---|
| Date | 2016-08-11 23:36 +0200 |
| Message-ID | <57aceffb$0$4222$e4fe514c@newszilla.xs4all.nl> |
| In reply to | #35258 |
On 08/11/2016 11:14 PM, Cecil Westerhof wrote:
> I am dabbling with Swing to do some GUI stuff. This is relatively new
> for me. At the moment I draw a rectangle for cropping an image. The
> position is selected by clicking on the centre from where I think the
> rectangle should be placed. This can be a little of, so I have to
> fine-tune it. For this I draw a little cross in the centre. Problem is
> that I paint it in black and when the centre is black, I will not see
> it. And with every colour I choose I can have this problem. Is there a
> smart way to make the cross always visible?
>
> I was thinking about a timer function which would alternate the colour
> of the cross between black and white, but was wondering if there is a
> better way.
>
> At the moment my code is:
> protected void paintComponent(Graphics g) {
> Graphics2D g2 = (Graphics2D) g;
> int centerX = x + cropWidth / 2;
> int centerY = y + cropHeight / 2;
>
> super.paintComponent(g);
> g2.setStroke(stroke);
> g.setColor(rectColor);
> g.drawImage(image, 0, 0, imageWidth, imageHeight, null);
> g.drawRect(x, y, cropWidth, cropHeight);
> g.drawLine(centerX - crossLength, centerY, centerX + crossLength, centerY);
> g.drawLine(centerX, centerY - crossLength, centerX, centerY + crossLength);
> }
>
Either do a black crosshair with a white border or draw in XOR-mode.
Silvio
[toc] | [prev] | [next] | [standalone]
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2016-08-12 00:20 +0200 |
| Message-ID | <871t1vlzhc.fsf@Equus.decebal.nl> |
| In reply to | #35260 |
On Thursday 11 Aug 2016 23:36 CEST, silvio@internet.com wrote:
> On 08/11/2016 11:14 PM, Cecil Westerhof wrote:
>> I am dabbling with Swing to do some GUI stuff. This is relatively
>> new for me. At the moment I draw a rectangle for cropping an image.
>> The position is selected by clicking on the centre from where I
>> think the rectangle should be placed. This can be a little of, so I
>> have to fine-tune it. For this I draw a little cross in the centre.
>> Problem is that I paint it in black and when the centre is black, I
>> will not see it. And with every colour I choose I can have this
>> problem. Is there a smart way to make the cross always visible?
>>
>> I was thinking about a timer function which would alternate the
>> colour of the cross between black and white, but was wondering if
>> there is a better way.
>>
>> At the moment my code is:
>> protected void paintComponent(Graphics g) {
>> Graphics2D g2 = (Graphics2D) g;
>> int centerX = x + cropWidth / 2;
>> int centerY = y + cropHeight / 2;
>>
>> super.paintComponent(g); g2.setStroke(stroke);
>> g.setColor(rectColor); g.drawImage(image, 0, 0, imageWidth,
>> imageHeight, null); g.drawRect(x, y, cropWidth, cropHeight);
>> g.drawLine(centerX - crossLength, centerY, centerX + crossLength,
>> centerY); g.drawLine(centerX, centerY - crossLength, centerX,
>> centerY + crossLength); }
>>
>
> Either do a black crosshair with a white border or draw in XOR-mode.
Why did I do not think about that. :'-(
I had already been experimenting and I got a good result with:
new Color(0, 255, 0)
as the cross colour. But that this colour is not significantly used in
my pictures, does not mean it is the same in others.
I changed the last part to (it has to be cleaned up of-course):
g2.setStroke(new BasicStroke(4.0f));
g.setColor(new Color(255, 255, 255));
g.drawLine(centerX - crossLength, centerY, centerX + crossLength, centerY);
g.drawLine(centerX, centerY - crossLength, centerX, centerY + crossLength);
g2.setStroke(new BasicStroke(2.0f));
g.setColor(new Color(0, 0, 0));
g.drawLine(centerX - crossLength, centerY, centerX + crossLength, centerY);
g.drawLine(centerX, centerY - crossLength, centerX, centerY + crossLength);
And that works great on the blackbird where I did not see the cross earlier on.
Maybe I should do the same for the rectangle itself.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-08-11 17:40 -0400 |
| Message-ID | <noirbo$u8j$1@dont-email.me> |
| In reply to | #35258 |
On 8/11/2016 5:14 PM, Cecil Westerhof wrote:
> I am dabbling with Swing to do some GUI stuff. This is relatively new
> for me. At the moment I draw a rectangle for cropping an image. The
> position is selected by clicking on the centre from where I think the
> rectangle should be placed. This can be a little of, so I have to
> fine-tune it. For this I draw a little cross in the centre. Problem is
> that I paint it in black and when the centre is black, I will not see
> it. And with every colour I choose I can have this problem. Is there a
> smart way to make the cross always visible?
The cleanest approach (you'll have to experiment to decide whether
it's also "best") might be to use the java.awt.Cursor class. When
entering "center selection mode," query and save the current Cursor,
then change it to CROSSHAIR_CURSOR for the duration. Restore the
original Cursor when finished.
If you're bound and determined to do your own cursor-painting,
I suppose you could paint two crosses in contrasting colors, one
with thicker strokes beneath one that's thinner. For example, you
might paint a white cross with 3-pixel strokes and then a one-pixel
black cross atop it.
... and there's probably something you could do with XOR, but
that might have weird interactions if you ever ran on a display with
a different ColorModel than you anticipated. I'd go for Cursor.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web