void EdStateMovie::StateOpening() { movieNode = new KrImNode(); shared->Engine()->Tree()->AddNode( shared->ImNode(), movieNode ); // Create the action, put it in a sprite resource. KrAction* movieAction = shared->CreateAnimationAction(); if ( movieAction ) { spriteResource = new KrSpriteResource( "AlignerSprite" ); spriteResource->AddAction( movieAction ); numFrames = spriteResource->GetActionByIndex( 0 )->NumFrames(); KrSprite* sprite = new KrSprite( spriteResource ); sprite->SetFrame( 0 ); sprite->SetNodeId( 0 ); KrRect rect = shared->Engine()->ScreenBounds(); sprite->SetPos( rect.Width() / 2, rect.Height() / 2 ); shared->Engine()->Tree()->AddNode( movieNode, sprite ); } shared->ConsoleNode()->SetVisible( false ); shared->SetInfoBox( false ); }
void KrButton::PlaceIcon() { GLASSERT( Engine() ); if ( icon ) { int width = bevel.width - 4; // Give some border space. int height = bevel.height - 4; if ( width > 0 && height > 0 ) { KrRect bounds; icon->QueryBoundingBox( &bounds ); GlFixed wScale = GlFixed( width ) / GlFixed( bounds.Width() ); GlFixed hScale = GlFixed( height ) / GlFixed( bounds.Height() ); GlFixed scale = GlMin( wScale, hScale ); GLASSERT( scale > 0 ); iconX = width - ( scale * bounds.Width() ).ToInt(); iconX = iconX / 2 - ( scale * bounds.xmin ).ToInt() + 1; iconY = height - ( scale * bounds.Height() ).ToInt(); iconY = iconY / 2 - ( scale * bounds.ymin ).ToInt() + 1; icon->SetScale( scale, scale ); icon->SetPos( iconX, iconY ); Engine()->Tree()->AddNode( holder, icon ); icon->SetZDepth( ICON_DEPTH ); } } }
void EdStateMovie::ZoomOut() { GlFixed scale = movieNode->XScale(); if ( scale.v > GlFixed_1 / 4 ) { scale /= 2; movieNode->SetScale( scale, scale ); KrImNode* image = shared->Engine()->Tree()->FindNodeById( 0 ); GLASSERT( image ); KrSprite* sprite = image->ToSprite(); GLASSERT( sprite ); shared->Engine()->Tree()->Walk(); //int x = sprite->CompositeXForm(0).x.ToInt(); //int y = sprite->CompositeXForm(0).y.ToInt(); KrRect screen = shared->Engine()->ScreenBounds(); GlFixed scale = movieNode->XScale(); GlFixed inverse = GlFixed( 1 ) / scale; sprite->SetPos( (inverse * screen.Width()).ToInt() / 2, (inverse*screen.Height()).ToInt()/2 ); } }
void BemGame::AddSpaceTiles() { // This functions adds the background bitmaps. (Pictures // of Space.) The Space picture is a tile that is rotated // for variaton. KrResource* resource = engine->Vault()->GetResource( KYRATAG_TILE, BEM_SPACE ); GLASSERT( resource ); KrTileResource* spaceTileRes = resource->ToTileResource(); GLASSERT( spaceTileRes ); int i, j; KrRect bounds = engine->FullScreenBounds(); for( i=0; i<(bounds.Width() / spaceTileRes->Size() + 1); i++ ) { for( j=0; j<(bounds.Height() / spaceTileRes->Size() + 1); j++ ) { KrTile* spaceTile = new KrTile( spaceTileRes ); GLASSERT( spaceTile ); spaceTile->SetPos( i * spaceTile->Size(), j * spaceTile->Size() ); spaceTile->SetRotation( (i+j) & 7 ); engine->Tree()->AddNode( backgroundTree, spaceTile ); } } }
void ListPop::SetListText(gedString text) { int width = Width() - 20, n; KrRect rect; gedString s(text); rect.Set(0, 0, 0, 0); if(s.length() > 5) { for(n = 1; n <= text.length() && rect.Width() < width; n++) { s = text.substr(0, n); rect = Text::GetDimensions(s); } if(s.length() != text.length() && n > 3) { s = s.substr(0, s.length() - 3) + "..."; SetToolTip(text); } } SetText(s); selectedText = text; }
KrRect Text::GetDimensionsFont(const gedString& text) { KrRect rect; rect.Zero(); GetDimensions(text, rect.xmax, rect.ymax, fontName); return rect; }
void RegionLoad::SetDefaultRegionView() { //Set default region (first region in view) //Must be used when view has a parent InvalidateDefaultRegion(); Actor *view = GameControl::Get()->GetEditView(); if(!view) return; KrRect rectView = view->getImage()->Bounds(); MapRegionsIterator it(regions); RegionLoad *pRegion; for( it.Begin(); !it.Done(); it.Next() ) { pRegion = *it.Key(); if(rectView.Intersect(pRegion->getImage()->Bounds())) { SetDefaultRegion(pRegion); break; } } }
void EdStateMovie::FrameTick() { KrImNode* image = shared->Engine()->Tree()->FindNodeById( 0 ); GLASSERT( image ); KrSprite* sprite = image->ToSprite(); GLASSERT( sprite ); sprite->DoStep(); int x = sprite->CompositeXForm(0).x.ToInt(); int y = sprite->CompositeXForm(0).y.ToInt(); KrRect screen = shared->Engine()->ScreenBounds(); GlFixed scale = movieNode->XScale(); GlFixed inverse = GlFixed( 1 ) / scale; if ( x < 0 ) sprite->SetPos( (inverse * screen.Width()).ToInt(), sprite->Y() ); if ( x > screen.Width() ) sprite->SetPos( 0, sprite->Y() ); if ( y < 0 ) sprite->SetPos( sprite->X(), (inverse*screen.Height()).ToInt() ); if ( y > screen.Height() ) sprite->SetPos( sprite->X(), 0 ); }
int main( int argc, char *argv[] ) { const SDL_version* sdlVersion = SDL_Linked_Version(); if ( sdlVersion->minor < 2 ) { printf( "SDL version must be at least 1.2.0\n" ); GLASSERT( 0 ); exit( 254 ); } if ( argc < 2 ) { printf( "Usage: krmapmaker map.xml\n" ); exit( 253 ); } TiXmlDocument doc( argv[1] ); doc.LoadFile(); XmlUtil xmlUtil( &doc ); if ( !xmlUtil.IsValidMap() ) { printf( "Not a valid map file.\n" ); exit( 252 ); } /* Initialize the SDL library */ if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) < 0 ) { #ifdef DEBUG GLOUTPUT( "Couldn't initialize SDL: %s\n",SDL_GetError()); #endif exit(255); } SDL_WM_SetCaption( "Kyra MapMaker", 0 ); int screenX = 800; int screenY = 600; SDL_Surface* screen = SDL_SetVideoMode( screenX, screenY, 32, SDL_SWSURFACE ); if ( screen ) { KrResourceVault fontVault; //fontVault.LoadDatFileFromMemory( fontDat, sizeof( fontDat ) ); KrFontResource* consoleFontRes = KrEncoder::CreateFixedFontResource( "CONSOLE", CONSOLEFONT_DAT, CONSOLEFONT_SIZE ); Layout layout( screen, consoleFontRes ); if ( layout.Engine()->Vault()->LoadDatFile( xmlUtil.DatFileName().c_str() ) != true ) { printf( "Couldn't load dat file.\n" ); exit( 250 ); } KrSquareWorldMap* worldMap = new KrSquareWorldMap( 100, 100, 100 ); // fixme hardcoded! layout.Engine()->Tree()->AddNode( layout.Map(), worldMap ); worldMap->SetPos( 0, screenY-1, Layout::MAIN_VIEW ); xmlUtil.Init( layout.Engine()->Vault(), layout.Engine(), layout.Map(), worldMap ); // xmlUtil.InsertLayers( layout.LayerBox() ); UILogic logic( &layout, &xmlUtil ); layout.SetLayer( xmlUtil.GetLayer( "null" ), 0 ); KrRGBA white; white.Set( 200, 200, 200 ); KrBox* whereBox = new KrBox( layout.Engine()->ScreenBounds( Layout::MAIN_VIEW ).Width(), layout.Engine()->ScreenBounds( Layout::MAIN_VIEW ).Height(), white, KrBoxResource::OUTLINE ); layout.Engine()->Tree()->AddNode( 0, whereBox ); whereBox->SetVisible( false ); whereBox->SetVisible( true, Layout::MINIMAP_VIEW ); layout.Engine()->Draw(); SDL_Event event; while ( SDL_WaitEvent( &event ) ) { if ( event.type == SDL_QUIT ) break; KrEventManager::Instance()->HandleEvent( event, layout.Engine() ); bool mapChanged = false; if ( ( event.type == SDL_MOUSEMOTION || event.type == SDL_MOUSEBUTTONDOWN ) && layout.Engine()->GetWindowFromPoint( event.motion.x, event.motion.y ) == Layout::MAIN_VIEW ) { KrVector2T< GlFixed > map; worldMap->ScreenToMap( event.motion.x, event.motion.y, &map, Layout::MAIN_VIEW ); layout.DisplayMapCoords( map.x.ToFloat(), map.y.ToFloat() ); if( event.type == SDL_MOUSEBUTTONDOWN || ( event.type == SDL_MOUSEMOTION && event.motion.state == 1 ) ) { if ( logic.CurrentImage() ) { worldMap->SetLoc( map.x.ToInt(), map.y.ToInt(), logic.CurrentImage()->Clone()->ToImage() ); mapChanged = true; } } } else if ( event.type == SDL_KEYDOWN ) { if ( event.key.keysym.sym == SDLK_UP ) { worldMap->SetPos( worldMap->X(), worldMap->Y() + worldMap->TileHeight(), Layout::MAIN_VIEW ); mapChanged = true; } else if ( event.key.keysym.sym == SDLK_DOWN ) { worldMap->SetPos( worldMap->X(), worldMap->Y() - worldMap->TileHeight(), Layout::MAIN_VIEW ); mapChanged = true; } else if ( event.key.keysym.sym == SDLK_RIGHT ) { worldMap->SetPos( worldMap->X() - worldMap->TileWidth(), worldMap->Y(), Layout::MAIN_VIEW ); mapChanged = true; } else if ( event.key.keysym.sym == SDLK_LEFT ) { worldMap->SetPos( worldMap->X() + worldMap->TileWidth(), worldMap->Y(), Layout::MAIN_VIEW ); mapChanged = true; } else if ( event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_7 ) { layout.SetRotation( event.key.keysym.sym - SDLK_0 ); logic.SetRotation( event.key.keysym.sym - SDLK_0 ); } } if ( mapChanged ) { layout.Engine()->Tree()->Walk(); KrRect bounds = worldMap->CompositeBounds( Layout::MAIN_VIEW ); // layout.Map()->SetPos( -bounds.xmin, // - layout.Engine()->ScreenBounds( Layout::MAIN_VIEW ).xmin, // -bounds.ymin, // - layout.Engine()->ScreenBounds( Layout::MAIN_VIEW ).ymin, // Layout::MINIMAP_VIEW ); GlFixed scale = GlMin( GlFixed( layout.Engine()->ScreenBounds( Layout::MINIMAP_VIEW ).Width() ) / GlFixed( bounds.Width() ), GlFixed( layout.Engine()->ScreenBounds( Layout::MINIMAP_VIEW ).Height() ) / GlFixed( bounds.Height() ) ); layout.Map()->SetPos( 0, ( GlFixed( Layout::UI_WIDTH ) / scale ).ToInt(), Layout::MINIMAP_VIEW ); layout.Engine()->Tree()->Root()->SetScale( scale, scale, Layout::MINIMAP_VIEW ); GLOUTPUT( "Minimap scale set to %f\n", scale.ToFloat() ); whereBox->SetPos( -worldMap->X(), bounds.Height() - 1 - worldMap->Y() ); } layout.Engine()->Draw(); } } SDL_Quit(); return 0; }
void RegionLoad::UpdateView() { /* Tests the intersection of all regions with the view (if moved) Call CreateActors of the areas that began to intercept and DestroyActors of the areas that are not more intercepting. */ //The coordinates changes solve the bug in activation-problem_view_parent.ged //(don't load left region) //Make sure view don't will shake KrImage *pImageView = GameControl::Get()->GetViewActor()->getImage(); Axis *pAxis = GameControl::Get()->GetAxis(); if(pImageView->IsInvalid(true)) { //Solve the alpha14.ged bug pImageView->CalcCompositeTransform(); engine->Tree()->Walk(pImageView, true, true); } else { pImageView->CalcTransform(); } //Get view bounds KrRect rectView = pImageView->Bounds(), viewPos; //Get view in screen and axis coordinates KrVector2T< GlFixed > screen, axis; pImageView->ObjectToScreen(0, 0, &screen); pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis ); //Make sure rect is (0, 0, ...) rectView.Translate(-rectView.xmin, -rectView.ymin); //Translate to correct position rectView.Translate(axis.x.ToInt(), axis.y.ToInt()); //Solve the bug: "PocketPC don't load checkers.ged" viewPos.Set(rectView.xmin, rectView.ymin, //zeroViewPos.x.ToInt(), zeroViewPos.y.ToInt(), 0, 0); if(viewPos != viewPosAnt) { MapRegions createdRegions, destroyedRegions; /*#ifdef DEBUG GLOUTPUT( " View pos: (%ld, %ld)\n", rectView.xmin, rectView.ymin); #endif*/ MapRegionsIterator it(regions); RegionLoad *pRegion; for( it.Begin(); !it.Done(); it.Next() ) { pRegion = *it.Key(); pRegion->getImage()->CalcTransform(); KrRect rectRegion = pRegion->getImage()->Bounds(); rectRegion.Translate(-rectRegion.xmin, -rectRegion.ymin); //To axis coordinate pRegion->getImage()->ObjectToScreen(0, 0, &screen); pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis ); rectRegion.Translate(axis.x.ToInt(), axis.y.ToInt()); //View and region in axis coordinates if(rectView.Intersect(rectRegion)) { if(!pRegion->bRegionInView) { createdRegions.Add(pRegion, 1); } } else { if(pRegion->bRegionInView) { destroyedRegions.Add(pRegion, 1); } } } //Destroy actors from regions outside the view //Solve the Move to Region.ged when add the 'sad' actor to two default regions //(some times) MapRegionsIterator it1(destroyedRegions); for(it1.Begin(); !it1.Done(); it1.Next()) { pRegion = *it1.Key(); pRegion->DestroyActors(); if(defaultRegion == pRegion) InvalidateDefaultRegion(); } //Call OnCreate after destroy old actors //Solve the Move to Region 2.ged actor move to a wrong position MapRegionsIterator it2(createdRegions); for(it2.Begin(); !it2.Done(); it2.Next()) { pRegion = *it2.Key(); RegionLoad *pOldDefaultRegion = defaultRegion; SetDefaultRegion(pRegion); pRegion->CreateActors(); RemoveCommonActorsFromOldDefaultRegion(pOldDefaultRegion); } viewPosAnt = viewPos; } }
void RegionLoad::DefineActors() { //Creates a list with actors that intercept the region regionActors.Clear(); KrVector2T< GlFixed > screen, axis; Axis *pAxis = GameControl::Get()->GetAxis(); //Get region bounds (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged) getImage()->CalcTransform(); KrRect rectRegion = getImage()->Bounds(); rectRegion.Translate(-rectRegion.xmin, -rectRegion.ymin); //To axis coordinate (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged) getImage()->ObjectToScreen(0, 0, &screen); pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis ); rectRegion.Translate(axis.x.ToInt(), axis.y.ToInt()); MapActorIterator it(mapActors); for(it.Begin(); !it.Done(); it.Next()) { ListActor *listActor = it.Value(); for(int il = 0; il < listActor->Count(); il++) { Actor *actor = (*listActor)[il]; if( actor->EditMode() && !actor->isRegion() && !actor->isView() && actor != pAxis ) { //Get actor bounds (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged, abuse2.ged) actor->getImage()->CalcCompositeTransform(); KrRect rectActor = actor->Bounds(); if(actor->getTextActor() && !rectActor.IsValid()) { //Solve the bug "Text actors aren't load after use the LoadGame function without Activation Regions" engine->Tree()->Walk(actor->getImage(), true, true); rectActor = actor->Bounds(); } if(actor->getTile() && !rectActor.IsValid()) { //Solve the bug "Text actors aren't load after use the LoadGame function without Activation Regions" engine->Tree()->Walk(actor->getImage(), true, true); rectActor = actor->Bounds(); } rectActor.Translate(-rectActor.xmin, -rectActor.ymin); //To axis coordinate (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged, abuse2.ged) actor->getImage()->ObjectToScreen(0, 0, &screen); pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis ); rectActor.Translate(axis.x.ToInt(), axis.y.ToInt()); if(rectActor.IsValid() && rectRegion.Intersect(rectActor)) { regionActors.Add(actor->getCloneName(), 1); } } } } viewPosAnt.Set(-123, 456, 0, 0); bRegionInView = false; }
void ScalingTest::DrawFrame() { if ( state == BOTH ) { scaleX.v += GlFixed_1 / 64; scaleY.v += GlFixed_1 / 64; if ( scaleX > GlFixed( 1.4 ) ) { scaleX.v = GlFixed_1 / 2; scaleY.v = GlFixed_1 / 2; state = HORIZONTAL; } } else if ( state == HORIZONTAL ) { scaleX.v += GlFixed_1 / 64; if ( scaleX > GlFixed( 1.4 ) ) { scaleX.v = GlFixed_1 / 2; scaleY.v = GlFixed_1 / 2; state = VERTICAL; } } else { scaleY.v += GlFixed_1 / 64; if ( scaleY > GlFixed( 1.4 ) ) { scaleX.v = GlFixed_1 / 8; scaleY.v = GlFixed_1 / 8; state = BOTH; } } ship->SetScale( scaleX, scaleY ); travellingShip->SetPos( travellingShip->X() - 2, travellingShip->Y() ); if ( travellingShip->X() < 0 ) { travellingShip->SetPos( engine->ScreenBounds().Width(), travellingShip->Y() ); } GlFixed tscale; tscale = 1.0 + sin( double( Frame() ) / 25.0 ) / 2.0; travellingShip->SetScale( tscale, tscale ); for( int i=0; i<3; ++i ) { canvas[i]->SetScale( scaleX, scaleY ); } char buffer[ 64 ]; sprintf( buffer, "scale: %.3f X %.3f", scaleX.ToDouble(), scaleY.ToDouble() ); textBox->SetTextChar( buffer, 0 ); textBox->SetTextChar( "Sprite", 1 ); textBox->SetTextChar( "Alpha Blended Canvas: fast -- bi-linear -- adaptive", 2 ); KrRect bounds; KrMatrix2 xForm; xForm.Set( SHIPX, SHIPY, scaleX, scaleY ); ship->SpriteResource()->GetAction( "BODY" )->CalculateBounds( 0, xForm, &bounds ); // Add the background alignment boxes. KrRGBA color;; color.Set( 255, 0, 0, 128 ); KrBoxResource* boxRes = new KrBoxResource( "databox", bounds.Width(), bounds.Height(), &color, 1, KrBoxResource::OUTLINE ); KrBox* box = new KrBox( boxRes ); box->SetPos( bounds.min.x, bounds.min.y ); engine->Tree()->AddNode( 0, box ); engine->Draw(); engine->Tree()->DeleteNode( box ); delete boxRes; }