Files
Avancerad_CPP/Lab7/button.cpp
2026-03-05 13:16:26 +01:00

114 lines
2.8 KiB
C++

//## begin module.cm preserve=no
// %X% %Q% %Z% %W%
//## end module.cm
//## begin module.cp preserve=no
//## end module.cp
//## Module: Button; Pseudo Package body
//## Subsystem: lab7
//## Source file: H:\kurs\avC++\lab7\Button.cpp
//## begin module.additionalIncludes preserve=no
//## end module.additionalIncludes
//## begin module.includes preserve=yes
#include <iostream.h>
//## end module.includes
// Button
#include "Button.h"
//## begin module.additionalDeclarations preserve=yes
//## end module.additionalDeclarations
// Class Button
Button::Button()
//## begin Button::Button%.hasinit preserve=no
//## end Button::Button%.hasinit
//## begin Button::Button%.initialization preserve=yes
//## end Button::Button%.initialization
{
//## begin Button::Button%.body preserve=yes
//## end Button::Button%.body
}
Button::Button (int xpos, int ypos, int width, int height, char* text)
//## begin Button::Button%940854117.hasinit preserve=no
//## end Button::Button%940854117.hasinit
//## begin Button::Button%940854117.initialization preserve=yes
//## end Button::Button%940854117.initialization
{
//## begin Button::Button%940854117.body preserve=yes
Button::xpos = xpos;
Button::ypos = ypos;
Button::width = width;
Button::height = height;
Button::text = text;
//## end Button::Button%940854117.body
}
Button::~Button()
{
//## begin Button::~Button%.body preserve=yes
//## end Button::~Button%.body
}
//## Other Operations (implementation)
void Button::handleMouseEvent (Event e)
{
//## begin Button::handleMouseEvent%940929796.body preserve=yes
the_BH->doOnClick();
//## end Button::handleMouseEvent%940929796.body
}
void Button::draw (Graphics& g)
{
//## begin Button::draw%940929797.body preserve=yes
Rectangle r;
int absX, absY;
getPpp()->getAbsPos(&r);
absX = r.getXpos() + xpos;
absY = r.getYpos() + ypos;
g.drawButton(absX, absY, width, height, text);
//## end Button::draw%940929797.body
}
void Button::handleKeyEvent (Event e)
{
//## begin Button::handleKeyEvent%941013995.body preserve=yes
//## end Button::handleKeyEvent%941013995.body
}
bool Button::isHit (int x, int y)
{
//## begin Button::isHit%941013997.body preserve=yes
return((x >= xpos) & (x < xpos + width) & (y >= ypos) & (y < ypos + height));
//## end Button::isHit%941013997.body
}
void Button::setAction (BH* bh)
{
//## begin Button::setAction%941013999.body preserve=yes
the_BH = bh;
//## end Button::setAction%941013999.body
}
// Additional Declarations
//## begin Button.declarations preserve=yes
//## end Button.declarations
//## begin module.epilog preserve=yes
//## end module.epilog