Jump to content
  • Advertisement
Sign in to follow this  
paic

[.net] Convert from D3DCOLORVALUE to System::Drawing::Color

This topic is 3663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have some troubles with conversion operators ! I have 2 classes which handle colors, one provided by the .NET framework (System::Drawing::Color) and the other by the DirectX SDK (D3DCOLORVALUE) They are basically the same, they juste store the RGB values and an alpha. The difference is one is using floats between 0 and 1 and the other ints between 0 and 255. So I'd like to create operators to implicitely converts one class to the other and vice versa. But I really don't understand how to do that ... I found a page in the MSDN saying that the correct way to define conversion operators is :
System::Drawing::Color op_Implicit(D3DCOLORVALUE value);
And when I use this syntax, it compiles fine. But when I try to use it by writing something like :
D3DCOLOR value src;
System::Drawing::Color dest;
dest = src;
The compiler tells me that no user-defined-conversion operator is available ... So I don't know what to do and google is not of much help on this :s Anybody has and idea ?? PS: I know how to create conversion functions as member of classes, but in my case, I don't have access to System::Drawing::Color nore D3DCOLORVALUE so I need to create a "global" conversion operator.

Share this post


Link to post
Share on other sites
Advertisement
I'm pretty new to .NET (I'm self-learning C# now), so pardon me if I grasp the wrong idea, but I thought you could use the help of this method:

Microsoft.DirectX.Direct3D.ColorValue.FromD3DColor(Microsoft.DirectX.PrivateImplementationDetails._D3DCOLORVALUE *Color)

and it's other siblings?

Share this post


Link to post
Share on other sites
I'm not using C# and MDX.
I'm using WinForms with C++ (managed C++) and the standard DX SDK. So I can't use your method.

For the moment, I use a function (something like : FromD3DCOLORVALUE(...)) which convert D3DCOLORVALUE to Color and another one which do the opposite, but I'm wondering if it's possible to create global conversion operators so that the conversion is implicitely done without me having to use a special function !

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!