Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Crash's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    JAville
    Posts
    2,889
    Reputation
    163
    Thanks
    3,289
    My Mood
    Sleepy

    Button + Slider Class

    Just a few things I wrote up.

    Sorry if they are a little messy.

    Button class :

    Code:
    class cButton{
    public:
    
    	int width, height, x, y;
    	bool isOn;
    	char *buttonText;
    	D3DCOLOR textCol, selTextCol, border, fill, selBor, selFill, overFill;
    	CD3DFont *buttonFont;
    
    	cButton();
    	cButton(int inX, int inY, int w, int h, bool on, char* text, D3DCOLOR borCol, D3DCOLOR fillCol, D3DCOLOR selBorCol, D3DCOLOR selFillCol, D3DCOLOR overFillCol, D3DCOLOR textColor, D3DCOLOR selTextColor){
    
    		x = inX; y = inY; width = w; height = h; isOn = on; buttonText = text; border = borCol; fill = fillCol;
    		selFill = selFillCol; selBor = selBorCol; overFill = overFillCol; textCol = textColor; selTextCol = selTextColor;
    
    	};
    	void drawButton(LPDIRECT3DDEVICE9 pDevice){
    
    		SIZE fSize;
    
    		this->buttonFont->GetTextExtent(this->buttonText, &fSize);
    
    		if(GetAsyncKeyState(VK_LBUTTON)&1){
    
    			if(isMouseinRegion(this->x, this->y, this->x + this->width, this->y + this->height)){
    
    				this->isOn = !this->isOn;
    
    			}
    
    		}
    
    		if(!this->isOn){
    		
    			if(isMouseinRegion(this->x, this->y, this->x + this->width, this->y + this->height)){
    			
    				DrawBox(this->x, this->y, this->width, this->height, this->overFill, this->border, pDevice);
    
    			} else {
    
    				DrawBox(this->x, this->y, this->width, this->height, this->fill, this->border, pDevice);
    
    			}
    			this->buttonFont->DrawText((float)((this->width / 2) - (fSize.cx / 2)), (float)((this->height / 2) - (fSize.cy / 2)), this->textCol, this->buttonText);
    
    		} else {
    
    			if(isMouseinRegion(this->x, this->y, this->x + this->width, this->y + this->height)){
    			
    				DrawBox(this->x, this->y, this->width, this->height, this->overFill, this->selBor, pDevice);
    
    			} else {
    
    				DrawBox(this->x, this->y, this->width, this->height, this->selFill, this->selBor, pDevice);
    
    			}
    			this->buttonFont->DrawText((float)((this->width / 2) - (fSize.cx / 2)), (float)((this->height / 2) - (fSize.cy / 2)), this->selTextCol, this->buttonText);
    
    		}
    		delete &fSize;
    
    	}
    	void setFont(CD3DFont *butFont){
    
    		this->buttonFont = butFont;
    
    	}
    
    };
    Slider class :

    Code:
    class cSlider{
    public:
    
    	int x, y, maxVal, minVal, length, barHeight, barWidth, xOffset, barX;
    	double startVal, curVal;
    	char cMin[20], cMax[20];
    	bool isSliding;
    	D3DCOLOR barCol, backBorderCol, backCol;
    	CD3DFont *sliderFont;
    
    	cSlider();
    	cSlider(int xValue, int yValue, int maxValue, int minValue, double startValue, int lengthValue, int barHeightValue, int barWidthValue, D3DCOLOR barColor, D3DCOLOR backBorderColor, D3DCOLOR backColor){
    
    		x = xValue; y = yValue; maxVal = maxValue; minVal = minValue; barX = (startValue / maxValue) * lengthValue + xValue; startVal = startValue;
    		length = lengthValue; barHeight = barHeightValue; barWidth = barWidthValue; barCol = barColor; isSliding = false;
    		sprintf_s(cMin, 20, "%d", minVal);
    		sprintf_s(cMax, 20, "%d", maxVal);
    
    	};
    	void drawSlider(LPDIRECT3DDEVICE9 pDevice){
    
    		this->curVal = ((this->barX - this->x) / (double)this->length) * this->maxVal;
    
    		if(GetAsyncKeyState(VK_LBUTTON) < 0){
    
    			POINT cPos;
    			GetCursorPos(&cPos);
    
    			if(!this->isSliding){
    
    				if(isMouseinRegion(this->barX, this->y, this->barX + this->barWidth, this->y + this->barHeight + 2)){
    
    					this->xOffset = cPos.x - this->barX;
    					this->isSliding = true;
    
    				}
    
    			} else {
    
    				this->barX = cPos.x - this->xOffset;
    
    				if(this->barX > this->x + this->length){
    				
    					this->barX = this->x + this->length;
    
    				}
    				if(this->barX < this->x){
    
    					this->barX = this->x;
    
    				}
    
    			}
    
    		} else {
    
    			this->isSliding = false;
    
    		}
    
    		DrawBox(this->x - 2, this->y, this->length + this->barWidth + 4, this->barHeight + 4, this->backCol, this->backBorderCol, pDevice);
    		FillRGB(this->barX, this->y + 2, this->barWidth, this->barHeight, this->barCol, pDevice);
    		SIZE tSize;
    		this->sliderFont->GetTextExtent(cMin, &tSize);
    		this->sliderFont->DrawText((float)(this->x - (tSize.cx / 2)), (float)(this->y + this->barHeight + 5), D3DCOLOR_XRGB(255, 255, 255), cMin);
    		this->sliderFont->GetTextExtent(cMax, &tSize);
    		this->sliderFont->DrawText((float)(this->x + this->length + this->barWidth - (tSize.cx / 2)), (float)(this->y + this->barHeight + 5), D3DCOLOR_XRGB(255, 255, 255), cMax);
    		delete &tSize;
    
    	}
    	void setFont(CD3DFont *slideFont){
    
    		sliderFont = slideFont;
    
    	}
    
    
    };
    ====Button Class====
    Constructor :
    (x, y, width, height, starting value(on/off), button text, border color, box color, selected border color, selected box color, box color when mouse is hovering over, normal text color, selected text color)

    - DrawButton -
    This has one parameter which is the device it just draws the button.

    - SetFont -
    Do this after initializing your font. It is used to draw the text.( Note : This uses CD3DFont not ID3DXFont )

    ( Integers )
    x, y - Coordinates of the button
    height, width - Of the button

    ( Booleans )
    isOn - Duh.

    ( Chars )
    buttonText - Duh.

    ( Colors )
    textCol, selTextCol - Off text / On text
    border, fill - Off border / box color
    selBor selFill - On border / box color
    overFill - Color when the mouse is hovering over the button for the box

    ====Slider Class====
    Constructor :
    (x, y, max value, min value, starting value, length of slider when drawn, bar height, bar width, bar color, back border color, back color)

    - DrawSlider -
    This has one parameter which is the device it just draws the slider.

    - SetFont -
    Do this after initializing your font. It is used to draw the max/min.( Note : This uses CD3DFont not ID3DXFont )

    ( Integers )
    x, y - The coordinates for the slider
    maxVal, minVal - The minimum and maximum value for the slider (ex : 0 - 200)
    length - Length of the slider when it is drawn
    barHeight, barWidth - Height/width of the bar that you drag
    xOffset, barX - The xOffset for dragging and the bar's x value

    ( Doubles )
    startVal, curVal - The starting value and the current value for the slider

    ( Bools )
    isSliding - Is the bar sliding ?

    ( Chars )
    cMin, cMax - For drawing the max/min values below the bar

    ( Colors )
    barCol - The bar's color
    backBorderCol, backCol - Border + back color for the slider

    Functions you will need :

    Code:
    bool isMouseinRegion(int x1, int y1, int x2, int y2)
    {
    
    	POINT cPos;
    	GetCursorPos(&cPos);
    
    	if(cPos.x > x1 && cPos.x < x2 && cPos.y > y1 && cPos.y < y2){
    
    		return true;
    
    	} else {
    
    		return false;
    
    	}
    
    }
    void FillRGB( int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9* pDevice )
    {
    
    	D3DRECT rec = { x, y, x + w, y + h };
    	pDevice->Clear( 1, &rec, D3DCLEAR_TARGET, color, 0, 0 );
    }
    void DrawBorder( int x, int y, int w, int h, int px, D3DCOLOR BorderColor, IDirect3DDevice9* pDevice )
    {
    	FillRGB( x, (y + h - px), w, px,    BorderColor, pDevice );
    	FillRGB( x, y, px, h,                BorderColor, pDevice );
    	FillRGB( x, y, w, px,                BorderColor, pDevice );
    	FillRGB( (x + w - px), y, px, h,    BorderColor, pDevice );
    }
    void DrawBox( int x, int y, int w, int h, D3DCOLOR BoxColor, D3DCOLOR BorderColor, IDirect3DDevice9* pDevice )
    {
    	FillRGB( x, y, w, h,        BoxColor, pDevice );
    	DrawBorder( x, y, w, h, 2,    BorderColor, pDevice );
    }
    How to use them :
    Code:
    //Global\\
    cButton myButton(2, 2, 100, 50, false, "Super Jump", D3DCOLOR_XRGB(0, 255, 0), D3DCOLOR_XRGB(0, 0, 0), D3DCOLOR_XRGB(255, 255, 255), D3DCOLOR_XRGB(0, 0, 0), D3DCOLOR_XRGB(100, 100, 100), D3DCOLOR_XRGB(0, 255, 0), D3DCOLOR_XRGB(0, 255, 0));
    
    //In your hooked D3D function\\
    
    //(After initializing your font)
    myButton.setFont( <font here> );
    
    //For drawing
    myButton.drawButton(pDevice);
    
    //Wherever you do your hacks\\
    if(myButton.isOn){
    //It's on
    } else {
    //It's off
    }
    
    //===================================
    
    //Global\\
    cSlider mySlider(10, 250, 100, 0, 10, 100, 10, 10, D3DCOLOR_XRGB(192, 192, 192), D3DCOLOR_XRGB(0, 0, 0), D3DCOLOR_XRGB(255, 255, 255));
    
    //In your hooked D3D function\\
    
    //( After initializing your font)
    mySlider.setFont( <font here> );
    
    //When drawing
    mySlider.drawSlider(pDevice);
    
    //Wherever you do your stuff
    double sliderValue = mySlider.curVal;
    //Do stuff with it
    Credits :
    Whoever for box drawing functions
    Me for the rest

    Don't like ? kthxbai
    Bug or something you think I should change ?
    Post away.

    Last edited by Crash; 08-24-2010 at 10:31 AM.

  2. The Following 10 Users Say Thank You to Crash For This Useful Post:

    CodeDemon (08-24-2010),DeadLinez (08-24-2010),GodHack2 (08-24-2010),J (08-24-2010),markoj (08-24-2010),ngh555 (08-24-2010),S0aD (03-01-2011),tempta43 (08-25-2010),why06 (01-18-2011),Yepikiyay (08-26-2010)

  3. #2
    markoj's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    s
    Posts
    1,067
    Reputation
    60
    Thanks
    407
    My Mood
    Bored
    Thank you very Much sir, testing now
    Dont ban me

  4. #3
    ngh555's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Posts
    126
    Reputation
    14
    Thanks
    58
    My Mood
    Devilish
    Man, awesome work!! thank you for helping the community.

    Keep up the good work!
    Originally Posted by flavjo
    Sorry for my chooby question but where do i find the C++ Express in my PC???
    Originally Posted by Deco
    i'll just punch him in the face nd steal his shoes *nigga style*

  5. #4
    Crash's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    JAville
    Posts
    2,889
    Reputation
    163
    Thanks
    3,289
    My Mood
    Sleepy
    I edited a few things for testing so there might be a bug.

  6. #5
    Mr.Mageman's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    87
    Reputation
    11
    Thanks
    17
    Nice but most people who isnt leechers wont use this (if they are determined)

  7. #6
    Crash's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    JAville
    Posts
    2,889
    Reputation
    163
    Thanks
    3,289
    My Mood
    Sleepy
    Ok I added on the constructors.

  8. #7
    Stephen's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Engine.exe
    Posts
    4,690
    Reputation
    184
    Thanks
    1,147
    My Mood
    Aggressive
    You asshole I said no. >.>

  9. #8
    Crash's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    JAville
    Posts
    2,889
    Reputation
    163
    Thanks
    3,289
    My Mood
    Sleepy
    Quote Originally Posted by Stephen View Post
    You asshole I said no. >.>
    DIP


    Blood is waiting.

  10. #9
    Stephen's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Engine.exe
    Posts
    4,690
    Reputation
    184
    Thanks
    1,147
    My Mood
    Aggressive
    ofc you are... Im still in TV and im leaving soon. so prob tomorrow

  11. #10
    gcflames12's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    wada
    Posts
    181
    Reputation
    10
    Thanks
    24
    Nice job crash and you just helped me alot. i had messed up my slider but its fixed thanks to you (:

  12. #11
    CodeDemon's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    vagina
    Posts
    1,074
    Reputation
    50
    Thanks
    936
    My Mood
    Fine
    Nice work crash ^^

  13. #12
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool
    Hmm looks nice my sliders are smaller
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  14. #13
    GodHack2's Avatar
    Join Date
    May 2010
    Gender
    male
    Posts
    645
    Reputation
    38
    Thanks
    762
    My Mood
    Amused
    nice work thanked





    beat this bitches ^^^^^^^

    Current Stats : Bored :/


    Respect list :
    Crash !
    Gordon'
    Markoj

  15. #14
    IcySeal's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    300
    Reputation
    34
    Thanks
    148
    My Mood
    Amused
    Quote Originally Posted by topblast View Post
    Hmm looks nice my sliders are smaller
    Just like something else of yours

  16. The Following 2 Users Say Thank You to IcySeal For This Useful Post:

    Beatz (08-25-2010),markoj (08-25-2010)

  17. #15
    whatup777's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    CA Source Code Section
    Posts
    4,030
    Reputation
    147
    Thanks
    351
    My Mood
    Dead
    Quote Originally Posted by IcySeal View Post


    Just like something else of yours
    That made me
    Quotes I live by.


    A foolish person learns from his mistakes, I wise person learns from others.
    Quote Originally Posted by AVGN View Post



    mhm

    i live in texas

    i was at the grocery store with my son. He saw a mexican guy, and he said "Look daddy! a mower man!"

    he's 4 yrs old

Page 1 of 2 12 LastLast

Similar Threads

  1. [Release] ProgressBar? With Crash's Slider class.
    By Nubzgetkillz in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 27
    Last Post: 01-20-2011, 10:34 PM
  2. [Release] ProgressBar? With Crash's Slider class.
    By Nubzgetkillz in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 6
    Last Post: 01-19-2011, 07:35 AM
  3. Guild Wars New Classes
    By Chronologix in forum General Gaming
    Replies: 24
    Last Post: 07-23-2006, 09:46 AM
  4. Banner/Button for advertising
    By Dave84311 in forum Help & Requests
    Replies: 17
    Last Post: 01-27-2006, 09:59 AM
  5. [Tutorial]Change class without respawn
    By vir2000 in forum Game Hacking Tutorials
    Replies: 0
    Last Post: 01-04-2006, 02:47 PM