Jump to content

Render basic 2D shapes on UI


StOneDOes
 Share

Recommended Posts

It would be nice to be able to render basic 2D shapes, in a way such that you can easily resize them at any time, as oppose to having static ones that you programmatically draw into a Pixmap.

For example I want to render a 2D rectangle on the UI. At the moment I'm restricted to using CreatePanel() and SetShape(). However this does not allow me to have an x2 and y2 value that are lesser than the x1 and y1 unless I write the additional logic to handle this situation; moving the whole panel to suit it.

Link to comment
Share on other sites

I'm not positive - but you could create a mesh with any number of vertices and assign it to the relative render layer at the correct z depth to display as a 2D widget.

You can draw sprites on top of widgets (I have done this to draw 1 pixel width lines) its kinda tempory until Josh adds support for line widgets though.

If x2 or y2 are less than x1 or y1 wont that flip the direction of the triangles making up the panel / sprite?

Link to comment
Share on other sites

I wonder...

If a custom widget was able to add a block in its draw method that created a triangle instead of just a rectangle with curved corners.  That would be cool.  Then we could make any primitive shape we wanted and it would still obey all the widget rules in regards to z depth ordering?


vector<Vertex> vertices;
vertices.push_back(Vertex(0,0,0));
vertices.push_back(Vertex(0,1,0));
vertices.push_back(Vertex(1,1,0));

AddBlock(vertices);

 

Link to comment
Share on other sites

8 hours ago, St0neD0es said:

For example I want to render a 2D rectangle on the UI. At the moment I'm restricted to using CreatePanel() and SetShape(). However this does not allow me to have an x2 and y2 value that are lesser than the x1 and y1 unless I write the additional logic to handle this situation; moving the whole panel to suit it.

I don't understand this part.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

On 1/22/2023 at 12:45 PM, SpiderPig said:

If x2 or y2 are less than x1 or y1 wont that flip the direction of the triangles making up the panel / sprite?

I wouldn't have thought so. Not sure.

 

22 hours ago, Josh said:

I don't understand this part.

Ok so CreatePanel() takes x1, y1, height, width (not actually x2 and y2). So if you are looking at this from the perspective of an RTS where you hold click and drag to select multiple units, the point where you click becomes x1 and y1, and where ever the mouse location is once you start dragging the mouse, becomes x2 and y2. But if x1 and y1 is at 200, 200, and x2 and y2 are 100, 100 then it is problematic because you can't have a negative width and height.

I can still achieve what I want using some logic, but I'm just suggesting simplicity. Does this make sense?

Link to comment
Share on other sites

I think it would be something like this:

panel->SetShape(Min(mouseposition.x, origin.x), Min(mouseposition.y, origin.y), Abs(origin.x - mouseposition.x) + 1, Abs(origin.y - mouseposition.y) + 1);

 

  • Like 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...