/* * ****************************************************************************** * * Copyright 2015 See AUTHORS file. * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * ***************************************************************************** */ package com.uwsoft.editor.renderer.factory.component; import box2dLight.RayHandler; import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.physics.box2d.World; import com.uwsoft.editor.renderer.components.DimensionsComponent; import com.uwsoft.editor.renderer.components.PolygonComponent; import com.uwsoft.editor.renderer.components.TextureRegionComponent; import com.uwsoft.editor.renderer.data.MainItemVO; import com.uwsoft.editor.renderer.data.ProjectInfoVO; import com.uwsoft.editor.renderer.data.SimpleImageVO; import com.uwsoft.editor.renderer.factory.EntityFactory; import com.uwsoft.editor.renderer.resources.IResourceRetriever; import com.uwsoft.editor.renderer.utils.ComponentRetriever; /** * Created by azakhary on 10/21/2015. */ public class ColorPrimitiveComponentFactory extends ComponentFactory { public ColorPrimitiveComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { super(rayHandler, world, rm); } @Override public void createComponents(Entity root, Entity entity, MainItemVO vo) { createCommonComponents(entity, vo, EntityFactory.COLOR_PRIMITIVE); createParentNodeComponent(root, entity); createNodeComponent(root, entity); createTextureRegionComponent(entity, vo); TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); PolygonComponent polygonComponent = ComponentRetriever.get(entity, PolygonComponent.class); dimensionsComponent.setPolygon(polygonComponent); float ppwu = dimensionsComponent.width/textureRegionComponent.region.getRegionWidth(); textureRegionComponent.setPolygonSprite(polygonComponent, 1f/ppwu); } @Override protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo) { DimensionsComponent component = new DimensionsComponent(); component.setFromShape(vo.shape); entity.add(component); return component; } protected TextureRegionComponent createTextureRegionComponent(Entity entity, MainItemVO vo) { TextureRegionComponent component = new TextureRegionComponent(); Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888); pixmap.setColor(Color.WHITE); pixmap.fill(); Texture texture = new Texture(pixmap); texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest); TextureRegion textureRegion = new TextureRegion(texture); component.region = textureRegion; component.isRepeat = false; component.isPolygon = true; entity.add(component); return component; } }