X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbcpopupmenu.C;h=a502ee084abd8686e74637a2689adfc8d5346dd1;hp=80a02f6adc3b92790919763d1d06470efbbdfa07;hb=ba9e9e32512994d5bccdd782bce844b2338992b7;hpb=6a9fa3df95fb5ef53e1b09fdd2297a8aaf549fe5 diff --git a/cinelerra-5.1/guicast/bcpopupmenu.C b/cinelerra-5.1/guicast/bcpopupmenu.C index 80a02f6a..a502ee08 100644 --- a/cinelerra-5.1/guicast/bcpopupmenu.C +++ b/cinelerra-5.1/guicast/bcpopupmenu.C @@ -37,8 +37,8 @@ #define TOTAL_IMAGES 3 -#define TRIANGLE_W 10 -#define TRIANGLE_H 10 +#define TRIANGLE_W xS(10) +#define TRIANGLE_H yS(10) BC_PopupMenu::BC_PopupMenu(int x, int y, int w, const char *text, @@ -118,8 +118,8 @@ int BC_PopupMenu::initialize() } else { // Move outside window if no title - x = -10; y = -10; - w = 10; h = 10; + x = -TRIANGLE_W; y = -TRIANGLE_H; + w = TRIANGLE_W; h = TRIANGLE_H; } BC_SubWindow::initialize(); @@ -134,28 +134,28 @@ int BC_PopupMenu::initialize() int BC_PopupMenu::set_images(VFrame **data) { - BC_Resources *resources = get_resources(); for( int i=0; i<3; ++i ) { delete images[i]; images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA); } - if( w_argument >= 0 ) - w = w_argument + margin + - resources->popupmenu_triangle_margin; - else - w = get_text_width(MEDIUMFONT, text) + margin + - resources->popupmenu_triangle_margin; - + w = w_argument > 0 ? w_argument : + calculate_w(margin, get_text_width(MEDIUMFONT, text), use_title); h = images[BUTTON_UP]->get_h(); return 0; } -int BC_PopupMenu::calculate_w(int w_argument) +int BC_PopupMenu::calculate_w(int margin, int text_width, int use_title) +{ + BC_Resources *resources = get_resources(); + int l = margin >= 0 ? margin : resources->popupmenu_margin; + int r = use_title < 0 ? l : l + resources->popupmenu_triangle_margin; + return l + text_width + r; +} + +int BC_PopupMenu::calculate_w(int text_width) { - return w_argument + - BC_WindowBase::get_resources()->popupmenu_margin + - BC_WindowBase::get_resources()->popupmenu_triangle_margin; + return calculate_w(-1, text_width, 0); } int BC_PopupMenu::calculate_h(VFrame **data) @@ -200,28 +200,29 @@ int BC_PopupMenu::get_margin() return margin; } -int BC_PopupMenu::draw_face(int dx) +int BC_PopupMenu::draw_face(int dx, int color) { if( !use_title ) return 0; - BC_Resources *resources = get_resources(); // Background draw_top_background(parent_window, 0, 0, w, h); draw_3segmenth(0, 0, w, images[status]); // Overlay text - set_color(get_resources()->popup_title_text); + if( color < 0 ) color = get_resources()->popup_title_text; + set_color(color); + int offset = status == BUTTON_DN ? 1 : 0; - int available_w = get_w() - margin*2 - resources->popupmenu_triangle_margin; + int available_w = get_w() - calculate_w(margin, 0, use_title); + if( !icon ) { + char *truncated = get_truncated_text(MEDIUMFONT, text, available_w); set_font(MEDIUMFONT); - char truncated[BCTEXTLEN]; - truncate_text(truncated, text, available_w); - BC_WindowBase::draw_center_text( dx + available_w/2 + margin + offset, (int)((float)get_h()/2 + get_text_ascent(MEDIUMFONT)/2 - 2) + offset, truncated); + delete [] truncated; } if( icon ) { @@ -230,15 +231,17 @@ int BC_PopupMenu::draw_face(int dx) get_h()/2 - icon->get_h()/2 + offset); } - if( use_title >= 0 ) - draw_triangle_down_flat(available_w + margin, - get_h()/2 - TRIANGLE_H/2, TRIANGLE_W, TRIANGLE_H); + if( use_title >= 0 ) { + int tx = get_w() - margin - get_resources()->popupmenu_triangle_margin; + int ty = get_h()/2 - TRIANGLE_H/2; + draw_triangle_down_flat(tx, ty, TRIANGLE_W, TRIANGLE_H); + } return 1; } int BC_PopupMenu::draw_title(int flush) { - draw_face(0); + draw_face(0, -1); flash(flush); return 0; } @@ -290,10 +293,12 @@ int BC_PopupMenu::menu_activate() w, h, 0, 1); } else - menu_popup->activate_menu(x+3, y+3, w, h, 0, 1); + menu_popup->activate_menu(x+xS(3), y+yS(3), w, h, 0, 1); popup_down = 1; if( use_title ) draw_title(1); } + else + deactivate_menu(); return 1; } @@ -334,9 +339,7 @@ int BC_PopupMenu::repeat_event(int64_t duration) int BC_PopupMenu::button_press_event() { int result = 0; - if( get_buttonpress() == 1 && - is_event_win() && - use_title ) { + if( get_buttonpress() == 1 && is_event_win() && use_title ) { top_level->hide_tooltip(); if( status == BUTTON_HI || status == BUTTON_UP ) status = BUTTON_DN; activate_menu();