Advertisement

Direct2d fill rect works incorrectly ?

Started by June 08, 2021 06:41 AM
3 comments, last by andrey4 3 years, 3 months ago

I use direct2d in order to make an editor. But i have a problem. When i use the funtion fill rect for drawing a button i pass the rect(x:100, y:100, width:400, height:400), but direct2d draws the rect less than i specified on a couple of pixel and when i check collision between the mouse and a button i get wrong behavior where the mouse intersected the button and the button change a color but pixels are not filled in that place.Blue is default color for the button and red is hover color. On the first image the cursore doesn't intersect the button and color doesn't change. On the second image the cursore intersects the button and color changes but the rest of area isn't filled

Looks like you have a mistake in how you set up the coordinates/sizes, but without any code, no idea. Plus your screenshots appears to have been scaled….. I am guessing you are also having D2D render onto a D3D surface of some form .

You should validate:

  • That you got the mouse cursor position correctly. Some APIs will need you to account for window position etc.
  • That your rendering is set up correctly to be 1:1 with the window, without any scaling.
    • You can check D3D is correct to start with by rendering a simple quad for your rect.

A simple check would be to try and position an item of known size in the top-left and bottom-right corners.

Advertisement

andrey4 said:
when i check collision between the mouse and a button

Do you check plain mouse-coords or do you transform them into render space using ScreenToClient WINAPI function? Remember that the title bar and sizing borders also count to the window, not just what you render!

thanks for your answers, i have fixed that, it was my stupid mistake, i was calling GetClientRect in WM_SIZE , but window was not resized, i was getting old window size

This topic is closed to new replies.

Advertisement