00001 #include "push_button.h"
00002 #include <cmath>
00003
00004 namespace crs {
00005 push_button::push_button( base_control *Parent, button_events *Events, const std::string Caption,
00006 const unsigned int Left, const unsigned int Top, const unsigned int Width,
00007 style::styles Style, const chtype clb, const chtype crb ):
00008 focused_ctrl( Parent, Events, Left, Top, Width, 1 ),
00009 styled_ctrl( Style, clb, crb ), mCaption( Caption ),
00010 caption( this, &push_button::getCaption, &push_button::setCaption ) {
00011 }
00012
00013 const std::string &push_button::getCaption() {
00014 return mCaption;
00015 }
00016 void push_button::setCaption( const std::string &Caption ) {
00017 mCaption = Caption;
00018 }
00019
00020 bool push_button::keyPress( const int key ) {
00021 if( ( key == 13 || key == ' ' ) && events )
00022 static_cast<button_events*>(events)->onPush();
00023 return true;
00024 }
00025
00026 void push_button::draw() {
00027 buffer[0] = sc::getLeftBorder( mStyle, custom_left_border );
00028 buffer.setText( mCaption, int( ( mWidth - mCaption.size() ) / 2 ), 0 );
00029 buffer[ mWidth - 1 ] = sc::getRightBorder( mStyle, custom_right_border );
00030 }
00031 }
00032