// Figure out the y-coord to start drawing the popup text. The text // is centered vertically within the popup. int popup_calc_starting_y(popup_info *pi, int flags) { int sy, total_h=0; int num_lines = pi->nlines > Popup_max_display[gr_screen.res] ? Popup_max_display[gr_screen.res] : pi->nlines; if ( flags & (PF_TITLE | PF_TITLE_BIG) ) { if ( flags & PF_TITLE_BIG ) { gr_set_font(FONT2); } else { gr_set_font(FONT1); } total_h += gr_get_font_height(); } if ( flags & PF_BODY_BIG ) { gr_set_font(FONT2); } else { gr_set_font(FONT1); } total_h += num_lines * gr_get_font_height(); sy = fl2i((Popup_text_coords[gr_screen.res][1] + Popup_text_coords[gr_screen.res][3]/2.0f) - total_h/2.0f + 0.5f); // if this is an input style box, add in some y if(flags & PF_INPUT){ sy += Popup_input_text_y_offset[gr_screen.res]; } return sy; }
void red_alert_blit_title() { const char *str = XSTR("Incoming Transmission", 1406); int w, h; // get the string size gr_set_font(Ra_flash_font[gr_screen.res]); gr_get_string_size(&w, &h, str); // set alpha color color flash_color; if(Ra_flash_up){ gr_init_alphacolor(&flash_color, (int)(255.0f * (Ra_flash_time / RA_FLASH_CYCLE)), 0, 0, 255); } else { gr_init_alphacolor(&flash_color, (int)(255.0f * (1.0f - (Ra_flash_time / RA_FLASH_CYCLE))), 0, 0, 255); } // draw gr_set_color_fast(&flash_color); gr_string(Ra_brief_text_wnd_coords[gr_screen.res][0] + ((Ra_brief_text_wnd_coords[gr_screen.res][2] - w) / 2), Ra_flash_y[gr_screen.res] - h - 5, str, GR_RESIZE_MENU); gr_set_color_fast(&Color_normal); // increment flash time Ra_flash_time += flFrametime; if(Ra_flash_time >= RA_FLASH_CYCLE){ Ra_flash_time = 0.0f; Ra_flash_up = !Ra_flash_up; } // back to the original font gr_set_font(FONT1); }
void ScreenRecoveryUI::Init() { gr_init(); gr_set_font("log"); gr_font_size(&log_char_width, &log_char_height); gr_set_font("menu"); gr_font_size(&char_width, &char_height); log_text_rows = gr_fb_height() / log_char_height; log_text_cols = gr_fb_width() / log_char_width; text_col = text_row = 0; text_rows = gr_fb_height() / char_height; if (max_menu_rows > kMaxMenuRows) max_menu_rows = kMaxMenuRows; if (text_rows > kMaxRows) text_rows = kMaxRows; text_top = 1; text_cols = gr_fb_width() / char_width; if (text_cols > kMaxCols - 1) text_cols = kMaxCols - 1; ScreenRecoveryUI::InitIcons(); text_first_row = (header_height / char_height) + 1; menu_item_start = text_first_row * char_height; max_menu_rows = (text_rows - text_first_row) / 3; pthread_create(&progress_t, NULL, progress_thread, NULL); RecoveryUI::Init(); }
void ScreenRecoveryUI::draw_dialog() { int x, y, w, h; if (dialog_icon == HEADLESS) { return; } draw_header_icon(); int iconHeight = gr_get_height(backgroundIcon[dialog_icon]); x = (gr_fb_width()/2 - (char_width*strlen(dialog_text))/2); if (dialog_show_log) { y = gr_get_height(headerIcon) + char_height; } else { y = (gr_fb_height()/2 + iconHeight/2); } SetColor(ERROR_TEXT); gr_text(x, y, dialog_text, 0); y += char_height+2; if (dialog_show_log) { int cx, cy; gr_set_font("log"); gr_font_size(&cx, &cy); int row; for (row = 0; row < log_text_rows; ++row) { gr_text(4, y, text[row], 0); y += cy+2; } gr_set_font("menu"); } if (dialog_icon == ERROR) { /* * This could be improved... * * Draw rect around text "Okay". * Text is centered horizontally. * Bottom of text is 4 lines from bottom of screen. * Rect width 4px * Rect padding 8px */ w = char_width*4; h = char_height; x = gr_fb_width()/2 - w/2; y = gr_fb_height() - h - 4*char_height; SetColor(HEADER); gr_fill(x-(4+8), y-(4+8), x+w+(4+8), y+h+(4+8)); SetColor(MENU_SEL_BG); gr_fill(x-8, y-8, x+w+8, y+h+8); SetColor(MENU_SEL_FG); gr_text(x, y, "Okay", 0); } }
void ScreenRecoveryUI::Init() { gr_init(); gr_set_font("log"); gr_font_size(&log_char_width, &log_char_height); gr_set_font("menu"); gr_font_size(&char_width, &char_height); log_text_rows = gr_fb_height() / log_char_height; log_text_cols = gr_fb_width() / log_char_width; text_col = text_row = 0; text_rows = gr_fb_height() / char_height; if (max_menu_rows > kMaxMenuRows) max_menu_rows = kMaxMenuRows; if (text_rows > kMaxRows) text_rows = kMaxRows; text_top = 1; text_cols = gr_fb_width() / char_width; if (text_cols > kMaxCols - 1) text_cols = kMaxCols - 1; LoadBitmap("icon_header", &headerIcon); header_height = gr_get_height(headerIcon); header_width = gr_get_width(headerIcon); text_first_row = (header_height / char_height) + 1; menu_item_start = text_first_row * char_height; max_menu_rows = (text_rows - text_first_row) / 3; backgroundIcon[NONE] = NULL; LoadBitmapArray("icon_installing", &installing_frames, &installation); backgroundIcon[INSTALLING_UPDATE] = installing_frames ? installation[0] : NULL; backgroundIcon[ERASING] = backgroundIcon[INSTALLING_UPDATE]; LoadBitmap("icon_info", &backgroundIcon[INFO]); LoadBitmap("icon_error", &backgroundIcon[ERROR]); backgroundIcon[NO_COMMAND] = NULL; LoadBitmap("icon_headless", &backgroundIcon[HEADLESS]); LoadBitmap("progress_empty", &progressBarEmpty); LoadBitmap("progress_fill", &progressBarFill); LoadBitmap("stage_empty", &stageMarkerEmpty); LoadBitmap("stage_fill", &stageMarkerFill); LoadLocalizedBitmap("installing_text", &backgroundText[INSTALLING_UPDATE]); LoadLocalizedBitmap("erasing_text", &backgroundText[ERASING]); LoadLocalizedBitmap("no_command_text", &backgroundText[NO_COMMAND]); LoadLocalizedBitmap("error_text", &backgroundText[ERROR]); pthread_create(&progress_t, NULL, progress_thread, NULL); RecoveryUI::Init(); }
// Redraw everything on the screen. Does not flip pages. // Should only be called with updateMutex locked. void ScreenRecoveryUI::draw_screen_locked() { draw_background_locked(currentIcon); if (DialogShowing()) { draw_dialog(); return; } SetColor(MENU); if (show_text) { if (currentIcon != ERASING && currentIcon != INSTALLING_UPDATE) draw_header_icon(); if (currentIcon == ERASING || currentIcon == INSTALLING_UPDATE || currentIcon == VIEWING_LOG) { int y = currentIcon == INSTALLING_UPDATE ? gr_fb_height() / 4 : header_height + 4; SetColor(LOG); int cx, cy; gr_set_font("log"); gr_font_size(&cx, &cy); // display from the bottom up, until we hit the top of the // screen or we've displayed the entire text buffer. int row = (text_first_row+log_text_rows-1) % log_text_rows; for (int ty = gr_fb_height() - cy, count = 0; ty > y+2 && count < log_text_rows; ty -= (cy+2), ++count) { gr_text(4, ty, text[row], 0); --row; if (row < 0) row = log_text_rows-1; } return; } if (show_menu) { gr_set_font("menu"); int nr_items = menu_items - menu_show_start; if (nr_items > max_menu_rows) nr_items = max_menu_rows; for (int i = 0; i < nr_items; ++i) { draw_menu_item(text_first_row + 3*i, menu[menu_show_start+i], ((menu_show_start+i) == menu_sel)); } } } }
void HudGaugeRadar::initialize() { int i; Radar_death_timer = 0; Radar_static_playing = 0; Radar_static_next = 0; Radar_avail_prev_frame = 1; Radar_calc_bright_dist_timer = timestamp(0); for ( i=0; i<NUM_FLICKER_TIMERS; i++ ) { Radar_flicker_timer[i]=timestamp(0); Radar_flicker_on[i]=0; } int w,h; gr_set_font(FONT1); Small_blip_string[0] = ubyte(SMALL_BLIP_CHAR); Small_blip_string[1] = 0; gr_get_string_size( &w, &h, Small_blip_string ); Small_blip_offset_x = -w/2; Small_blip_offset_y = -h/2; Large_blip_string[0] = ubyte(LARGE_BLIP_CHAR); Large_blip_string[1] = 0; gr_get_string_size( &w, &h, Large_blip_string ); Large_blip_offset_x = -w/2; Large_blip_offset_y = -h/2; HudGauge::initialize(); }
// Draw the title centered within the popup void popup_draw_title(int sy, char *line, int flags) { int w, h, sx; if ( flags & PF_TITLE_BIG ) { gr_set_font(FONT2); } else { gr_set_font(FONT1); } gr_get_string_size(&w, &h, line); sx = fl2i(Title_coords[gr_screen.res][4] - w/2.0f + 0.5f); popup_set_title_color(flags); gr_string(sx,sy,line,GR_RESIZE_MENU); }
void pilot_set_short_callsign(player *p, int max_width) { strcpy_s(p->short_callsign, p->callsign); gr_set_font(FONT1); gr_force_fit_string(p->short_callsign, CALLSIGN_LEN - 1, max_width); gr_get_string_size( &(p->short_callsign_width), NULL, p->short_callsign ); }
void gr_string_win(int x, int y, char *s) { int old_bitmap = gr_screen.current_bitmap; gr_set_font(FONT1); gr_string(x,y,s); gr_screen.current_bitmap = old_bitmap; }
void debug_draw() { int i; gr_clear(); gr_set_font(FONT1); gr_set_color_fast( &Color_bright ); gr_string( 0x8000, 3, "Debug Console" ); gr_set_color_fast( &Color_normal ); for (i=0; i<DROWS; i++ ) { gr_string( 0, i*16+16, debug_text[i] ); } int t = timer_get_fixed_seconds() / (F1_0/3); if ( t & 1 ) { int w,h; char c; c = debug_text[debug_y][command_line_pos+1]; debug_text[debug_y][command_line_pos+1] = 0; gr_get_string_size( &w, &h, debug_text[debug_y] ); //gr_string( w, debug_y*16, "_" ); gr_rect(w+1,debug_y*16+1+16,2,14); debug_text[debug_y][command_line_pos+1] = c; } gr_flip(); }
// called once per frame when game state is GS_STATE_RED_ALERT void red_alert_do_frame(float frametime) { int i, k; // ensure that the red alert interface has been initialized if (!Red_alert_inited) { Int3(); return; } // commit if skipping briefing, but not in multi - Goober5000 if (!(Game_mode & GM_MULTIPLAYER)) { if (The_mission.flags & MISSION_FLAG_NO_BRIEFING) { red_alert_button_pressed(RA_CONTINUE); return; } } k = Ui_window.process() & ~KEY_DEBUGGED; switch (k) { case KEY_ESC: // gameseq_post_event(GS_EVENT_ENTER_GAME); gameseq_post_event(GS_EVENT_MAIN_MENU); break; } // end switch for (i=0; i<NUM_BUTTONS; i++){ if (Buttons[gr_screen.res][i].button.pressed()){ red_alert_button_pressed(i); } } GR_MAYBE_CLEAR_RES(Background_bitmap); if (Background_bitmap >= 0) { gr_set_bitmap(Background_bitmap); gr_bitmap(0, 0, GR_RESIZE_MENU); } Ui_window.draw(); // hud_anim_render(&Flash_anim, frametime); gr_set_font(FONT1); if ( timestamp_elapsed(Text_delay) ) { int finished_wipe = 0; if ( Briefing->num_stages > 0 ) { finished_wipe = brief_render_text(0, Ra_brief_text_wnd_coords[gr_screen.res][RA_X_COORD], Ra_brief_text_wnd_coords[gr_screen.res][RA_Y_COORD], Ra_brief_text_wnd_coords[gr_screen.res][RA_H_COORD], frametime, 0); } if (finished_wipe) { red_alert_voice_play(); } } // blit incoming transmission red_alert_blit_title(); gr_flip(); }
// Draw the message text nicely formatted in the popup void popup_draw_msg_text(popup_info *pi, int flags) { int sx, sy, i, w, h; int line_index; int line_count; // figure out the starting display line_index = popup_calc_starting_index(pi); // figure out the starting y: sy = popup_calc_starting_y(pi, flags); // draw title if required if ( flags & (PF_TITLE | PF_TITLE_BIG) ) { popup_draw_title(sy, pi->title, flags); sy += gr_get_font_height(); } // draw body if ( flags & PF_BODY_BIG ) { gr_set_font(FONT2); } else { gr_set_font(FONT1); } popup_set_text_color(flags); line_count = 0; for ( i = line_index; i < pi->nlines; i++, line_count++ ) { // if we've already displayed the max # of lines if(line_count >= Popup_max_display[gr_screen.res]){ break; } gr_get_string_size(&w, &h, pi->msg_lines[i]); sx = fl2i(Title_coords[gr_screen.res][4] - w/2.0f + 0.5f); gr_string(sx, sy + line_count * h, pi->msg_lines[i], GR_RESIZE_MENU); } // maybe draw "more" h = 10; if(i < pi->nlines){ gr_set_color_fast(&Color_more_bright); gr_string(Title_coords[gr_screen.res][4], sy + (Popup_max_display[gr_screen.res]) * h, XSTR("More", 459), GR_RESIZE_MENU); } gr_set_font(FONT1); // reset back to regular font size }
void UI_WINDOW::draw() { UI_GADGET *tmp; gr_reset_clip(); gr_set_font(f_id); if (foreground_bmap_id >= 0) { gr_set_bitmap(foreground_bmap_id); gr_bitmap(x, y); } if (flags & WIN_FILLED) { ui_draw_box_out(x, y, x+w-1, y+h-1); } if (flags & WIN_BORDER) { ui_draw_frame(x-BORDER_WIDTH, y-BORDER_WIDTH, x+w+BORDER_WIDTH-1, y+h+BORDER_WIDTH-1); } if (first_gadget) { tmp = first_gadget; do { if (!tmp->hidden) tmp->draw(); tmp = tmp->next; } while (tmp != first_gadget); } if (first_gadget) { tmp = first_gadget; do { if (!tmp->hidden && (tmp->kind == UI_KIND_BUTTON) && ((UI_BUTTON *) tmp)->button_down()){ tmp->draw(); } tmp = tmp->next; } while (tmp != first_gadget); } // draw all xstrs draw_xstrs(); // draw tooltips draw_tooltip(); // convenient debug code for showing mouse coords if(Cmdline_mouse_coords){ int mx, my; mouse_get_pos(&mx, &my); // mprintf(("MOUSE (%d, %d)\n", mx, my)); gr_set_color_fast(&Color_normal); gr_printf_no_resize(mx, my - 12, "%d %d", mx, my); } }
void HudGaugeRadarStd::drawBlips(int blip_type, int bright, int distort) { blip *b = NULL; blip *blip_head = NULL; int x, y; Assert((blip_type >= 0) && (blip_type < MAX_BLIP_TYPES)); // Need to set font. gr_set_font(FONT1); // get the appropriate blip list if (bright) blip_head = &Blip_bright_list[blip_type]; else blip_head = &Blip_dim_list[blip_type]; // draw all blips of this type for (b = GET_FIRST(blip_head); b != END_OF_LIST(blip_head); b = GET_NEXT(b)) { gr_set_color_fast(b->blip_color); plotBlip(b, &x, &y); // maybe draw cool blip to indicate current target if (b->flags & BLIP_CURRENT_TARGET) { b->rad = Radar_blip_radius_target; current_target_x = x; current_target_y = y; } else { b->rad = Radar_blip_radius_normal; } // maybe distort blip if (distort) { blipDrawDistorted(b, x, y); } else if (b->flags & BLIP_DRAW_DISTORTED) { blipDrawFlicker(b, x, y); } else { if (b->radar_image_2d == -1 && b->radar_color_image_2d == -1) drawContactCircle(x, y, b->rad); else drawContactImage(x, y, b->rad, b->radar_image_2d, b->radar_color_image_2d, b->radar_image_size); } } }
// Draw all the active radar blips void draw_radar_blips_std(int blip_type, int bright, int distort) { blip* b = NULL; blip* blip_head = NULL; Assert((blip_type >= 0) && (blip_type < MAX_BLIP_TYPES)); // Need to set font. gr_set_font(FONT1); // get the appropriate blip list if (bright) blip_head = &Blip_bright_list[blip_type]; else blip_head = &Blip_dim_list[blip_type]; // draw all blips of this type for (b = GET_FIRST(blip_head); b != END_OF_LIST(blip_head); b = GET_NEXT(b)) { gr_set_color_fast(b->blip_color); // maybe draw cool blip to indicate current target if (b->flags & BLIP_CURRENT_TARGET) { b->rad = Current_radar_global->Radar_blip_radius_target[gr_screen.res]; current_target_x = b->x; current_target_y = b->y; } else { b->rad = Current_radar_global->Radar_blip_radius_normal[gr_screen.res]; } // maybe distort blip if (distort) { radar_blip_draw_distorted_std(b); } else if (b->flags & BLIP_DRAW_DISTORTED) { radar_blip_draw_flicker_std(b); } else { if (b->radar_image_2d == -1) radar_draw_circle_std(b->x, b->y, b->rad); else radar_draw_image_std(b->x, b->y, b->rad, b->radar_image_2d, b->radar_image_size); } } }
// ---------------------------------------------------------------------- // hud_init_msg_window() // // Called from HUD_init(), which is called from game_level_init() // void hud_init_msg_window() { int i, h; MSG_WINDOW_WIDTH = gr_screen.clip_width - 20; Hud_list_start = 0; Hud_list_end = 0; for (i=0; i<SCROLL_BUFFER_LINES; i++) HUD_pending[i].text[0] = HUD_pending[i].text[MAX_HUD_LINE_LEN - 1] = 0; for ( i=0; i < MAX_ACTIVE_BUFFER_LINES; i++ ) { HUD_active_msgs_list[i].total_life = 1; } Scroll_time_id = 1; // determine the height of the msg window, which depends on the font height gr_set_font(FONT1); h = gr_get_font_height(); //ACTIVE_BUFFER_LINES = Players[Player_num].HUD_config.num_msg_window_lines; // ACTIVE_BUFFER_LINES = HUD_config.num_msg_window_lines; ACTIVE_BUFFER_LINES = 4; MSG_WINDOW_FONT_HEIGHT = h; MSG_WINDOW_HEIGHT = MSG_WINDOW_FONT_HEIGHT * (ACTIVE_BUFFER_LINES-1); // starting a mission, free the scroll-back buffers, but only if we've been // through this function once already if ( HUD_msg_inited == TRUE ) { hud_free_scrollback_list(); } list_init( &Msg_scrollback_free_list ); list_init( &Msg_scrollback_used_list ); // first slot is reserved for dummy node for (i=1; i < MAX_MSG_SCROLLBACK_LINES; i++) { Msg_scrollback_lines[i].text = NULL; list_append(&Msg_scrollback_free_list, &Msg_scrollback_lines[i]); } Active_index=0; Scroll_needed=0; Scroll_in_progress=0; OLD_ACTIVE_BUFFER_LINES = ACTIVE_BUFFER_LINES; HUD_init_fixed_text(); HUD_msg_inited = TRUE; }
// draw overlay on the screen void help_overlay_blit(int overlay_id, int resolution_index) { int idx, width, height; int plinecount = help_overlaylist[overlay_id].plinecount; int textcount = help_overlaylist[overlay_id].textcount; int rbracketcount = help_overlaylist[overlay_id].rbracketcount; int lbracketcount = help_overlaylist[overlay_id].lbracketcount; Assert(overlay_id >= 0 && overlay_id < MAX_HELP_OVERLAYS); // this draws each line of help text with white on black text (use the first resolution index for the string) gr_set_font(help_overlaylist[overlay_id].fontlist.at(resolution_index)); for (idx = 0; idx < textcount; idx++) { gr_set_color_fast(&Color_black); gr_get_string_size(&width, &height, help_overlaylist[overlay_id].textlist.at(0).at(idx).string, strlen(help_overlaylist[overlay_id].textlist.at(0).at(idx).string)); gr_rect(help_overlaylist[overlay_id].textlist.at(resolution_index).at(idx).x_coord-2*HELP_PADDING, help_overlaylist[overlay_id].textlist.at(resolution_index).at(idx).y_coord-3*HELP_PADDING, width+4*HELP_PADDING, height+4*HELP_PADDING, GR_RESIZE_MENU); gr_set_color_fast(&Color_bright_white); gr_printf_menu(help_overlaylist[overlay_id].textlist.at(resolution_index).at(idx).x_coord, help_overlaylist[overlay_id].textlist.at(resolution_index).at(idx).y_coord, help_overlaylist[overlay_id].textlist.at(0).at(idx).string); } gr_set_font(FONT1); // this draws each right bracket for (idx = 0; idx < rbracketcount; idx++) { gr_set_bitmap(help_right_bracket_bitmap); gr_bitmap(help_overlaylist[overlay_id].rbracketlist.at(resolution_index).at(idx).x_coord, help_overlaylist[overlay_id].rbracketlist.at(resolution_index).at(idx).y_coord, GR_RESIZE_MENU); } // this draws each left bracket for (idx = 0; idx < lbracketcount; idx++) { gr_set_bitmap(help_left_bracket_bitmap); gr_bitmap(help_overlaylist[overlay_id].lbracketlist.at(resolution_index).at(idx).x_coord, help_overlaylist[overlay_id].lbracketlist.at(resolution_index).at(idx).y_coord, GR_RESIZE_MENU); } // this draws each 2d line for the help screen //gr_set_color_fast(&Color_yellow); gr_set_color(255, 255, 0); for (idx = 0; idx<plinecount; idx++) { gr_pline_special(&help_overlaylist[overlay_id].plinelist.at(resolution_index).at(idx).vtx, HELP_PLINE_THICKNESS, GR_RESIZE_MENU); } }
void dc_draw(bool show_prompt = FALSE) { gr_clear(); gr_set_font(dc_font); gr_set_color_fast( &Color_bright ); gr_string( 0x8000, 3, dc_title.c_str(), GR_RESIZE_NONE ); gr_set_color_fast( &Color_normal ); dc_draw_window(show_prompt); gr_flip(); }
static void use_fv_font() { // save old font and set new one if (Fiction_viewer_fontnum >= 0) { Fiction_viewer_old_fontnum = gr_get_current_fontnum(); gr_set_font(Fiction_viewer_fontnum); } else { Fiction_viewer_old_fontnum = -1; } }
void UI_INPUTBOX::create(UI_WINDOW *wnd, int _x, int _y, int _w, int _text_len, char *_text, int _flags, int pixel_lim, color *clr) { int tw, th; Assert(_text_len >= 0); Assert((int) strlen(_text) <= _text_len); gr_set_font(wnd->f_id); gr_get_string_size( &tw, &th, "*" ); // check to see if the user passed in a text color otherwise use the default green color if (clr){ text_color = clr; } else { text_color = &CBRIGHT; } base_create( wnd, UI_KIND_INPUTBOX, _x, _y, _w, th+4 ); text = (char *) vm_malloc( _text_len + 1); // input boxes no longer use background _flags |= UI_INPUTBOX_FLAG_NO_BACK; // if its in "password" mode, allocate a second string // and copy it if (_flags & UI_INPUTBOX_FLAG_PASSWD) { passwd_text = (char *) vm_malloc(_text_len + 1); memset(passwd_text, INPUTBOX_PASSWD_CHAR, strlen(_text)); passwd_text[strlen(_text)] = 0; } else { passwd_text = NULL; } init_cursor(); if ( _text_len > 0 ) { strncpy( text, _text, _text_len ); } text[_text_len] = 0; position = strlen(_text); oldposition = position; length = _text_len; pressed_down = 0; // first_time = 1; changed_flag = 0; flags = _flags; pixel_limit = pixel_lim; locked = 0; valid_chars = NULL; invalid_chars = NULL; }
// Split off the title and break up the body lines void popup_split_lines(popup_info *pi, int flags) { int nlines, i, body_offset = 0; int n_chars[POPUP_MAX_LINES]; const char *p_str[POPUP_MAX_LINES]; gr_set_font(FONT1); n_chars[0]=0; nlines = split_str(pi->raw_text, 1000, n_chars, p_str, POPUP_MAX_LINES); Assert(nlines >= 0 && nlines <= POPUP_MAX_LINES ); if ( flags & (PF_TITLE | PF_TITLE_BIG) ) { // get first line out strncpy(pi->title, p_str[0], n_chars[0]); pi->title[n_chars[0]] = 0; body_offset = 1; } if ( flags & PF_BODY_BIG ) { gr_set_font(FONT2); } nlines = split_str(pi->raw_text, Popup_text_coords[gr_screen.res][2], n_chars, p_str, POPUP_MAX_LINES); Assert(nlines >= 0 && nlines <= POPUP_MAX_LINES ); pi->nlines = nlines - body_offset; for ( i = 0; i < pi->nlines; i++ ) { Assert(n_chars[i+body_offset] < POPUP_MAX_LINE_CHARS); strncpy(pi->msg_lines[i], p_str[i+body_offset], n_chars[i+body_offset]); pi->msg_lines[i][n_chars[i+body_offset]] = 0; } gr_set_font(FONT1); }
void UI_ICON::draw() { if (uses_bmaps) { gr_reset_clip(); if (disabled_flag) { if (bmap_ids[ICON_DISABLED] != -1) { gr_set_bitmap(bmap_ids[ICON_DISABLED]); gr_bitmap(x,y); } } else if (this->is_mouse_on()) { if (B1_PRESSED) { if (bmap_ids[ICON_SELECTED] != -1) { gr_set_bitmap(bmap_ids[ICON_SELECTED]); gr_bitmap(x, y); } } else { if (bmap_ids[ICON_HIGHLIGHT] != -1) { gr_set_bitmap(bmap_ids[ICON_HIGHLIGHT]); gr_bitmap(x, y); } } } else { if (bmap_ids[ICON_NORMAL] != -1) { gr_set_bitmap(bmap_ids[ICON_NORMAL]); gr_bitmap(x, y); } } } else { gr_set_font(my_wnd->f_id); gr_set_clip(x, y, w, h); ui_draw_box_out(0, 0, w-1, h-1); if (disabled_flag) gr_set_color_fast(&CDARK_GRAY); else gr_set_color_fast(&CBLACK); if (text) ui_string_centered(Middle(w), Middle(h), text); gr_reset_clip(); } }
void radar_frame_init() { radar_null_nblips(); radx = i2fl(Radar_radius[gr_screen.res][0])/2.0f; rady = i2fl(Radar_radius[gr_screen.res][1])/2.0f; int w,h; gr_set_font(FONT1); Small_blip_string[0] = ubyte(SMALL_BLIP_CHAR); Small_blip_string[1] = 0; gr_get_string_size( &w, &h, Small_blip_string ); Small_blip_offset_x = -w/2; Small_blip_offset_y = -h/2; Large_blip_string[0] = ubyte(LARGE_BLIP_CHAR); Large_blip_string[1] = 0; gr_get_string_size( &w, &h, Large_blip_string ); Large_blip_offset_x = -w/2; Large_blip_offset_y = -h/2; }
// Draw all the active radar blips void draw_radar_blips(int rcol, int is_dim, int distort) { blip *b=NULL; blip *blip_head=NULL; // Need to set font. gr_set_font(FONT1); if ( is_dim ) { blip_head = &Blip_dim_list[rcol]; } else { blip_head = &Blip_bright_list[rcol]; } for ( b = GET_FIRST(blip_head); b !=END_OF_LIST(blip_head); b = GET_NEXT(b) ) { Assert((rcol >= 0) && (rcol < MAX_RADAR_COLORS)); if ( is_dim ) { gr_set_color_fast( &Radar_colors[RADAR_BLIP_DIM][rcol] ); } else { gr_set_color_fast( &Radar_colors[RADAR_BLIP_BRIGHT][rcol] ); } if (b->flags & BLIP_CURRENT_TARGET) { // draw cool blip to indicate current target b->rad = Radar_blip_radius_target[gr_screen.res]; } else { b->rad = Radar_blip_radius_normal[gr_screen.res]; } if ( distort ) { radar_blip_draw_distorted(b); } else if ( b->flags & BLIP_DRAW_DISTORTED ) { radar_blip_draw_flicker(b); } else{ radar_draw_circle( b->x, b->y, b->rad ); } } }
void UI_LISTBOX::create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, int _numitems, char **_list, char *_check_list, int _max_items) { int tw, th, nrows; int real_h; gr_set_font(wnd->f_id); gr_get_string_size(&tw, &th, "*"); nrows = _h / th; real_h = nrows * th; base_create( wnd, UI_KIND_LISTBOX, _x, _y, _w, real_h ); max_items = _max_items; list = _list; num_items = _numitems; check_list = _check_list; num_items_displayed = nrows; first_item = 0; current_item = -1; toggled_item = -1; last_scrolled = 0; textheight = th; dragging = 0; selected_item = -1; key_buffer_count = 0; last_typed = timer_get_milliseconds(); if (_numitems > nrows) { scrollbar.create( wnd, _x+_w+3, _y, real_h, 0, _numitems-nrows, 0, nrows ); scrollbar.set_parent(this); has_scrollbar = 1; } else { has_scrollbar = 0; } };
// Render button. How it draws exactly depends on it's current state. void UI_BUTTON::draw() { int offset, frame_num = -1; if (uses_bmaps) { gr_reset_clip(); // if button is down, draw it that way if (button_down()) { if (bmap_ids[B_PRESSED] >= 0){ frame_num = B_PRESSED; } // otherwise if button is disabled, draw it that way } else if (disabled_flag) { if (bmap_ids[B_DISABLED] >= 0){ frame_num = B_DISABLED; } // otherwise, if button is highlighted (mouse is over it, but mouse buttons not down) draw it that way } else if (m_flags & BF_HIGHLIGHTED) { if (bmap_ids[B_HIGHLIGHT] >= 0){ frame_num = B_HIGHLIGHT; } // otherwise, just draw it normally } else { if (bmap_ids[B_NORMAL] >= 0){ frame_num = B_NORMAL; } } if (frame_num >= 0) { gr_set_bitmap(bmap_ids[frame_num]); gr_bitmap(x, y); } } else { gr_set_font(my_wnd->f_id); gr_set_clip( x, y, w, h ); // draw the button's box if (button_down()) { ui_draw_box_in( 0, 0, w-1, h-1 ); offset = 1; } else { ui_draw_box_out( 0, 0, w-1, h-1 ); offset = 0; } // now draw the button's text if (disabled_flag){ gr_set_color_fast(&CDARK_GRAY); } else if (my_wnd->selected_gadget == this){ gr_set_color_fast(&CBRIGHT_GREEN); } else { gr_set_color_fast(&CBLACK); } if (text){ ui_string_centered( Middle(w) + offset, Middle(h) + offset, text ); } 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, 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(); }
// Draw all the active radar blips void HudGaugeRadarDradis::drawBlips(int blip_type, int bright, int distort) { blip *b = NULL; blip *blip_head; vec3d pos; float alpha; Assert((blip_type >= 0) && (blip_type < MAX_BLIP_TYPES)); //long frametime = timer_get_approx_seconds(); // Need to set font. gr_set_font(FONT1); if(bright) { blip_head = &Blip_bright_list[blip_type]; } else { blip_head = &Blip_dim_list[blip_type]; } float scale_factor = 1.0f; // draw all blips of this type for (b = GET_FIRST(blip_head); b != END_OF_LIST(blip_head); b = GET_NEXT(b)) { plotBlip(b, &pos, &alpha); gr_set_color_fast(b->blip_color); scale_factor = 1.0f; // maybe draw cool blip to indicate current target if (b->flags & BLIP_CURRENT_TARGET) { if (radar_target_id_flags & RTIF_PULSATE) { scale_factor *= 1.3f + (sinf(10 * f2fl(Missiontime)) * 0.3f); } if (radar_target_id_flags & RTIF_BLINK) { if (Missiontime & 8192) continue; } if (radar_target_id_flags & RTIF_ENLARGE) { scale_factor *= 1.3f; } alpha = 1.0; b->rad = Radar_blip_radius_target; drawContact(&pos, -1, target_brackets, b->dist, alpha, scale_factor); } else { b->rad = Radar_blip_radius_normal; } // maybe distort blip if (distort) { blipDrawDistorted(b, &pos, alpha); } else { if (b->flags & BLIP_DRAW_DISTORTED) { blipDrawFlicker(b, &pos, alpha); } else if (b->radar_image_2d >= 0 || b->radar_color_image_2d >= 0) { drawContact(&pos, b->radar_image_2d, b->radar_color_image_2d, b->dist, alpha, scale_factor); } else { drawContact(&pos, -1, unknown_contact_icon, b->dist, alpha, scale_factor); } } } }
void credits_do_frame(float frametime) { int i, k, next, percent, bm1, bm2; int bx1, by1, bw1, bh1; int bx2, by2, bw2, bh2; // Use this id to trigger the start of music playing on the credits screen if ( timestamp_elapsed(Credits_music_begin_timestamp) ) { Credits_music_begin_timestamp = 0; credits_start_music(); } k = Ui_window.process(); switch (k) { case KEY_ESC: gameseq_post_event(GS_EVENT_MAIN_MENU); key_flush(); break; case KEY_CTRLED | KEY_UP: case KEY_SHIFTED | KEY_TAB: if ( !(Player->flags & PLAYER_FLAGS_IS_MULTI) ) { credits_screen_button_pressed(CUTSCENES_BUTTON); break; } // else, react like tab key. case KEY_CTRLED | KEY_DOWN: case KEY_TAB: credits_screen_button_pressed(TECH_DATABASE_BUTTON); break; default: break; } // end switch for (i=0; i<NUM_BUTTONS; i++){ if (Buttons[i][gr_screen.res].button.pressed()){ if (credits_screen_button_pressed(i)){ return; } } } gr_reset_clip(); GR_MAYBE_CLEAR_RES(Background_bitmap); if (Background_bitmap >= 0) { gr_set_bitmap(Background_bitmap); gr_bitmap(0, 0); } percent = (int) (100.0f - (CREDITS_ARTWORK_DISPLAY_TIME - Credits_counter) * 100.0f / CREDITS_ARTWORK_FADE_TIME); if (percent < 0){ percent = 0; } next = Credits_artwork_index + 1; if (next >= NUM_IMAGES){ next = 0; } if (Credits_bmps[Credits_artwork_index] < 0) { char buf[40]; if (gr_screen.res == GR_1024) { sprintf(buf, NOX("2_CrIm%.2d"), Credits_artwork_index); } else { sprintf(buf, NOX("CrIm%.2d"), Credits_artwork_index); } Credits_bmps[Credits_artwork_index] = bm_load(buf); } if (Credits_bmps[next] < 0) { char buf[40]; if (gr_screen.res == GR_1024) { sprintf(buf, NOX("2_CrIm%.2d"), Credits_artwork_index); } else { sprintf(buf, NOX("CrIm%.2d"), next); } Credits_bmps[next] = bm_load(buf); } bm1 = Credits_bmps[Credits_artwork_index]; bm2 = Credits_bmps[next]; if((bm1 != -1) && (bm2 != -1)){ Assert(percent >= 0 && percent <= 100); // get width and height bm_get_info(bm1, &bw1, &bh1, NULL, NULL, NULL); bm_get_info(bm2, &bw2, &bh2, NULL, NULL, NULL); // determine where to draw the coords bx1 = Credits_image_coords[gr_screen.res][CREDITS_X_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_W_COORD] - bw1)/2); by1 = Credits_image_coords[gr_screen.res][CREDITS_Y_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_H_COORD] - bh1)/2); bx2 = Credits_image_coords[gr_screen.res][CREDITS_X_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_W_COORD] - bw2)/2); by2 = Credits_image_coords[gr_screen.res][CREDITS_Y_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_H_COORD] - bh2)/2); gr_cross_fade(bm1, bm2, bx1, by1, bx2, by2, (float)percent / 100.0f); } /* if (CreditsWin01 != -1) { gr_set_bitmap(CreditsWin01); gr_bitmap(233, 5); } if (CreditsWin02 != -1) { gr_set_bitmap(CreditsWin02); gr_bitmap(616, 8); } if (CreditsWin03 != -1) { gr_set_bitmap(CreditsWin03); gr_bitmap(233, 299); } if (CreditsWin04 != -1) { gr_set_bitmap(CreditsWin04); gr_bitmap(215, 8); } */ Ui_window.draw(); for (i=TECH_DATABASE_BUTTON; i<=CREDITS_BUTTON; i++){ if (Buttons[i][gr_screen.res].button.button_down()){ break; } } if (i > CREDITS_BUTTON){ Buttons[CREDITS_BUTTON][gr_screen.res].button.draw_forced(2); } gr_set_clip(Credits_text_coords[gr_screen.res][CREDITS_X_COORD], Credits_text_coords[gr_screen.res][CREDITS_Y_COORD], Credits_text_coords[gr_screen.res][CREDITS_W_COORD], Credits_text_coords[gr_screen.res][CREDITS_H_COORD]); gr_set_font(FONT1); gr_set_color_fast(&Color_normal); int sy; if ( Credit_position > 0 ) { sy = fl2i(Credit_position+0.5f); } else { sy = fl2i(Credit_position-0.5f); } gr_string(0x8000, sy, Credit_text); int temp_time; temp_time = timer_get_milliseconds(); Credits_frametime = temp_time - Credits_last_time; Credits_last_time = temp_time; timestamp_inc(Credits_frametime / 1000.0f); float fl_frametime = i2fl(Credits_frametime) / 1000.f; if (keyd_pressed[KEY_LSHIFT]) { Credit_position -= fl_frametime * CREDITS_SCROLL_RATE * 4.0f; } else { Credit_position -= fl_frametime * CREDITS_SCROLL_RATE; } if (Credit_position < Credit_stop_pos){ Credit_position = Credit_start_pos; } Credits_counter += fl_frametime; while (Credits_counter >= CREDITS_ARTWORK_DISPLAY_TIME) { Credits_counter -= CREDITS_ARTWORK_DISPLAY_TIME; Credits_artwork_index = next; } gr_flip(); }