void kmatrix_phallic () { int sw, sh, aw; char message[80]; if (PhallicMan==-1) strcpy (message,"There was no record set for this level."); else sprintf (message,"%s had the best record at %d points.",Players[PhallicMan].callsign,PhallicLimit); grd_curcanv->cv_font = GAME_FONT; gr_set_fontcolor(gr_find_closest_color(63,63,63),-1); gr_get_string_size(message, &sw, &sh, &aw); gr_string( CENTERSCREEN-(sw/2), FSPACY(55+72+3), message); }
void dc_draw_cursor( SCP_string &cmd_string, int x, int y ) { int t; int w, h; // gr_string width and height t = timer_get_fixed_seconds() / (F1_0/3); if ( t & 1 ) { gr_get_string_size( &w, &h, cmd_string.c_str() ); w %= (DCOLS * col_width); //gr_string( w, debug_y*16, "_" ); gr_rect(gr_screen.center_offset_x + (x + (w + 1)), gr_screen.center_offset_y + (y + (h + 1)), 2, fl2i(font::get_current_font()->getHeight()), GR_RESIZE_NONE); } }
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; font::set_font(font::FONT1); ubyte sc = lcl_get_font_index(font::FONT1); if (sc == 0) { Warning(LOCATION, "1st font doesn't have a special characters index, radar may not work"); } Small_blip_string[0] = sc + 5; 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] = sc + 6; 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 dc_draw(bool show_prompt = FALSE) { gr_clear(); font::set_font(dc_font); gr_set_color_fast( &Color_bright ); int w; gr_get_string_size(&w, nullptr, dc_title.c_str()); gr_string((gr_screen.clip_width - w) / 2, 3, dc_title.c_str(), GR_RESIZE_NONE ); gr_set_color_fast( &Color_normal ); dc_draw_window(show_prompt); 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 HudGaugeFixedMessages::render(float frametime) { HUD_ft *hp; hp = &HUD_fixed_text[0]; if (!timestamp_elapsed(hp->end_time)) { gr_set_color((hp->color >> 16) & 0xff, (hp->color >> 8) & 0xff, hp->color & 0xff); if (center_text) { int w = 0; gr_get_string_size(&w, nullptr, hp->text); renderString(position[0] - (w / 2), position[1], hp->text); } else { renderString(position[0], position[1], hp->text); } //renderString(0x8000, MSG_WINDOW_Y_START + MSG_WINDOW_HEIGHT + 8, hp->text); }
// blit the pilot squadron logo void multi_pinfo_blit_squadron_logo() { char place_text[100]; int w; player *p = Multi_pinfo_popup_player->m_player; // if we don't have a bitmap handle, blit a placeholder if(Mp_squad.bitmap == -1){ gr_set_color_fast(&Color_normal); // if there is no image if(strlen(p->m_squad_filename) <= 0){ strcpy_s(place_text,XSTR("No/Invalid Image", 1053)); } // if the image is xferring else if(multi_xfer_lookup(p->m_squad_filename)){ strcpy_s(place_text,XSTR("Image Transferring", 691)); } // if we're not accepting images else if(!(Net_player->p_info.options.flags & MLO_FLAG_ACCEPT_PIX) || !(Netgame.options.flags & MSO_FLAG_ACCEPT_PIX)){ strcpy_s(place_text,XSTR("No Image", 692)); } // otherwise we wait else { strcpy_s(place_text,XSTR("Waiting", 690)); } // center the text gr_get_string_size(&w, NULL, place_text); gr_string(Multi_pinfo_squad_coords[gr_screen.res][0] + ((Multi_pinfo_squad_coords[gr_screen.res][2] - w)/2), Multi_pinfo_squad_coords[gr_screen.res][1], place_text, GR_RESIZE_MENU); } // otherwise blit the bitmap else { gr_set_bitmap(Mp_squad.bitmap); // gr_bitmap(MPI_SQUAD_X, MPI_SQUAD_Y, GR_RESIZE_MENU); // get width and heigh int bm_w, bm_h; bm_get_info(Mp_squad.bitmap, &bm_w, &bm_h, NULL, NULL, NULL); gr_bitmap(Multi_pinfo_squad_coords[gr_screen.res][0] + ((Multi_pinfo_squad_coords[gr_screen.res][2] - bm_w)/2), Multi_pinfo_squad_coords[gr_screen.res][1] + ((Multi_pinfo_squad_coords[gr_screen.res][3] - bm_h)/2), GR_RESIZE_MENU); // g3_draw_2d_poly_bitmap(Multi_pinfo_squad_coords[gr_screen.res][0], Multi_pinfo_squad_coords[gr_screen.res][1], Multi_pinfo_squad_coords[gr_screen.res][2], Multi_pinfo_squad_coords[gr_screen.res][3]); } }
UI_GADGET_SCROLLBAR * ui_add_gadget_scrollbar( UI_WINDOW * wnd, short x, short y, short w, short h, int start, int stop, int position, int window_size ) { int tw, th, taw; UI_GADGET_SCROLLBAR * scrollbar; char up[2]; char down[2]; up[0] = 30; up[1] = 0; down[0] = 31; down[1] = 0; gr_get_string_size( up, &tw, &th, &taw ); w = tw + 10; if (stop < start ) stop = start; scrollbar = (UI_GADGET_SCROLLBAR *)ui_gadget_add( wnd, 3, x, y+w, x+w-1, y+h-w-1 ); scrollbar->up_button = ui_add_gadget_button( wnd, x, y, w, w, up, NULL ); scrollbar->up_button->parent = (UI_GADGET *)scrollbar; scrollbar->down_button =ui_add_gadget_button( wnd, x, y+h-w, w, w, down, NULL ); scrollbar->down_button->parent = (UI_GADGET *)scrollbar; scrollbar->horz = 0; scrollbar->width = scrollbar->x2-scrollbar->x1+1; scrollbar->height = scrollbar->y2-scrollbar->y1+1; scrollbar->start = start; scrollbar->stop = stop; scrollbar->position = position; scrollbar->window_size = window_size; scrollbar->fake_length = scrollbar->height; scrollbar->fake_position = 0; if (stop!=start) scrollbar->fake_size = (window_size * scrollbar->height)/(stop-start+1+window_size); else scrollbar->fake_size = scrollbar->height; if (scrollbar->fake_size < 7) scrollbar->fake_size = 7; scrollbar->dragging = 0; scrollbar->moved=0; scrollbar->last_scrolled = 0; return scrollbar; }
void editor_sub_status( const char *format, ... ) { int w,h,aw; va_list ap; va_start(ap, format); vsprintf(sub_status_line, format, ap); va_end(ap); gr_set_current_canvas( NULL ); gr_set_curfont(editor_font); gr_set_fontcolor( BM_XRGB(0,0,31), CGREY ); gr_get_string_size( sub_status_line, &w, &h, &aw ); gr_string( 500, 583, sub_status_line ); gr_set_fontcolor( CBLACK, CWHITE ); gr_setcolor( CGREY ); gr_rect( 500+w, 583, 799, 599 ); }
// automatically split up any input text, send it, and leave the remainder void chatbox_autosplit_line() { char *remainder,msg[150]; int msg_pixel_width; // if the chat line is getting too long, fire off the message, putting the last // word on the next input line. memset(msg,0,150); Chat_inputbox.get_text(msg); remainder = ""; // determine if the width of the string in pixels is > than the inputbox width -- if so, // then send the message gr_get_string_size(&msg_pixel_width, NULL, msg); // if ( msg_pixel_width >= (Chatbox_inputbox_w - Player->short_callsign_width) ) { if ( msg_pixel_width >= (Chatbox_inputbox_w - 25)) { remainder = strrchr(msg, ' '); if ( remainder ) { *remainder = '\0'; remainder++; } else { remainder = ""; } // if I'm the server, then broadcast the packet chatbox_recall_add(msg); send_game_chat_packet(Net_player, msg, MULTI_MSG_ALL,NULL); chatbox_add_line(msg, MY_NET_PLAYER_NUM); // display any remainder of text on the next line Chat_inputbox.set_text(remainder); } else if((Chat_inputbox.pressed() && (strlen(msg) > 0)) || (strlen(msg) >= CHATBOX_MAX_LEN)) { // tack on the null terminator in the boundary case int x = strlen(msg); if(x >= CHATBOX_MAX_LEN){ msg[CHATBOX_MAX_LEN-1] = '\0'; } // if I'm the server, then broadcast the packet chatbox_recall_add(msg); send_game_chat_packet(Net_player, msg, MULTI_MSG_ALL,NULL); chatbox_add_line(msg, MY_NET_PLAYER_NUM); // display any remainder of text on the next line Chat_inputbox.set_text(remainder); } }
void scores_rprintf(int x, int y, char * format, ... ) { va_list args; char buffer[128]; int w, h, aw; char *p; va_start(args, format ); vsprintf(buffer,format,args); va_end(args); //replace the digit '1' with special wider 1 for (p=buffer;*p;p++) if (*p=='1') *p=132; gr_get_string_size(buffer, &w, &h, &aw ); gr_string( x-w, y, buffer ); }
void ui_draw_inputbox( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox ) { int w, h, aw; #if 0 //ndef OGL if ((inputbox->status==1) || (inputbox->position != inputbox->oldposition)) #endif { gr_set_current_canvas( inputbox->canvas ); gr_setcolor( CBLACK ); gr_rect( 0, 0, inputbox->width-1, inputbox->height-1 ); gr_get_string_size(inputbox->text, &w, &h, &aw ); if (dlg->keyboard_focus_gadget == (UI_GADGET *)inputbox) { if (inputbox->first_time) { gr_set_fontcolor( CBLACK, -1 ); gr_setcolor( CRED ); gr_rect(2, 2, 2 + w, 2 + h); } else gr_set_fontcolor( CRED, -1 ); } else gr_set_fontcolor( CWHITE, -1 ); inputbox->status = 0; gr_string( 2, 2, inputbox->text ); //gr_setcolor( CBLACK ); //gr_rect( 2+w, 0, inputbox->width-1, inputbox->height-1 ); if (dlg->keyboard_focus_gadget == (UI_GADGET *)inputbox && !inputbox->first_time ) { gr_setcolor(CRED); Vline( 2,inputbox->height-3, 2+w+1 ); Vline( 2,inputbox->height-3, 2+w+2 ); } } }
static void con_draw(void) { int i = 0, y = 0; if (con_size <= 0) return; gr_set_default_canvas(); auto &canvas = *grd_curcanv; auto &game_font = *GAME_FONT; gr_set_curfont(canvas, GAME_FONT); const uint8_t color = BM_XRGB(0, 0, 0); gr_settransblend(canvas, 7, GR_BLEND_NORMAL); const auto &&fspacy1 = FSPACY(1); const auto &&line_spacing = LINE_SPACING(*canvas.cv_font, *GAME_FONT); y = fspacy1 + (line_spacing * con_size); gr_rect(canvas, 0, 0, SWIDTH, y, color); gr_settransblend(canvas, GR_FADE_OFF, GR_BLEND_NORMAL); i+=con_scroll_offset; gr_set_fontcolor(canvas, BM_XRGB(255, 255, 255), -1); y = cli_draw(y, line_spacing); const auto &&fspacx = FSPACX(); const auto &&fspacx1 = fspacx(1); for (;;) { auto &b = con_buffer[CON_LINES_MAX - 1 - i]; gr_set_fontcolor(canvas, get_console_color_by_priority(b.priority), -1); int w,h; gr_get_string_size(game_font, b.line, &w, &h, nullptr); y -= h + fspacy1; gr_string(canvas, game_font, fspacx1, y, b.line, w, h); i++; if (y<=0 || CON_LINES_MAX-1-i <= 0 || i < 0) break; } gr_rect(canvas, 0, 0, SWIDTH, line_spacing, color); gr_set_fontcolor(canvas, BM_XRGB(255, 255, 255),-1); gr_printf(canvas, game_font, fspacx1, fspacy1, "%s LOG", DESCENT_VERSION); gr_string(canvas, game_font, SWIDTH - fspacx(110), fspacy1, "PAGE-UP/DOWN TO SCROLL"); }
// write out the current description in the bottom window void techroom_render_desc(int xo, int yo, int ho) { int y, z, len, font_height; char line[MAX_TEXT_LINE_LEN + 1]; font_height = gr_get_font_height(); y = 0; z = Text_offset; while (y + font_height <= ho) { if (z >= Text_size){ break; } len = Text_line_size[z]; if (len > MAX_TEXT_LINE_LEN){ len = MAX_TEXT_LINE_LEN; } strncpy(line, Text_lines[z], len); line[len] = 0; gr_string(xo, yo + y, line, GR_RESIZE_MENU); y += font_height; z++; } // maybe output 'more' indicator if ( z < Text_size ) { // can be scrolled down int more_txt_x = Tech_desc_coords[gr_screen.res][0] + (Tech_desc_coords[gr_screen.res][2]/2) - 10; // FIXME should move these to constants since they don't move int more_txt_y = Tech_desc_coords[gr_screen.res][1] + Tech_desc_coords[gr_screen.res][3]; // located below brief text, centered int w, h; gr_get_string_size(&w, &h, XSTR("more", 1469), strlen(XSTR("more", 1469))); gr_set_color_fast(&Color_black); gr_rect(more_txt_x-2, more_txt_y, w+3, h, GR_RESIZE_MENU); gr_set_color_fast(&Color_more_indicator); gr_string(more_txt_x, more_txt_y, XSTR("more", 1469), GR_RESIZE_MENU); // base location on the input x and y? } }
//show a message in a nice little box void show_boxed_message(char *msg, int RenderFlag) { int w,h,aw; int x,y; gr_set_current_canvas(NULL); gr_set_curfont( MEDIUM1_FONT ); gr_set_fontcolor(BM_XRGB(31, 31, 31), -1); gr_get_string_size(msg,&w,&h,&aw); x = (SWIDTH-w)/2; y = (SHEIGHT-h)/2; nm_draw_background(x-BORDERX,y-BORDERY,x+w+BORDERX,y+h+BORDERY); gr_printf( 0x8000, y, msg ); // If we haven't drawn behind it, need to flip if (!RenderFlag) gr_flip(); }
// 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); } }
UI_GADGET_LISTBOX * ui_add_gadget_listbox(UI_WINDOW *wnd, short x, short y, short w, short h, short numitems, char **list) { int tw, th, taw, i; UI_GADGET_LISTBOX * listbox; gr_get_string_size("*", &tw, &th, &taw ); i = h / th; h = i * th; listbox = (UI_GADGET_LISTBOX *)ui_gadget_add( wnd, 2, x, y, x+w-1, y+h-1 ); listbox->list = list; listbox->width = w; listbox->height = h; listbox->num_items = numitems; listbox->num_items_displayed = i; listbox->first_item = 0; listbox->current_item = -1; listbox->last_scrolled = 0; listbox->textheight = th; listbox->dragging = 0; listbox->selected_item = -1; listbox->moved = 1; listbox->scrollbar = ui_add_gadget_scrollbar( wnd, x+w+3, y, 0, h, 0, numitems-i, 0, i ); listbox->scrollbar->parent = (UI_GADGET *)listbox; gr_set_current_canvas( listbox->canvas ); gr_setcolor(CBLACK); gr_rect( 0, 0, w-1, h-1); gr_draw_sunken_border( -2, -2, w+listbox->scrollbar->width+4, h+1); return listbox; }
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; } };
void hud_add_msg_to_scrollback(const char *text, int source, int t) { char buf[HUD_MSG_LENGTH_MAX], *ptr, *str; int w, max_width, x, offset = 0; size_t msg_len; max_width = Hud_mission_log_list2_coords[gr_screen.res][2]; msg_len = strlen(text); if (msg_len == 0) return; w = 0; Assert(msg_len < HUD_MSG_LENGTH_MAX); strcpy_s(buf, text); ptr = strstr(buf, NOX(": ")); if (ptr) { gr_get_string_size(&w, NULL, buf, (int)(ptr - buf)); } // if (ptr) { // gr_get_string_size(&w, NULL, buf, ptr - buf + 2); // if (w < max_width - 20) // offset = w; // } x = 0; str = buf; while ((ptr = split_str_once(str, max_width - x)) != NULL) { hud_add_line_to_scrollback(str, source, t, x, 1, w); if ( str == ptr ) break; str = ptr; x = offset; t = w = 0; } hud_add_line_to_scrollback(str, source, t, x, 3, w); }
UI_GADGET_INPUTBOX * ui_add_gadget_inputbox( UI_DIALOG * dlg, short x, short y, short length, short slength, char * text ) { int h, w, aw; UI_GADGET_INPUTBOX * inputbox; gr_get_string_size( NULL, &w, &h, &aw ); inputbox = (UI_GADGET_INPUTBOX *)ui_gadget_add( dlg, 6, x, y, x+aw*slength-1, y+h-1+4 ); inputbox->text = d_malloc(length + 1); strncpy( inputbox->text, text, length ); inputbox->position = strlen(inputbox->text); inputbox->oldposition = inputbox->position; inputbox->width = aw*slength; inputbox->height = h+4; inputbox->length = length; inputbox->slength = slength; inputbox->pressed = 0; inputbox->first_time = 1; return inputbox; }
void scores_rprintf(int x, int y, unsigned char * format, ...) { va_list args; unsigned char buffer[128]; int w, h, aw; unsigned char *p; x *= f2fl(Scale_x); y *= f2fl(Scale_y); va_start(args, format); vsprintf(buffer, format, args); va_end(args); //replace the digit '1' with special wider 1 for (p = buffer; *p; p++) if (*p == '1') *p = 132; gr_get_string_size(buffer, &w, &h, &aw); w *= f2fl(Scale_factor); gr_scale_string(x - w, y, Scale_factor, Scale_factor, buffer); }
void name_frame(automap *am) { char name_level_left[128],name_level_right[128]; int wr,h,aw; if (Current_level_num > 0) sprintf(name_level_left, "%s %i",TXT_LEVEL, Current_level_num); else sprintf(name_level_left, "Secret Level %i",-Current_level_num); if (PLAYING_BUILTIN_MISSION && Current_level_num > 0) sprintf(name_level_right,"%s %d: ",system_name[(Current_level_num-1)/4],((Current_level_num-1)%4)+1); else strcpy(name_level_right, " "); strcat(name_level_right, Current_level_name); gr_set_curfont(GAME_FONT); gr_set_fontcolor(am->green_31,-1); gr_printf((SWIDTH/64),(SHEIGHT/48),"%s", name_level_left); gr_get_string_size(name_level_right,&wr,&h,&aw); gr_printf(grd_curcanv->cv_bitmap.bm_w-wr-(SWIDTH/64),(SHEIGHT/48),"%s", name_level_right); }
void ui_draw_inputbox( UI_GADGET_INPUTBOX * inputbox ) { int w, h, aw; if ((inputbox->status==1) || (inputbox->position != inputbox->oldposition)) { ui_mouse_hide(); gr_set_current_canvas( inputbox->canvas ); if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)inputbox) { if (inputbox->first_time) gr_set_fontcolor( CBLACK, CRED ); else gr_set_fontcolor( CRED, CBLACK ); } else gr_set_fontcolor( CWHITE, CBLACK ); inputbox->status = 0; gr_string( 2, 2, inputbox->text ); gr_get_string_size(inputbox->text, &w, &h, &aw ); gr_setcolor( CBLACK ); gr_rect( 2+w, 0, inputbox->width-1, inputbox->height-1 ); if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)inputbox && !inputbox->first_time ) { gr_setcolor(CRED); Vline( 2,inputbox->height-3, 2+w+1 ); Vline( 2,inputbox->height-3, 2+w+2 ); } ui_mouse_show(); } }
void dc_init(void) { if (debug_inited) { return; } debug_inited = TRUE; // Init window settings dc_font = font::FONT1; row_height = ((fl2i(font::get_current_font()->getHeight())) * 3) / 2; // Row/Line height, in pixels // This assumes that FONT1 is monospaced! gr_get_string_size(&col_width, nullptr, " "); // Col/Character width, in pixels dc_scroll_x = 0; dc_scroll_y = 0; DCOLS = (gr_screen.center_w / col_width) - 1; // Subtract as needed. Windowed mode has some quirks with the resolution DROWS = (gr_screen.center_h / row_height) - 2; DBCOLS = DCOLS; DBROWS = 2 * DROWS; // Init History dc_history.clear(); dc_history.push_back(""); last_oldcommand = dc_history.begin(); // Init buffers dc_buffer.clear(); dc_buffer.push_back(""); dc_command_buf.reserve(MAX_CLI_LEN); dc_command_buf.clear(); sprintf(dc_title, "FreeSpace Open v%i.%i.%i", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD); dc_printf("Debug console started.\n" ); }
void HudGaugeMessages::processMessageBuffer() { int sw, x, offset = 0; size_t i; char *msg; char *split_str, *ptr; for ( i = 0; i < HUD_msg_buffer.size(); i++ ) { msg = new char [HUD_msg_buffer[i].text.size()+1]; strcpy(msg, HUD_msg_buffer[i].text.c_str()); ptr = strstr(msg, NOX(": ")) + 2; if ( ptr ) { gr_get_string_size(&sw, NULL, msg, (int)(ptr - msg)); offset = sw; } x = 0; split_str = msg; while ((ptr = split_str_once(split_str, Max_width - x - 7)) != NULL) { // the 7 is a fudge hack // make sure that split went ok, if not then bail if (ptr == split_str) { break; } addPending(split_str, HUD_msg_buffer[i].source, x); split_str = ptr; x = offset; } addPending(split_str, HUD_msg_buffer[i].source, x); delete[] msg; } }
void HudGaugeThrottle::initMatchSpeedOffsets(int x, int y, bool custom) { Match_speed_offsets[0] = x; Match_speed_offsets[1] = y; Use_custom_match_speed = custom; font::FSFont* fsFont = font::get_font(font_num); if (fsFont->getType() == font::VFNT_FONT) { ubyte sc = lcl_get_font_index(font_num); // NOTE: default to normal m because either // a) the german font has no special m (its an a) // b) the font has no special characters if (sc == 0 || Lcl_gr) { Match_speed_icon = 'm'; } else { Match_speed_icon = sc + 3; } Match_speed_draw_background = false; } else { // Default version for other fonts, draw a black character on a rectangle Match_speed_icon = 'm'; Match_speed_draw_background = true; } SCP_stringstream stream; stream << static_cast<char>(Match_speed_icon); const SCP_string& iconStr = stream.str(); gr_get_string_size(&Match_speed_icon_width, nullptr, iconStr.c_str()); }
// automatically split up any input text, send it, and leave the remainder void chatbox_autosplit_line() { char *remainder,msg[150]; char temp[150]; int msg_pixel_width; int target, target_length = -1; // if the chat line is getting too long, fire off the message, putting the last // word on the next input line. memset(msg,0,150); Chat_inputbox.get_text(msg); remainder = ""; // check if this message is supposed to have a recipient target = chatbox_get_msg_target_type(msg); target_length = chatbox_get_msg_target_length(msg); // determine if the width of the string in pixels is > than the inputbox width -- if so, // then send the message gr_get_string_size(&msg_pixel_width, NULL, msg); // if ( msg_pixel_width >= (Chatbox_inputbox_w - Player->short_callsign_width) ) { if ( msg_pixel_width >= (Chatbox_inputbox_w - 25)) { remainder = strrchr(msg, ' '); if ( remainder ) { *remainder = '\0'; remainder++; } else { remainder = ""; } // if I'm the server, then broadcast the packet chatbox_recall_add(msg); if (target != MULTI_MSG_EXPR) { send_game_chat_packet(Net_player, msg, target); } else { // copy the name of the player the message is being sent to strncpy(temp, msg+1, target_length-2); temp[target_length-2] = '\0'; send_game_chat_packet(Net_player, msg, target, NULL, temp); } chatbox_add_line(msg, MY_NET_PLAYER_NUM); if (target != MULTI_MSG_ALL) { // we need to add the target the message is going to before we add the rest of the string strncpy(temp, msg, target_length); temp[target_length] = ' '; temp[target_length+1] = '\0'; strcat_s(temp, remainder); Chat_inputbox.set_text(temp); } else { // display any remainder of text on the next line Chat_inputbox.set_text(remainder); } } else if((Chat_inputbox.pressed() && (msg[0] != '\0')) || (strlen(msg) >= CHATBOX_MAX_LEN)) { // tack on the null terminator in the boundary case int x = strlen(msg); if(x >= CHATBOX_MAX_LEN){ msg[CHATBOX_MAX_LEN-1] = '\0'; } // if I'm the server, then broadcast the packet chatbox_recall_add(msg); if (target != MULTI_MSG_EXPR) { send_game_chat_packet(Net_player, msg, target); } else { // copy the name of the player the message is being sent to strncpy(temp, msg+1, target_length-2); temp[target_length-2] = '\0'; send_game_chat_packet(Net_player, msg, target, NULL, temp); } chatbox_add_line(msg, MY_NET_PLAYER_NUM); // display any remainder of text on the next line Chat_inputbox.set_text(remainder); } }
void menubar_init( char * file ) { int i,j, np; int aw, w, h; CFILE * infile; char buffer[200]; char buf1[200]; char buf2[200]; int menu, item; num_menus = state = 0; for (i=0; i < MAXMENUS; i++ ) { Menu[i].x = Menu[i].y = Menu[i].w = Menu[i].h = 0; Menu[i].ShowBar = 0; Menu[i].CurrentItem = 0; Menu[i].NumItems = 0; Menu[i].Displayed = 0; Menu[i].Background = 0; for (j=0; j< MAXITEMS; j++ ) { Menu[i].Item[j].x = Menu[i].Item[j].y = Menu[i].Item[j].w = Menu[i].Item[j].h = 0; Menu[i].Item[j].Text = NULL; Menu[i].Item[j].Hotkey = -1; Menu[i].Item[j].user_function = NULL; } } infile = cfopen( file, "rt" ); if (!infile) return; while ( cfgets( buffer, 200, infile) != NULL ) { if ( buffer[0] == ';' ) continue; //mprintf( 0, "%s\n", buffer ); CommaParse( 0, buf1, buffer ); menu = atoi( buf1 ); if (menu >= MAXMENUS) Error("Too many menus (%d).",menu); CommaParse( 1, buf1, buffer ); item = atoi(buf1 ); if (item >= MAXITEMS) Error("Too many items (%d) in menu %d.",item+1,menu); CommaParse( 2, buf1, buffer ); ul_xlate(buf1); if (buf1[0] != '-' ) { sprintf( buf2, " %s ", buf1 ); Menu[menu].Item[item].Text = d_strdup(buf2); } else Menu[menu].Item[item].Text = d_strdup(buf1); Menu[menu].Item[item].InactiveText = d_strdup(Menu[menu].Item[item].Text); j= 0; for (i=0; i<=strlen(Menu[menu].Item[item].Text); i++ ) { np = Menu[menu].Item[item].Text[i]; if (np != CC_UNDERLINE) Menu[menu].Item[item].InactiveText[j++] = np; } CommaParse( 3, buf1, buffer ); if (buf1[0]=='{' && buf1[1] =='}') Menu[menu].Item[item].Hotkey = -1; else { i = DecodeKeyText(buf1); if (i<1) { Error("Unknown key, %s, in %s\n", buf1, file ); } else { Menu[menu].Item[item].Hotkey = i; } } CommaParse( 4, buf1, buffer ); if (strlen(buf1)) { Menu[menu].Item[item].user_function = func_get(buf1, &np); // if (!strcmp(buf1,"do-wall-dialog")) { // mprintf( 0, "Found function %s\n", buf1); // mprintf( 0, "User function %s\n", Menu[menu].Item[item].user_function); // } if (Menu[menu].Item[item].user_function==NULL) { Error( "Unknown function, %s, in %s\n", buf1, file ); //ui_messagebox( -2, -2, 1, buffer, "Ok" ); } } Menu[menu].Item[item].x = Menu[menu].x; Menu[menu].Item[item].y = Menu[menu].y; if ( Menu[menu].Item[item].Text[0] == '-' ) { w = 1; h = 3; } else { gr_get_string_size( Menu[menu].Item[item].Text, &w, &h, &aw ); w += 2; h += 2; } if (menu==0) { Menu[0].h = h; Menu[0].Item[item].x = Menu[0].x + Menu[0].w; Menu[0].Item[item].y = Menu[0].y; Menu[item+1].x = Menu[0].x + Menu[0].w; Menu[item+1].y = Menu[0].h - 2; Menu[0].Item[item].w = w; Menu[0].Item[item].h = h; Menu[0].w += w; }else { if ( w > Menu[menu].w ) { Menu[menu].w = w; for (i=0; i< Menu[menu].NumItems; i++ ) Menu[menu].Item[i].w = Menu[menu].w; } Menu[menu].Item[item].w = Menu[menu].w; Menu[menu].Item[item].x = Menu[menu].x; Menu[menu].Item[item].y = Menu[menu].y+Menu[menu].h; Menu[menu].Item[item].h = h; Menu[menu].h += h; } if ( item >= Menu[menu].NumItems ) { Menu[menu].NumItems = item+1; } if ( menu >= num_menus ) num_menus = menu+1; } Menu[0].w = 700; cfclose( infile ); for (i=0; i<num_menus; i++ ) Menu[i].Background = gr_create_bitmap(Menu[i].w, Menu[i].h ); menubar_hid = 1; }
void credits_do_frame(float frametime) { GR_DEBUG_SCOPE("Credits do frame"); 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, GR_RESIZE_MENU); } 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 >= Credits_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"), next); } 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)){ GR_DEBUG_SCOPE("Render credits bitmap"); 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); auto alpha = (float)percent / 100.0f; gr_set_bitmap(bm1, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f - alpha); gr_bitmap(bx1, by1, GR_RESIZE_MENU); gr_set_bitmap(bm2, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, alpha); gr_bitmap(bx2, by2, GR_RESIZE_MENU); } 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_RESIZE_MENU); font::set_font(font::FONT1); gr_set_color_fast(&Color_normal); int y_offset = 0; for (SCP_vector<SCP_string>::iterator iter = Credit_text_parts.begin(); iter != Credit_text_parts.end(); ++iter) { size_t currentPos = 0; size_t lineEnd; do { int height; int width; lineEnd = iter->find('\n', currentPos); auto length = lineEnd - currentPos; if (lineEnd == SCP_string::npos) { length = std::numeric_limits<size_t>::max(); } gr_get_string_size(&width, &height, iter->c_str() + currentPos, static_cast<int>(length)); // Check if the text part is actually visible if (Credit_position + y_offset + height > 0.0f) { float x = static_cast<float>((gr_screen.clip_width_unscaled - width) / 2); gr_string(x, Credit_position + y_offset, iter->c_str() + currentPos, GR_RESIZE_MENU, static_cast<int>(length)); } y_offset += height; currentPos = lineEnd + 1; } while (lineEnd < iter->length() && lineEnd != SCP_string::npos); } int temp_time; temp_time = timer_get_milliseconds(); Credits_frametime = temp_time - Credits_last_time; Credits_last_time = temp_time; timestamp_inc(i2f(Credits_frametime) / TIMESTAMP_FREQUENCY); 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(); }