#include "../include/xcv_license.h" //PCH namespace Widgets95 {//-. //<-' bool ui::button::_special_handler(int key, int modifiers) { button *c = nullptr; assert(_ui); if(key==GLUT_KEY_UP||key==GLUT_KEY_LEFT) { c = dynamic_cast(_ui->_find_prev_control(this)); } else if(key==GLUT_KEY_DOWN||key==GLUT_KEY_RIGHT) { c = dynamic_cast(_ui->_find_next_control(this)); } else return true; if(c) c->activate(); return false; } /****************************** WIDGETS_95_Button::mouse_down_handler() **********/ bool ui::button::_mouse_down_handler(int local_x, int local_y) { //EXPERIMENTAL //spacebar_mouse_click? if(local_x==-1&&e.curr_modifiers) return true; set_int_val(1); return false; } /****************************** WIDGETS_95_Button::mouse_up_handler() **********/ bool ui::button::_mouse_up_handler(int local_x, int local_y, bool inside) { if(inside) execute_callback(); set_int_val(0); return false; } /****************************** WIDGETS_95_Button::mouse_held_down_handler() ******/ bool ui::button::_mouse_held_down_handler(int local_x, int local_y, bool inside) { if(inside!=e.prev_inside) redraw(); return false; } /********************************************** WIDGETS_95_Button::draw() **********/ void ui::button::_draw(int toggled) { int press = this==e::get_pressed(); //EXPERIMENTAL if(press&&e.spacebar_is_down&&e.curr_modifiers) press = 0; if(toggled!=-1) //2022: style_hide? if(press||toggled) //draw_pressed() { //NOTE: This NEW look matches the //scrollbar buttons. //window::draw_color(0); //window::draw_border_rect(0,0,w,h,0xFF); //double black border window::draw_color(128); window::draw_border_rect(0,0,_w,_h,0xF); } else window::draw_raised_rect(0,0,_w,_h); //draw_text(int press) { if(!window::draw_pic(_picture,_w/2,_h/2)) //+press { int x=0, w = _w; if(control*ch=first_child()) { if(!ch->_hidden) { x+=_x_lr; w-=x+_x_rl; } for(;ch;ch=ch->next()) { if(!ch->_hidden) { w-=ch->_w; if(left==ch->_alignment) x = ch->area()-_x_abs; } } } //I have no clue how to calculate this. int y = (_h-_font.height)/2+2; draw_name(x+std::max(w-name_span(),0)/2,y+press); } if(this==e::get_active()) { //REMINDER: This tweak is concerned with label spacing //and collision with the stippled border. window::draw_active_rect(3-press,3-press,_w-3+press,_h-3+press,press); } } } /************************************** WIDGETS_95_Button::update_area() **********/ void ui::button::_update_area(int add) { if(int name_w=name_span()) { enum{ lineup=20 }; name_w+=lineup; name_w = lineup*int(name_w/(float)lineup+0.5f); //HACK: This is out-of-order. for(control*ch=first_child();ch;ch=ch->next()) { if(!ch->_hidden) name_w+=ch->_w; } _w = std::max(_w,name_w+lineup/2+add); } if(_alignment) //YUCK { if(_w%2==0) _w++; //Odds squares focus rect. } } //---. }//<-'