KrColorTransform KrScheme::CalcDarkSec() const { KrColorTransform xform = secondary; KrColorTransform dark; dark.Darken( DARK ); xform.Composite( dark ); return xform; }
KrRGBA KrScheme::CalcBrightLine() const { KrRGBA lightGrey = primary; KrColorTransform xform; xform.Brighten( BRIGHT ); xform.ApplyTransform( &lightGrey ); return lightGrey; }
KrRGBA KrScheme::CalcShadowLine() const { KrRGBA darkGrey = primary; KrColorTransform xform; xform.Darken( DARK ); xform.ApplyTransform( &darkGrey ); return darkGrey; }
void EdWidgetTile::Select( bool select ) { KrColorTransform color; if ( select ) { color.Brighten( 200 ); box->SetColor( color ); } else { box->SetColor( color ); } }
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(); }
void BemGame::ProcessRightWindow() { GlFixed scale = engine->Tree()->Root()->XScale( 4 ); const GlFixed step = 0.03; KrColorTransform color; if ( rightDormant ) { --rightDormant; if ( rightDormant == 0 ) rightTarget = 0.3 + random.DRand( 1.2 ); } else { if ( scale < rightTarget ) { color.TintRed( 100 ); scale += step; if ( scale > rightTarget ) scale = rightTarget; } if ( scale > rightTarget ) { color.TintBlue( 100 ); scale -= step; if ( scale < rightTarget ) scale = rightTarget; } if ( scale == rightTarget ) rightDormant = 15; } KrMatrix2 matrix; matrix.Set( ( scale * -actor[0].sprite->X()).ToIntRound() + engine->ScreenBounds( 4 ).Width() / 2, ( scale * (-actor[0].sprite->Y() + 100) ).ToIntRound() + engine->ScreenBounds( 4 ).Height() / 2, scale, scale ); engine->Tree()->Root()->SetTransform( matrix, 4 ); engine->Tree()->Root()->SetColor( color, 4 ); }
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 ); }
void BemGame::MoveParticles() { // const GlFixed g = -0.003; const int alphaDelta = 3; GlFixed half; half.v = GlFixed_1 / 2; // GlFixed oldz; Particle* particle; GlCircleListIterator<Particle> it( particleList ); for( it.Begin(); !it.Done(); it.Next() ) { particle = &it.Current(); particle->x += particle->vx; particle->y += particle->vy; // oldz = particle->z; particle->z += particle->vz; // particle->vz += g; GlFixed mapx = particle->x + half; GlFixed mapy = particle->y + half; int tx = mapx.ToInt(); int ty = mapy.ToInt(); // Check for gizmo hit: if ( GetMap( tx, MAPY - 1 - ty ) == GIZMO ) { engine->Tree()->DeleteNode( particle->sprite ); it.Remove(); it.Prev(); continue; } int sx, sy; isoMath->TileToScreen( particle->x, particle->y, particle->z, &sx, &sy ); particle->sprite->SetPos( sx, sy ); GlFixed x, y, z; isoMath->TileToWorld( particle->x, particle->y, particle->z, &x, &y, &z ); particle->sprite->SetZDepth( -z.v ); KrColorTransform color; color = particle->sprite->CTransform(); // Get rid of off screen: if ( color.Alpha() <= alphaDelta || sx < 0 || sy < 0 || sx > engine->FullScreenBounds().max.x || sy > engine->FullScreenBounds().max.y ) { engine->Tree()->DeleteNode( particle->sprite ); it.Remove(); it.Prev(); continue; } color.SetAlpha( color.Alpha() - alphaDelta ); particle->sprite->SetColor( color ); } }
void BemGame::DrawFrame() { AddText( engine ); int i; // The whole demo works because it takes exactly 12 ticks for a // Drone or Brain to walk one tile. So every 12 subticks // we calculate a new direction for the actor. subtick++; tick++; teleFrame++; if ( subtick == SUBTICK ) { subtick = 0; for ( i=0; i<numActors; i++ ) { ProcessMap( &actor[i] ); } } // calculate the tinting, from map 4.5,4.5 float rad = float( tick ) / 45.0; float fred = fabs( sin( rad*1.5 ) ) * 0.5; float fgreen = fabs( sin( rad*2.5 ) ) * 0.5; float fblue = fabs( sin( rad*3.5 ) ) * 0.5; float falpha = fabs( sin( rad ) ) * 0.3; KrColorTransform gizmoColor; gizmoColor.TintRed( U8( fred * 255.0 )); gizmoColor.TintGreen( U8( fgreen * 255.0 )); gizmoColor.TintBlue( U8( fblue * 255.0 )); gizmoColor.TintAlpha( U8( falpha * 255.0 )); gizmo->SetColor( gizmoColor ); // update all the actors. for( i=0; i<numActors; i++ ) { KrColorTransform actorColor; float d = DistanceFromCenter( &actor[i] ); if ( d < 3.0 ) { float fraction = 1.0 - d / 3.0; actorColor.TintRed( U8( fred * 255.0 * fraction )); actorColor.TintGreen( U8( fgreen * 255.0 * fraction )); actorColor.TintBlue( U8( fblue * 255.0 * fraction )); actorColor.TintAlpha( U8( falpha * 255.0 * fraction )); } actor[i].sprite->SetColor( actorColor ); actor[i].sprite->DoStep(); // In order to sort with the particles, sort with // the world Y. GlFixed wx, wy, wz, tx, ty; isoMath->ScreenToFlatTile( actor[i].sprite->X(), actor[i].sprite->Y(), 0, &tx, &ty ); isoMath->TileToWorld( tx, ty, 0, &wx, &wy, &wz ); actor[i].sprite->SetZDepth( -wy.v ); } // The teleport in and out special effect. Done "by hand" // counting frames with a switch. Looks cool and tests // the visibility stuff. if ( teleFrame > 9 && numActors > 0 ) { KrColorTransform cform; switch ( teleFrame ) { case 10: teleSprite = actor[ random.Rand( numActors ) ].sprite; cform.Brighten( 128 ); break; case 11: cform.Brighten( 200 ); cform.SetAlpha( 220 ); break; case 12: case 13: cform.Brighten( 255 ); cform.SetAlpha( 200 ); break; case 14: { GlFixed x, y; isoMath->ScreenToFlatTile( teleSprite->X(), teleSprite->Y(), 0, &x, &y ); AddParticles( x, y ); teleSprite->SetVisible( false ); } break; case 35: case 36: case 37: case 38: case 39: case 40: teleSprite->SetVisible( true ); cform.TintBlue( 240 - 30 * ( teleFrame - 35 ) ); cform.SetAlpha( 100 + 20 * ( teleFrame - 35 ) ); break; case 41: teleFrame = 0; break; default: break; } teleSprite->SetColor( cform ); } MoveParticles(); // Since the map coordinates only change if the subtick rolled // over, we only change the mini map every 12 frames. if ( subtick == 0 ) DrawMiniMap(); if ( UseWindows() ) ProcessRightWindow(); engine->Draw(); }
KrColorTransform KrScheme::CalcDark() const { KrColorTransform dark; dark.Darken( DARK ); return dark; }
KrColorTransform KrScheme::CalcHiPrimary() const { KrColorTransform light; light.Brighten( BRIGHT ); return light; }
TileTest::TileTest( SDL_Surface* _screen ) { drawn = false; screen = _screen; engine = new KrEngine( screen ); //GLOUTPUT( "TileTest::TileTest\n" ); engine->Validate(); // check validity int i, j; // Classes to hold other objects: engine->Vault()->LoadDatFile( "standardtest.dat" ); KrTileResource* noAlphaRes = engine->Vault()->GetTileResource( "NOALPHA" ); KrTileResource* alphaRes = engine->Vault()->GetTileResource( "ALPHA" ); GLASSERT( noAlphaRes && alphaRes ); // Transforms: KrColorTransform alphaCForm; alphaCForm.SetAlpha( 255 * 70 / 100 ); KrColorTransform redCForm; redCForm.SetRed( 255 * 50 / 100, 127 ); KrColorTransform blueCForm; blueCForm.SetBlue( 255 * 50 / 100, 127 ); KrColorTransform greenAlphaCForm; greenAlphaCForm.SetGreen( 255 * 50 / 100, 127 ); greenAlphaCForm.SetAlpha( 255 * 70 / 100 ); KrColorTransform blueAlphaCForm; blueAlphaCForm.SetBlue( 255 * 50 / 100, 127 ); blueAlphaCForm.SetAlpha( 255 * 70 / 100 ); // Containers: KrImNode* c0 = new KrImNode; // background KrImNode* c1 = new KrImNode; // tiles KrImNode* c2 = new KrImNode; // canvas engine->Tree()->AddNode( 0, c0 ); engine->Tree()->AddNode( c0, c1 ); engine->Tree()->AddNode( c0, c2 ); c1->SetPos( 0, 0 ); c2->SetPos( 420, 0 ); c1->SetZDepth( 1 ); c2->SetZDepth( 1 ); // ---------- Background ----------- // KrSpriteResource* backSpriteRes = engine->Vault()->GetSpriteResource( "BACKGROUND" ); GLASSERT( backSpriteRes ); KrAction* action = backSpriteRes->GetActionByIndex( 0 ); GLASSERT( action ); const KrRle& rle = action->Frame( 0 ); for ( i=0; i <= (screen->w) / rle.Width(); i++ ) { for ( j=0; j <= (screen->h) / rle.Height(); j++ ) { KrSprite* sprite = new KrSprite( backSpriteRes ); sprite->SetPos( i*rle.Width(), j*rle.Height() ); GLASSERT( sprite ); engine->Tree()->AddNode( c0, sprite ); } } // ---------- The "no alpha" tile. // no transform: for ( i=0; i<8; i++ ) { noAlpha[i][0] = new KrTile( noAlphaRes ); noAlpha[i][0]->SetPos( i*noAlpha[i][0]->Size(), 0 ); noAlpha[i][0]->SetRotation( i ); GLASSERT( noAlpha ); engine->Tree()->AddNode( c1, noAlpha[i][0] ); } // alpha: for ( i=0; i<8; i++ ) { noAlpha[i][1] = new KrTile( noAlphaRes ); noAlpha[i][1]->SetColor( alphaCForm ); noAlpha[i][1]->SetPos( i*noAlpha[i][1]->Size(), 1*noAlpha[i][1]->Size() ); noAlpha[i][1]->SetRotation( i ); GLASSERT( noAlpha[i][1] ); engine->Tree()->AddNode( c1, noAlpha[i][1] ); } // red: for ( i=0; i<8; i++ ) { noAlpha[i][2] = new KrTile( noAlphaRes ); noAlpha[i][2]->SetColor( redCForm ); noAlpha[i][2]->SetPos( i*noAlpha[i][2]->Size(), 2*noAlpha[i][2]->Size() ); noAlpha[i][2]->SetRotation( i ); GLASSERT( noAlpha[i][2] ); engine->Tree()->AddNode( c1, noAlpha[i][2] ); } // combination: for ( i=0; i<8; i++ ) { noAlpha[i][3] = new KrTile( noAlphaRes ); noAlpha[i][3]->SetColor( blueAlphaCForm ); noAlpha[i][3]->SetPos( i*noAlpha[i][3]->Size(), 3*noAlpha[i][3]->Size() ); noAlpha[i][3]->SetRotation( i ); GLASSERT( noAlpha ); engine->Tree()->AddNode( c1, noAlpha[i][3] ); } // ---------- The "alpha" tile. // no transform: for ( i=0; i<8; i++ ) { // i=6; alpha[i][0] = new KrTile( alphaRes ); alpha[i][0]->SetPos( i*alpha[i][0]->Size(), 4*alpha[i][0]->Size() ); alpha[i][0]->SetRotation( i ); GLASSERT( alpha[i][0] ); engine->Tree()->AddNode( c1, alpha[i][0] ); } // alpha: for ( i=0; i<8; i++ ) { alpha[i][1] = new KrTile( alphaRes ); alpha[i][1]->SetColor( alphaCForm ); alpha[i][1]->SetPos( i*alpha[i][1]->Size(), 5*alpha[i][1]->Size() ); alpha[i][1]->SetRotation( i ); GLASSERT( alpha[i][1] ); engine->Tree()->AddNode( c1, alpha[i][1] ); } // red: for ( i=0; i<8; i++ ) { alpha[i][2] = new KrTile( alphaRes ); alpha[i][2]->SetColor( redCForm ); alpha[i][2]->SetPos( i*alpha[i][2]->Size(), 6*alpha[i][2]->Size() ); alpha[i][2]->SetRotation( i ); GLASSERT( alpha[i][2] ); engine->Tree()->AddNode( c1, alpha[i][2] ); } // combination: for ( i=0; i<8; i++ ) { alpha[i][3] = new KrTile( alphaRes ); alpha[i][3]->SetColor( blueAlphaCForm ); alpha[i][3]->SetPos( i*alpha[i][3]->Size(), 7*alpha[i][3]->Size() ); alpha[i][3]->SetRotation( i ); GLASSERT( alpha[i][3] ); engine->Tree()->AddNode( c1, alpha[i][3] ); } // ----------- A canvas ----------------- // KrCanvasResource* canvasResource = new KrCanvasResource( "mycanvas", 50, 50, true ); engine->Vault()->AddResource( canvasResource ); KrRGBA* pixels = canvasResource->Pixels(); KrRGBA color; for( i=0; i<canvasResource->Width(); i++ ) { for( j=0; j<canvasResource->Height(); j++ ) { color.c.red = i*4 + 50; color.c.green = j*4 + 50; color.c.blue = 0; color.c.alpha = 255 - i; pixels[ j*canvasResource->Width() + i ] = color; } // Put in a diagonal line: color.Set( 0, 0, 255 ); pixels[ i*canvasResource->Width() + i ] = color; } const int NUMCANVASDIV2 = NUMCANVAS / 2; for ( i=0; i<NUMCANVASDIV2; i++ ) { GlFixed sx; GlFixed sy; // The left canvas: canvas[i*2] = new KrCanvas( canvasResource ); engine->Tree()->AddNode( c2, canvas[i*2] ); canvas[i*2]->SetPos( 0, i * canvas[i*2]->Height() * 3 / 2 ); sx.v = GlFixed_1 * (i+1) / 3; sy.v = GlFixed_1 * (i+1) / 3; canvas[i*2]->SetScale( sx, sy ); // The right canvas: canvas[i*2+1] = new KrCanvas( canvasResource ); engine->Tree()->AddNode( c2, canvas[i*2+1] ); canvas[i*2+1]->SetPos( 100, i * canvas[i*2+1]->Height() * 3 / 2 ); sx.v = GlFixed_1 * (NUMCANVASDIV2 + 1 - i) / 3; sy.v = GlFixed_1 * (i+1) / 3; canvas[i*2+1]->SetScale( sx, sy ); } }