//------------- Begin of function VgaBuf::bar_alpha --------------// // // Draw a bar with alpha-blendinig // // Syntax : bar( x1, y1, x2, y2, color ) // // <int> x1,y1 - the top left vertex of the bar // <int> x2,y2 - the bottom right vertex of the bar // <int> logAlpha - negative log alpha (right bit shift count, 0 to 5) // <int> color index - the index of a 256 color palette // // logAlpha : 0=transparent ... 5=opaque colorCode // void VgaBuf::bar_alpha(int x1,int y1,int x2,int y2,int logAlpha, int colorCode) { err_when( !buf_locked ); if( logAlpha <= 0 ) { err_when(logAlpha < 0); // if logAlpha == 0, no change } else if( logAlpha < 5 ) { if( is_front ) mouse.hide_area(x1,y1,x2,y2); IMGbarAlpha(cur_buf_ptr, cur_pitch, x1, y1, x2, y2, logAlpha, translate_color(colorCode) ); if( is_front ) mouse.show_area(); } else // logAlpha >= 5, equivalence to VgaBuf::bar { if( is_front ) mouse.hide_area(x1,y1,x2,y2); IMGbar(cur_buf_ptr, cur_pitch, x1, y1, x2, y2, translate_color(colorCode) ); if( is_front ) mouse.show_area(); } }
//------------- Begin of function VgaBuf::bar --------------// // // Draw a bar without bliting // // Syntax : bar( x1, y1, x2, y2, color ) // // <int> x1,y1 - the top left vertex of the bar // <int> x2,y2 - the bottom right vertex of the bar // <int> color index - the index of a 256 color palette // void VgaBuf::bar(int x1,int y1,int x2,int y2,int colorCode) { err_when( !buf_locked ); if( is_front ) mouse.hide_area(x1,y1,x2,y2); IMGbar(cur_buf_ptr, cur_pitch, x1, y1, x2, y2, translate_color(colorCode) ); if( is_front ) mouse.show_area(); }
void GetA::paint(int paintCursor) { err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) ); err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) ); int cursorX = font_ptr->text_width(input_field, cursor_pos); int leftX = font_ptr->text_width(input_field, mark_begin()); int rightX = font_ptr->text_width(input_field, mark_end()); // create a temp buffer to store character int rightLimit = x_limit - x; int textWidth = font_ptr->text_width(input_field, -1, rightLimit ) + 1; int textHeight = font_ptr->max_font_height; char *bitmap = sys.common_data_buf; err_when( 2*sizeof(short) + textWidth * textHeight > COMMON_DATA_BUF_SIZE ); *(short *)bitmap = textWidth; bitmap += sizeof(short); *(short *)bitmap = textHeight; bitmap += sizeof(short); memset( bitmap, TRANSPARENT_CODE, textWidth * textHeight ); if( back_ground_bitmap && !Vga::use_back_buf ) { short backGroundWidth = *(short *)back_ground_bitmap; short backGroundHeight = *(1+(short *)back_ground_bitmap); // fill backGround switch(align_flag) { case 0: IMGbltArea(bitmap, textWidth, 0, 0, back_ground_bitmap, 0, 0, MIN(textWidth, backGroundWidth)-1, MIN(textHeight, backGroundHeight)-1 ); break; case 1: { int l = (x_limit - x + 1 - textWidth ) / 2; if( l >= 0 && l < backGroundWidth ) IMGbltArea(bitmap, textWidth, 0, 0, back_ground_bitmap, l, 0, MIN(l+textWidth, backGroundWidth)-1, MIN(textHeight, backGroundHeight)-1 ); } break; case -1: { int l = x_limit - textWidth + 1 - x; if( l < backGroundWidth ) IMGbltArea(bitmap, textWidth, 0, 0, back_ground_bitmap, l, 0, MIN(x_limit-x+1, backGroundWidth)-1, MIN(textHeight, backGroundHeight)-1 ); } break; default: err_here(); } } font_ptr->put_to_buffer(bitmap, textWidth, 0, 0, input_field); if( paintCursor && enable_flag && cursorX < x_limit ) { // horizontal bar for selected area if( leftX < textWidth ) { IMGbar( bitmap, textWidth, leftX, font_ptr->height()-1, MIN(rightX, textWidth-1), font_ptr->height()-1, 0); } // vertical bar if( cursorX < textWidth ) IMGbar( bitmap, textWidth, cursorX, 0, cursorX, font_ptr->height()-1, 0); } if( !Vga::use_back_buf) { mouse.hide_area(x,y, x_limit, y+font_ptr->max_font_height-1 ); switch( align_flag ) { case 0: // left justified if( !back_ground_bitmap ) { if( x+textWidth <= x_limit ) // fill right vga_util.blt_buf( x+textWidth, y, x_limit, y + font_ptr->max_font_height-1, 0); IMGjoinTrans(vga_front.buf_ptr(), vga_front.buf_pitch(), vga_back.buf_ptr(), vga_back.buf_pitch(), x, y, sys.common_data_buf); } else { short backGroundWidth = *(short *)back_ground_bitmap; short backGroundHeight = *(1+(short *)back_ground_bitmap); if( textWidth < backGroundWidth && x+textWidth <= x_limit ) // fill right vga_front.put_bitmap_area(x, y, back_ground_bitmap, textWidth, 0, MIN(x_limit-x, backGroundWidth-1), backGroundHeight-1 ); vga_front.put_bitmap_trans(x, y, sys.common_data_buf); } break; case 1: // center justified if( !back_ground_bitmap ) { int l = x + (x_limit - x + 1 - textWidth ) / 2; if( x < l ) { vga_util.blt_buf( x, y, l-1, y + font_ptr->max_font_height-1, 0); } if( l+textWidth <= x_limit ) { vga_util.blt_buf( l+textWidth, y, x_limit, y + font_ptr->max_font_height-1, 0); } IMGjoinTrans(vga_front.buf_ptr(), vga_front.buf_pitch(), vga_back.buf_ptr(), vga_back.buf_pitch(), l, y, sys.common_data_buf); } else { int l = x + (x_limit - x + 1 - textWidth ) / 2; short backGroundWidth = *(short *)back_ground_bitmap; short backGroundHeight = *(1+(short *)back_ground_bitmap); if( x < l && l-x <= backGroundWidth) { vga_front.put_bitmap_area(x, y, back_ground_bitmap, 0, 0, MIN(l-x, backGroundWidth)-1, backGroundHeight-1); } if( l+textWidth <= x_limit && l+textWidth-x < backGroundWidth) { vga_front.put_bitmap_area(x, y, back_ground_bitmap, l+textWidth-x, 0, MIN(x_limit-x+1, backGroundWidth)-1, backGroundHeight-1); } vga_front.put_bitmap_trans(l, y, sys.common_data_buf); } break; case -1: // right justified if( !back_ground_bitmap ) { int l = x_limit - textWidth + 1; if( x < l ) // fill left vga_util.blt_buf( x, y, l-1, y + font_ptr->max_font_height-1, 0); IMGjoinTrans(vga_front.buf_ptr(), vga_front.buf_pitch(), vga_back.buf_ptr(), vga_back.buf_pitch(), l, y, sys.common_data_buf); } else { short backGroundWidth = *(short *)back_ground_bitmap; short backGroundHeight = *(1+(short *)back_ground_bitmap); int l = x_limit - textWidth + 1; if( x < l ) vga_front.put_bitmap_area(0, 0, back_ground_bitmap, 0, 0, MIN(l-x, backGroundWidth)-1, backGroundHeight-1 ); vga_front.put_bitmap_trans(l, y, sys.common_data_buf); } break; default: err_here(); } mouse.show_area(); } else { switch( align_flag ) { case 0: // left justified IMGbltTrans( vga_back.buf_ptr(), vga_back.buf_pitch(), x, y, sys.common_data_buf); break; case 1: // center justified { int l = x + (x_limit - x + 1 - textWidth ) / 2; IMGbltTrans( vga_back.buf_ptr(), vga_back.buf_pitch(), l, y, sys.common_data_buf); } // BUGHERE : fill left and right break; case -1: // right justified IMGbltTrans( vga_back.buf_ptr(), vga_back.buf_pitch(), x_limit - textWidth + 1, y, sys.common_data_buf); break; default: err_here(); } } }
void Font::put_paragraph(int x1, int y1, int x2, int y2, const char *textPtr, int lineSpace, int startLine, char dispFlag) { if( !init_flag || y1+font_height-1 > y2 ) return; //--------- define vars ---------------// int x,y,wordX; int newWord; short textChar; const char *wordPtr; char flag_under_line=0; // attribute control flags char flag_hyper_field=0; int under_line_x1; // parameters for drawing under line HyperField* hyper_field_ptr = hyper_field_array; FontInfo* fontInfo; //--------- initialize vars ---------------// x = x1; y = y1; wordX = x1; // the x of the start of the word wordPtr = textPtr; newWord = 0; line_count=0; hyper_field_count = 0; //---------- prepare for display font ----------// if( dispFlag ) { err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT ); if( !Vga::use_back_buf ) // if not say word by word, turn off mouse one time, otherwise turn off mouse one word at a time mouse.hide_area( x1,y1,x2,y2 ); // if the mouse cursor is in that area, hide it } //--------- loop for displaying textPtr ----------// while(1) { //------ space appear, process the previous word ------// if ( newWord ) { if( x-1 > x2 ) // it is still okay if x-1==x2 because x is the next pixel, not the last displayed pixel { if( line_count >= startLine-1 ) // startLine start from 1 { y += font_height + lineSpace; if ( y + font_height - 1 > y2 ) // no further space for printing textPtr, end break; } x = x1; line_count++; } else { x = wordX; } //--------- Process current word ----------// for( ; wordPtr < textPtr && *wordPtr ; wordPtr++, x+=inter_char_space ) // wordPtr point to the current word which will be printed { textChar = *((unsigned char*)wordPtr); // textChar is <unsiged char> //#ifdef GERMAN // textChar = translate_german_char(textChar); //#endif //---------- control char: '_' -------------// if( textChar == '_' ) // e.g. _Title_, a line will be drawn under the word "Title" { if( flag_under_line ) // current '_' is the closing one, the open '_' has appeared previously { if( dispFlag && line_count >= startLine-1 ) // startLine start from 1 IMGbar(Vga::active_buf->buf_ptr(), Vga::active_buf->buf_pitch(), under_line_x1, y+font_height, x, y+font_height, HYPER_FIELD_COLOR ); } else under_line_x1 = x; flag_under_line = !flag_under_line; continue; } //-------- control char: '~' -----------// else if( textChar == '~' ) // e.g. ~Captial~, the word "Capital" is a hyper-textPtred field, pressing on it will link to the topic "Capital" { if( !flag_hyper_field ) // current '~' is the opening one { hyper_field_ptr->x1 = x; hyper_field_ptr->y1 = y; hyper_field_ptr->text_ptr = (wordPtr+1); // skip current '~' } else // current '~' is the closing one { hyper_field_ptr->x2 = x; hyper_field_ptr->y2 = y+font_height; hyper_field_ptr->text_len = wordPtr - hyper_field_ptr->text_ptr; hyper_field_count++; hyper_field_ptr++; err_when( hyper_field_count >= MAX_HYPER_FIELD ); } flag_hyper_field = !flag_hyper_field; continue; } //-------- control char: FIRST_NATION_COLOR_CODE_IN_TEXT -----------// else if( textChar >= FIRST_NATION_COLOR_CODE_IN_TEXT && textChar <= LAST_NATION_COLOR_CODE_IN_TEXT ) // display nation color bar in text { if( x2 >= 0 && x+NATION_COLOR_BAR_WIDTH-1 > x2 ) // exceed right border x2 break; char colorCode = game.color_remap_array[textChar-FIRST_NATION_COLOR_CODE_IN_TEXT].main_color; nation_array.disp_nation_color(x, y+2, colorCode); x += NATION_COLOR_BAR_WIDTH; } //--------------- space character ------------------// else if( textChar == ' ' ) { if( x+space_width > x2 ) break; x += space_width; } //----------- display char ------------// else if( textChar >= first_char && textChar <= last_char ) { fontInfo = font_info_array+textChar-first_char; // character width = offset of next character - current offset if( x2 >= 0 && x+fontInfo->width-1 > x2 ) // exceed right border x2 break; if( fontInfo->width > 0 ) { if( dispFlag && line_count >= startLine-1 ) // startLine start from 1 { // if( flag_hyper_field ) // mainColor = HYPER_FIELD_COLOR; IMGbltTrans( Vga::active_buf->buf_ptr(), Vga::active_buf->buf_pitch(), x, y+fontInfo->offset_y, font_bitmap_buf + fontInfo->bitmap_offset ); } x += fontInfo->width; } } } //--------- next line ----------------------// if( *textPtr == '\n' ) // next line { if( line_count >= startLine-1 ) // startLine start from 1 { y += font_height + lineSpace; if ( y + font_height - 1 > y2 ) // no further space for printing textPtr, end break; } x = x1; textPtr++; line_count++; } if( *textPtr == '\0' ) // all paragraph has been printed break; wordPtr = textPtr; wordX = x; newWord = 0; } //------------ process spacing -------------// if( *textPtr == ' ' || *textPtr == '\n' || *textPtr == '\0' ) // not space newWord = 1; else { textChar = *((unsigned char*)textPtr); // textChar is <unsiged char> //#ifdef GERMAN // textChar = translate_german_char(textChar); //#endif if( textChar >= first_char && textChar <= last_char ) { fontInfo = font_info_array+textChar-first_char; if( textChar >= FIRST_NATION_COLOR_CODE_IN_TEXT && textChar <= LAST_NATION_COLOR_CODE_IN_TEXT ) // display nation color bar in text x += NATION_COLOR_BAR_WIDTH; else if( textChar == ' ' ) x+=space_width; else if( fontInfo->width > 0 ) // current font width x+=fontInfo->width; else x+=space_width; } else { x+=space_width; } x+=inter_char_space; } if( *textPtr && *textPtr != '\n' ) // when finished, remain as NULL for next cycle to detect textPtr++; } //------------ finish displaying ----------------// if( dispFlag ) { if( !Vga::use_back_buf ) mouse.show_area(); } // while( *textPtr == '\n' || *textPtr == '\r' ) // textPtr++; next_text_ptr = textPtr; // the current pointer in the textPtr next_text_y = y + font_height + lineSpace; line_count++; }