My gradientclass
Page 1 of 5 12345 Last
  1. #1

    My gradientclass

    Every function here works but if you know way to improve this or better way to do it im willing to listen :)
    Have fun!

    Credz: Fready (from his original thread about gradient drawing which i came up when searching via google)

    Screenshot of functions drawn and at use of course:



    CPP-file:

    [hide]
    Code:
    #include "CGradient.h"
    
    cGradient gGradient;
    
    void cGradient::FillGradientVertical(int x, int y, int w, int h,int r, int g, int b, int a)
    {
    int iRed,iGreen,iBlue;
    
    for(int i = 1; i < h; i++)
    	{
    		iRed = (int)((float)i/h*r);
    		iGreen = (int)((float)i/h*g);
    		iBlue = (int)((float)i/h*b);
    		FillRGBA(x, y + i, w, 1,Color(r-iRed,g-iGreen,b-iBlue,a));
    	}
    }
    void cGradient::FillGradientHorizontal(int x, int y, int w, int h,int r, int g, int b, int a)
    {
    int iRed,iGreen,iBlue;
    
    for(int i = 1; i < w; i++)
    	{
    		iRed = (int)((float)i/w*r);
    		iGreen = (int)((float)i/w*g);
    		iBlue = (int)((float)i/w*b);
    		FillRGBA(x + i, y, 1, h,Color(r-iRed,g-iGreen,b-iBlue,a));
    	}
    }
    
    void cGradient::FillGradientCircle(int x, int y, float radius,int r, int g, int b, int a)
    {
    int iRed,iGreen,iBlue;
    
    for(int i = 1; i < radius; i++)
    	{
    		iRed = (int)((float)i/radius*r);
    		iGreen = (int)((float)i/radius*g);
    		iBlue = (int)((float)i/radius*b);
    		m_pMatSystemSurface->DrawColoredCircle( x, y, i, r-iRed,g-iGreen,b-iBlue,a);
    	}
    }
    void cGradient::DrawGradientLine(int x, int y, int x1, int y1, int r, int g, int b, int a)
    {
    int iRed,iGreen,iBlue;
    
    for(int i = 1; i < y1; i++)
    	{
    		iRed = (int)((float)i/y1*r);
    		iGreen = (int)((float)i/y1*g);
    		iBlue = (int)((float)i/y1*b);
    		m_pMatSystemSurface->DrawSetColor(r-iRed,g-iGreen,b-iBlue,a);
    		m_pMatSystemSurface->DrawLine(x + i, y + i, x1, y1);
    	}
    }
    void cGradient::FillGradientWeirdPipe(int x, int y, float radius,int r, int g, int b, int a)
    {
    int iRed,iGreen,iBlue;
    
    for(int i = 1; i < radius; i++)
    	{
    		iRed = (int)((float)i/radius*r);
    		iGreen = (int)((float)i/radius*g);
    		iBlue = (int)((float)i/radius*b);
    		m_pMatSystemSurface->DrawColoredCircle( x + i, y + i, radius, r-iRed, g-iGreen, b-iBlue, a );
    	}
    }
    [/hide]

    Headerfile:

    [hide]
    Code:
    #ifndef __CGRADIENT_H__
    #define __CGRADIENT_H__
    
    #include "sdk.h"
    
    class cGradient
    {
    public:
    	void FillGradientVertical(int x, int y, int w, int h,int r, int g, int b, int a);
    	void FillGradientHorizontal(int x, int y, int w, int h,int r, int g, int b, int a);
    	void FillGradientCircle(int x, int y, float radius,int r, int g, int b, int a);
    	void DrawGradientLine(int x, int y, int x1, int y1,int r, int g, int b, int a);
    	void FillGradientWeirdPipe(int x, int y, float radius,int r, int g, int b, int a);
    }
    extern cGradient gGradient;
    #endif
    [/hide]
    Last edited by mencore; 23rd November 2008 at 12:30.

  2. #2
    FUCKING NICE CODE HARDCORE THX IM GONNA USE THIS EVEN IF I DONT EVEN HAVE MENU BUT HOTKEYS LOL

  3. #3
    HOW LEET


    skyh4x: you cant get this to work.

  4. #4
    Quote Originally Posted by Critycal View Post
    HOW LEET


    skyh4x: you cant get this to work.
    hahahaah lol

  5. #5
    Quote Originally Posted by C0dens(skyhax in disguise) View Post
    OH NOESSSSSS

    Quote Originally Posted by Critycal View Post
    HOW LEET


    skyh4x: you cant get this to work.
    +1

  6. #6
    Quote Originally Posted by C0dens View Post
    OH NOESSSSSS
    Rifk, you can't even call a function without getting 20 compile errors. Don't even try it.

  7. #7
    Imma rip this right now for MY fx_firebullets Ho0o0o0o0ok

  8. #8
    Quote Originally Posted by Lawgiver View Post
    Rifk, you can't even call a function without getting 20 compile errors. Don't even try it.
    I lol'd irl. +10 000000000

  9. #9
    D: we r epic at dissin skyh4x kik

    i guess he was hoping for the .cpp for the whole menu LOL
    Last edited by Critycal; 23rd November 2008 at 15:01.

  10. #10
    Quote Originally Posted by Critycal View Post

    i guess he was hoping for the .cpp for the whole menu LOL
    I was :(, i dont wanna have top rip for a mouse gui8-|

Page 1 of 5 12345 Last

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in