Select Git revision
spinbox.cpp
spinbox.cpp 2.44 KiB
#include "spinbox.hpp"
#include "graphics.hpp"
#include "widget.hpp"
using namespace genv;
using namespace std;
int mouse_x = 0;
int mouse_y = 0;
SpinBox::SpinBox(Application* parent,int x, int y, int sizey, int min, int max, int start) : Widget(parent,x,y,sizey*3,sizey), _min(min), _max(max), _num(start), _isselected(0)
{
}
void SpinBox::draw()
{
_sizex = _sizey;
gout << move_to (_x,_y) << color(50,50,50) << box(_sizex,_sizey);
gout << move_to(_x + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2);
gout << move_to(_x + _sizey + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2);
gout << move_to(_x +2*_sizey + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2);
int text_width = gout.twidth(to_string(_num));
int text_height = gout.cascent() + gout.cdescent();
gout << move_to(_x + (_sizex - text_width) / 2, _y + (_sizey - text_height) / 2 + gout.cascent())
<< color(255, 0, 0)
<< text(to_string(_num));
}
void SpinBox::draw2()
{
_sizex = _sizey;
gout << move_to (_x,_y) << color(50,50,50) << box(_sizex,_sizey);
gout << move_to(_x + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2);
gout << move_to(_x + _sizey + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2);
gout << move_to(_x +2*_sizey + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2);
int text_width = gout.twidth(to_string(_num));
int text_height = gout.cascent() + gout.cdescent();
gout << move_to(_x + (_sizex - text_width) / 2, _y + (_sizey - text_height) / 2 + gout.cascent())
<< color(0, 255, 0)
<< text(to_string(_num));
}
bool SpinBox::isover(int ms_x, int ms_y)
{
return (ms_x >= _x) and (ms_x <= _x + _sizex) and (ms_y >= _y) and (ms_y <= _y + _sizey);
}
int SpinBox::getter()
{
return _num;
}