How can I draw a thinner line with wxPen?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Cris
Experienced Solver
Experienced Solver
Posts: 58
Joined: Thu Feb 17, 2005 2:40 pm

How can I draw a thinner line with wxPen?

Post by Cris »

Hello,
I have a small problem. I need to draw some colored lines.
wxDc.SetPen(wxPen(wxColour(255,0,0),1, wxDOT))

And I found the line looks too thick.
While wxPen(const wxColour& colour, int width = 1, int style = wxSOLID), there is no way to set the width to be a float value or to make it smaller than 1.

How could I draw a thinner line? Thanks a lot.

Cris
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

How would you do that ? If you draw < 1 pixel straight horizontal or vertical it would not be drawn. If you need anti aliasing for e.g. circles then you need to have something like AntiGrain

http://www.antigrain.com/

It is truly worth considering if the overhead justifies the pixel thickness.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Cris
Experienced Solver
Experienced Solver
Posts: 58
Joined: Thu Feb 17, 2005 2:40 pm

Re

Post by Cris »

Hello, Jorg,
The reason I think the line drawn in wxWidgets looks too thick is that I draw the same line on Mac using Cocoa and the line looks much thinner.
So that I have to find the way to make the line thinner or looks similar like the line drawn in Cocoa.
Thanks.

Cris
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

What I don't understand is if your physical pixel size is 1 (meaning 1:1 on the screen) how can your line be thinner, because the bitmap buffer from your videocard simply can't display pixels of .5 thickness. 1 is the smallest size. If it looks thinner, show two screenshots. My best guess is that you are seeing antialiasing, and that is not standard supported in wxWidgets. You will have to tap into the windows image API and / or use a library that does that for you.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
User avatar
sherazjaved
Knows some wx things
Knows some wx things
Posts: 44
Joined: Thu Feb 02, 2006 5:06 am
Location: Pakistan
Contact:

Post by sherazjaved »

DC.SetPen(wxPen( wxColor( CUtilities:: InverseColor(255),CUtilities:: InverseColor(255), CUtilities:: InverseColor(34) ),1,wxSOLID) );

you can change this hilighted value to change the Pen Width and after that draw a Line using DrawLine() method
Mac OS X Server 10.4.5, X-Code 2.4, Gcc 4.0
Solaris 8.0 9.0, Gcc
Windows XP SP2, VC6.0
------------------------------------
Sheraz
valery_s
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Jun 04, 2021 10:33 am

Re: How can I draw a thinner line with wxPen?

Post by valery_s »

So many years have passed but the problem still exit. I'm using wxWidgets 3.1.5 on Windows 10 and I just tried to draw a black line by one pixel width. And I getting a line no less then 2 pixels width, and a line colour seems to be not so black but rather dark gray. Is it something wrong with me or wxWidgtes?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How can I draw a thinner line with wxPen?

Post by doublemax »

valery_s wrote: Fri Jun 04, 2021 11:17 am So many years have passed but the problem still exit. I'm using wxWidgets 3.1.5 on Windows 10 and I just tried to draw a black line by one pixel width. And I getting a line no less then 2 pixels width, and a line colour seems to be not so black but rather dark gray. Is it something wrong with me or wxWidgtes?
Can you show a screenshot and some code?

I suspect that you're working on a high dpi screen with font scaling >100% and that your application is not DPI aware.
Use the source, Luke!
valery_s
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Jun 04, 2021 10:33 am

Re: How can I draw a thinner line with wxPen?

Post by valery_s »

Yes, my screen resolution is 2560 x 1440. But how can I make my application be DPI aware ? I'm novice in wxWidgets.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How can I draw a thinner line with wxPen?

Post by doublemax »

valery_s wrote: Fri Jun 04, 2021 11:44 am Yes, my screen resolution is 2560 x 1440. But how can I make my application be DPI aware ? I'm novice in wxWidgets.
The resolution itself is not important, it's about the scaling value set in Windows 10 settings.

In principle dpi-awareness is set through an application manifest. How to integrate that depends on your compiler/IDE.

If you build any of the wxWidgets samples with the provides makefiles / solution files, the resulting executable should be dpi-aware. Please try that with the "drawing" sample and check how it looks.

A non-dpiaware app will be scaled up by Windows and everything looks a bit "blurry".
Use the source, Luke!
valery_s
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Jun 04, 2021 10:33 am

Re: How can I draw a thinner line with wxPen?

Post by valery_s »

I'm using VS2019 Community and a classic C++ project. Never before faced such a problem. Ok, will try to solve.
valery_s
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Jun 04, 2021 10:33 am

Re: How can I draw a thinner line with wxPen?

Post by valery_s »

Yes, now changed the windows scale from 125 to 100 % and all become clear and precise.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How can I draw a thinner line with wxPen?

Post by doublemax »

valery_s wrote: Fri Jun 04, 2021 12:17 pm Yes, now changed the windows scale from 125 to 100 % and all become clear and precise.
In VS, project properties -> Manifest Tool -> Input and Output, you can set the DPI awareness flag.
Use the source, Luke!
Post Reply