void ui_draw_shad(int x1, int y1, int x2, int y2, color* c1, color* c2) { gr_set_color_fast(c1); ui_hline(x1 + 0, x2 - 1, y1 + 0); ui_vline(y1 + 1, y2 + 0, x1 + 0); gr_set_color_fast(c2); ui_hline(x1 + 1, x2, y2 - 0); ui_vline(y1 + 0, y2 - 1, x2 - 0); }
void ui_draw_sunken_border(int x1, int y1, int x2, int y2) { gr_set_color_fast(&CGRAY); ui_hline(x1 - 1, x2 + 1, y1 - 1); ui_vline(y1 - 1, y2 + 1, x1 - 1); gr_set_color_fast(&CBRIGHT); ui_hline(x1 - 1, x2 + 1, y2 + 1); ui_vline(y1, y2 + 1, x2 + 1); }
void ui_draw_line_in(int x1, int y1, int x2, int y2) { gr_set_color_fast(&CGRAY); ui_hline(x1, x2, y1); ui_hline(x1, x2 - 1, y2 - 1); ui_vline(y1 + 1, y2 - 2, x1); ui_vline(y1 + 1, y2 - 2, x2 - 1); gr_set_color_fast(&CBRIGHT); ui_hline(x1 + 1, x2 - 1, y1 + 1); ui_hline(x1, x2, y2); ui_vline(y1 + 2, y2 - 2, x1 + 1); ui_vline(y1 + 1, y2 - 1, x2); }
void UI_INPUTBOX::draw() { int invis, w1, h1, tw, th; int text_x, text_y; if (hidden){ return; } w1 = w; h1 = h; invis = flags & UI_INPUTBOX_FLAG_INVIS; gr_set_font(my_wnd->f_id); gr_reset_clip(); if (!invis && !(flags & UI_INPUTBOX_FLAG_NO_BACK)) { // draw the entire text box region ui_draw_sunken_border( x-2, y-2, x+w+1, y+h+1 ); gr_set_color_fast( &CBLACK ); gr_rect( 0, 0, w, h, GR_RESIZE_MENU ); w1 -= 4; h1 -= 4; gr_set_clip( x + 1, y + 1, w1 + 1, h1 + 1, GR_RESIZE_MENU ); } else { gr_set_clip( x - 1, y - 1, w1 + 1, h1 + 1, GR_RESIZE_MENU ); } if (flags & UI_INPUTBOX_FLAG_PASSWD){ gr_get_string_size(&tw, &th, passwd_text); } else { gr_get_string_size(&tw, &th, text); } if (!disabled_flag && !(flags & UI_INPUTBOX_FLAG_NO_BACK)) { gr_set_color_fast( &CBLACK ); // color the background behind the text gr_rect( 0, 0, tw + 1, th, GR_RESIZE_MENU_NO_OFFSET ); } if ( (my_wnd->selected_gadget == this) || disabled_flag ) { gr_set_color_fast(text_color); } else { gr_set_color_fast(&CWHITE); } // coords of where to draw the text text_x = 1; text_y = 1; if(flags & UI_INPUTBOX_FLAG_TEXT_CEN){ // if we fit within the text area, draw it centered if(tw <= w1 - 5){ text_x += (w1 - tw)/2; } } // draw the text if (flags & UI_INPUTBOX_FLAG_PASSWD){ gr_string(text_x, text_y, passwd_text, GR_RESIZE_MENU); } else { gr_string(text_x, text_y, text, GR_RESIZE_MENU); } // draw the "cursor" if (!disabled_flag) { if (my_wnd->selected_gadget == this) { if (cursor_first_frame == -1) { gr_set_color_fast(text_color); ui_vline(1, h1, text_x + tw + 4); ui_vline(1, h1, text_x + tw + 5); } else { // draw animating cursor int time_delta = timer_get_milliseconds() - cursor_elapsed_time; if ( (time_delta / 1000.0f) > (1.0f / cursor_fps) ) { // advance frame cursor_elapsed_time += time_delta; cursor_current_frame++; if (cursor_current_frame >= cursor_nframes) { cursor_current_frame = 0; } } // draw current frame gr_set_bitmap(cursor_first_frame + cursor_current_frame); gr_bitmap(text_x + tw + 4, 1, GR_RESIZE_MENU_NO_OFFSET); } } } gr_reset_clip(); }
void UI_INPUTBOX::draw() { int invis, w1, h1, tw, th; int text_x, text_y; if (hidden){ return; } w1 = w; h1 = h; invis = flags & UI_INPUTBOX_FLAG_INVIS; gr_set_font(my_wnd->f_id); gr_reset_clip(); if (!invis && !(flags & UI_INPUTBOX_FLAG_NO_BACK)) { // draw the entire text box region ui_draw_sunken_border( x-2, y-2, x+w+1, y+h+1 ); gr_set_color_fast( &CBLACK ); gr_rect( 0, 0, w, h ); w1 -= 4; h1 -= 4; gr_set_clip( x + 1, y + 1, w1 + 1, h1 + 1 ); } else { gr_set_clip( x - 1, y - 1, w1 + 1, h1 + 1 ); } if (flags & UI_INPUTBOX_FLAG_PASSWD){ gr_get_string_size(&tw, &th, passwd_text); } else { gr_get_string_size(&tw, &th, text); } // If first_time is set, that means this input box got // focus, but nothing is typed yet, so all the text is // selected, if you type a character it will replace the // text, if you type an arrow it will unselect it. // So it needs to be colored differently to show this. if (!disabled_flag && !(flags & UI_INPUTBOX_FLAG_NO_BACK)) { // if ( (my_wnd->selected_gadget == this) && first_time ) { // gr_set_color_fast( text_color ); // } else { gr_set_color_fast( &CBLACK ); // } // color the background behind the text gr_rect( 0, 0, tw + 1, th ); } if ( (my_wnd->selected_gadget == this) || disabled_flag ) { gr_set_color_fast(text_color); } else { gr_set_color_fast(&CWHITE); } // coords of where to draw the text text_x = 1; text_y = 1; if(flags & UI_INPUTBOX_FLAG_TEXT_CEN){ // if we fit within the text area, draw it centered if(tw <= w1 - 5){ text_x += (w1 - tw)/2; } } // draw the text if (flags & UI_INPUTBOX_FLAG_PASSWD){ gr_string(text_x, text_y, passwd_text); } else { gr_string(text_x, text_y, text); } // draw the "cursor" if (!disabled_flag) { if (my_wnd->selected_gadget == this) { if (cursor_first_frame == -1) { gr_set_color_fast(text_color); ui_vline(1, h1, text_x + tw + 4); ui_vline(1, h1, text_x + tw + 5); } else { // draw animating cursor int time_delta = timer_get_milliseconds() - cursor_elapsed_time; if ( (time_delta / 1000.0f) > (1.0f / cursor_fps) ) { // advance frame cursor_elapsed_time += time_delta; cursor_current_frame++; if (cursor_current_frame >= cursor_nframes) { cursor_current_frame = 0; } } // draw current frame gr_set_bitmap(cursor_first_frame + cursor_current_frame); gr_bitmap(text_x + tw + 4, 1); } } } gr_reset_clip(); }
void UI_INPUTBOX::draw() { int invis, w1, h1, tw, th; int text_x, text_y; if (hidden){ return; } w1 = w; h1 = h; invis = flags & UI_INPUTBOX_FLAG_INVIS; font::set_font(my_wnd->f_id); gr_reset_clip(); if (!invis && !(flags & UI_INPUTBOX_FLAG_NO_BACK)) { // draw the entire text box region ui_draw_sunken_border( x-2, y-2, x+w+1, y+h+1 ); gr_set_color_fast( &CBLACK ); gr_rect( 0, 0, w, h, GR_RESIZE_MENU ); w1 -= 4; h1 -= 4; gr_set_clip( x + 1, y + 1, w1 + 1, h1 + 1, GR_RESIZE_MENU ); } else { gr_set_clip( x - 1, y - 1, w1 + 1, h1 + 1, GR_RESIZE_MENU ); } if (flags & UI_INPUTBOX_FLAG_PASSWD){ gr_get_string_size(&tw, &th, passwd_text); } else { gr_get_string_size(&tw, &th, text); } if (!disabled_flag && !(flags & UI_INPUTBOX_FLAG_NO_BACK)) { gr_set_color_fast( &CBLACK ); // color the background behind the text gr_rect( 0, 0, tw + 1, th, GR_RESIZE_MENU_NO_OFFSET ); } if ( (my_wnd->selected_gadget == this) || disabled_flag ) { gr_set_color_fast(text_color); } else { gr_set_color_fast(&CWHITE); } // coords of where to draw the text text_x = 1; text_y = 1; if(flags & UI_INPUTBOX_FLAG_TEXT_CEN){ // if we fit within the text area, draw it centered if(tw <= w1 - 5){ text_x += (w1 - tw)/2; } } // draw the text if (flags & UI_INPUTBOX_FLAG_PASSWD){ gr_string(text_x, text_y, passwd_text, GR_RESIZE_MENU); } else { gr_string(text_x, text_y, text, GR_RESIZE_MENU); } // draw the "cursor" if (!disabled_flag) { if (my_wnd->selected_gadget == this) { if (cursor_first_frame == -1) { gr_set_color_fast(text_color); ui_vline(1, h1, text_x + tw + 4); ui_vline(1, h1, text_x + tw + 5); } else { // draw animating cursor // new method is simpler and should give the same results unless the target device is super slow // i.e. can't render an interface frame in less than the anim frame delays (retail 15 fps == 66.67 msec) cursor_current_frame = bm_get_anim_frame(cursor_first_frame, i2fl(timer_get_milliseconds()) / 1000.0f, 0.0f, true); // draw current frame gr_set_bitmap(cursor_first_frame + cursor_current_frame); gr_bitmap(text_x + tw + 4, 1, GR_RESIZE_MENU_NO_OFFSET); } } } gr_reset_clip(); }