Directx 9 Color Picker Function

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Uzman Üye
Katılım
11 Ara 2016
Mesajlar
176
Tepki puanı
6
Yaş
29
9 HİZMET YILI
p0AQVo.png

 /////////////////Color Picker Function///////////

Kod:
   LPDIRECT3DTEXTURE9 ColorPickerTexture;
 LPD3DXSPRITE ColorPickerSprite;
 int ColorPickerWidth;
 int ColorPickerHeight;
 int ColorPickerX;
int ColorPickerY;
 ////


 ///
D3DCOLOR HSLToRGB(float H, float S, float L)
 {
     float Q;

     if (L < 0.5f)
         Q = L * (S + 1.0f);
     else
         Q = L + S - (L * S);

     float P = 2 * L - Q;

     float RGBs[3];

     RGBs[0] = H + (1.0f / 3.0f);
     RGBs[1] = H;
     RGBs[2] = H - (1.0f / 3.0f);

     for (int i = 0; i < 3; ++i)
     {
         if (RGBs[i] < 0)
             RGBs[i] += 1.0f;

         if (RGBs[i] > 1)
             RGBs[i] -= 1.0f;

         if (RGBs[i] < (1.0f / 6.0f))
             RGBs[i] = P + ((Q - P) * 6 * RGBs[i]);
         else if (RGBs[i] < 0.5f)
             RGBs[i] = Q;
         else if (RGBs[i] < (2.0f / 3.0f))
             RGBs[i] = P + ((Q - P) * 6 * ((2.0f / 3.0f) - RGBs[i]));
         else
             RGBs[i] = P;
     }

     return D3DCOLOR_XRGB(int(RGBs[0] * 255.0f), int(RGBs[1] * 255.0f), int(RGBs[2] * 255.0f));
 }

 void ColorPicker_Destroy()
 {
     if (ColorPickerSprite != NULL)
     {
         ColorPickerSprite->Release();
         ColorPickerSprite = NULL;
     }

     if (ColorPickerTexture != NULL)
     {
         ColorPickerTexture->Release();
         ColorPickerTexture = NULL;
     }
 }

 HRESULT ColorPicker_Init(LPDIRECT3DDEVICE9 Device, int Width, int Height)
 {
     ColorPickerWidth = Width;
     ColorPickerHeight = Height;

     bool Bits32 = true;
     ColorPicker_Destroy();

     HRESULT CreateTextureReturn;

     CreateTextureReturn = Device->CreateTexture(Width, Height, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &ColorPickerTexture, 0);

     if (FAILED(CreateTextureReturn))
     {
         Bits32 = false;

         CreateTextureReturn = Device->CreateTexture(Width, Height, 1, 0, D3DFMT_X4R4G4B4, D3DPOOL_MANAGED, &ColorPickerTexture, 0);

         if (FAILED(CreateTextureReturn))
             return CreateTextureReturn;
     }

     D3DLOCKED_RECT Palette;
    
     CreateTextureReturn = ColorPickerTexture->LockRect(0, &Palette, 0, 0);

     if (FAILED(CreateTextureReturn))
     {
         ColorPicker_Destroy();
         return CreateTextureReturn;
     }

     float H = 0;
     float S = 0.99f;
     float L = 1.0f;

     D3DCOLOR Color;

     BYTE R;
     BYTE G;
     BYTE B;

     DWORD* Colors32 = ((DWORD*)Palette.pBits) - 1;
     WORD* Colors = ((WORD*)Palette.pBits) - 1;

     for (int i = 0; i < Width; ++i)
     {
         for (int j = 0; j < Height; ++j)
         {
             Color = HSLToRGB(H, S, L);

             if (Bits32)
             {
                 Colors32++;
                 *Colors32 = Color;
             }
             else
             {
                 R = ((Color >> 16) & 0xFF) / 0x10;
                 G = ((Color >> 8) & 0xFF) / 0x10;
                 B = ((Color >> 0) & 0xFF) / 0x10;

                 Colors++;

                 *Colors = (0xFF << 12) |  (R << 8) |  (G << 4) |  (B << 0);
             }

             H += (1.0f / Width);
         }

         L -= (1.0f / Height);
         H = 0.0f;
     }

     ColorPickerTexture->UnlockRect(0);

     if (ColorPickerSprite == NULL)
         D3DXCreateSprite(Device, &ColorPickerSprite);

     return S_OK;
 }

 LPDIRECT3DTEXTURE9 ColorPicker_GetTexture()
 {
     return ColorPickerTexture;
 }

 void DrawColorPicker(float X, float Y, LPDIRECT3DDEVICE9 Device)
 {
	 ColorPickerX= X;
	 ColorPickerY= Y;
	  
     if (ColorPickerSprite != NULL)
     {
         ColorPickerSprite->Begin(D3DXSPRITE_ALPHABLEND);
         ColorPickerSprite->Draw(ColorPicker_GetTexture(), NULL, NULL, &D3DXVECTOR3(X, Y, 0.0f), 0xFFFFFFFF);
         ColorPickerSprite->End();
     }
 }

 D3DCOLOR GetPickedColor(int X, int Y)
 {
     float H = X * (1.0f / ColorPickerWidth);
     float S = 0.99f;
     float L = 1.0f - Y * (1.0f / ColorPickerHeight);

     return HSLToRGB(H, S, L);
 }

/////////Renk Şeçme Fonksiyonu 

Kod:
 void ColorPickedBox(char*isim, int x, int y, int w, int h, D3DCOLOR*Renk, LPDIRECT3DDEVICE9 pDevice, bool*num)
 {
	 POINT CUR;
	 GetCursorPos(&CUR);
     D3DRECT rec = { x, y, x + w, y + h };
     pDevice->Clear(1, &rec, D3DCLEAR_TARGET,*Renk, 0, 0);
	 RECT rect;
	 SetRect(&rect, x + w + w / 4, y + (h / 5), x + w + 5, y + (h / 6));
	 Directx_Font->DrawTextA(NULL, isim, -1, &rect, DT_LEFT | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 249));
	 if (CUR.x > x && CUR.x < x + w && CUR.y > y && CUR.y < y + h)
	 {
		 if (GetAsyncKeyState(VK_LBUTTON) & 1)
		 {
			 *num = !*num;
		 }
	 }
	 if (*num == true)
	 {
		
 if (GetAsyncKeyState(VK_LBUTTON) && MouseHover(ColorPickerX, ColorPickerY, ColorPickerWidth, ColorPickerHeight))
		 {


			 *Renk = GetPickedColor(CUR.x - ColorPickerX, CUR.y - ColorPickerY);

		 }

//////Color Picker çizdirme

Kod:
DrawColorPicker(100, 300, pDevice);//X noktası, Y noktası
ColorPicker_Init(pDevice, 150, 150);///Genişlik,Yükseklik



Oluşturacağımız Değişkenler;
Not=Değişkenleri cpp dosyasındaki include tanımlamarının altına oluşturun.
gqgQVN.png


D3DCOLOR PickedColor;////veya isterseniz önceden tanımlayabilirsiniz.Örnek=D3DCOLOR PickedColor = D3DCOLOR_ARGB(255, 112, 112, 112);

bool menucolor;//

////Renk Seçme Kodu////
Not=Mantığı checkbox ile aynıdır.Kutuya tıkladığımızda renk seçme aktif olur tekrar tıkladığımızda renk seçmeye devam etmez

Kod:
ColorPickedBox("Menu Color", 100, 460, 20, 20, &PickedColor, pDevice, &menucolor);///x,y,genişlik,yükseklik,renk değişkeni,pDevice,aktif

Eğer Color pickerin renk seçici ile kapanmasını istiyorsanız.Color Picker i Bu şekide çizin.

Kod:
	if (menucolor==1)
		{
DrawColorPicker(100, 300, pDevice);//X noktası, Y noktası

ColorPicker_Init(pDevice, 150, 150);///Genişlik,Yükseklik
			
			
		}
 
Seçkin Üye
Katılım
13 Ara 2015
Mesajlar
410
Tepki puanı
1
10 HİZMET YILI
listbox çiziminide paylaşta tam olsun
 
Banlı Üye
Katılım
22 Tem 2017
Mesajlar
129
Tepki puanı
10
Yaş
28
8 HİZMET YILI
C++ programlama dilini Öğrenmek isteyenler için Yararlı Bir konu +++ :)
 
<Ç0rumlu>
Ultra Üye
Katılım
19 May 2016
Mesajlar
1,546
Tepki puanı
135
Ödüller
10
Yaş
28
10 HİZMET YILI
yararlı konu teşekkürler
 
ÖLÜYÜM
Süper Moderator
Katılım
21 Eki 2015
Mesajlar
5,105
Çözümler
51
Tepki puanı
4,553
Ödüller
20
10 HİZMET YILI
Eyw Teşekürler
 
Üye
Katılım
18 Ağu 2017
Mesajlar
46
Tepki puanı
7
Yaş
28
8 HİZMET YILI
Please give credit's because this is SandyWF's source code. And this released in UC year 2015
 
Üye
Katılım
19 Ağu 2017
Mesajlar
6
Tepki puanı
0
Yaş
27
8 HİZMET YILI
iRHnlafNTC_a5LVIb7PrdA.png

Hocam color picker görünüyor gayet güzel ama gel gelelim renk seçme şeysini ekleyince şurralarda hata veriyor
 
Üye
Katılım
18 Ağu 2017
Mesajlar
46
Tepki puanı
7
Yaş
28
8 HİZMET YILI
iRHnlafNTC_a5LVIb7PrdA.png

Hocam color picker görünüyor gayet güzel ama gel gelelim renk seçme şeysini ekleyince şurralarda hata veriyor
If you can't handle this how are you going to select the color and apply? Include DirectX SDK and add mouseover function
I will be share but there will be no difference because you don't know c++.
Turkish:
Paylaşacağım fakat bir fark yaratmayacak çünkü C++ bilmiyorsun.
Kod:
bool MouseHover(int x, int y, int w, int h, LPDIRECT3DDEVICE9 pDevice)
{
    POINT globalMouse;
    GetCursorPos(&globalMouse);
    ScreenToClient(GetForegroundWindow(), &globalMouse);
    if (globalMouse.x > x && globalMouse.y > y && globalMouse.x <= x + w && globalMouse.y <= y + h)
    {
        return true;
    }

    return false;
}
error line change with this
Turkish:
hata satırını bunla değiştir
Kod:
if (GetAsyncKeyState(VK_LBUTTON) && MouseClick(ColorPickerX, ColorPickerY, ColorPickerWidth, ColorPickerHeight,pDevice))
 
Üye
Katılım
19 Ağu 2017
Mesajlar
6
Tepki puanı
0
Yaş
27
8 HİZMET YILI
If you can't handle this how are you going to select the color and apply? Include DirectX SDK and add mouseover function
I will be share but there will be no difference because you don't know c++.
Turkish:
Paylaşacağım fakat bir fark yaratmayacak çünkü C++ bilmiyorsun.
Kod:
bool MouseHover(int x, int y, int w, int h, LPDIRECT3DDEVICE9 pDevice)
{
    POINT globalMouse;
    GetCursorPos(&globalMouse);
    ScreenToClient(GetForegroundWindow(), &globalMouse);
    if (globalMouse.x > x && globalMouse.y > y && globalMouse.x <= x + w && globalMouse.y <= y + h)
    {
        return true;
    }

    return false;
}
error line change with this
Turkish:
hata satırını bunla değiştir
Kod:
if (GetAsyncKeyState(VK_LBUTTON) && MouseClick(ColorPickerX, ColorPickerY, ColorPickerWidth, ColorPickerHeight,pDevice))
Are not you Turk ?

And do not look down on people


Do not be arrogant
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst