Archived

This topic is now archived and is closed to further replies.

GotzBoost

how to make rounded rectangle in direct x 8???

Recommended Posts

The easiest way would be to use GDI onto the screen. Here's a GDI line function:

void DrawLine(int x,int y,int x2,int y2, COLORREF color) {
HDC hdc;
IDirect3DSurface9 *backbuffer;
device->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&backbuffer);
backbuffer->GetDC(&hdc);
HPEN hpen = (HPEN)SelectObject(hdc,CreatePen(PS_SOLID,0,color));
MoveToEx(hdc,x,y,NULL);
LineTo(hdc,x2,y2);
DeleteObject(SelectObject(hdc,hpen));
backbuffer->ReleaseDC(hdc);
backbuffer->Release();
}


The code assumes there's a variable named 'device' for your IDirect3DDevice9 as a global variable, or if you put it in a class, a variable in the class. If I didn't forget something, it should work, though slowly.

Or you could draw the rounded rectangle in Paint, save it to a picture, and draw the picture onto the screen. That would probably be alot faster.

[edited by - mike29936 on May 26, 2004 8:00:09 AM]

[edited by - mike29936 on May 26, 2004 8:00:52 AM]

Share this post


Link to post
Share on other sites
Ok, can I do something similar to this?
http://myhtpc.net/images/screens/large/music1.jpg
I am writing a touch screen app that needs a nice button look, like those, including the beveled effect. I would just create a image and use the image as a button I need to be able to resize the button, as the end user will be able to add custom text to the buttons, and I don''t wont the text getting outside the button. How would I go about doing this?

Share this post


Link to post
Share on other sites
It looks like you need alpha transparency for the buttons, so you should create a picture with alpha transparency, load it, and scale it to the needed size.

For the text, I believe ID3DXFont can limit text to a rectangle, but I just noticed you said in DirectX 8, and I''ve only used DirectX 9, so I don''t know whether ID3DXFont is in DX8.

However, if the GDI-to-backbuffer I showed you as the first solution works, then you should be able to use GDI to draw text, and I''m very sure that GDI can limit text to a rectangle.

And you could always create a custom text-drawer if you need something more.

Share this post


Link to post
Share on other sites
Using GDI may be the easiest way, but it isn't the fastest way. In fact, GDI is horribly slow. If you aren't concerned with speed *at all*, then you can use GDI. However, if it is a factor, use the method that Mike presented. It looks better, too, since you can customize the button's appearance with an image editor.

ID3DXFont was available in DX8, but it was incredibly slow, since it actually used GDI. Therefore, it'd probably be better just to use GDI in the first place Make no mistake though: in DX9, ID3DXFont is fully 3D (ie no GDI), and is quite fast.


Dustin Franklin
Mircrosoft DirectX MVP

[edited by - circlesoft on May 26, 2004 5:28:46 PM]

Share this post


Link to post
Share on other sites
Ok, bare with me here. Not that strong with DX, trying my best to get there though. How would I scale an image if I do go that route? And does the DX font class have a way of telling me what the width is of the drawn text? So that I know how much to scale the image.

And I'm assuming that if I create a white button, that some how I can overlay a different color over top of it to change it's color on the fly?

What all ref and lib do I need to point to for GDI?

[edited by - GotzBoost on May 26, 2004 5:37:04 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Bueller.... Bueller.... Bueller.... Bueller.... Has anyone seen Ferris....

Hello? Any help?

Share this post


Link to post
Share on other sites
The rounded rect in that image(music1.jpg) is made using a sprite that looks like a rounded rect(using a colorkey/alphachannel).

Also the best way of doing it.

/MindWipe

Share this post


Link to post
Share on other sites
(1) In your image editing program, such as photoshop, make the background a single color (magenta works well). Then, draw your button on top of this. The magenta portion of the image will be part that is alpha blended.

(2) Load your image using D3DXCreateTextureFromFileEx(). One of the parameters will be a ColorKey. For this parameter, supply the RGB for magenta (or whatever color you chose is step 1).

(3) Use ID3DXSprite to display and ID3DXFont to render the font (search the forum or SDK for help on this).

Share this post


Link to post
Share on other sites
quote:
Original post by circlesoft
(1) In your image editing program, such as photoshop, make the background a single color (magenta works well). Then, draw your button on top of this. The magenta portion of the image will be part that is alpha blended.

(2) Load your image using D3DXCreateTextureFromFileEx(). One of the parameters will be a ColorKey. For this parameter, supply the RGB for magenta (or whatever color you chose is step 1).


You could do that - though personally, I''d recommend that you work with a file format that has full support for alpha channels. The DirectX SDK comes with a tool called ''DXTex'' - this will let you combine a regular image with an ''alpha map'' (a black and white picture which specifies which parts of the image are transparent - white is fully opaque, black is fully transparent, grey is somewhere between the two), and save the result as a .DXT file. D3DXCreateTextureFromFile() will then let you load that in with no problem. Also, because DXTex allows you to use greys in your alpha map, you can do partial transparency (translucency).

Share this post


Link to post
Share on other sites