Make bottom right text group same location as normal chat group, reduce code duplication.

This commit is contained in:
UnknownShadow200 2016-06-20 20:21:07 +10:00
parent f533e99418
commit 11f2695771
4 changed files with 25 additions and 42 deletions

View File

@ -58,7 +58,7 @@ namespace ClassicalSharp.Gui {
status.SetUsePlaceHolder( 1, false );
bottomRight = new TextGroupWidget( game, 3, chatFont, chatUrlFont,
Anchor.BottomOrRight, Anchor.BottomOrRight );
bottomRight.YOffset = blockSize * 3 / 2;
bottomRight.YOffset = blockSize + 15;
bottomRight.Init();
normalChat = new TextGroupWidget( game, chatLines, chatFont, chatUrlFont,
Anchor.LeftOrTop, Anchor.BottomOrRight );

View File

@ -134,9 +134,9 @@ namespace ClassicalSharp.Gui {
void DrawPosition() {
int index = 0;
TextureRec xy = new TextureRec( 2, posTex.Y1, baseWidth, posTex.Height );
TextureRec uv = new TextureRec( 0, posTex.V1, posTex.U2, posTex.V2 );
IGraphicsApi.Make2DQuad( xy, uv, game.ModelCache.vertices, ref index );
Texture tex = posTex;
tex.X1 = 2; tex.Width = baseWidth;
IGraphicsApi.Make2DQuad( ref tex, FastColour.White, game.ModelCache.vertices, ref index );
Vector3I pos = Vector3I.Floor( game.LocalPlayer.Position );
curX = baseWidth + 2;
@ -214,12 +214,12 @@ namespace ClassicalSharp.Gui {
void AddChar( int charIndex, ref int index ) {
int width = widths[charIndex];
TextureRec xy = new TextureRec( curX, posTex.Y1, width, posTex.Height );
TextureRec uv = new TextureRec( (baseWidth + charIndex * 16) / texWidth,
posTex.V1, width / texWidth, posTex.V2 );
Texture tex = posTex;
tex.X1 = curX; tex.Width = width;
tex.U1 = (baseWidth + charIndex * 16) / texWidth;
tex.U2 = tex.U1 + width / texWidth;
curX += width;
IGraphicsApi.Make2DQuad( xy, uv, game.ModelCache.vertices, ref index );
IGraphicsApi.Make2DQuad( ref tex, FastColour.White, game.ModelCache.vertices, ref index );
}
void AddInt( int value, ref int index, bool more ) {

View File

@ -46,24 +46,14 @@ namespace ClassicalSharp.Gui {
int texLoc = game.BlockInfo.GetTextureLoc( Block.Dirt, Side.Top );
TerrainAtlas1D atlas = game.TerrainAtlas1D;
TextureRec tex = atlas.GetTexRec( texLoc, 1, out atlasIndex );
Texture tex = new Texture( 0, 0, 0, game.Width, 64,
atlas.GetTexRec( texLoc, 1, out atlasIndex ) );
tex.U2 = (float)game.Width / 64;
bool bound = false;
while( drawnY < height ) {
float x1 = 0, x2 = game.Width;
float y1 = drawnY, y2 = drawnY + 64;
#if USE_DX
// NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx",
// i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this.
x1 -= 0.5f; x2 -= 0.5f;
y1 -= 0.5f; y2 -= 0.5f;
#endif
vertices[index++] = new VertexP3fT2fC4b( x1, y1, 0, tex.U1, tex.V1, col );
vertices[index++] = new VertexP3fT2fC4b( x2, y1, 0, tex.U2, tex.V1, col );
vertices[index++] = new VertexP3fT2fC4b( x2, y2, 0, tex.U2, tex.V2, col );
vertices[index++] = new VertexP3fT2fC4b( x1, y2, 0, tex.U1, tex.V2, col );
tex.Y1 = drawnY;
IGraphicsApi.Make2DQuad( ref tex, col, vertices, ref index );
if( index >= vertices.Length )
DrawBackgroundVertices( ref index, atlasIndex, ref bound );
drawnY += 64;

View File

@ -276,6 +276,14 @@ namespace ClassicalSharp.GraphicsAPI {
internal VertexP3fT2fC4b[] texVerts = new VertexP3fT2fC4b[4];
internal int texVb;
public virtual void Draw2DTexture( ref Texture tex, FastColour col ) {
int index = 0;
Make2DQuad( ref tex, col, texVerts, ref index );
SetBatchFormat( VertexFormat.P3fT2fC4b );
UpdateDynamicIndexedVb( DrawMode.Triangles, texVb, texVerts, 4, 6 );
}
public static void Make2DQuad( ref Texture tex, FastColour col,
VertexP3fT2fC4b[] vertices, ref int index ) {
float x1 = tex.X1, y1 = tex.Y1, x2 = tex.X2, y2 = tex.Y2;
#if USE_DX
// NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx",
@ -283,25 +291,10 @@ namespace ClassicalSharp.GraphicsAPI {
x1 -= 0.5f; x2 -= 0.5f;
y1 -= 0.5f; y2 -= 0.5f;
#endif
texVerts[0] = new VertexP3fT2fC4b( x1, y1, 0, tex.U1, tex.V1, col );
texVerts[1] = new VertexP3fT2fC4b( x2, y1, 0, tex.U2, tex.V1, col );
texVerts[2] = new VertexP3fT2fC4b( x2, y2, 0, tex.U2, tex.V2, col );
texVerts[3] = new VertexP3fT2fC4b( x1, y2, 0, tex.U1, tex.V2, col );
SetBatchFormat( VertexFormat.P3fT2fC4b );
UpdateDynamicIndexedVb( DrawMode.Triangles, texVb, texVerts, 4, 6 );
}
public static void Make2DQuad( TextureRec xy, TextureRec uv,
VertexP3fT2fC4b[] vertices, ref int index ) {
float x1 = xy.U1, y1 = xy.V1, x2 = xy.U2, y2 = xy.V2;
#if USE_DX
x1 -= 0.5f; x2 -= 0.5f;
y1 -= 0.5f; y2 -= 0.5f;
#endif
vertices[index++] = new VertexP3fT2fC4b( x1, y1, 0, uv.U1, uv.V1, FastColour.White );
vertices[index++] = new VertexP3fT2fC4b( x2, y1, 0, uv.U2, uv.V1, FastColour.White );
vertices[index++] = new VertexP3fT2fC4b( x2, y2, 0, uv.U2, uv.V2, FastColour.White );
vertices[index++] = new VertexP3fT2fC4b( x1, y2, 0, uv.U1, uv.V2, FastColour.White );
vertices[index++] = new VertexP3fT2fC4b( x1, y1, 0, tex.U1, tex.V1, col );
vertices[index++] = new VertexP3fT2fC4b( x2, y1, 0, tex.U2, tex.V1, col );
vertices[index++] = new VertexP3fT2fC4b( x2, y2, 0, tex.U2, tex.V2, col );
vertices[index++] = new VertexP3fT2fC4b( x1, y2, 0, tex.U1, tex.V2, col );
}
/// <summary> Updates the various matrix stacks and properties so that the graphics API state