.


:




:

































 

 

 

 


. , ,




 

 

++, - , . . , , . (mixin).

imagebutton.hpp

#ifndef _IMAGEBUTTON_HPP_

#define _IMAGEBUTTON_HPP_

 

//************************************************************************

 

#include "button.hpp"

#include "imagecontrol.hpp"

 

//************************************************************************

 

// ,

class ImageButton

: public Button, public ImageControl

{

 

//------------------------------------------------------------------------

 

public:

 

// -

ImageButton (const std::string & _text, const std::string & _imageFilename);

 

// Button

void draw (int _x, int _y) override;

 

//------------------------------------------------------------------------

 

};

 

//************************************************************************

 

#endif // _IMAGEBUTTON_HPP_

 

 

imagebutton.cpp

 

//************************************************************************

 

#include "imagebutton.hpp"

 

//************************************************************************

 

ImageButton::ImageButton (const std::string & _text,

const std::string & _imageFilename)

 

 

//

: Button(_text)

, ImageControl(_imageFilename)

{

}

 

//************************************************************************

 

//

void ImageButton::draw (int _x, int _y)

{

//

int width, height;

calculateTextSize(width, height);

 

 

// , 3

width += getImageWidth() + 3 * PADDING;

 

 

// - + 2

if (getImageHeight() > height)

height = getImageHeight();

height += 2 * PADDING;

 

 

// ( Button::drawRectangle)

drawRectangle(_x, _y, width, height);

 

 

// ( ImageConrol::drawImage)

drawImage(_x + PADDING,_y + PADDING);

 

 

// ( Button::drawText)

drawText(_x + getImageWidth() + 2 * PADDING, _y + PADDING);

}

 

- ImageButton , Button, ImageControl. ImageButton , :

 

 

ImageButton / :

 

 

ImageButton ib(OK, ok.png);

Button * pButton = & ib;

ImageControl * pControl = & ib;

 

 

, , ImageButton, pButton pControl . . , pButton . . , . , .

 





:


: 2016-07-29; !; : 351 |


:

:

, .
==> ...

1651 - | 1577 -


© 2015-2024 lektsii.org - -

: 0.009 .