void TestBlitter::DrawFrame() { numTest = 0; KrRGBA newColor; KrRGBA baseColor; KrColorTransform cform; newColor.Set( 160, 110, 40, 80 ); baseColor.Set( 20, 80, 200 ); cform.Set( 40, 80, 50, 90, 30, 40, 200 ); SetUp( newColor, baseColor, cform ); char buf[ 256 ]; sprintf( buf, " color surface resulting" ); textBox->SetTextChar( buf, 0 ); int line = 1; for( int i=0; i<numTest; i++ ) { if ( i%3 == 0 ) { // ++line; sprintf( buf, " Optimal %3d %3d %3d", test[i].r.ToIntRoundUp(), test[i].g.ToIntRoundUp(), test[i].b.ToIntRoundUp() ); textBox->SetTextChar( buf, line ); ++line; } bool ok = (( test[i].r.ToIntRoundUp() - test[i].resultColor.c.red ) < 10 ) && (( test[i].g.ToIntRoundUp() - test[i].resultColor.c.green ) < 10 ) && (( test[i].b.ToIntRoundUp() - test[i].resultColor.c.blue ) < 10 ); sprintf( buf, "%20s %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %s", test[i].name.c_str(), test[i].newColor.c.red, test[i].newColor.c.green, test[i].newColor.c.blue, test[i].newColor.c.alpha, test[i].surfaceColor.c.red, test[i].surfaceColor.c.green, test[i].surfaceColor.c.blue, test[i].surfaceColor.c.alpha, test[i].resultColor.c.red, test[i].resultColor.c.green, test[i].resultColor.c.blue, ok ? "[ok]" : "[error]" ); textBox->SetTextChar( buf, line ); ++line; } engine->Draw(); }
Text::Text(const gedString& text, int x, int y, int align, Actor *parent, int red, int green, int blue, const gedString &fontName, int iniASCIIChar, int nChars, bool _bEditable, bool _hasBorder, bool _hasBackGround, bool _getFocus, KrRGBA _borderColor, KrRGBA _cursorColor, KrRGBA _backGroundColor) { this->fontName = fontName; this->iniASCIIChar = iniASCIIChar; this->nChars = nChars; this->text = text; bEditable = _bEditable; bDrawBorder = _hasBorder; bDrawBackground = _hasBackGround; bGetFocus = _getFocus; borderColor = _borderColor; cursorColor = _cursorColor; backGroundColor = _backGroundColor; textBox = NULL; fontResource = GameControl::Get()->GetFont(fontName, iniASCIIChar, nChars); if(fontResource) { const int lineSpacing = 0; int nLines = 1; gedString maxTextWidth; bool bOnlyBlank = true; if(bEditable) { for(int i = 0; i < text.size(); i++) { if(text[i] != '\n') { maxTextWidth += 'O'; } else { maxTextWidth += '\n'; nLines++; } if( text[i] != ' ' && text[i] != '\t' && text[i] != '\r' && text[i] != '\n') { bOnlyBlank = false; } } } else { maxTextWidth = text; for(int i = 0; i < text.size(); i++) { if(text[i] == '\n') { nLines++; } } } int textWidth; if(nLines == 1) { textWidth = fontResource->FontWidth(maxTextWidth.c_str()); } else { int height; GetDimensions(maxTextWidth, textWidth, height, fontName); } switch(align) { case ALIGN_CENTER: align = KrTextBox::CENTER; break; case ALIGN_RIGHT: align = KrTextBox::RIGHT; break; case ALIGN_AUTOMATIC: //Only left (solve the text jump in textJump.ged) //if(nLines == 1) align = KrTextBox::CENTER; /*else*/ align = KrTextBox::LEFT; break; default: align = KrTextBox::LEFT; break; } if(bEditable && !bDrawBackground) { //Draw a invisible background if editable text has no background backGroundColor.all = 0; backGroundColor.c.alpha = 1; } textBox = new KrTextWidget( fontResource, textWidth, nLines*(fontResource->FontHeight() + lineSpacing), lineSpacing, (KrTextBox::Alignment)align, parent, nLines > 1, bEditable, bDrawBorder, bDrawBackground, bGetFocus, borderColor, cursorColor, backGroundColor); KrColorTransform color; // sky change color of text ColorScheme *cs = get_color_scheme(); color.Set(cs->editor_text_r, 0, cs->editor_text_g, 0, cs->editor_text_b, 0, 255); textBox->SetColor(color); if(x == CENTER_TEXT) x = (parent->Width() - textWidth) / 2; if(y == CENTER_TEXT) y = (parent->Height() - fontResource->FontHeight()) / 2; textBox->SetNodeId((int)textBox); engine->Tree()->AddNode( parent?parent->getImage():NULL, textBox ); textBox->SetPos(x, y); if(!bEditable || !bOnlyBlank || (!InGameMode() && !InStandAloneMode())) { SetText(text); //After add tree } fontResource->refCount++; //Call walk here to update the compositeBounds //So, the text will be load by the RegionLoad::DefineActors() //Solve the reload - text bug.ged //Only in game mode (solve the Issue 80) if(parent && GameControl::Get()->getGameMode()) { engine->Tree()->CalculateCompositBounds(parent->getImage()); } } }
void Text::SetColor(int r, int g, int b) { KrColorTransform color; color.Set(r, 0, g, 0, b, 0, 255); if(textBox) textBox->SetColor(color); }
void TestBlitter::SetUp( KrRGBA newColorBase, KrRGBA surfaceColorBase, KrColorTransform cformBase ) { KrRGBA newColor; KrRGBA surfaceColor; KrColorTransform cform; // NoAlpha in source // -- Simple transform cform.Set( 255, 0, 255, 0, 255, 0, 255 ); surfaceColor = surfaceColorBase; newColor = newColorBase; newColor.c.alpha = 255; Run( surfaceColor, newColor, cform, false ); // -- Color transform cform = cformBase; cform.SetAlpha( 255 ); surfaceColor = surfaceColorBase; newColor = newColorBase; newColor.c.alpha = 255; Run( surfaceColor, newColor, cform, false ); // -- Alpha transform cform = cformBase; cform.SetRed( 255, 0 ); cform.SetGreen( 255, 0 ); cform.SetBlue( 255, 0 ); surfaceColor = surfaceColorBase; newColor = newColorBase; newColor.c.alpha = 255; Run( surfaceColor, newColor, cform, false ); // -- Full transform cform = cformBase; surfaceColor = surfaceColorBase; newColor = newColorBase; newColor.c.alpha = 255; Run( surfaceColor, newColor, cform, false ); // Alpha in source // -- Simple transform cform.Set( 255, 0, 255, 0, 255, 0, 255 ); surfaceColor = surfaceColorBase; newColor = newColorBase; Run( surfaceColor, newColor, cform, true ); // -- Color transform cform = cformBase; cform.SetAlpha( 255 ); surfaceColor = surfaceColorBase; newColor = newColorBase; Run( surfaceColor, newColor, cform, true ); // -- Alpha transform cform = cformBase; cform.SetRed( 255, 0 ); cform.SetGreen( 255, 0 ); cform.SetBlue( 255, 0 ); surfaceColor = surfaceColorBase; newColor = newColorBase; Run( surfaceColor, newColor, cform, true ); // -- Full transform cform = cformBase; surfaceColor = surfaceColorBase; newColor = newColorBase; Run( surfaceColor, newColor, cform, true ); }