/** * Copyright (C) 2009-2014 Cars and Tracks Development Project (CTDP). * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package net.ctdp.rfdynhud.widgets.standard.tinyposition; import java.awt.Font; import java.io.IOException; import net.ctdp.rfdynhud.gamedata.LiveGameData; import net.ctdp.rfdynhud.gamedata.VehicleScoringInfo; import net.ctdp.rfdynhud.properties.PropertiesContainer; import net.ctdp.rfdynhud.properties.PropertyLoader; import net.ctdp.rfdynhud.render.DrawnString; import net.ctdp.rfdynhud.render.DrawnString.Alignment; import net.ctdp.rfdynhud.render.DrawnStringFactory; import net.ctdp.rfdynhud.render.TextureImage2D; import net.ctdp.rfdynhud.util.PropertyWriter; import net.ctdp.rfdynhud.util.SubTextureCollector; import net.ctdp.rfdynhud.valuemanagers.Clock; import net.ctdp.rfdynhud.values.IntValue; import net.ctdp.rfdynhud.widgets.base.widget.Widget; import net.ctdp.rfdynhud.widgets.standard._util.StandardWidgetSet; /** * The {@link TinyPositionWidget} displays the current driver's position. * * @author Marvin Froehlich (CTDP) */ public class TinyPositionWidget extends Widget { private DrawnString ds = null; private final IntValue v = new IntValue(); public TinyPositionWidget() { super( StandardWidgetSet.INSTANCE, StandardWidgetSet.WIDGET_PACKAGE_EXTRA, 9.3f, 5.1f ); getBorderProperty().setBorder( "" ); getBackgroundProperty().setColorValue( "#00000000" ); getFontProperty().setFont( "DS-DIGITAL", Font.PLAIN, 60, true, true ); getFontColorProperty().setColor( "#BBBBBB" ); } /** * {@inheritDoc} */ @Override public void prepareForMenuItem() { super.prepareForMenuItem(); getFontProperty().setFont( "DS-DIGITAL", Font.PLAIN, 22, false, true ); getFontColorProperty().setColor( "#666666" ); } /** * {@inheritDoc} */ @Override public void saveProperties( PropertyWriter writer ) throws IOException { super.saveProperties( writer ); } /** * {@inheritDoc} */ @Override public void loadProperty( PropertyLoader loader ) { super.loadProperty( loader ); } /** * {@inheritDoc} */ @Override public void getProperties( PropertiesContainer propsCont, boolean forceAll ) { super.getProperties( propsCont, forceAll ); } /** * {@inheritDoc} */ @Override protected void initSubTextures( LiveGameData gameData, boolean isEditorMode, int widgetInnerWidth, int widgetInnerHeight, SubTextureCollector collector ) { } /** * {@inheritDoc} */ @Override protected void initialize( LiveGameData gameData, boolean isEditorMode, DrawnStringFactory dsf, TextureImage2D texture, int width, int height ) { int h = TextureImage2D.getStringHeight( "0/20", getFontProperty() ); ds = dsf.newDrawnString( "ds", width / 2, ( height - h ) / 2, Alignment.CENTER, false, getFont(), isFontAntiAliased(), getFontColor() ); } @Override protected void drawWidget( Clock clock, boolean needsCompleteRedraw, LiveGameData gameData, boolean isEditorMode, TextureImage2D texture, int offsetX, int offsetY, int width, int height ) { VehicleScoringInfo vsi = gameData.getScoringInfo().getViewedVehicleScoringInfo(); int place = vsi.getPlace( getConfiguration().getUseClassScoring() ); int num = getConfiguration().getUseClassScoring() ? gameData.getScoringInfo().getNumVehiclesInSameClass( vsi ) : gameData.getScoringInfo().getNumVehicles(); v.update( ( ( place & 0xFF ) << 16 ) | ( num & 0xFFFF ) ); if ( needsCompleteRedraw || ( clock.c() && v.hasChanged() ) ) { ds.draw( offsetX, offsetY, place + "/" + num, texture ); } } }