// This event is called when the user resizes the main_window. Note that unlike the other // events, this event is part of the drawable_window base class that main_window inherits from. // So you won't see any statements in the constructor that say "register the main_window::on_window_resized function" void main_window:: on_window_resized () { // when you override any of the drawable_window events you have to make sure you // call the drawable_window's version of them because it needs to process // the events as well. So we do that here. drawable_window::on_window_resized(); // The rest of this function positions the widgets on the window unsigned long width,height; get_size(width,height); // Don't do anything if the user just made the window too small. That is, leave // the widgets where they are. if (width < 500 || height < 350) return; // Set the size of the probability tables and the drawing area for the graph graph_drawer.set_size(width-370,height-10-mbar.height()); cpt_grid.set_size((width-graph_drawer.width())-35,height-237); ppt_grid.set_size((width-graph_drawer.width())-35,height-237); // tell the tabbed display to make itself just the right size to contain // the two probability tables. tables.fit_to_contents(); // Now position all the widgets in the window. Note that much of the positioning // is relative to other widgets. This part of the code I just figured out by // trying stuff and rerunning the program to see if it looked nice. sel_node_index.set_pos(graph_drawer.right()+14,graph_drawer.top()+18); sel_node_text_label.set_pos(sel_node_index.left(),sel_node_index.bottom()+5); sel_node_text.set_pos(sel_node_text_label.right()+5,sel_node_index.bottom()); sel_node_num_values_label.set_pos(sel_node_index.left(), sel_node_text.bottom()+5); sel_node_num_values.set_pos(sel_node_num_values_label.right(), sel_node_text.bottom()+5); sel_node_is_evidence.set_pos(sel_node_index.left(),sel_node_num_values.bottom()+5); sel_node_evidence_label.set_pos(sel_node_index.left(),sel_node_is_evidence.bottom()+5); sel_node_evidence.set_pos(sel_node_evidence_label.right()+5,sel_node_is_evidence.bottom()); tables.set_pos(sel_node_index.left(),sel_node_evidence.bottom()+5); sel_node_evidence.set_width(tables.right()-sel_node_evidence.left()+1); sel_node_text.set_width(tables.right()-sel_node_text.left()+1); sel_node_num_values.set_width(tables.right()-sel_node_num_values.left()+1); // Tell the named rectangle to position itself such that it fits around the // tabbed display that contains the probability tables and the label at the top of the // screen. selected_node_rect.wrap_around(sel_node_index.get_rect()+ tables.get_rect()); // finally set the button to be at the bottom of the named rectangle btn_calculate.set_pos(selected_node_rect.left(), selected_node_rect.bottom()+5); }
win ( ): drawable_window(true), lbl_last_keydown(*this), lbl_mod_shift(*this), lbl_mod_control(*this), lbl_mod_alt(*this), lbl_mod_meta(*this), lbl_mod_caps_lock(*this), lbl_mod_num_lock(*this), lbl_mod_scroll_lock(*this), b(*this), btn_count(*this), btn_get_clipboard(*this), btn_set_clipboard(*this), btn_show_message(*this), cb1(*this,rectangle(100,100,200,200),255,0,0), cb2(*this,rectangle(150,150,250,240),0,255,0), cbl(*this), cbox(*this), group1(*this), group2(*this), group3(*this), keyboard_count(1), keydown(*this), keyup(*this), l1(*this), l2(*this), l3(*this), lb(*this), leave_count(*this), left_down(*this), left_up(*this), middle_down(*this), middle_up(*this), mouse_state(*this), mt(*this), nrect(*this), pos(*this), rb(*this), right_down(*this), right_up(*this), sb2(*this,scroll_bar::VERTICAL), sb3(*this,scroll_bar::VERTICAL), sb_enabled(*this), sbl2(*this), sbl3(*this), sbl(*this), sb_shown(*this), sb(*this,scroll_bar::HORIZONTAL), scroll(*this), tab_label(*this), tabs(*this), tf(*this), mbar(*this) { bool use_bdf_fonts = false; if (use_bdf_fonts) { ifstream fin("/home/davis/source/10x20.bdf"); f.read_bdf_file(fin,0xFFFF); mt.set_main_font(&f); } //mt.hide(); mt.set_pos(5,200); lbl_last_keydown.set_text("?"); lbl_mod_shift.set_text("?"); lbl_mod_control.set_text("?"); lbl_mod_alt.set_text("?"); lbl_mod_meta.set_text("?"); lbl_mod_caps_lock.set_text("?"); lbl_mod_num_lock.set_text("?"); lbl_mod_scroll_lock.set_text("?"); lbl_last_keydown.set_pos(20,420); lbl_mod_shift.set_pos(20,lbl_last_keydown.bottom()+5); lbl_mod_control.set_pos(20,lbl_mod_shift.bottom()+5); lbl_mod_alt.set_pos(20,lbl_mod_control.bottom()+5); lbl_mod_meta.set_pos(20,lbl_mod_alt.bottom()+5); lbl_mod_caps_lock.set_pos(20,lbl_mod_meta.bottom()+5); lbl_mod_num_lock.set_pos(20,lbl_mod_caps_lock.bottom()+5); lbl_mod_scroll_lock.set_pos(20,lbl_mod_num_lock.bottom()+5); lb.set_pos(580,200); lb.set_size(200,300); if (use_bdf_fonts) lb.set_main_font(&f); dlib::queue<string>::kernel_2a_c qos; string a; a = "Davis"; qos.enqueue(a); a = "king"; qos.enqueue(a); a = "one"; qos.enqueue(a); a = "two"; qos.enqueue(a); a = "three"; qos.enqueue(a); a = "yo yo yo alsdkjf asfj lsa jfsf\n this is a long phrase"; qos.enqueue(a); a = "four"; qos.enqueue(a); a = "five"; qos.enqueue(a); a = "six"; qos.enqueue(a); a = "seven"; qos.enqueue(a); a = "eight"; qos.enqueue(a); a = "nine"; qos.enqueue(a); a = "ten"; qos.enqueue(a); a = "eleven"; qos.enqueue(a); a = "twelve"; qos.enqueue(a); for (int i = 0; i < 1000; ++i) { a = "thirteen"; qos.enqueue(a); } lb.load(qos); lb.select(1); lb.select(2); lb.select(3); lb.select(5); lb.enable_multiple_select(); lb.set_double_click_handler(*this,&win::lb_double_click); // lb.disable_multiple_select(); btn_show_message.set_pos(50,350); btn_show_message.set_name("message_box()"); mbar.set_number_of_menus(2); mbar.set_menu_name(0,"File",'F'); mbar.set_menu_name(1,"Help",'H'); mbar.menu(0).add_menu_item(menu_item_text("show msg click",*this,&win::on_show_msg_click,'s')); mbar.menu(0).add_menu_item(menu_item_text("get clipboard",*this,&win::on_get_clipboard,'g')); mbar.menu(0).add_menu_item(menu_item_text("set clipboard",*this,&win::on_set_clipboard,'c')); mbar.menu(0).add_menu_item(menu_item_separator()); mbar.menu(0).add_submenu(menu_item_submenu("submenu",'m'), submenu); submenu.add_menu_item(menu_item_separator()); submenu.add_menu_item(menu_item_separator()); submenu.add_menu_item(menu_item_text("show msg click",*this,&win::on_show_msg_click,'s')); submenu.add_menu_item(menu_item_text("get clipboard",*this,&win::on_get_clipboard,'g')); submenu.add_menu_item(menu_item_text("set clipboard",*this,&win::on_set_clipboard,'c')); submenu.add_menu_item(menu_item_separator()); submenu.add_menu_item(menu_item_separator()); mbar.menu(1).add_menu_item(menu_item_text("About",*this,&win::on_menu_help,'A')); btn_show_message.set_click_handler(*this,&win::on_show_msg_click); btn_get_clipboard.set_pos(btn_show_message.right()+5,btn_show_message.top()); btn_get_clipboard.set_name("get_from_clipboard()"); btn_get_clipboard.set_click_handler(*this,&win::on_get_clipboard); btn_get_clipboard.set_style(button_style_toolbar1()); btn_set_clipboard.set_pos(btn_get_clipboard.right()+5,btn_get_clipboard.top()); btn_set_clipboard.set_name("put_on_clipboard()"); btn_set_clipboard.set_click_handler(*this,&win::on_set_clipboard); nrect.set_size(700,500); nrect.set_name("test widgets"); nrect.set_pos(2,mbar.bottom()+2); //throw dlib::error("holy crap batman"); tab_label.set_pos(10,440); tabs.set_click_handler(*this,&win::tab_change); tabs.set_pos(5,mbar.bottom()+10); tabs.set_size(280,100); tabs.set_number_of_tabs(3); tabs.set_tab_name(0,"davis"); tabs.set_tab_name(1,"edward"); tabs.set_tab_name(2,"king alsklsdkfj asfd"); tabs.set_tab_group(0,group1); tabs.set_tab_group(1,group2); tabs.set_tab_group(2,group3); l1.set_text("group one"); l2.set_text("group two"); l3.set_text("group three"); group1.add(l1,0,0); group2.add(l2,20,10); group3.add(l3,0,0); sb_enabled.set_name("enabled"); sb_shown.set_name("shown"); sb_shown.set_checked(); sb_enabled.set_checked(); sb_shown.set_click_handler(*this,&win::cb_sb_shown); sb_enabled.set_click_handler(*this,&win::cb_sb_enabled); sb_shown.set_tooltip_text("I'm a checkbox"); rb.set_click_handler(*this,&win::rb_click); sb3.set_pos(440,mbar.bottom()+10); sb3.set_max_slider_pos(300); sb3.set_slider_pos(150); sb3.set_length(300); sb2.set_pos(470,mbar.bottom()+10); sb2.set_max_slider_pos(300); sb2.set_length(300); sb.set_pos(500,mbar.bottom()+10); sb.set_max_slider_pos(30); sb.set_length(300); sb.set_scroll_handler(*this,&win::scroll_handler); sb2.set_scroll_handler(*this,&win::scroll2_handler); sb3.set_scroll_handler(*this,&win::scroll3_handler); sbl.set_pos(540,mbar.bottom()+20); sbl2.set_pos(540,mbar.bottom()+40); sbl3.set_pos(540,mbar.bottom()+60); cbox.set_pos(300,mbar.bottom()+30); cbox.set_name("davis king"); cbox.set_click_handler(*this,&win::cbox_clicked); cbl.set_pos(300,cbox.get_rect().bottom()+1); cbox.set_checked(); sb_enabled.set_pos(cbox.get_rect().left(),cbox.get_rect().bottom()+20); sb_shown.set_pos(sb_enabled.get_rect().left(),sb_enabled.get_rect().bottom()+2); if (use_bdf_fonts) rb.set_main_font(&f); rb.set_name("radio button"); rb.set_pos(sb_shown.get_rect().left(),sb_shown.get_rect().bottom()+2); cb1.set_z_order(10); cb2.set_z_order(20); pos.set_pos(50,50); left_up.set_pos(50,70); left_down.set_pos(50,90); middle_up.set_pos(50,110); middle_down.set_pos(50,130); right_up.set_pos(50,150); right_down.set_pos(50,170); mouse_state.set_pos(50,190); leave_count.set_pos(50,210); scroll_count = 0; scroll.set_pos(50,230); btn_count.set_pos(50,250); keydown.set_pos(50,270); keyup.set_pos(50,290); tf.set_pos(50,310); tf.set_text("Davis685g@"); tf.set_width(500); tf.set_text_color(rgb_pixel(255,0,0)); button_count = 0; count = 0; b.set_name("button"); b.set_pos(540,100); b.set_click_handler(*this,&win::on_click); b.set_tooltip_text("hurray i'm a button!"); if (use_bdf_fonts) b.set_main_font(&f); set_size(800,500); nrect.wrap_around( cbox.get_rect() + rb.get_rect() + sb_enabled.get_rect() + sb_shown.get_rect()); flip = 0; open_file_box(*this,&win::on_open_file); open_existing_file_box(*this,&win::on_open_file); save_file_box(*this,&win::on_open_file); if (use_bdf_fonts) tf.set_main_font(&f); if (use_bdf_fonts) tabs.set_main_font(&f); }