agate-svn-commit Mailing List for AgateLib (Page 26)
Status: Alpha
Brought to you by:
kanato
You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
(86) |
May
(77) |
Jun
|
Jul
(1) |
Aug
(31) |
Sep
(12) |
Oct
(31) |
Nov
(53) |
Dec
(39) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(53) |
Feb
(14) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
(7) |
Dec
(13) |
2011 |
Jan
(17) |
Feb
(5) |
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
(21) |
Dec
|
2012 |
Jan
(6) |
Feb
(14) |
Mar
(5) |
Apr
(4) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
(8) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(1) |
Oct
(5) |
Nov
(9) |
Dec
(5) |
2014 |
Jan
(3) |
Feb
(2) |
Mar
(4) |
Apr
(3) |
May
|
Jun
(5) |
Jul
(33) |
Aug
(69) |
Sep
(35) |
Oct
(4) |
Nov
(1) |
Dec
|
From: <ka...@us...> - 2009-04-25 07:39:10
|
Revision: 912 http://agate.svn.sourceforge.net/agate/?rev=912&view=rev Author: kanato Date: 2009-04-25 07:39:00 +0000 (Sat, 25 Apr 2009) Log Message: ----------- Remove unused obsolete functions from MDX1_Surface. Modified Paths: -------------- branches/font/Drivers/AgateMDX/MDX1_Surface.cs Modified: branches/font/Drivers/AgateMDX/MDX1_Surface.cs =================================================================== --- branches/font/Drivers/AgateMDX/MDX1_Surface.cs 2009-04-25 07:18:27 UTC (rev 911) +++ branches/font/Drivers/AgateMDX/MDX1_Surface.cs 2009-04-25 07:39:00 UTC (rev 912) @@ -65,7 +65,7 @@ #endregion - #region --- TextureCoordinates structure + #region --- TextureCoordinates structure --- struct TextureCoordinates { @@ -183,7 +183,7 @@ private void InitVerts() { SetVertsTextureCoordinates(mVerts, 0, mSrcRect); - SetVertsColor(mVerts, 0, 4); + SetVertsColor(new Gradient(Color.White), mVerts, 0, 4); } public void LoadFromStream(Stream st) { @@ -281,173 +281,84 @@ #endregion - #region --- Overriden base class methods --- + #region --- Drawing to screen functions --- - public override Gradient ColorGradient - { - get - { - return base.ColorGradient; - } - set - { - base.ColorGradient = value; + public override void Draw(SurfaceState state) + { + for (int i = 0; i < state.DrawInstances.Count; i++) + { + Draw(state, state.DrawInstances[i]); + } + } + private void Draw(SurfaceState state, SurfaceDrawInstance inst) + { + float destX = inst.DestLocation.X; + float destY = inst.DestLocation.Y; + Rectangle srcRect = inst.GetSourceRect(SurfaceSize); + SizeF displaySize = state.GetDisplaySize(srcRect.Size); + PointF rotationCenter = state.GetRotationCenter(displaySize); + bool alphaBlend = true; + float mRotationCos = (float)Math.Cos(state.RotationAngle); + float mRotationSin = (float)Math.Sin(state.RotationAngle); - SetVertsColor(mVerts, 0, 4); - } - } - public override double RotationAngle - { - get - { - return base.RotationAngle; - } - set - { - base.RotationAngle = value; + if (displaySize.Width < 0) + destX -= displaySize.Width; + if (displaySize.Height < 0) + destY -= displaySize.Height; - mRotationCos = (float)Math.Cos(RotationAngle); - mRotationSin = (float)Math.Sin(RotationAngle); - - } - } + if (TesselateFactor == 1) + { + SetVertsTextureCoordinates(mVerts, 0, srcRect); + SetVertsColor(state.ColorGradient, mVerts, 0, 4); + SetVertsPosition(mVerts, 0, + new RectangleF(destX, destY, + srcRect.Width * (float)state.ScaleWidth, + srcRect.Height * (float)state.ScaleHeight), + rotationCenter.X, rotationCenter.Y, + state.DisplayAlignment, mRotationCos, mRotationSin); - #endregion + mDevice.DrawBuffer.CacheDrawIndexedTriangles(mVerts, mIndices, mTexture.Value, alphaBlend); + } + else + { + TextureCoordinates texCoords = GetTextureCoordinates(mSrcRect); + float texWidth = texCoords.Right - texCoords.Left; + float texHeight = texCoords.Bottom - texCoords.Top; - #region --- Drawing Helper functions --- + float displayWidth = displaySize.Width / (float)TesselateFactor; + float displayHeight = displaySize.Height / (float)TesselateFactor; - #region --- Old --- - [Obsolete("Old DX method.")] - protected void RotatePointInPlace(ref PointF pt, PointF rotation) - { - //PointF local = new PointF(pt.X - rotation.X, pt.Y - rotation.Y); - float localX = pt.X - rotation.X; - float localY = pt.Y - rotation.Y; + for (int j = 0; j < TesselateFactor; j++) + { + TextureCoordinates coords = texCoords; + coords.Top = texCoords.Top + j * texHeight / TesselateFactor; + coords.Bottom = coords.Top + texHeight / TesselateFactor; - double cos = Math.Cos(RotationAngle); - double sin = Math.Sin(RotationAngle); + for (int i = 0; i < TesselateFactor; i++) + { + coords.Left = texCoords.Left + i * texWidth / TesselateFactor; + coords.Right = coords.Left + texWidth / TesselateFactor; - pt.X = (int)(cos * localX + sin * localY); - pt.Y = (int)(-sin * localX + cos * localY); + float dx = destX + i * displayWidth * mRotationCos + j * displayHeight * mRotationSin; + float dy = destY - i * displayWidth * mRotationSin + j * displayHeight * mRotationCos; - pt.X += rotation.X; - pt.Y += rotation.Y; + SetVertsPosition(mExtraVerts, 0, + new RectangleF(dx, dy, + displayWidth, displayHeight), + rotationCenter.X, rotationCenter.Y, + state.DisplayAlignment, mRotationCos, mRotationSin); + SetVertsColor(state.ColorGradient, mExtraVerts, 0, 4, + i / (double)TesselateFactor, j / (double)TesselateFactor, 1.0 / TesselateFactor, 1.0 / TesselateFactor); - } - [Obsolete("Old DX method.")] - protected void RotatePointInPlace(ref CustomVertex.TransformedColoredTextured pt, PointF rotation) - { - //PointF local = new PointF(pt.X - rotation.X, pt.Y - rotation.Y); - float localX = pt.X - rotation.X; - float localY = pt.Y - rotation.Y; + SetVertsTextureCoordinates(mExtraVerts, 0, coords); - double cos = Math.Cos(RotationAngle); - double sin = Math.Sin(RotationAngle); + mDevice.DrawBuffer.CacheDrawIndexedTriangles( + mExtraVerts, mIndices, mTexture.Value, alphaBlend); + } + } + } + } - pt.X = (float)(cos * localX + sin * localY); - pt.Y = (float)(-sin * localX + cos * localY); - - pt.X += rotation.X; - pt.Y += rotation.Y; - - } - [Obsolete("Old DX method.")] - protected void TranslatePointInPlace(ref PointF[] pt, PointF origin) - { - for (int i = 0; i < pt.Length; i++) - { - pt[i].X -= origin.X; - pt[i].Y -= origin.Y; - } - } - - [Obsolete("Old DX method.")] - protected void TranslatePointInPlace(ref PointF pt, PointF origin) - { - pt.X -= origin.X; - pt.Y -= origin.Y; - } - [Obsolete("Old DX method.")] - protected void TranslatePointInPlace(ref CustomVertex.TransformedColoredTextured pt, PointF origin) - { - pt.X -= origin.X; - pt.Y -= origin.Y; - } - - - #endregion - - protected void DrawWithoutVB(float destX, float destY, bool alphaBlend) - { - // find center - PointF rotation = Origin.CalcF(RotationCenter, DisplaySize); - - DrawWithoutVB(destX, destY, mSrcRect, rotation.X, rotation.Y, alphaBlend); - } - protected void DrawWithoutVB(float destX, float destY, Rectangle srcRect, - float rotationCenterX, float rotationCenterY, bool alphaBlend) - { - if (DisplayWidth < 0) - { - destX -= DisplayWidth; - } - if (DisplayHeight < 0) - { - destY -= DisplayHeight; - } - - if (TesselateFactor == 1) - { - SetVertsTextureCoordinates(mVerts, 0, srcRect); - SetVertsColor(mVerts, 0, 4); - SetVertsPosition(mVerts, 0, - new RectangleF(destX, destY, - srcRect.Width * (float)ScaleWidth, - srcRect.Height * (float)ScaleHeight), - rotationCenterX, rotationCenterY); - - mDevice.DrawBuffer.CacheDrawIndexedTriangles(mVerts, mIndices, mTexture.Value, alphaBlend); - } - else - { - TextureCoordinates texCoords = GetTextureCoordinates(mSrcRect); - float texWidth = texCoords.Right - texCoords.Left; - float texHeight = texCoords.Bottom - texCoords.Top; - - float displayWidth = DisplayWidth / (float)TesselateFactor; - float displayHeight = DisplayHeight / (float)TesselateFactor; - - for (int j = 0; j < TesselateFactor; j++) - { - TextureCoordinates coords = texCoords; - coords.Top = texCoords.Top + j * texHeight / TesselateFactor; - coords.Bottom = coords.Top + texHeight / TesselateFactor; - - for (int i = 0; i < TesselateFactor; i++) - { - coords.Left = texCoords.Left + i * texWidth / TesselateFactor; - coords.Right = coords.Left + texWidth / TesselateFactor; - - float dx = destX + i * displayWidth * mRotationCos + j * displayHeight * mRotationSin; - float dy = destY - i * displayWidth * mRotationSin + j * displayHeight * mRotationCos; - - SetVertsPosition(mExtraVerts, 0, - new RectangleF(dx, dy, - displayWidth, displayHeight), - rotationCenterX, rotationCenterY); - SetVertsColor(mExtraVerts, 0, 4, - i / (double)TesselateFactor, j / (double)TesselateFactor, 1.0 / TesselateFactor, 1.0 / TesselateFactor); - - SetVertsTextureCoordinates(mExtraVerts, 0, coords); - - mDevice.DrawBuffer.CacheDrawIndexedTriangles( - mExtraVerts, mIndices, mTexture.Value, alphaBlend); - } - } - } - - } - private void SetVertsTextureCoordinates(PositionColorNormalTexture[] verts, int startIndex, Rectangle srcRect) { @@ -456,13 +367,6 @@ SetVertsTextureCoordinates(verts, startIndex, texCoords); } - private void SetVertsTextureCoordinates(PositionColorNormalTexture[] verts, int startIndex, - RectangleF srcRect) - { - TextureCoordinates texCoords = GetTextureCoordinates(srcRect); - - SetVertsTextureCoordinates(verts, startIndex, texCoords); - } private void SetVertsTextureCoordinates(PositionColorNormalTexture[] verts, int startIndex, TextureCoordinates texCoords) { @@ -484,7 +388,6 @@ return GetTextureCoordinates(new RectangleF( srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height)); } - private TextureCoordinates GetTextureCoordinates(RectangleF srcRect) { // if you change these, besure to uncomment the divisions below. @@ -507,14 +410,14 @@ return texCoords; } - private void SetVertsColor(PositionColorNormalTexture[] verts, int startIndex, int count) + private void SetVertsColor(Gradient ColorGradient, PositionColorNormalTexture[] verts, int startIndex, int count) { verts[startIndex].Color = ColorGradient.TopLeft.ToArgb(); verts[startIndex + 1].Color = ColorGradient.TopRight.ToArgb(); verts[startIndex + 2].Color = ColorGradient.BottomLeft.ToArgb(); verts[startIndex + 3].Color = ColorGradient.BottomRight.ToArgb(); } - private void SetVertsColor(PositionColorNormalTexture[] verts, int startIndex, int count, + private void SetVertsColor(Gradient ColorGradient, PositionColorNormalTexture[] verts, int startIndex, int count, double x, double y, double width, double height) { verts[startIndex].Color = ColorGradient.Interpolate(x, y).ToArgb(); @@ -522,15 +425,11 @@ verts[startIndex + 2].Color = ColorGradient.Interpolate(x, y + height).ToArgb(); verts[startIndex + 3].Color = ColorGradient.Interpolate(x + width, y + height).ToArgb(); } - private void SetVertsPosition(PositionColorNormalTexture[] verts, int index, - Rectangle dest, float rotationCenterX, float rotationCenterY) - { - SetVertsPosition(verts, index, new RectangleF(dest.X, dest.Y, dest.Width, dest.Height), - rotationCenterX, rotationCenterY); - } private void SetVertsPosition(PositionColorNormalTexture[] verts, int index, - RectangleF dest, float rotationCenterX, float rotationCenterY) + RectangleF dest, float rotationCenterX, float rotationCenterY, + OriginAlignment DisplayAlignment, + float mRotationCos, float mRotationSin) { float destX = dest.X -0.5f; float destY = dest.Y -0.5f; @@ -579,266 +478,19 @@ } } - [Obsolete("Old DX method.")] - protected void DrawWithoutVBNoRotation(RectangleF destRect, bool alphaBlend) - { - DrawWithoutVBNoRotation(new RectangleF(new PointF(0, 0), (SizeF)SurfaceSize), - destRect, alphaBlend); - } - [Obsolete("Old DX method.")] - protected void DrawWithoutVBNoRotation(RectangleF srcRect, RectangleF destRect, bool alphaBlend) - { - //CustomVertex.TransformedColoredTextured[] verts = new CustomVertex.TransformedColoredTextured[4]; - int startIndex = 0; - AddRectToVB(mVerts, startIndex, srcRect, destRect); - - mDevice.SetDeviceStateTexture(mTexture.Value); - mDevice.AlphaBlend = alphaBlend; - - mDevice.Device.VertexFormat = CustomVertex.PositionColoredTextured.Format; - mDevice.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, mVerts); - - } - - - [Obsolete("Old DX method.")] - private void AddRectToVB(PositionColorNormalTexture[] verts, int startIndex, - RectangleF srcRect, RectangleF destRect) - { - // find center - PointF centerpt = Origin.CalcF(DisplayAlignment, DisplaySize); - - float left = destRect.Left - 0.5f; - float top = destRect.Top - 0.5f; - float right = destRect.Right - 0.5f;// +(float)Math.Floor(destRect.Width / (float)srcRect.Width); - float bottom = destRect.Bottom - 0.5f;// +(float)Math.Floor(destRect.Height / (float)srcRect.Height); - - PointF[] corners = new PointF[4] - { - new PointF(left, top), - new PointF(right, top), - new PointF(left, bottom), - new PointF(right, bottom) - }; - - PointF[] uv = new PointF[4] - { - new PointF(mSrcRect.Left + srcRect.Left, mSrcRect.Top + srcRect.Top), - new PointF(mSrcRect.Left + srcRect.Right, mSrcRect.Top + srcRect.Top), - new PointF(mSrcRect.Left + srcRect.Left, mSrcRect.Top + srcRect.Bottom), - new PointF(mSrcRect.Left + srcRect.Right, mSrcRect.Top + srcRect.Bottom) - }; - - TranslatePointInPlace(ref corners, centerpt); - - - for (int i = 0; i < 4; i++) - { - verts[startIndex + i] = new PositionColorNormalTexture( - corners[i].X, corners[i].Y, 0.0F, Color.ToArgb(), - uv[i].X / (float)mTextureSize.Width, uv[i].Y / (float)mTextureSize.Height, - 0, 0, -1); - } - } - - - #endregion - #region --- Drawing to screen functions --- - - public override void Draw(float destX, float destY) - { - DrawWithoutVB(destX, destY, true); - } - - public override void Draw(float destX, float destY, Rectangle srcRect, float rotationCenterX, float rotationCenterY) - { - DrawWithoutVB(destX, destY, srcRect, rotationCenterX, rotationCenterY, true); - } - public override void Draw(float destX, float destY, float rotationCenterX, float rotationCenterY) - { - DrawWithoutVB(destX, destY, mSrcRect, rotationCenterX, rotationCenterY, true); - } - public override void Draw(Rectangle destRect) - { - Draw(new Rectangle(0, 0, mSrcRect.Width, mSrcRect.Height), destRect); - } - public override void Draw(RectangleF srcRect, RectangleF destRect) - { - srcRect.X += mSrcRect.X; - srcRect.Y += mSrcRect.Y; - - //DrawWithoutVBNoRotation(srcRect, destRect, true); - //if (mRotationCos != 1.0f) - //{ - // float oldcos = mRotationCos; - // float oldsin = mRotationSin; - - // SetVertsColor(mExtraVerts, 0, 4); - // SetVertsTextureCoordinates(mExtraVerts, 0, srcRect); - // SetVertsPosition(mExtraVerts, 0, destRect, 0, 0); - - // mRotationCos = oldcos; - // mRotationSin = oldsin; - //} - //else - //{ - if (TesselateFactor == 1) - { - SetVertsColor(mExtraVerts, 0, 4); - SetVertsTextureCoordinates(mExtraVerts, 0, srcRect); - SetVertsPosition(mExtraVerts, 0, destRect, 0, 0); - - mDevice.DrawBuffer.CacheDrawIndexedTriangles(mExtraVerts, mExtraIndices, mTexture.Value, true); - } - else - { - SetVertsColor(mExtraVerts, 0, 4); - - RectangleF src = new RectangleF(); - RectangleF dest = new RectangleF(); - - for (int j = 0; j < TesselateFactor; j++) - { - src.Y = srcRect.Top + j * srcRect.Height / (float)TesselateFactor; - src.Height = srcRect.Height / (float)TesselateFactor; - - dest.Y = destRect.Top + j * destRect.Height / (float)TesselateFactor; - dest.Height = destRect.Height / (float)TesselateFactor; - - for (int i = 0; i < TesselateFactor; i++) - { - src.X = srcRect.X + i * srcRect.Width / (float)TesselateFactor; - src.Width = srcRect.Width / (float)TesselateFactor; - - dest.X = destRect.X + i * destRect.Width / (float)TesselateFactor; - dest.Width = destRect.Width / (float)TesselateFactor; - - - SetVertsColor(mExtraVerts, 0, 4, - i / (double)TesselateFactor, j / (double)TesselateFactor, - 1.0 / TesselateFactor, 1.0 / TesselateFactor); - - SetVertsTextureCoordinates(mExtraVerts, 0, src); - SetVertsPosition(mExtraVerts, 0, dest, 0, 0); - - mDevice.DrawBuffer.CacheDrawIndexedTriangles(mExtraVerts, mExtraIndices, mTexture.Value, true); - } - } - } - } - - /// <summary> - /// This needs to be updated to use the same approach as Draw(Rectangle, Rectangle) - /// </summary> - /// <param name="srcRects"></param> - /// <param name="destRects"></param> - public override void DrawRects(RectangleF[] srcRects, RectangleF[] destRects, int start, int length) - { - - PositionColorNormalTexture[] verts = - new PositionColorNormalTexture[srcRects.Length * 4]; - short[] indices = new short[srcRects.Length * 6]; - - int startIndex = 0; - int indexIndex = 0; - - for (int i = start; i < start + length; i++) - { - AddRectToVB(verts, startIndex, srcRects[i], destRects[i]); - - indices[indexIndex] = (short)startIndex; - indices[indexIndex + 1] = (short)(startIndex + 1); - indices[indexIndex + 2] = (short)(startIndex + 2); - indices[indexIndex + 3] = (short)(startIndex + 2); - indices[indexIndex + 4] = (short)(startIndex + 1); - indices[indexIndex + 5] = (short)(startIndex + 3); - - - startIndex += 4; - indexIndex += 6; - } - - mDevice.DrawBuffer.CacheDrawIndexedTriangles(verts, indices, mTexture.Value, true); - - //mDevice.SetDeviceStateTexture(mTexture.Value); - //mDevice.AlphaBlend = true; - - //mDevice.VertexFormat = CustomVertex.TransformedColoredTextured.Format; - ////mDevice.Device.DrawUserPrimitives(PrimitiveType.TriangleList, 2 * srcRects.Length, verts); - //mDevice.Device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0, indexIndex, - // srcRects.Length * 2, indices, true, verts); - } - - #endregion + #endregion #region --- Overriden public properties --- - public override int SurfaceHeight - { - get { return mSrcRect.Height; } - } - public override int SurfaceWidth - { - get { return mSrcRect.Width; } - } - public override Size SurfaceSize { get { return mSrcRect.Size; } } #endregion - #region --- Surface querying --- + #region --- Surface saving --- - public override bool IsSurfaceBlank() - { - return IsSurfaceBlank((int)(Display.AlphaThreshold * 255.0)); - } - public override bool IsSurfaceBlank(int alphaThreshold) - { - for (int i = 0; i < SurfaceHeight; i++) - { - if (IsRowBlank(i) == false) - return false; - } - - return true; - - } - - public override bool IsRowBlank(int row) - { - Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0); - - int stride; - GraphicsStream stm = surf.LockRectangle( - Interop.Convert(mSrcRect), LockFlags.ReadOnly, out stride); - - bool retval = this.IsRowBlankScanARGB(stm.InternalData, row, this.SurfaceWidth, - stride, (int)(Display.AlphaThreshold * 255.0), 0xff000000, 24); - - surf.UnlockRectangle(); - - return retval; - } - - public override bool IsColumnBlank(int col) - { - Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0); - - int stride; - GraphicsStream stm = surf.LockRectangle(Interop.Convert(mSrcRect), - LockFlags.ReadOnly, out stride); - - bool retval = this.IsColBlankScanARGB(stm.InternalData, col, this.SurfaceHeight, - stride, (int)(Display.AlphaThreshold * 255.0), 0xff000000, 24); - - surf.UnlockRectangle(); - - return retval; - } - public override void SaveTo(string frameFile, ImageFileFormat format) { Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-25 07:18:39
|
Revision: 911 http://agate.svn.sourceforge.net/agate/?rev=911&view=rev Author: kanato Date: 2009-04-25 07:18:27 +0000 (Sat, 25 Apr 2009) Log Message: ----------- Fix layout of inline images. Modified Paths: -------------- branches/font/AgateLib/DisplayLib/TextLayout.cs Modified: branches/font/AgateLib/DisplayLib/TextLayout.cs =================================================================== --- branches/font/AgateLib/DisplayLib/TextLayout.cs 2009-04-25 07:11:48 UTC (rev 910) +++ branches/font/AgateLib/DisplayLib/TextLayout.cs 2009-04-25 07:18:27 UTC (rev 911) @@ -73,11 +73,17 @@ { public ISurface Surface { get; set; } public SurfaceState State { get; set; } - + public static bool DebugRects; public override void Draw() { + if (State == null) + State = Surface.State.Clone(); + + State.DrawInstances.SetCount(1); + State.DrawInstances[0] = new SurfaceDrawInstance(Location); + this.Surface.Draw(State); if (DebugRects) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-25 07:11:58
|
Revision: 910 http://agate.svn.sourceforge.net/agate/?rev=910&view=rev Author: kanato Date: 2009-04-25 07:11:48 +0000 (Sat, 25 Apr 2009) Log Message: ----------- Implement stateless drawing in AgateOTK. Modified Paths: -------------- branches/font/AgateLib/ImplementationBase/SurfaceImpl.cs branches/font/Drivers/AgateOTK/GL_Surface.cs Modified: branches/font/AgateLib/ImplementationBase/SurfaceImpl.cs =================================================================== --- branches/font/AgateLib/ImplementationBase/SurfaceImpl.cs 2009-04-25 06:57:02 UTC (rev 909) +++ branches/font/AgateLib/ImplementationBase/SurfaceImpl.cs 2009-04-25 07:11:48 UTC (rev 910) @@ -56,10 +56,7 @@ #region --- Drawing the surface to the screen --- - public virtual void Draw(SurfaceState state) - { - throw new NotImplementedException(); - } + public abstract void Draw(SurfaceState state); #endregion Modified: branches/font/Drivers/AgateOTK/GL_Surface.cs =================================================================== --- branches/font/Drivers/AgateOTK/GL_Surface.cs 2009-04-25 06:57:02 UTC (rev 909) +++ branches/font/Drivers/AgateOTK/GL_Surface.cs 2009-04-25 07:11:48 UTC (rev 910) @@ -65,8 +65,6 @@ TextureCoordinates mTexCoord; - float mRotationCos = 1.0f; - float mRotationSin = 0.0f; public GL_Surface(string filename) { @@ -177,155 +175,87 @@ } + public override void Draw(SurfaceState state) + { + for (int i = 0; i < state.DrawInstances.Count; i++) + { + Draw(state, state.DrawInstances[i]); + } + } + private void Draw(SurfaceState state, SurfaceDrawInstance inst) + { + float destX = inst.DestLocation.X; + float destY = inst.DestLocation.Y; + Rectangle srcRect = inst.GetSourceRect(SurfaceSize); + SizeF displaySize = state.GetDisplaySize(SurfaceSize); + PointF rotationCenter = state.GetRotationCenter(displaySize); + float mRotationCos = (float)Math.Cos(state.RotationAngle); + float mRotationSin = (float)Math.Sin(state.RotationAngle); + SizeF dispSize = new SizeF( + srcRect.Width * (float)state.ScaleWidth, + srcRect.Height * (float)state.ScaleHeight); - public override double RotationAngle - { - get - { - return base.RotationAngle; - } - set - { - base.RotationAngle = value; + if (displaySize.Width < 0) + destX -= dispSize.Width; - mRotationCos = (float)Math.Cos(RotationAngle); - mRotationSin = (float)Math.Sin(RotationAngle); + if (displaySize.Height < 0) + destY -= dispSize.Height; - } - } + mTexCoord = GetTextureCoords(srcRect); + if (TesselateFactor == 1) + { + BufferQuad(destX, destY, rotationCenter.X, rotationCenter.Y, + dispSize.Width, dispSize.Height, mTexCoord, state.ColorGradient, + state.DisplayAlignment, mRotationCos, mRotationSin); + } + else + { + TextureCoordinates texCoord = new TextureCoordinates(); + float texWidth = mTexCoord.Right - mTexCoord.Left; + float texHeight = mTexCoord.Bottom - mTexCoord.Top; - public override void Draw(Rectangle destRect) - { - Draw(mSourceRect, destRect); - } - public override void Draw(RectangleF srcRect, RectangleF destRect) - { - srcRect.X += mSourceRect.X; - srcRect.Y += mSourceRect.Y; - - TextureCoordinates texcoords = GetTextureCoords(srcRect); - RectangleF dest = new RectangleF(destRect.X, destRect.Y, destRect.Width, destRect.Height); + float _displayWidth = displaySize.Width / (float)TesselateFactor; + float _displayHeight = displaySize.Height / (float)TesselateFactor; - if (TesselateFactor == 1) - { - mState.DrawBuffer.AddQuad(mTextureID, Color, texcoords, dest); - } - else - { - float texWidth = texcoords.Right - texcoords.Left; - float texHeight = texcoords.Bottom - texcoords.Top; + for (int j = 0; j < TesselateFactor; j++) + { + texCoord.Top = mTexCoord.Top + j * texHeight / TesselateFactor; + texCoord.Bottom = mTexCoord.Top + (j + 1) * texHeight / TesselateFactor; - for (int j = 0; j < TesselateFactor; j++) - { - RectangleF subRect = dest; - TextureCoordinates coords = texcoords; + for (int i = 0; i < TesselateFactor; i++) + { + texCoord.Left = mTexCoord.Left + i * texWidth / TesselateFactor; + texCoord.Right = mTexCoord.Left + (i + 1) * texWidth / TesselateFactor; - subRect.Y = dest.Top + j * dest.Height / (float)TesselateFactor; - subRect.Height = dest.Height / (float)TesselateFactor; + float dx = destX + i * _displayWidth * mRotationCos + j * _displayHeight * mRotationSin; + float dy = destY - i * _displayWidth * mRotationSin + j * _displayHeight * mRotationCos; - coords.Top = texcoords.Top + texHeight * j / TesselateFactor; - coords.Bottom = coords.Top + texHeight / TesselateFactor; + double cx = i / (double)TesselateFactor; + double cy = j / (double)TesselateFactor; - for (int i = 0; i < TesselateFactor; i++) - { - subRect.X = dest.Left + i * dest.Width / (float)TesselateFactor; - subRect.Width = dest.Width / (float)TesselateFactor; + Gradient color = new Gradient( + state.ColorGradient.Interpolate(cx, cy), + state.ColorGradient.Interpolate(cx + 1.0 / TesselateFactor, cy), + state.ColorGradient.Interpolate(cx, cy + 1.0 / TesselateFactor), + state.ColorGradient.Interpolate(cx + 1.0 / TesselateFactor, cy + 1.0 / TesselateFactor)); - coords.Left = texcoords.Left + texWidth * i / TesselateFactor; - coords.Right = coords.Left + texWidth / TesselateFactor; + BufferQuad(dx, dy, + rotationCenter.X, rotationCenter.Y, + _displayWidth, _displayHeight, texCoord, color, + state.DisplayAlignment, mRotationCos, mRotationSin); - mState.DrawBuffer.AddQuad(mTextureID, Color, coords, subRect); - } - } - } - - } - public override void Draw(float destX, float destY) - { - Point rotatePoint = Origin.Calc(RotationCenter, DisplaySize); - - Draw(destX, destY, rotatePoint.X, rotatePoint.Y); - } - - - public override void Draw(float destX, float destY, float rotationCenterX, float rotationCenterY) - { - Draw(destX, destY, mSourceRect, rotationCenterX, rotationCenterY); - } - - public override void Draw(float destX, float destY, Rectangle srcRect, float rotationCenterX, float rotationCenterY) - { - SizeF dispSize = new SizeF( - srcRect.Width * (float)ScaleWidth, - srcRect.Height * (float)ScaleHeight); - - if (DisplaySize.Width < 0) - destX -= dispSize.Width; - - if (DisplaySize.Height < 0) - destY -= dispSize.Height; - - mTexCoord = GetTextureCoords(srcRect); - - if (TesselateFactor == 1) - { - BufferQuad(destX, destY, rotationCenterX, rotationCenterY, - dispSize.Width, dispSize.Height, mTexCoord, ColorGradient); - } - else - { - TextureCoordinates texCoord = new TextureCoordinates(); - float texWidth = mTexCoord.Right - mTexCoord.Left; - float texHeight = mTexCoord.Bottom - mTexCoord.Top; - - float displayWidth = DisplayWidth / (float)TesselateFactor; - float displayHeight = DisplayHeight / (float)TesselateFactor; - - for (int j = 0; j < TesselateFactor; j++) - { - texCoord.Top = mTexCoord.Top + j * texHeight / TesselateFactor; - texCoord.Bottom = mTexCoord.Top + (j + 1) * texHeight / TesselateFactor; - - for (int i = 0; i < TesselateFactor; i++) - { - texCoord.Left = mTexCoord.Left + i * texWidth / TesselateFactor; - texCoord.Right = mTexCoord.Left + (i+1) * texWidth / TesselateFactor; - - float dx = destX + i * displayWidth * mRotationCos + j * displayHeight * mRotationSin; - float dy = destY - i * displayWidth * mRotationSin + j * displayHeight * mRotationCos; - - double cx = i / (double)TesselateFactor; - double cy = j / (double)TesselateFactor; - - Gradient color = new Gradient( - ColorGradient.Interpolate(cx, cy), - ColorGradient.Interpolate(cx + 1.0 / TesselateFactor, cy), - ColorGradient.Interpolate(cx, cy + 1.0 / TesselateFactor), - ColorGradient.Interpolate(cx + 1.0 / TesselateFactor, cy + 1.0 / TesselateFactor)); - - BufferQuad(dx, dy, - rotationCenterX, rotationCenterY, - displayWidth, displayHeight, texCoord, color); - - } - } - } - //GL.PushMatrix(); - - //GL.Translatef(-translatePoint.X, -translatePoint.Y, 0); - //GL.Rotatef((float)-RotationAngleDegrees, 0.0f, 0.0f, 1.0f); - - - // restore the matrix - //GL.PopMatrix(); - } - + } + } + } + } + PointF[] cachePt = new PointF[4]; private void BufferQuad(float destX, float destY, float rotationCenterX, float rotationCenterY, - float displayWidth, float displayHeight, TextureCoordinates texCoord, Gradient color) + float displayWidth, float displayHeight, TextureCoordinates texCoord, Gradient color, + OriginAlignment DisplayAlignment, float mRotationCos, float mRotationSin) { // order is @@ -335,7 +265,8 @@ PointF[] pt = cachePt; SetPoints(pt, destX, destY, - rotationCenterX, rotationCenterY, displayWidth, displayHeight); + rotationCenterX, rotationCenterY, displayWidth, displayHeight, + DisplayAlignment, mRotationCos, mRotationSin); //RectangleF destRect = new RectangleF(new PointF(-rotationCenterX, -rotationCenterY), // new SizeF(displayWidth, displayHeight)); @@ -345,7 +276,8 @@ } private void SetPoints(PointF[] pt, float destX, float destY, float rotationCenterX, float rotationCenterY, - float destWidth, float destHeight) + float destWidth, float destHeight, OriginAlignment DisplayAlignment, + float mRotationCos, float mRotationSin) { const int index = 0; PointF centerPoint = Origin.CalcF(DisplayAlignment, new SizeF(destWidth, destHeight)); @@ -482,23 +414,6 @@ get { return mSourceRect.Size; } } - public override bool IsSurfaceBlank() - { - return false; - } - public override bool IsSurfaceBlank(int alphaThreshold) - { - return false; - } - public override bool IsRowBlank(int row) - { - return false; - } - public override bool IsColumnBlank(int col) - { - return false; - } - public override void BeginRender() { GL.Viewport(0, 0, SurfaceWidth, SurfaceHeight); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-25 06:57:23
|
Revision: 909 http://agate.svn.sourceforge.net/agate/?rev=909&view=rev Author: kanato Date: 2009-04-25 06:57:02 +0000 (Sat, 25 Apr 2009) Log Message: ----------- Implement stateless drawing in AgateLib and AgateDrawing. Modified Paths: -------------- branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs branches/font/AgateLib/BitmapFont/BitmapFontOptions.cs branches/font/AgateLib/DisplayLib/Cache/FontStateCache.cs branches/font/AgateLib/DisplayLib/FontState.cs branches/font/AgateLib/DisplayLib/FontSurface.cs branches/font/AgateLib/DisplayLib/ISprite.cs branches/font/AgateLib/DisplayLib/ISurface.cs branches/font/AgateLib/DisplayLib/OriginAlignment.cs branches/font/AgateLib/DisplayLib/Surface.cs branches/font/AgateLib/DisplayLib/SurfaceState.cs branches/font/AgateLib/DisplayLib/TextLayout.cs branches/font/AgateLib/Geometry/Rectangle.cs branches/font/AgateLib/ImplementationBase/SurfaceImpl.cs branches/font/AgateLib/Sprites/Sprite.cs branches/font/AgateLib/Sprites/SpriteFrame.cs branches/font/Drivers/AgateDrawing/Drawing_Surface.cs branches/font/Drivers/AgateMDX/MDX1_Surface.cs branches/font/Drivers/AgateOTK/GL_Surface.cs branches/font/Tests/Display/OrthoProjection/Ortho.cs branches/font/Tests/Display/RotatingSpriteTester/RotatingSpriteTester.cs branches/font/Tests/Display/ScreenCapture/ScreenCapture.cs branches/font/Tests/Display/SurfaceTester/frmSurfaceTester.Designer.cs branches/font/Tests/Fonts/Fonts/Fonts.cs branches/font/Tests/Fonts/TextLayout/TextLayout.cs Added Paths: ----------- branches/font/AgateLib/DisplayLib/Cache/SurfaceStateCache.cs Modified: branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs =================================================================== --- branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -38,7 +38,6 @@ public class BitmapFontImpl : FontSurfaceImpl { Surface mSurface; - FontMetrics mFontMetrics; int mCharHeight; @@ -347,8 +346,6 @@ cache.NeedsRefresh = false; } } - - } /// <summary> Modified: branches/font/AgateLib/BitmapFont/BitmapFontOptions.cs =================================================================== --- branches/font/AgateLib/BitmapFont/BitmapFontOptions.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/BitmapFont/BitmapFontOptions.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -25,7 +25,6 @@ namespace AgateLib.BitmapFont { - /// <summary> /// Class which indicates how a bitmap font should be generated /// from an operating system font. Modified: branches/font/AgateLib/DisplayLib/Cache/FontStateCache.cs =================================================================== --- branches/font/AgateLib/DisplayLib/Cache/FontStateCache.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/DisplayLib/Cache/FontStateCache.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -1,4 +1,22 @@ -using System; +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (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.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2009. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; using System.Collections.Generic; using System.Linq; using System.Text; Added: branches/font/AgateLib/DisplayLib/Cache/SurfaceStateCache.cs =================================================================== --- branches/font/AgateLib/DisplayLib/Cache/SurfaceStateCache.cs (rev 0) +++ branches/font/AgateLib/DisplayLib/Cache/SurfaceStateCache.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -0,0 +1,29 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (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.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2009. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.DisplayLib.Cache +{ + public abstract class SurfaceStateCache + { + } +} Modified: branches/font/AgateLib/DisplayLib/FontState.cs =================================================================== --- branches/font/AgateLib/DisplayLib/FontState.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/DisplayLib/FontState.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -1,4 +1,22 @@ -using System; +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (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.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2009. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; using System.Collections.Generic; using System.Linq; using System.Text; Modified: branches/font/AgateLib/DisplayLib/FontSurface.cs =================================================================== --- branches/font/AgateLib/DisplayLib/FontSurface.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/DisplayLib/FontSurface.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -387,9 +387,9 @@ int lastIndex = 0; string result = string.Empty; - Point dest; + PointF dest; - dest = Point.Empty; + dest = PointF.Empty; TextLayout layout = new TextLayout(); int lineHeight = FontHeight; @@ -450,12 +450,12 @@ { foreach (var item in layout.Where(x => x.LineIndex == lineIndex)) { - item.Location = new Point( + item.Location = new PointF( item.Location.X, item.Location.Y + lineShift); } } - private void PushLayoutImage(int lineIndex, TextLayout layout, ref Point dest, ref int lineHeight, + private void PushLayoutImage(int lineIndex, TextLayout layout, ref PointF dest, ref int lineHeight, ref int spaceAboveLine, ISurface surface) { int newSpaceAbove; @@ -489,12 +489,19 @@ layout.Add(t); } - private void PushLayoutText(int lineIndex, TextLayout layout, ref Point dest, string text) + private void PushLayoutText(int lineIndex, TextLayout layout, ref PointF dest, string text) { if (string.IsNullOrEmpty(text)) return; - LayoutText t = new LayoutText { Font = this, Location = dest, Text = text, LineIndex = lineIndex }; + LayoutText t = new LayoutText + { + Font = this, + State = State.Clone(), + Location = dest, + Text = text, + LineIndex = lineIndex + }; layout.Add(t); Modified: branches/font/AgateLib/DisplayLib/ISprite.cs =================================================================== --- branches/font/AgateLib/DisplayLib/ISprite.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/DisplayLib/ISprite.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -18,10 +18,10 @@ // using System; using System.Collections.Generic; +using AgateLib.Geometry; namespace AgateLib.DisplayLib { - using Geometry; /// <summary> /// Basic interface implemented by different sprite classes. Modified: branches/font/AgateLib/DisplayLib/ISurface.cs =================================================================== --- branches/font/AgateLib/DisplayLib/ISurface.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/DisplayLib/ISurface.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -137,6 +137,6 @@ SurfaceState State { get; } - void Draw(Point Location, SurfaceState State); + void Draw(SurfaceState State); } } Modified: branches/font/AgateLib/DisplayLib/OriginAlignment.cs =================================================================== --- branches/font/AgateLib/DisplayLib/OriginAlignment.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/DisplayLib/OriginAlignment.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -64,6 +64,12 @@ /// Point indicates bottom-right. /// </summary> BottomRight = 0x33, + + /// <summary> + /// Specified indicates that the value in question is specified through + /// some other means. + /// </summary> + Specified = 0xFF, } } Modified: branches/font/AgateLib/DisplayLib/Surface.cs =================================================================== --- branches/font/AgateLib/DisplayLib/Surface.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/DisplayLib/Surface.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -82,6 +82,7 @@ public sealed class Surface : IRenderTarget, IDisposable, ISurface { SurfaceImpl impl; + SurfaceState mState = new SurfaceState(); /// <summary> /// Creates a surface object from a resource. @@ -277,174 +278,192 @@ public Size SurfaceSize { get { return impl.SurfaceSize; } } - /// <summary> - /// Get or sets the width of the surface in pixels when it will be displayed on screen. - /// </summary> - public int DisplayWidth - { - get { return impl.DisplayWidth; } - set { impl.DisplayWidth = value; } - } - /// <summary> - /// Gets or sets the height of the surface in pixels when it is displayed on screen. - /// </summary> - public int DisplayHeight - { - get { return impl.DisplayHeight; } - set { impl.DisplayHeight = value; } - } - /// <summary> - /// Gets or sets the Size of the area used by this surface when displayed on screen. - /// </summary> - public Size DisplaySize - { - get - { - Size sz = new Size(DisplayWidth, DisplayHeight); + /// <summary> + /// Gets or sets the state of the surface. + /// </summary> + public SurfaceState State + { + get { return mState; } + set { mState = value; } + } - return sz; - } - set - { - DisplayWidth = value.Width; - DisplayHeight = value.Height; - } - } + /// <summary> + /// Get or sets the width of the surface in pixels when it will be displayed on screen. + /// </summary> + public int DisplayWidth + { + get { return (int)(mState.ScaleWidth * SurfaceWidth); } + set { ScaleWidth = value / (double)SurfaceWidth; } + } + /// <summary> + /// Gets or sets the height of the surface in pixels when it is displayed on screen. + /// </summary> + public int DisplayHeight + { + get { return (int)(mState.ScaleHeight * SurfaceHeight); } + set { ScaleHeight = value / (double)SurfaceHeight; } + } + /// <summary> + /// Gets or sets the Size of the area used by this surface when displayed on screen. + /// </summary> + public Size DisplaySize + { + get + { + Size sz = new Size(DisplayWidth, DisplayHeight); - /// <summary> - /// Alpha value for displaying this surface. - /// Valid values range from 0.0 (completely transparent) to 1.0 (completely opaque). - /// Internally stored as a byte, so granularity is only 1/255.0. - /// </summary> - public double Alpha - { - get { return impl.Alpha; } - set { impl.Alpha = value; } - } - /// <summary> - /// Gets or sets the rotation angle in radians. - /// Positive angles indicate rotation in the Counter-Clockwise direction. - /// </summary> - public double RotationAngle - { - get { return impl.RotationAngle; } - set { impl.RotationAngle = value; } - } - /// <summary> - /// Gets or sets the rotation angle in degrees. - /// Positive angles indicate rotation in the Counter-Clockwise direction. - /// </summary> - public double RotationAngleDegrees - { - get { return RotationAngle * 180.0 / Math.PI; } - set { RotationAngle = value * Math.PI / 180.0; } - } - /// <summary> - /// Gets or sets the point on the surface which is used to rotate around. - /// </summary> - public OriginAlignment RotationCenter - { - get { return impl.RotationCenter; } - set { impl.RotationCenter = value; } - } - /// <summary> - /// Gets or sets the point where the surface is aligned to when drawn. - /// </summary> - public OriginAlignment DisplayAlignment - { - get { return impl.DisplayAlignment; } - set { impl.DisplayAlignment = value; } - } + return sz; + } + set + { + DisplayWidth = value.Width; + DisplayHeight = value.Height; + } + } - /// <summary> - /// Gets or sets the amount the width is scaled when this surface is drawn. - /// 1.0 is no scaling. - /// Scale values can be negative, this causes the surface to be mirrored - /// in that direction. This does not affect how the surface is aligned; - /// eg. if DisplayAlignment is top-left and ScaleWidth < 0, the surface - /// will still be drawn to the right of the point supplied to Draw(Point). - /// </summary> - public double ScaleWidth - { - get { return impl.ScaleWidth; } - set { impl.ScaleWidth = value; } - } - /// <summary> - /// Gets or sets the amount the height is scaled when this surface is drawn. - /// 1.0 is no scaling. - /// </summary> - public double ScaleHeight - { - get { return impl.ScaleHeight; } - set { impl.ScaleHeight = value; } - } - /// <summary> - /// Sets the amount of scaling when this surface is drawn. - /// 1.0 is no scaling. - /// Scale values can be negative, this causes the surface to be mirrored - /// in that direction. This does not affect how the surface is aligned; - /// eg. if DisplayAlignment is top-left and ScaleWidth < 0, the surface - /// will still be drawn to the right of the point supplied to Draw(Point). - /// </summary> - /// <param name="width"></param> - /// <param name="height"></param> - public void SetScale(double width, double height) - { - impl.SetScale(width, height); - } - /// <summary> - /// Gets the amount of scaling when this surface is drawn. - /// 1.0 is no scaling. - /// Scale values can be negative, this causes the surface to be mirrored - /// in that direction. This does not affect how the surface is aligned; - /// eg. if DisplayAlignment is top-left and ScaleWidth < 0, the surface - /// will still be drawn to the right of the point supplied to Draw(Point). - /// </summary> - /// <param name="width"></param> - /// <param name="height"></param> - public void GetScale(out double width, out double height) - { - impl.GetScale(out width, out height); - } + /// <summary> + /// Alpha value for displaying this surface. + /// Valid values range from 0.0 (completely transparent) to 1.0 (completely opaque). + /// Internally stored as a byte, so granularity is only 1/255.0. + /// If a gradient is used, getting this property returns the alpha value for the top left + /// corner of the gradient. + /// </summary> + public double Alpha + { + get { return Color.A / 255.0; } + set + { + Gradient g = mState.ColorGradient; + g.SetAlpha(value); - - /// <summary> - /// Gets or sets the multiplicative color for this surface. - /// Setting this is equivalent to setting the ColorGradient property - /// with a gradient with the same color in all corners. If a gradient - /// is being used, getting this property returns the top-left color in the gradient. - /// </summary> - public Color Color - { - get { return impl.Color; } - set { impl.Color = value; } - } - /// <summary> - /// Gets or sets the gradient for this surface. - /// </summary> - public Gradient ColorGradient - { - get { return impl.ColorGradient; } - set { impl.ColorGradient = value; } - } + mState.ColorGradient = g; + } + } + /// <summary> + /// Gets or sets the rotation angle in radians. + /// Positive angles indicate rotation in the Counter-Clockwise direction. + /// </summary> + public double RotationAngle + { + get { return mState.RotationAngle; } + set { mState.RotationAngle = value; } + } + /// <summary> + /// Gets or sets the rotation angle in degrees. + /// Positive angles indicate rotation in the Counter-Clockwise direction. + /// </summary> + public double RotationAngleDegrees + { + get { return RotationAngle * 180.0 / Math.PI; } + set { RotationAngle = value * Math.PI / 180.0; } + } + /// <summary> + /// Gets or sets the point on the surface which is used to rotate around. + /// </summary> + public OriginAlignment RotationCenter + { + get { return mState.RotationCenter; } + set { mState.RotationCenter = value; } + } + /// <summary> + /// Gets or sets the point where the surface is aligned to when drawn. + /// </summary> + public OriginAlignment DisplayAlignment + { + get { return mState.DisplayAlignment; } + set { mState.DisplayAlignment = value; } + } - /// <summary> - /// Increments the rotation angle of this surface. - /// </summary> - /// <param name="radians">Value in radians to increase the rotation by.</param> - public void IncrementRotationAngle(double radians) - { - impl.IncrementRotationAngle(radians); - } - /// <summary> - /// Increments the rotation angle of this surface. Value supplied is in degrees. - /// </summary> - /// <param name="degrees"></param> - public void IncrementRotationAngleDegrees(double degrees) - { - impl.IncrementRotationAngleDegrees(degrees); - } + /// <summary> + /// Gets or sets the amount the width is scaled when this surface is drawn. + /// 1.0 is no scaling. + /// Scale values can be negative, this causes the surface to be mirrored + /// in that direction. This does not affect how the surface is aligned; + /// eg. if DisplayAlignment is top-left and ScaleWidth < 0, the surface + /// will still be drawn to the right of the point supplied to Draw(Point). + /// </summary> + public double ScaleWidth + { + get { return mState.ScaleWidth; } + set { mState.ScaleWidth = value; } + } + /// <summary> + /// Gets or sets the amount the height is scaled when this surface is drawn. + /// 1.0 is no scaling. + /// </summary> + public double ScaleHeight + { + get { return mState.ScaleHeight; } + set { mState.ScaleHeight = value; } + } + /// <summary> + /// Sets the amount of scaling when this surface is drawn. + /// 1.0 is no scaling. + /// Scale values can be negative, this causes the surface to be mirrored + /// in that direction. This does not affect how the surface is aligned; + /// eg. if DisplayAlignment is top-left and ScaleWidth < 0, the surface + /// will still be drawn to the right of the point supplied to Draw(Point). + /// </summary> + /// <param name="width"></param> + /// <param name="height"></param> + public void SetScale(double width, double height) + { + ScaleWidth = width; + ScaleHeight = height; + } + /// <summary> + /// Gets the amount of scaling when this surface is drawn. + /// 1.0 is no scaling. + /// Scale values can be negative, this causes the surface to be mirrored + /// in that direction. This does not affect how the surface is aligned; + /// eg. if DisplayAlignment is top-left and ScaleWidth < 0, the surface + /// will still be drawn to the right of the point supplied to Draw(Point). + /// </summary> + /// <param name="width"></param> + /// <param name="height"></param> + public void GetScale(out double width, out double height) + { + width = mState.ScaleWidth; + height = mState.ScaleHeight; + } + + /// <summary> + /// Gets or sets the multiplicative color for this surface. + /// Setting this is equivalent to setting the ColorGradient property + /// with a gradient with the same color in all corners. If a gradient + /// is being used, getting this property returns the top-left color in the gradient. + /// </summary> + public Color Color + { + get { return mState.Color; } + set { mState.Color = value; } + } + /// <summary> + /// Gets or sets the gradient for this surface. + /// </summary> + public Gradient ColorGradient + { + get { return mState.ColorGradient; } + set { mState.ColorGradient = value; } + } + /// <summary> + /// Increments the rotation angle of this surface. + /// </summary> + /// <param name="radians">Value in radians to increase the rotation by.</param> + public void IncrementRotationAngle(double radians) + { + mState.RotationAngle += radians; + } + /// <summary> + /// Increments the rotation angle of this surface. Value supplied is in degrees. + /// </summary> + /// <param name="degrees"></param> + public void IncrementRotationAngleDegrees(double degrees) + { + mState.IncrementRotationAngleDegrees(degrees); + } + #endregion #region --- Drawing to the screen --- @@ -466,7 +485,10 @@ /// <param name="destY"></param> public void Draw(int destX, int destY) { - impl.Draw((float) destX, (float)destY); + mState.DrawInstances.SetCount(1); + mState.DrawInstances[0] = new SurfaceDrawInstance(new PointF(destX, destY)); + + impl.Draw(State); } /// <summary> /// Draws this surface to the screen at the specified point, @@ -477,8 +499,11 @@ /// <param name="destY"></param> public void Draw(float destX, float destY) { - impl.Draw(destX, destY); - } + mState.DrawInstances.SetCount(1); + mState.DrawInstances[0] = new SurfaceDrawInstance(new PointF(destX, destY)); + + impl.Draw(State); + } /// <summary> /// Draws this surface to the screen at the specified point, /// using all the state information defined in the properties @@ -487,7 +512,7 @@ /// <param name="destPt"></param> public void Draw(Point destPt) { - impl.Draw(destPt.X, destPt.Y); + Draw(destPt.X, destPt.Y); } /// <summary> /// Draws this surface to the screen at the specified point, @@ -497,7 +522,7 @@ /// <param name="destPt"></param> public void Draw(Vector2 destPt) { - impl.Draw(destPt.X, destPt.Y); + Draw(destPt.X, destPt.Y); } /// <summary> /// Draws this surface to the screen at the specified point, @@ -507,7 +532,7 @@ /// <param name="destPt"></param> public void Draw(PointF destPt) { - impl.Draw(destPt.X, destPt.Y); + Draw(destPt.X, destPt.Y); } /// <summary> /// Draws this surface to the screen at the specified point, @@ -521,7 +546,7 @@ /// to the top-left of the surface.</param> public void Draw(PointF destPt, PointF rotationCenter) { - impl.Draw(destPt.X, destPt.Y, rotationCenter.X, rotationCenter.Y); + Draw(destPt, Rectangle.Empty, rotationCenter); } /// <summary> /// Draws this surface to the screen at the specified point, @@ -532,15 +557,33 @@ /// </summary> public void Draw(float destX, float destY, float rotationCenterX, float rotationCenterY) { - impl.Draw(destX, destY, rotationCenterX, rotationCenterY); + Draw(new PointF(destX, destY), new PointF(rotationCenterX, rotationCenterY)); } + internal void Draw(PointF destPt, Rectangle srcRect, PointF rotationCenter) + { + OriginAlignment oldrotation = State.RotationCenter; + PointF oldcenter = State.RotationCenterLocation; - public void Draw(Point location, SurfaceState state) + State.RotationCenter = OriginAlignment.Specified; + State.RotationCenterLocation = rotationCenter; + + State.DrawInstances.SetCount(1); + State.DrawInstances[0] = new SurfaceDrawInstance(destPt, srcRect); + + impl.Draw(State); + + State.RotationCenterLocation = oldcenter; + State.RotationCenter = oldrotation; + } + + public void Draw(SurfaceState state) { // TODO: fix this - Draw(location); + impl.Draw(state); } + + SurfaceState rectState; /// <summary> /// Draws a portion of this surface to the specified destination /// rectangle. @@ -553,7 +596,22 @@ /// <param name="destRect"></param> public void Draw(Rectangle srcRect, Rectangle destRect) { - impl.Draw(srcRect, destRect); + if (rectState == null) + rectState = State.Clone(); + else + State.CopyTo(rectState, false); + + rectState.RotationAngle = 0; + rectState.ScaleWidth = destRect.Width / (double)srcRect.Width; + rectState.ScaleHeight = destRect.Height / (double)srcRect.Height; + + rectState.DrawInstances[0] = new SurfaceDrawInstance + { + SourceRect = srcRect, + DestLocation = new PointF(destRect.X, destRect.Y), + }; + + impl.Draw(rectState); } /// <summary> @@ -566,10 +624,30 @@ /// </summary> /// <param name="destRect"></param> public void Draw(Rectangle destRect) - { - impl.Draw(destRect); + { + Draw(new Rectangle(0, 0, SurfaceWidth, SurfaceHeight), destRect); } + void Draw(RectangleF srcRect, RectangleF destRect) + { + if (rectState == null) + rectState = State.Clone(); + else + State.CopyTo(rectState, false); + + rectState.RotationAngle = 0; + rectState.ScaleWidth = destRect.Width / (double)srcRect.Width; + rectState.ScaleHeight = destRect.Height / (double)srcRect.Height; + + rectState.DrawInstances[0] = new SurfaceDrawInstance + { + SourceRect = Rectangle.Round(srcRect), + DestLocation = new PointF(destRect.X, destRect.Y), + }; + + impl.Draw(rectState); + } + /// <summary> /// Draws the surface using an array of source and destination rectangles. /// This method will throw an exception if the two arrays are not the same size. @@ -583,7 +661,8 @@ throw new ArgumentException( "Source and dest rect arrays are not the same size! Use overload which indicates length of arrays to use."); } - impl.DrawRects(srcRects, destRects, 0, srcRects.Length); + + DrawRects(srcRects, destRects, 0, srcRects.Length); } /// <summary> /// Draws the surface using an array of source and destination rectangles. @@ -598,7 +677,8 @@ throw new ArgumentException( "Source and dest rect arrays are not the same size! Use overload which indicates length of arrays to use."); } - impl.DrawRects(srcRects, destRects, 0, srcRects.Length); + + DrawRects(srcRects, destRects, 0, srcRects.Length); } /// <summary> @@ -611,8 +691,10 @@ /// <param name="length">Number of elements in the arrays to use.</param> public void DrawRects(Rectangle[] srcRects, Rectangle[] destRects, int start, int length) { - impl.DrawRects(srcRects, destRects, start, length); - } + // TODO: optimize this + for (int i = start; i < length; i++) + Draw(srcRects[i], destRects[i]); + } /// <summary> /// Draws the surface using an array of source and destination rectangles. /// This method will throw an exception if the two arrays are not the same size. @@ -623,8 +705,10 @@ /// <param name="length">Number of elements in the arrays to use.</param> public void DrawRects(RectangleF[] srcRects, RectangleF[] destRects, int start, int length) { - impl.DrawRects(srcRects, destRects, start, length); - } + // TODO: optimize this + for (int i = start; i < length; i++) + Draw(srcRects[i], destRects[i]); + } #endregion @@ -847,20 +931,6 @@ #endregion - internal void Draw(float x, float y, Rectangle srcRect, float rotationCenterX, float rotationCenterY) - { - impl.Draw(x, y, srcRect, rotationCenterX, rotationCenterY); - } - - #region ISurface Members - - - public SurfaceState State - { - get { return impl.State; } - } - - #endregion } } Modified: branches/font/AgateLib/DisplayLib/SurfaceState.cs =================================================================== --- branches/font/AgateLib/DisplayLib/SurfaceState.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/DisplayLib/SurfaceState.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -1,140 +1,265 @@ -using System; +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (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.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2009. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; using System.Collections.Generic; using System.Linq; using System.Text; using AgateLib.Geometry; +using AgateLib.DisplayLib.Cache; namespace AgateLib.DisplayLib { - public class SurfaceState - { - private double mScaleWidth = 1.0; - private double mScaleHeight = 1.0; + public class SurfaceState + { + private SurfaceStateCache mCache; + private double mScaleWidth = 1.0; + private double mScaleHeight = 1.0; + private OriginAlignment mAlignment = OriginAlignment.TopLeft; + private double mRotation = 0; + private OriginAlignment mRotationSpot = OriginAlignment.Center; + private PointF mRotationCenter = new PointF(); + private Gradient mGradient = new Gradient(Color.White); + private DrawInstanceList mDrawInstances = new DrawInstanceList(); - private OriginAlignment mAlignment = OriginAlignment.TopLeft; - private double mRotation = 0; - private OriginAlignment mRotationSpot = OriginAlignment.Center; - private Gradient mGradient = new Gradient(Color.White); + public SurfaceState() + { + mDrawInstances.Add(new SurfaceDrawInstance()); + } + public SurfaceState Clone() + { + SurfaceState retval = new SurfaceState(); + CopyTo(retval, true); - public SurfaceState Clone() - { - SurfaceState retval = new SurfaceState - { - ScaleWidth = mScaleWidth, - ScaleHeight = mScaleHeight, - DisplayAlignment = mAlignment, - RotationAngle = mRotation, - RotationCenter = mRotationSpot, - ColorGradient = mGradient, - }; + return retval; + } + public void CopyTo(SurfaceState target, bool copyDrawInstances) + { + target.ScaleWidth = mScaleWidth; + target.ScaleHeight = mScaleHeight; + target.DisplayAlignment = mAlignment; + target.RotationAngle = mRotation; + target.RotationCenter = mRotationSpot; + target.ColorGradient = mGradient; - return retval; - } + if (copyDrawInstances) + { + target.mDrawInstances.Clear(); + target.mDrawInstances.Capacity = mDrawInstances.Count; + target.mDrawInstances.AddRange(mDrawInstances); + } + } - #region --- Surface properties --- + /// <summary> + /// Location the surface will be drawn. + /// </summary> + public DrawInstanceList DrawInstances + { + get { return mDrawInstances; } + set { mDrawInstances = value; } + } - /// <summary> - /// Alpha value for displaying this surface. - /// Valid values range from 0.0 (completely transparent) to 1.0 (completely opaque). - /// Internally stored as a byte, so granularity is only 1/255.0. - /// If a gradient is used, getting this property returns the alpha value for the top left - /// corner of the gradient. - /// </summary> - public double Alpha - { - get { return Color.A / 255.0; } - set - { - mGradient.SetAlpha(value); - } - } - /// <summary> - /// Gets or sets the rotation angle in radians. - /// Positive angles indicate rotation in the Counter-Clockwise direction. - /// </summary> - public virtual double RotationAngle - { - get { return mRotation; } - set { mRotation = value % (2 * Math.PI); } - } - /// <summary> - /// Gets or sets the rotation angle in degrees. - /// Positive angles indicate rotation in the Counter-Clockwise direction. - /// </summary> - public double RotationAngleDegrees - { - get { return RotationAngle * 180.0 / Math.PI; } - set { RotationAngle = value * Math.PI / 180.0; } - } - /// <summary> - /// Gets or sets the point on the surface which is used to rotate around. - /// </summary> - public virtual OriginAlignment RotationCenter - { - get { return mRotationSpot; } - set { mRotationSpot = value; } - } - /// <summary> - /// Gets or sets the point where the surface is aligned to when drawn. - /// </summary> - public virtual OriginAlignment DisplayAlignment - { - get { return mAlignment; } - set { mAlignment = value; } - } + /// <summary> + /// Alpha value for displaying this surface. + /// Valid values range from 0.0 (completely transparent) to 1.0 (completely opaque). + /// Internally stored as a byte, so granularity is only 1/255.0. + /// If a gradient is used, getting this property returns the alpha value for the top left + /// corner of the gradient. + /// </summary> + public double Alpha + { + get { return Color.A / 255.0; } + set + { + mGradient.SetAlpha(value); + } + } + /// <summary> + /// Gets or sets the rotation angle in radians. + /// Positive angles indicate rotation in the Counter-Clockwise direction. + /// </summary> + public double RotationAngle + { + get { return mRotation; } + set { mRotation = value % (2 * Math.PI); } + } + /// <summary> + /// Gets or sets the rotation angle in degrees. + /// Positive angles indicate rotation in the Counter-Clockwise direction. + /// </summary> + public double RotationAngleDegrees + { + get { return RotationAngle * 180.0 / Math.PI; } + set { RotationAngle = value * Math.PI / 180.0; } + } + /// <summary> + /// Gets or sets the point on the surface which is used to rotate around. + /// </summary> + public OriginAlignment RotationCenter + { + get { return mRotationSpot; } + set { mRotationSpot = value; } + } + /// <summary> + /// Specifies the point in screen space the surface is rotated around. This value + /// is only used if RotationCenter is set to OriginAlignment.Specified. Setting this + /// value will set the RotationCenter to OriginAlignment.Specified. + /// </summary> + public PointF RotationCenterLocation + { + get { return mRotationCenter; } + set + { + mRotationSpot = OriginAlignment.Specified; + mRotationCenter = value; + } + } + /// <summary> + /// Gets or sets the point where the surface is aligned to when drawn. + /// </summary> + public OriginAlignment DisplayAlignment + { + get { return mAlignment; } + set { mAlignment = value; } + } - /// <summary> - /// Gets or sets the amount the width is scaled when this surface is drawn. - /// 1.0 is no scaling. - /// Scale values can be negative, this causes the surface to be mirrored - /// in that direction. This does not affect how the surface is aligned; - /// eg. if DisplayAlignment is top-left and ScaleWidth < 0, the surface - /// will still be drawn to the right of the point supplied to Draw(Point). - /// </summary> - public double ScaleWidth - { - get { return mScaleWidth; } - set { mScaleWidth = value; } - } - /// <summary> - /// Gets or sets the amount the height is scaled when this surface is drawn. - /// 1.0 is no scaling. - /// </summary> - public double ScaleHeight - { - get { return mScaleHeight; } - set { mScaleHeight = value; } - } + /// <summary> + /// Gets or sets the amount the width is scaled when this surface is drawn. + /// 1.0 is no scaling. + /// Scale values can be negative, this causes the surface to be mirrored + /// in that direction. This does not affect how the surface is aligned; + /// eg. if DisplayAlignment is top-left and ScaleWidth < 0, the surface + /// will still be drawn to the right of the point supplied to Draw(Point). + /// </summary> + public double ScaleWidth + { + get { return mScaleWidth; } + set { mScaleWidth = value; } + } + /// <summary> + /// Gets or sets the amount the height is scaled when this surface is drawn. + /// 1.0 is no scaling. + /// </summary> + public double ScaleHeight + { + get { return mScaleHeight; } + set { mScaleHeight = value; } + } - /// <summary> - /// Gets or sets the multiplicative color for this surface. - /// Setting this is equivalent to setting the ColorGradient property - /// with a gradient with the same color in all corners. If a gradient - /// is being used, getting this property returns the top-left color in the gradient. - /// </summary> - public virtual Color Color - { - get { return mGradient.TopLeft; } - set { mGradient = new Gradient(value); } - } - /// <summary> - /// Gets or sets the gradient for this surface. - /// </summary> - public virtual Gradient ColorGradient - { - get { return mGradient; } - set { mGradient = value; } - } + /// <summary> + /// Gets or sets the multiplicative color for this surface. + /// Setting this is equivalent to setting the ColorGradient property + /// with a gradient with the same color in all corners. If a gradient + /// is being used, getting this property returns the top-left color in the gradient. + /// </summary> + public Color Color + { + get { return mGradient.TopLeft; } + set { mGradient = new Gradient(value); } + } + /// <summary> + /// Gets or sets the gradient for this surface. + /// </summary> + public Gradient ColorGradient + { + get { return mGradient; } + set { mGradient = value; } + } - /// <summary> - /// Increments the rotation angle of this surface. Value supplied is in degrees. - /// </summary> - /// <param name="degrees"></param> - public void IncrementRotationAngleDegrees(double degrees) - { - mRotation += degrees * Math.PI / 180.0; - } + /// <summary> + /// Increments the rotation angle of this surface. Value supplied is in degrees. + /// </summary> + /// <param name="degrees"></param> + public void IncrementRotationAngleDegrees(double degrees) + { + mRotation += degrees * Math.PI / 180.0; + } - #endregion - } + /// <summary> + /// The cache is used by the display implementation to store data to improve performance + /// when drawing with this state object. Do not set this value unless you are writing + /// a driver or otherwise know what you are doing. + /// </summary> + public SurfaceStateCache Cache + { + get { return mCache; } + set { mCache = value; } + } + + public SizeF GetDisplaySize(Size surfaceSize) + { + return new SizeF( + (float)ScaleWidth * surfaceSize.Width, + (float)ScaleHeight * surfaceSize.Height); + } + public PointF GetRotationCenter(SizeF displaySize) + { + if (RotationCenter == OriginAlignment.Specified) + return RotationCenterLocation; + else + return Origin.CalcF(RotationCenter, displaySize); + } + } + + public struct SurfaceDrawInstance + { + public SurfaceDrawInstance(PointF location) : this() + { + DestLocation = location; + } + public SurfaceDrawInstance(PointF location, Rectangle sourceRect) : this() + { + DestLocation = location; + SourceRect = sourceRect; + } + + public PointF DestLocation { get; set; } + /// <summary> + /// If SourceRect is empty (all values are zero), then it is ignored. + /// </summary> + public Rectangle SourceRect { get; set; } + + /// <summary> + /// Gets the actual source rectangle that should be used when drawing from the surface. + /// </summary> + /// <param name="surfaceSize"></param> + /// <returns></returns> + public Rectangle GetSourceRect(Size surfaceSize) + { + if (SourceRect == Rectangle.Empty) + return new Rectangle(Point.Empty, surfaceSize); + else + return SourceRect; + } + } + + public class DrawInstanceList : List<SurfaceDrawInstance> + { + public void SetCount(int newCount) + { + if (Count == newCount) + return; + + while (Count < newCount) + Add(new SurfaceDrawInstance()); + + if (Count > newCount) + RemoveRange(newCount, Count - newCount); + } + } } Modified: branches/font/AgateLib/DisplayLib/TextLayout.cs =================================================================== --- branches/font/AgateLib/DisplayLib/TextLayout.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/DisplayLib/TextLayout.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -6,69 +6,82 @@ namespace AgateLib.DisplayLib { - public class TextLayout : List<LayoutItem> - { - public void DrawAll() - { - foreach (LayoutItem item in this) - { - item.Draw(); - } - } + public class TextLayout : List<LayoutItem> + { + public void DrawAll() + { + foreach (LayoutItem item in this) + { + item.Draw(); + } + } - public void Translate(Point dist) - { - foreach (LayoutItem item in this) - { - item.Location = new Point( - item.Location.X + dist.X, - item.Location.Y + dist.Y); - } - } - } + public void Translate(Point dist) + { + foreach (LayoutItem item in this) + { + item.Location = new PointF( + item.Location.X + dist.X, + item.Location.Y + dist.Y); + } + } + } - public abstract class LayoutItem - { - Point mLocation; + public abstract class LayoutItem + { + PointF mLocation; - public abstract void Draw(); - public Point Location - { - get { return mLocation; } - set { mLocation = value; } - } - public int X - { - get { return mLocation.X; } - set { mLocation.X = value; } - } - public int Y - { - get { return mLocation.Y; } - set { mLocation.Y = value; } - } - public int LineIndex { get; set; } - } + public abstract void Draw(); + public virtual PointF Location + { + get { return mLocation; } + set { mLocation = value; } + } + public float X + { + get { return mLocation.X; } + set { mLocation.X = value; } + } + public float Y + { + get { return mLocation.Y; } + set { mLocation.Y = value; } + } + public int LineIndex { get; set; } + } - public class LayoutText : LayoutItem - { - public FontSurface Font { get; set; } - public string Text { get; set; } - - public override void Draw() - { - Font.DrawText(Location, Text); - } - } - public class LayoutSurface : LayoutItem - { - public ISurface Surface { get; set; } - public SurfaceState State { get; set; } + public class LayoutText : LayoutItem + { + public FontSurface Font { get; set; } + public FontState State { get; set; } + public string Text + { + get { return State.Text; } + set { State.Text = value; } + } + public override PointF Location + { + get { return State.Location; } + set { State.Location = value; } + } + public override void Draw() + { + Font.DrawText(State); + } + } + public class LayoutSurface : LayoutItem + { + public ISurface Surface { get; set; } + public SurfaceState State { get; set; } - public override void Draw() - { - this.Surface.Draw(Location, State); - Display.DrawRect(new Rectangle(Location, Surface.DisplaySize), Color.White); - } - } + public static bool DebugRects; + + public override void Draw() + { + this.Surface.Draw(State); + + if (DebugRects) + Display.DrawRect(new Rectangle(Point.Round(Location), Surface.DisplaySize), Color.Blue); + } + } } Modified: branches/font/AgateLib/Geometry/Rectangle.cs =================================================================== --- branches/font/AgateLib/Geometry/Rectangle.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/Geometry/Rectangle.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -397,5 +397,20 @@ return true; } - } + + /// <summary> + /// Returns a rectangle structure with all the values (location, size) from the + /// floating point rectangle structure rounded to the nearest integer. + /// </summary> + /// <param name="rect"></param> + /// <returns></returns> + public static Rectangle Round(RectangleF rect) + { + return new Rectangle( + (int)Math.Round(rect.X), + (int)Math.Round(rect.Y), + (int)Math.Round(rect.Width), + (int)Math.Round(rect.Height)); + } + } } \ No newline at end of file Modified: branches/font/AgateLib/ImplementationBase/SurfaceImpl.cs =================================================================== --- branches/font/AgateLib/ImplementationBase/SurfaceImpl.cs 2009-04-22 06:15:32 UTC (rev 908) +++ branches/font/AgateLib/ImplementationBase/SurfaceImpl.cs 2009-04-25 06:57:02 UTC (rev 909) @@ -37,8 +37,6 @@ private int mTesselate = 1; - private SurfaceState mState = new SurfaceState(); - #endregion #region --- Creation / Destruction --- @@ -58,245 +56,16 @@ #region --- Drawing the surface to the screen --- - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method should Draw the surface to the screen, ignoring - /// all scaling, rotation and alignment state data. - /// Color and Alpha are still to be used. - /// - /// It is recommended to override this method, as the base class - /// implementation saves the state, draws, then restores the state. - /// </summary> - /// <param name="destRect"></param> - public virtual void Draw(Rectangle destRect) - { - // save the state - Size displaySize = DisplaySize; - OriginAlignment displayAlignment = DisplayAlignment ; - double angle = RotationAngle; + public virtual void Draw(SurfaceState state) + { + throw new NotImplementedException(); + } - // reset the state - DisplaySize = destRect.Size; - DisplayAlignment = OriginAlignment.TopLeft; - RotationAngle = 0; + #endregion - // draw with no state values - Draw(destRect.Location); + #region --- Surface Data Manipulations --- - // restore the state. - RotationAngle = angle; - DisplayAlignment = displayAlignment; - DisplaySize = displaySize; - } - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method should draw a portion of the surface to the screen, ignoring - /// all scaling, rotation and alignment state data. - /// Color and Alpha are still to be used. - /// - /// This method automatically converts Rectangle structures into RectangleF - /// structures and calls the Draw overload which takes them. This can be - /// overriden if the implementation is more natural to use integral values. - /// </summary> - /// <param name="srcRect"></param> - /// <param name="destRect"></param> - public virtual void Draw(Rectangle srcRect, Rectangle destRect) - { - Draw(new RectangleF(srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height), - new RectangleF(destRect.X, destRect.Y, destRect.Width, destRect.Height)); - } - - - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method should draw a portion of the surface to the screen, using - /// all scaling, rotation and alignment state data. - /// - /// This method must be overriden. - /// </summary> - /// <param name="x"></param> - /// <param name="y"></param> - /// <param name="srcRect"></param> - /// <param name="rotationCenterX"></param> - /// <param name="rotationCenterY"></param> - public abstract void Draw(float x, float y, Rectangle srcRect, float rotationCenterX, float rotationCenterY); - - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method should draw a portion of the surface to the screen, ignoring - /// all scaling, rotation and alignment state data. - /// Color and Alpha are still to be used. - /// - /// This method must be overriden. - /// </summary> - /// <param name="srcRect"></param> - /// <param name="destRect"></param> - public abstract void Draw(RectangleF srcRect, RectangleF destRect); - - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method should draw the surface to the screen, using all the - /// scaling, rotation, etc. state data in the stored Surface object. - /// The base class method calls Draw(PointF). - /// - /// This method may be overriden, if it is convenient to provide an - /// alternate implementation which takes integral drawing values. - /// </summary> - /// <param name="destPt"></param> - public virtual void Draw(Point destPt) - { - Draw((float)destPt.X, (float)destPt.Y); - } - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method should draw the surface to the screen, using all the - /// scaling, rotation, etc. state data in the stored Surface object. - /// - /// This method must be overriden. - /// </summary> - /// <param name="destX"></param> - /// <param name="destY"></param> - public abstract void Draw(float destX, float destY); - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method should draw the surface to the screen, using all the - /// scaling, rotation, etc. state data in the stored Surface object, - /// except for RotationCenter. Use the point passed for the center - /// of rotation. - /// - /// This method must be overriden. - /// </summary> - /// <param name="destX"></param> - /// <param name="destY"></param> - /// <param name="rotationCenterX"></param> - /// <param name="rotationCenterY"></param> - public abstract void Draw(float destX, float destY, float rotationCenterX, float rotationCenterY); - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method should draw the surface to the screen, with the same result - /// as if Draw was called once for each Point passed. - /// </summary> - /// <param name="destPts"></param> - public virtual void DrawPoints(Point[] destPts) - { - for (int i = 0; i < destPts.Length; i++) - Draw(destPts[i]); - } - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method draws the surface at (0, 0). The base class implementation - /// simply calls Draw(Point.Empty). - /// </summary> - public virtual void Draw() { Draw(Point.Empty); } - - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method should draw the surface to the screen, with the same result - /// as if Draw was called once for each src and dest rect pairs. - /// It should be overridden, to minimize calls across managed/unmanaged boundaries. - /// </summary> - /// <param name="srcRects"></param> - /// <param name="destRects"></param> - /// <param name="start">Element in the array to start with.</param> - /// <param name="length">Number of elements in the arrays to use.</param> - public virtual void DrawRects(Rectangle[] srcRects, Rectangle[] destRects, int start, int length) - { - for (int i = 0; i < length; i++) - { - Draw(srcRects[i + start], destRects[i + start]); - } - } - - /// <summary> - /// For function use, see documentation of Surface. - /// - /// Info for developers: - /// This method should draw the surface to the screen, with the same result - /// as if Draw was called once for each src and dest rect pairs. - /// It should be overridden, to minimize calls across managed/unmanaged boundaries. - /// </summary> - /// <param name="srcRects"></param> - /// <param name="destRects"></param> - /// <param name="start">Element in the arrays to start with.</param> - /// <param name="length">Number of elements in the arrays to use.</param> - public virtual void DrawRects(RectangleF[] srcRects, RectangleF[] destRects, int start, int length) - { - for (int i = 0; i < length; i++) - { - Draw(srcRects[i + start], destRects[i + start]); - } - } - #endregion - #region --- Queueing rects to draw to the screen --- - - private Queue<Rectangle> srcRectList; - private Queue<Rectangle> destRectList; - - /// <summary> - /// Sets up data structures to queue rects to draw to the screen. - /// </summary> - public void BeginQueueRects() - { - BeginQueueRects(100); - } - /// <summary> - /// Sets up data structures to queue rects to draw to the screen. - /// </summary> - /// <param name="guessCount">A good guess for how many rects you are going to draw.</param> - public void BeginQueueRects(int guessCount) - { - srcRectList = new Queue<Rectangle>(guessCount); - destRectList = new Queue<Rectangle>(guessCount); - } - /// <summary> - /// Adds a src/dest rectangle pair to the queue. Make sure to call - /// BeginQueueRects first. - /// </summary> - /// <param name="src_rect"></param> - /// <param name="dest_rect"></param> - public void QueueRect(Rectangle src_rect, Rectangle dest_rect) - { - srcRectList.Enqueue(src_rect); - destRectList.Enqueue(dest_rect); - } - /// <summary> - /// Ends adding rects to the queue and draws all of them to the screen. - /// </summary> - public void EndQueueRects() - { - Rectangle[] srcRects = srcRectList.ToArray(); - Rectangle[] destRects = destRectList.ToArray(); - - DrawRects(srcRects, destRects, 0, srcRects.Length); - - srcRectList = null; - destRectList = null; - } - - #endregion - #region --- Surface Data Manipulations --- - - /// <summary> + /// <summary> /// Saves the surface data to the specified file in the specified format. /// </summary> /// <param name="filename"></param> @@ -361,16 +130,8 @@ #region --- Surface properties --- + /// <summary> - /// Gets or sets the state of the surface. - /// </summary> - public SurfaceState State - { - get { return mState; } - set { mState = value; } - } - - /// <summary> /// Gets or sets how many squares the surface should be broken into when drawn. /// </summary> public int TesselateFactor @@ -403,180 +164,6 @@ } /// <summary> - /// Get or sets the width of the surface in pixels when it will be displayed on screen. - /// </summary> - public int DisplayWidth - { - get { return (int)(mState.ScaleWidth * SurfaceWidth); } - set { ScaleWidth = value / (double)SurfaceWidth; } - } - /// <summary> - /// Gets or sets the height of the surface in pixels when it is displayed on screen. - /// </summary> - public int DisplayHeight - { - get { return (int)(mState.ScaleHeight * SurfaceHeight); } - set { ScaleHeight = value / (double)SurfaceHeight; } - } - /// <summary> - /// Gets or sets the Size of the area used by this surface when displayed on screen. - /// </summary> - public Size DisplaySize - { - get - { - Size sz = new Size(DisplayWidth, DisplayHeight); - - return sz; - } - set - { - DisplayWidth = value.Width; - DisplayHeight = value.Height; - } - } - - /// <summary> - /// Alpha value for dis... [truncated message content] |
From: <ka...@us...> - 2009-04-22 06:15:32
|
Revision: 908 http://agate.svn.sourceforge.net/agate/?rev=908&view=rev Author: kanato Date: 2009-04-22 06:15:32 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Override OnEnabledChanged in textbox to set dirty flag. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/TextBox.cs Modified: branches/gui-3.2/AgateLib/Gui/TextBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-04-22 06:14:56 UTC (rev 907) +++ branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-04-22 06:15:32 UTC (rev 908) @@ -148,10 +148,15 @@ { IPTime = Timing.TotalMilliseconds; } - //public bool MultiLine { get; set; } internal double IPTime { get; set; } public bool MultiLine { get; set; } + + protected internal override void OnEnabledChanged() + { + base.OnEnabledChanged(); + SetDirty(); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-22 06:14:57
|
Revision: 907 http://agate.svn.sourceforge.net/agate/?rev=907&view=rev Author: kanato Date: 2009-04-22 06:14:56 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Turn off alpha blending when writing to cached textbox surface. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-04-22 06:14:12 UTC (rev 906) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-04-22 06:14:56 UTC (rev 907) @@ -148,14 +148,21 @@ IRenderTarget old = Display.RenderTarget; Display.RenderTarget = c.TextBoxSurface; + Display.EnableAlphaBlend = false; Display.BeginFrame(); Display.Clear(Color.FromArgb(0,0,0,0)); + if (textBox.Enabled) + Scheme.WidgetFont.Color = Scheme.FontColor; + else + Scheme.WidgetFont.Color = Scheme.FontColorDisabled; + Scheme.WidgetFont.DrawText(-c.Origin.X, -c.Origin.Y, textBox.Text); Display.EndFrame(); Display.RenderTarget = old; + Display.EnableAlphaBlend = true; c.Dirty = false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-22 06:14:14
|
Revision: 906 http://agate.svn.sourceforge.net/agate/?rev=906&view=rev Author: kanato Date: 2009-04-22 06:14:12 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Add space down to activate button with focus. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/Button.cs Modified: branches/gui-3.2/AgateLib/Gui/Button.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Button.cs 2009-04-22 06:13:29 UTC (rev 905) +++ branches/gui-3.2/AgateLib/Gui/Button.cs 2009-04-22 06:14:12 UTC (rev 906) @@ -23,7 +23,7 @@ } internal bool DrawActivated { - get { return mouseDownIn && MouseIn; } + get { return mouseDownIn && MouseIn || spaceDownFocus; } } internal bool IsDefaultButton { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-22 06:13:30
|
Revision: 905 http://agate.svn.sourceforge.net/agate/?rev=905&view=rev Author: kanato Date: 2009-04-22 06:13:29 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Add OnEnabledChanged method. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/Widget.cs Modified: branches/gui-3.2/AgateLib/Gui/Widget.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Widget.cs 2009-04-22 06:12:30 UTC (rev 904) +++ branches/gui-3.2/AgateLib/Gui/Widget.cs 2009-04-22 06:13:29 UTC (rev 905) @@ -148,7 +148,11 @@ public bool Enabled { get { return mEnabled; } - set { mEnabled = value; } + set + { + mEnabled = value; + OnEnabledChanged(); + } } public Point Location @@ -386,6 +390,8 @@ protected internal virtual void OnMouseEnter() { } protected internal virtual void OnMouseLeave() { } + protected internal virtual void OnEnabledChanged() { } + public bool ContainsScreenPoint(Point screenMousePoint) { return new Rectangle(ScreenLocation, Size).Contains(screenMousePoint); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-22 06:12:31
|
Revision: 904 http://agate.svn.sourceforge.net/agate/?rev=904&view=rev Author: kanato Date: 2009-04-22 06:12:30 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Add Display.EnableAlphaBlend method to get proper font appearance in text boxes. Modified Paths: -------------- branches/gui-3.2/AgateLib/DisplayLib/Display.cs branches/gui-3.2/AgateLib/ImplementationBase/DisplayImpl.cs branches/gui-3.2/Drivers/AgateDrawing/Drawing_Display.cs branches/gui-3.2/Drivers/AgateMDX/DrawBuffer.cs branches/gui-3.2/Drivers/AgateMDX/MDX1_Display.cs branches/gui-3.2/Drivers/AgateOTK/GL_Display.cs Modified: branches/gui-3.2/AgateLib/DisplayLib/Display.cs =================================================================== --- branches/gui-3.2/AgateLib/DisplayLib/Display.cs 2009-04-22 05:12:24 UTC (rev 903) +++ branches/gui-3.2/AgateLib/DisplayLib/Display.cs 2009-04-22 06:12:30 UTC (rev 904) @@ -378,8 +378,12 @@ return impl.EnumScreenModes(); } + internal static bool EnableAlphaBlend + { + get { return impl.EnableAlphaBlend; } + set { impl.EnableAlphaBlend = value; } + } - /// <summary> /// Event fired when PackAllSurfacesEvent /// </summary> Modified: branches/gui-3.2/AgateLib/ImplementationBase/DisplayImpl.cs =================================================================== --- branches/gui-3.2/AgateLib/ImplementationBase/DisplayImpl.cs 2009-04-22 05:12:24 UTC (rev 903) +++ branches/gui-3.2/AgateLib/ImplementationBase/DisplayImpl.cs 2009-04-22 06:12:30 UTC (rev 904) @@ -69,6 +69,11 @@ public abstract PixelFormat DefaultSurfaceFormat { get; } /// <summary> + /// Hack to make fonts in GUI work better. + /// </summary> + internal protected abstract bool EnableAlphaBlend { get; set; } + + /// <summary> /// Event raised when the current render target is changed. /// </summary> /// <param name="oldRenderTarget"></param> Modified: branches/gui-3.2/Drivers/AgateDrawing/Drawing_Display.cs =================================================================== --- branches/gui-3.2/Drivers/AgateDrawing/Drawing_Display.cs 2009-04-22 05:12:24 UTC (rev 903) +++ branches/gui-3.2/Drivers/AgateDrawing/Drawing_Display.cs 2009-04-22 06:12:30 UTC (rev 904) @@ -45,6 +45,8 @@ private Stack<Geometry.Rectangle> mClipRects = new Stack<Geometry.Rectangle>(); private Geometry.Rectangle mCurrentClipRect; + bool mEnableAlphaBlend = true; + #endregion #region --- Events and Event Handlers --- @@ -201,6 +203,7 @@ protected override void OnBeginFrame() { mGraphics = Graphics.FromImage(mRenderTarget.BackBuffer); + SetAlphaBlend(); } protected override void OnEndFrame() { @@ -240,6 +243,28 @@ #endregion + protected override bool EnableAlphaBlend + { + get + { + return mEnableAlphaBlend; + } + set + { + FlushDrawBuffer(); + mEnableAlphaBlend = value; + + SetAlphaBlend(); + } + } + private void SetAlphaBlend() + { + if (EnableAlphaBlend) + mGraphics.CompositingMode = CompositingMode.SourceOver; + else + mGraphics.CompositingMode = CompositingMode.SourceCopy; + } + protected override void ProcessEvents() { System.Windows.Forms.Application.DoEvents(); Modified: branches/gui-3.2/Drivers/AgateMDX/DrawBuffer.cs =================================================================== --- branches/gui-3.2/Drivers/AgateMDX/DrawBuffer.cs 2009-04-22 05:12:24 UTC (rev 903) +++ branches/gui-3.2/Drivers/AgateMDX/DrawBuffer.cs 2009-04-22 06:12:30 UTC (rev 904) @@ -98,7 +98,6 @@ return; mDevice.SetDeviceStateTexture(mTexture); - mDevice.AlphaBlend = mAlphaBlend; mDevice.VertexFormat = PositionColorNormalTexture.Format; try Modified: branches/gui-3.2/Drivers/AgateMDX/MDX1_Display.cs =================================================================== --- branches/gui-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-04-22 05:12:24 UTC (rev 903) +++ branches/gui-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-04-22 06:12:30 UTC (rev 904) @@ -837,5 +837,18 @@ } #endregion + + protected override bool EnableAlphaBlend + { + get + { + return mDevice.AlphaBlend; + } + set + { + FlushDrawBuffer(); + mDevice.AlphaBlend = value; + } + } } } \ No newline at end of file Modified: branches/gui-3.2/Drivers/AgateOTK/GL_Display.cs =================================================================== --- branches/gui-3.2/Drivers/AgateOTK/GL_Display.cs 2009-04-22 05:12:24 UTC (rev 903) +++ branches/gui-3.2/Drivers/AgateOTK/GL_Display.cs 2009-04-22 06:12:30 UTC (rev 904) @@ -44,6 +44,7 @@ private int mMaxLightsUsed = 0; private bool mSupportsFramebuffer; private bool mNonPowerOf2Textures; + bool mEnableAlphaBlend = true; public bool NonPowerOf2Textures { @@ -135,6 +136,7 @@ protected override void OnBeginFrame() { mRenderTarget.BeginRender(); + SetAlphaBlend(); } protected override void OnEndFrame() @@ -197,7 +199,7 @@ { mState.DrawBuffer.Flush(); - GL.ClearColor(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, 1.0f); + GL.ClearColor(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f); GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit); } @@ -610,5 +612,27 @@ #endregion #endregion + + protected override bool EnableAlphaBlend + { + get + { + return mEnableAlphaBlend; + } + set + { + mEnableAlphaBlend = value; + FlushDrawBuffer(); + SetAlphaBlend(); + } + } + + private void SetAlphaBlend() + { + if (mEnableAlphaBlend) + GL.Enable(EnableCap.Blend); + else + GL.Disable(EnableCap.Blend); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-22 05:12:30
|
Revision: 903 http://agate.svn.sourceforge.net/agate/?rev=903&view=rev Author: kanato Date: 2009-04-22 05:12:24 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Add AngleBetween and DistanceBetween for vectors. Modified Paths: -------------- trunk/AgateLib/Geometry/Vector2.cs trunk/AgateLib/Geometry/Vector3.cs Modified: trunk/AgateLib/Geometry/Vector2.cs =================================================================== --- trunk/AgateLib/Geometry/Vector2.cs 2009-04-21 06:23:40 UTC (rev 902) +++ trunk/AgateLib/Geometry/Vector2.cs 2009-04-22 05:12:24 UTC (rev 903) @@ -184,5 +184,27 @@ { return a.X * b.X + a.Y * b.Y; } + + /// <summary> + /// Computes and returns the angle between two vectors. + /// </summary> + /// <param name="a"></param> + /// <param name="b"></param> + /// <returns></returns> + public static float AngleBetween(Vector2 a, Vector2 b) + { + return (float)Math.Acos(DotProduct(a, b) / (a.Magnitude * b.Magnitude)); + } + + /// <summary> + /// Computes and returns the distance between two points. + /// </summary> + /// <param name="a"></param> + /// <param name="b"></param> + /// <returns></returns> + public static float DistanceBetween(Vector2 a, Vector2 b) + { + return (a - b).Magnitude; + } } } Modified: trunk/AgateLib/Geometry/Vector3.cs =================================================================== --- trunk/AgateLib/Geometry/Vector3.cs 2009-04-21 06:23:40 UTC (rev 902) +++ trunk/AgateLib/Geometry/Vector3.cs 2009-04-22 05:12:24 UTC (rev 903) @@ -207,5 +207,27 @@ a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X); } + + /// <summary> + /// Computes and returns the angle between two vectors. + /// </summary> + /// <param name="a"></param> + /// <param name="b"></param> + /// <returns></returns> + public static float AngleBetween(Vector3 a, Vector3 b) + { + return (float)Math.Acos(DotProduct(a, b) / (a.Magnitude * b.Magnitude)); + } + + /// <summary> + /// Computes and returns the distance between two points. + /// </summary> + /// <param name="a"></param> + /// <param name="b"></param> + /// <returns></returns> + public static float DistanceBetween(Vector3 a, Vector3 b) + { + return (a - b).Magnitude; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-21 06:23:54
|
Revision: 902 http://agate.svn.sourceforge.net/agate/?rev=902&view=rev Author: kanato Date: 2009-04-21 06:23:40 +0000 (Tue, 21 Apr 2009) Log Message: ----------- Add return as a control key. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/GuiRoot.cs branches/gui-3.2/AgateLib/Gui/TextBox.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs Modified: branches/gui-3.2/AgateLib/Gui/GuiRoot.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/GuiRoot.cs 2009-04-21 06:23:09 UTC (rev 901) +++ branches/gui-3.2/AgateLib/Gui/GuiRoot.cs 2009-04-21 06:23:40 UTC (rev 902) @@ -380,19 +380,8 @@ private bool WidgetAcceptControlKey(ref Widget widget, InputEventArgs e) { return widget.AcceptInputKey(e.KeyCode); - - //while (widget.AcceptInputKey(e.KeyCode) == false) - //{ - // widget = widget.Parent; - - // if (widget == this) - // return false; - //} - - //return true; } - private void ProcessControlKey(InputEventArgs e) { switch (e.KeyCode) @@ -412,9 +401,18 @@ case KeyCode.Right: MoveFocus(Direction.Right); break; + + case KeyCode.Return: + ClickDefaultButton(); + break; } } + private void ClickDefaultButton() + { + // TODO: implmement this method + } + private void MoveFocus(Direction direction) { if (focusControl == null) @@ -451,7 +449,6 @@ return; SetFocusControl(newFocus, direction, WidgetPoint(focusControl)); - } private Point WidgetPoint(Widget focusControl) @@ -472,6 +469,7 @@ case KeyCode.Left: case KeyCode.Down: case KeyCode.Right: + case KeyCode.Return: case KeyCode.Tab: return widget.AcceptInputKey(e.KeyCode); } @@ -487,6 +485,7 @@ case KeyCode.Left: case KeyCode.Down: case KeyCode.Right: + case KeyCode.Return: case KeyCode.Tab: return true; } Modified: branches/gui-3.2/AgateLib/Gui/TextBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-04-21 06:23:09 UTC (rev 901) +++ branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-04-21 06:23:40 UTC (rev 902) @@ -30,6 +30,16 @@ switch (e.KeyCode) { + case AgateLib.InputLib.KeyCode.Shift: + case AgateLib.InputLib.KeyCode.ShiftLeft: + case AgateLib.InputLib.KeyCode.ShiftRight: + case AgateLib.InputLib.KeyCode.Control: + case AgateLib.InputLib.KeyCode.ControlLeft: + case AgateLib.InputLib.KeyCode.ControlRight: + case AgateLib.InputLib.KeyCode.Alt: + case AgateLib.InputLib.KeyCode.CapsLock: + return; + case AgateLib.InputLib.KeyCode.Left: InsertionPoint--; break; @@ -88,7 +98,6 @@ SetDirty(); } - protected internal override bool AcceptInputKey(AgateLib.InputLib.KeyCode keyCode) { switch (keyCode) @@ -96,6 +105,14 @@ case AgateLib.InputLib.KeyCode.Left: case AgateLib.InputLib.KeyCode.Right: return true; + case AgateLib.InputLib.KeyCode.Up: + case AgateLib.InputLib.KeyCode.Down: + case AgateLib.InputLib.KeyCode.Enter: + if (MultiLine) + return true; + else + return false; + default: return false; } @@ -135,5 +152,6 @@ internal double IPTime { get; set; } + public bool MultiLine { get; set; } } } Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-04-21 06:23:09 UTC (rev 901) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-04-21 06:23:40 UTC (rev 902) @@ -138,11 +138,11 @@ int bottom = ip.Y + Scheme.InsertionPointHeight; if (ip.Y < 0) - c.Origin.Y -= ip.Y; + c.Origin.Y += ip.Y; if (bottom > surfSize.Height) c.Origin.Y += bottom - surfSize.Height; if (ip.X < 0) - c.Origin.X -= ip.X; + c.Origin.X += ip.X; if (ip.X >= surfSize.Width) c.Origin.X += ip.X - surfSize.Width + 1; @@ -156,6 +156,8 @@ Display.EndFrame(); Display.RenderTarget = old; + + c.Dirty = false; } @@ -193,7 +195,9 @@ location.X += Scheme.TextBox.StretchRegion.X; location.Y += Scheme.TextBox.StretchRegion.Y; - if (textBox.Cache == null) + TextBoxCache c = (TextBoxCache)textBox.Cache; + + if (c == null || c.TextBoxSurface == null) { Scheme.WidgetFont.DrawText( location, @@ -201,8 +205,6 @@ } else { - TextBoxCache c = (TextBoxCache)textBox.Cache; - c.TextBoxSurface.Draw(location); } @@ -227,16 +229,26 @@ Size sz = Scheme.WidgetFont.StringDisplaySize( textBox.Text.Substring(0, textBox.InsertionPoint)); + int lines = 0; + if (textBox.MultiLine) + { + for (int i = 0; i < textBox.Text.Length; i++) + { + if (textBox.Text[i] == '\n') + lines++; + } + } + Point loc = new Point( sz.Width + Scheme.TextBox.StretchRegion.X, - Scheme.TextBox.StretchRegion.Y); + lines * Scheme.WidgetFont.FontHeight + Scheme.TextBox.StretchRegion.Y); TextBoxCache c = textBox.Cache as TextBoxCache; if (c != null) { - loc.X += c.Origin.X; - loc.Y += c.Origin.Y; + loc.X -= c.Origin.X; + loc.Y -= c.Origin.Y; } loc.Y++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-21 06:23:13
|
Revision: 901 http://agate.svn.sourceforge.net/agate/?rev=901&view=rev Author: kanato Date: 2009-04-21 06:23:09 +0000 (Tue, 21 Apr 2009) Log Message: ----------- Implement space bar activates button. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/Button.cs Modified: branches/gui-3.2/AgateLib/Gui/Button.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Button.cs 2009-04-21 06:22:40 UTC (rev 900) +++ branches/gui-3.2/AgateLib/Gui/Button.cs 2009-04-21 06:23:09 UTC (rev 901) @@ -12,6 +12,7 @@ public Button(string text) { Name = text; Text = text; } bool mouseDownIn = false; + bool spaceDownFocus = false; public override bool CanHaveFocus { @@ -37,6 +38,25 @@ } } + protected internal override void OnKeyDown(InputEventArgs e) + { + if (e.KeyCode == KeyCode.Space) + { + spaceDownFocus = true; + } + + base.OnKeyDown(e); + } + protected internal override void OnKeyUp(InputEventArgs e) + { + if (e.KeyCode == KeyCode.Space) + { + spaceDownFocus = false; + OnClick(); + } + + base.OnKeyUp(e); + } protected internal override void OnMouseDown(InputEventArgs e) { if (Enabled == false) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-21 06:22:50
|
Revision: 900 http://agate.svn.sourceforge.net/agate/?rev=900&view=rev Author: kanato Date: 2009-04-21 06:22:40 +0000 (Tue, 21 Apr 2009) Log Message: ----------- Add some error checking to make sure FontSurface.impl is not null. Modified Paths: -------------- branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs Modified: branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs =================================================================== --- branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-04-21 05:42:31 UTC (rev 899) +++ branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-04-21 06:22:40 UTC (rev 900) @@ -92,6 +92,8 @@ impl = Display.Impl.CreateFont(fontFamily, sizeInPoints, style); Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose); + + System.Diagnostics.Debug.Assert(impl != null); } /// <summary> /// Constructs a FontSurface object from a resource. @@ -113,6 +115,8 @@ throw new AgateResourceException(string.Format( "The resource {0} is of type {1} which cannot be used to construct a font.", resourceName, res.GetType().Name)); + + System.Diagnostics.Debug.Assert(impl != null); } /// <summary> /// Creates a bitmap font using the options passed in. The Display driver @@ -124,6 +128,8 @@ impl = Display.Impl.CreateFont(bitmapOptions); Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose); + + System.Diagnostics.Debug.Assert(impl != null); } public string FontName @@ -136,6 +142,9 @@ /// <param name="implToUse"></param> private FontSurface(FontSurfaceImpl implToUse) { + if (implToUse == null) + throw new ArgumentNullException("implToUse"); + impl = implToUse; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-21 05:42:36
|
Revision: 899 http://agate.svn.sourceforge.net/agate/?rev=899&view=rev Author: kanato Date: 2009-04-21 05:42:31 +0000 (Tue, 21 Apr 2009) Log Message: ----------- Implement textbox clipping and horizontal scrolling. Modified Paths: -------------- branches/gui-3.2/AgateLib/AgateApplication.cs branches/gui-3.2/AgateLib/Gui/GuiRoot.cs branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs branches/gui-3.2/AgateLib/Gui/TextBox.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs branches/gui-3.2/AgateLib/Gui/Widget.cs branches/gui-3.2/Tests/GuiTests/RenderGui.cs Added Paths: ----------- branches/gui-3.2/AgateLib/Gui/Cache/ branches/gui-3.2/AgateLib/Gui/Cache/WidgetCache.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Cache/ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Cache/TextBoxCache.cs Modified: branches/gui-3.2/AgateLib/AgateApplication.cs =================================================================== --- branches/gui-3.2/AgateLib/AgateApplication.cs 2009-04-21 03:21:08 UTC (rev 898) +++ branches/gui-3.2/AgateLib/AgateApplication.cs 2009-04-21 05:42:31 UTC (rev 899) @@ -115,7 +115,11 @@ { get { - mInitParams = mInitParams ?? GetAppInitParameters(); + if (mInitParams == null) + { + mInitParams = GetAppInitParameters(); + AdjustAppInitParameters(ref mInitParams); + } return mInitParams; } } @@ -280,11 +284,20 @@ /// Gets the initialization parameters. /// </summary> /// <returns></returns> + [Obsolete("Override AdjustAppInitParameters")] protected virtual AppInitParameters GetAppInitParameters() { return new AppInitParameters(); } + /// <summary> + /// Adjusts the initialization parameters. + /// </summary> + /// <param name="initParams"></param> + protected virtual void AdjustAppInitParameters(ref AppInitParameters initParams) + { + } + protected virtual Size WindowSize { get { return new Size(800, 600); } } protected virtual bool FullScreen { get { return false; } } Added: branches/gui-3.2/AgateLib/Gui/Cache/WidgetCache.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Cache/WidgetCache.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/Cache/WidgetCache.cs 2009-04-21 05:42:31 UTC (rev 899) @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui.Cache +{ + public class WidgetCache + { + public WidgetCache() + { + Dirty = true; + } + + public bool Dirty { get; set; } + } +} Modified: branches/gui-3.2/AgateLib/Gui/GuiRoot.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/GuiRoot.cs 2009-04-21 03:21:08 UTC (rev 898) +++ branches/gui-3.2/AgateLib/Gui/GuiRoot.cs 2009-04-21 05:42:31 UTC (rev 899) @@ -28,6 +28,7 @@ this.Size = Display.RenderTarget.Size; base.UpdateGui(); + ThemeEngine.Update(this); } protected internal override void RecalcSizeRange() { @@ -61,7 +62,6 @@ public void DoUpdate() { OnUpdate(); - UpdateGui(); } bool isRunning = false; Modified: branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs 2009-04-21 03:21:08 UTC (rev 898) +++ branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs 2009-04-21 05:42:31 UTC (rev 899) @@ -59,5 +59,7 @@ /// <param name="screenLocation"></param> /// <returns></returns> bool HitTest(Widget widget, Point screenLocation); + + void Update(GuiRoot guiRoot); } } Modified: branches/gui-3.2/AgateLib/Gui/TextBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-04-21 03:21:08 UTC (rev 898) +++ branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-04-21 05:42:31 UTC (rev 899) @@ -85,6 +85,8 @@ break; } + + SetDirty(); } protected internal override bool AcceptInputKey(AgateLib.InputLib.KeyCode keyCode) @@ -112,9 +114,19 @@ InsertionPoint = Text.Length; ResetIPBlinking(); + + SetDirty(); } } + private void SetDirty() + { + if (Cache == null) + return; + + Cache.Dirty = true; + } + private void ResetIPBlinking() { IPTime = Timing.TotalMilliseconds; Added: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Cache/TextBoxCache.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Cache/TextBoxCache.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Cache/TextBoxCache.cs 2009-04-21 05:42:31 UTC (rev 899) @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.DisplayLib; +using AgateLib.Geometry; + +namespace AgateLib.Gui.ThemeEngines.Mercury.Cache +{ + class TextBoxCache : Gui.Cache.WidgetCache + { + public Surface TextBoxSurface { get; set; } + + public Point Origin; + } +} Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-04-21 03:21:08 UTC (rev 898) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-04-21 05:42:31 UTC (rev 899) @@ -2,9 +2,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Diagnostics; using AgateLib.DisplayLib; using AgateLib.Geometry; -using System.Diagnostics; +using AgateLib.Gui.ThemeEngines.Mercury.Cache; namespace AgateLib.Gui.ThemeEngines.Mercury { @@ -21,6 +22,26 @@ public MercuryScheme Scheme { get; set; } public static bool DebugOutlines { get; set; } + #region --- Updates --- + + public void Update(GuiRoot guiRoot) + { + UpdateCaches(guiRoot); + } + + private void UpdateCaches(Container container) + { + foreach (var widget in container.Children) + { + if (widget is Container) + UpdateCaches((Container)widget); + else if (widget is TextBox) + UpdateCache((TextBox)widget); + } + } + + #endregion + #region --- Interface Dispatchers --- public void DrawWidget(Widget widget) @@ -42,7 +63,6 @@ if (widget is TextBox) DrawTextBox((TextBox)widget); } - public Size RequestClientAreaSize(Container widget, Size clientSize) { throw new NotImplementedException(); @@ -81,10 +101,64 @@ return 0; } + #endregion #region --- TextBox --- + + private void UpdateCache(TextBox textBox) + { + if (textBox.Cache == null) + textBox.Cache = new TextBoxCache(); + + TextBoxCache c = (TextBoxCache)textBox.Cache; + + if (c.Dirty == false) + return; + + Size fixedSize = StretchRegionFixedSize(Scheme.TextBox.Image.SurfaceSize, + Scheme.TextBox.StretchRegion); + + Size surfSize = new Size(textBox.Size.Width - fixedSize.Width, + textBox.Size.Height - fixedSize.Height); + + if (c.TextBoxSurface == null || c.TextBoxSurface.SurfaceSize != surfSize) + { + if (c.TextBoxSurface != null) + c.TextBoxSurface.Dispose(); + + c.TextBoxSurface = new Surface(surfSize); + c.Origin = Point.Empty; + } + + Point ip = InsertionPointLocation(textBox); + ip.X -= Scheme.TextBox.StretchRegion.X; + ip.Y -= Scheme.TextBox.StretchRegion.Y; + int bottom = ip.Y + Scheme.InsertionPointHeight; + + if (ip.Y < 0) + c.Origin.Y -= ip.Y; + if (bottom > surfSize.Height) + c.Origin.Y += bottom - surfSize.Height; + if (ip.X < 0) + c.Origin.X -= ip.X; + if (ip.X >= surfSize.Width) + c.Origin.X += ip.X - surfSize.Width + 1; + + IRenderTarget old = Display.RenderTarget; + Display.RenderTarget = c.TextBoxSurface; + Display.BeginFrame(); + + Display.Clear(Color.FromArgb(0,0,0,0)); + + Scheme.WidgetFont.DrawText(-c.Origin.X, -c.Origin.Y, textBox.Text); + + Display.EndFrame(); + Display.RenderTarget = old; + } + + private void DrawTextBox(TextBox textBox) { Surface image = Scheme.TextBox.Image; @@ -94,7 +168,7 @@ Point location = textBox.PointToScreen(new Point(0, 0)); Size size = textBox.Size; - + DrawStretchImage(location, size, image, Scheme.TextBox.StretchRegion); @@ -119,27 +193,57 @@ location.X += Scheme.TextBox.StretchRegion.X; location.Y += Scheme.TextBox.StretchRegion.Y; - Scheme.WidgetFont.DrawText( - location, - textBox.Text); + if (textBox.Cache == null) + { + Scheme.WidgetFont.DrawText( + location, + textBox.Text); + } + else + { + TextBoxCache c = (TextBoxCache)textBox.Cache; + c.TextBoxSurface.Draw(location); + } + if (textBox.HasFocus) { - size = Scheme.WidgetFont.StringDisplaySize( - textBox.Text.Substring(0, textBox.InsertionPoint)); + Point loc = InsertionPointLocation(textBox); - Point loc = new Point( - size.Width + Scheme.TextBox.StretchRegion.X, - Scheme.TextBox.StretchRegion.Y); - loc = textBox.PointToScreen(loc); - loc.Y++; - DrawInsertionPoint(textBox, loc, Scheme.WidgetFont.FontHeight - 2, + DrawInsertionPoint(textBox, loc, Scheme.InsertionPointHeight, Timing.TotalMilliseconds - textBox.IPTime); } } + /// <summary> + /// Returns the local insertion point location in the textbox in pixels. + /// </summary> + /// <param name="textBox"></param> + /// <returns></returns> + private Point InsertionPointLocation(TextBox textBox) + { + Size sz = Scheme.WidgetFont.StringDisplaySize( + textBox.Text.Substring(0, textBox.InsertionPoint)); + + Point loc = new Point( + sz.Width + Scheme.TextBox.StretchRegion.X, + Scheme.TextBox.StretchRegion.Y); + + TextBoxCache c = textBox.Cache as TextBoxCache; + + if (c != null) + { + loc.X += c.Origin.X; + loc.Y += c.Origin.Y; + } + + loc.Y++; + + return loc; + } + private void DrawInsertionPoint(Widget widget, Point location, int size, double time) { int val = (int)time / Scheme.InsertionPointBlinkTime; @@ -520,6 +624,12 @@ // return false; //} + private Size StretchRegionFixedSize(Size imageSize, Rectangle stretchRegion) + { + return new Size( + imageSize.Width - stretchRegion.Width, + imageSize.Height - stretchRegion.Height); + } private void DrawStretchImage(Point loc, Size size, Surface surface, Rectangle stretchRegion) @@ -600,7 +710,6 @@ } } - private void SetControlFontColor(Widget widget) { if (widget.Enabled) @@ -608,6 +717,5 @@ else Scheme.WidgetFont.Color = Scheme.FontColorDisabled; } - } } \ No newline at end of file Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs 2009-04-21 03:21:08 UTC (rev 898) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs 2009-04-21 05:42:31 UTC (rev 899) @@ -151,6 +151,10 @@ } + public int InsertionPointHeight + { + get { return WidgetFont.FontHeight - 2; } + } public int InsertionPointBlinkTime { get { return mInsertionPointBlinkTime; } @@ -162,6 +166,7 @@ mInsertionPointBlinkTime = value; } } + public FontSurface WidgetFont { get; set; } public FontSurface TitleFont { get; set; } public int DropShadowSize { get; set; } Modified: branches/gui-3.2/AgateLib/Gui/Widget.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Widget.cs 2009-04-21 03:21:08 UTC (rev 898) +++ branches/gui-3.2/AgateLib/Gui/Widget.cs 2009-04-21 05:42:31 UTC (rev 899) @@ -48,6 +48,8 @@ } } + public Cache.WidgetCache Cache { get; set; } + public virtual bool CanHaveFocus { get { return false; } } public bool HasFocus { Modified: branches/gui-3.2/Tests/GuiTests/RenderGui.cs =================================================================== --- branches/gui-3.2/Tests/GuiTests/RenderGui.cs 2009-04-21 03:21:08 UTC (rev 898) +++ branches/gui-3.2/Tests/GuiTests/RenderGui.cs 2009-04-21 05:42:31 UTC (rev 899) @@ -18,14 +18,16 @@ new RenderGui().Run(args); } + protected override void AdjustAppInitParameters(ref AppInitParameters initParams) + { + initParams.ShowSplashScreen = false; + } protected override void Initialize() { this.GuiRoot = new GuiRoot(); CreateGui(); - - } Label fps; @@ -60,12 +62,8 @@ for (int i = 0; i < 4; i++) { - rightPanel.Children.Add(new RadioButton("Radio " + i.ToString())); - - if (i % 2 == 1) - leftPanel.Children.Add(new Button("Button Left " + i.ToString())); - else - rightPanel.Children[i].Enabled = false; + rightPanel.Children.Add(new CheckBox("Check " + i.ToString())); + leftPanel.Children.Add(new Button("Button Left " + i.ToString())); } hideMouse = leftPanel.Children[0] as Button; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-21 03:21:14
|
Revision: 898 http://agate.svn.sourceforge.net/agate/?rev=898&view=rev Author: kanato Date: 2009-04-21 03:21:08 +0000 (Tue, 21 Apr 2009) Log Message: ----------- Refactor MercuryScheme.cs so data is in separate classes. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/GuiRoot.cs branches/gui-3.2/AgateLib/InternalResources/agate-black-gui.zip Added Paths: ----------- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs Removed Paths: ------------- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs Modified: branches/gui-3.2/AgateLib/Gui/GuiRoot.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/GuiRoot.cs 2009-04-20 06:18:37 UTC (rev 897) +++ branches/gui-3.2/AgateLib/Gui/GuiRoot.cs 2009-04-21 03:21:08 UTC (rev 898) @@ -12,7 +12,7 @@ { public sealed class GuiRoot : Container { - IGuiThemeEngine themeEngine = new ThemeEngines.Mercury(); + IGuiThemeEngine themeEngine = new ThemeEngines.Mercury.Mercury(); public GuiRoot() { Copied: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs (from rev 896, branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs) =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-04-21 03:21:08 UTC (rev 898) @@ -0,0 +1,613 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using System.Diagnostics; + +namespace AgateLib.Gui.ThemeEngines.Mercury +{ + public class Mercury : IGuiThemeEngine + { + public Mercury() + : this(MercuryScheme.CreateDefaultScheme()) + { } + public Mercury(MercuryScheme scheme) + { + this.Scheme = scheme; + } + + public MercuryScheme Scheme { get; set; } + public static bool DebugOutlines { get; set; } + + #region --- Interface Dispatchers --- + + public void DrawWidget(Widget widget) + { + if (widget is GuiRoot) + return; + + if (DebugOutlines) + { + Display.DrawRect(new Rectangle(widget.ScreenLocation, widget.Size), + Color.Red); + } + + if (widget is Window) DrawWindow((Window)widget); + if (widget is Label) DrawLabel((Label)widget); + if (widget is Button) DrawButton((Button)widget); + if (widget is CheckBox) DrawCheckbox((CheckBox)widget); + if (widget is RadioButton) DrawRadioButton((RadioButton)widget); + if (widget is TextBox) DrawTextBox((TextBox)widget); + } + + + public Size RequestClientAreaSize(Container widget, Size clientSize) + { + throw new NotImplementedException(); + } + public Size CalcMinSize(Widget widget) + { + if (widget is Label) return CalcMinLabelSize((Label)widget); + if (widget is Button) return CalcMinButtonSize((Button)widget); + if (widget is CheckBox) return CalcMinCheckBoxSize((CheckBox)widget); + if (widget is TextBox) return CalcMinTextBoxSize((TextBox)widget); + if (widget is RadioButton) return CalcMinRadioButtonSize((RadioButton)widget); + + return Size.Empty; + } + public Size CalcMaxSize(Widget widget) + { + if (widget is TextBox) return CalcTextBoxMaxSize((TextBox)widget); + + return new Size(9000, 9000); + } + public bool HitTest(Widget widget, Point screenLocation) + { + if (widget is Button) return HitTestButton((Button)widget, screenLocation); + if (widget is CheckBox) return HitTestCheckBox((CheckBox)widget, screenLocation); + if (widget is TextBox) return HitTestTextBox((TextBox)widget, screenLocation); + + return true; + } + + public int ThemeMargin(Widget widget) + { + if (widget is Button) return Scheme.Button.Margin; + if (widget is CheckBox) return Scheme.CheckBox.Margin; + if (widget is TextBox) return Scheme.TextBox.Margin; + + return 0; + } + + #endregion + + #region --- TextBox --- + + private void DrawTextBox(TextBox textBox) + { + Surface image = Scheme.TextBox.Image; + + if (textBox.Enabled == false) + image = Scheme.TextBox.Disabled; + + Point location = textBox.PointToScreen(new Point(0, 0)); + Size size = textBox.Size; + + DrawStretchImage(location, size, + image, Scheme.TextBox.StretchRegion); + + if (textBox.Enabled) + { + if (textBox.HasFocus) + { + DrawStretchImage(location, size, + Scheme.TextBox.Focus, Scheme.TextBox.StretchRegion); + } + if (textBox.MouseIn) + { + DrawStretchImage(location, size, + Scheme.TextBox.Hover, Scheme.TextBox.StretchRegion); + } + } + + Scheme.WidgetFont.DisplayAlignment = OriginAlignment.TopLeft; + + SetControlFontColor(textBox); + + location.X += Scheme.TextBox.StretchRegion.X; + location.Y += Scheme.TextBox.StretchRegion.Y; + + Scheme.WidgetFont.DrawText( + location, + textBox.Text); + + if (textBox.HasFocus) + { + size = Scheme.WidgetFont.StringDisplaySize( + textBox.Text.Substring(0, textBox.InsertionPoint)); + + Point loc = new Point( + size.Width + Scheme.TextBox.StretchRegion.X, + Scheme.TextBox.StretchRegion.Y); + + loc = textBox.PointToScreen(loc); + loc.Y++; + + DrawInsertionPoint(textBox, loc, Scheme.WidgetFont.FontHeight - 2, + Timing.TotalMilliseconds - textBox.IPTime); + } + } + + private void DrawInsertionPoint(Widget widget, Point location, int size, double time) + { + int val = (int)time / Scheme.InsertionPointBlinkTime; + //Debug.Print("{0} {1}", time, val); + + if (val % 2 == 1) + return; + + Display.DrawLine(location, + new Point(location.X, location.Y + size), + Scheme.WidgetFont.Color); + } + + private Size CalcMinTextBoxSize(TextBox textBox) + { + Size retval = new Size(); + + retval.Width = 40; + retval.Height = Scheme.WidgetFont.FontHeight; + retval.Height += Scheme.TextBox.Image.SurfaceHeight - Scheme.TextBox.StretchRegion.Height; + + return retval; + } + private Size CalcTextBoxMaxSize(TextBox textBox) + { + Size retval = CalcMinTextBoxSize(textBox); + + retval.Width = 9000; + + return retval; + } + + private bool HitTestTextBox(TextBox textBox, Point screenLocation) + { + Point local = textBox.PointToClient(screenLocation); + + return true; + } + + #endregion + #region --- CheckBox --- + + private void DrawCheckbox(CheckBox checkbox) + { + Surface surf; + + if (checkbox.Enabled == false) + surf = Scheme.CheckBox.Disabled; + else + surf = Scheme.CheckBox.Image; + + Point destPoint = checkbox.PointToScreen( + Origin.Calc(OriginAlignment.CenterLeft, checkbox.Size)); + + surf.DisplayAlignment = OriginAlignment.CenterLeft; + surf.Draw(destPoint); + + if (checkbox.Enabled) + { + if (checkbox.HasFocus) + { + Scheme.CheckBox.Focus.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.CheckBox.Focus.Draw(destPoint); + } + if (checkbox.MouseIn) + { + Scheme.CheckBox.Hover.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.CheckBox.Hover.Draw(destPoint); + } + if (checkbox.Checked) + { + Scheme.CheckBox.Check.Color = Color.White; + Scheme.CheckBox.Check.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.CheckBox.Check.Draw(destPoint); + } + } + else if (checkbox.Checked) + { + Scheme.CheckBox.Check.Color = Color.Gray; + Scheme.CheckBox.Check.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.CheckBox.Check.Draw(destPoint); + } + + SetControlFontColor(checkbox); + + destPoint.X += surf.DisplayWidth + Scheme.CheckBox.Spacing; + + Scheme.WidgetFont.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.WidgetFont.DrawText(destPoint, checkbox.Text); + } + private Size CalcMinCheckBoxSize(CheckBox checkbox) + { + Size text = Scheme.WidgetFont.StringDisplaySize(checkbox.Text); + Size box = Scheme.CheckBox.Image.SurfaceSize; + + return new Size( + box.Width + Scheme.CheckBox.Spacing + text.Width, + Math.Max(box.Height, text.Height)); + } + private bool HitTestCheckBox(CheckBox checkBox, Point screenLocation) + { + Point local = checkBox.PointToClient(screenLocation); + + int right = Scheme.CheckBox.Image.SurfaceWidth + + Scheme.WidgetFont.StringDisplayWidth(checkBox.Text) + Scheme.CheckBox.Spacing * 2; + + if (local.X > right) + return false; + + return true; + } + + #endregion + #region --- Radio Button --- + + private void DrawRadioButton(RadioButton radiobutton) + { + Surface surf; + + if (radiobutton.Enabled == false) + surf = Scheme.RadioButton.Disabled; + else + surf = Scheme.RadioButton.Image; + + Point destPoint = radiobutton.PointToScreen( + Origin.Calc(OriginAlignment.CenterLeft, radiobutton.Size)); + + surf.DisplayAlignment = OriginAlignment.CenterLeft; + surf.Draw(destPoint); + + if (radiobutton.Enabled) + { + if (radiobutton.HasFocus) + { + Scheme.RadioButton.Focus.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.RadioButton.Focus.Draw(destPoint); + } + if (radiobutton.MouseIn) + { + Scheme.RadioButton.Hover.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.RadioButton.Hover.Draw(destPoint); + } + if (radiobutton.Checked) + { + Scheme.RadioButton.Check.Color = Color.White; + Scheme.RadioButton.Check.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.RadioButton.Check.Draw(destPoint); + } + } + else if (radiobutton.Checked) + { + Scheme.RadioButton.Check.Color = Scheme.FontColorDisabled; + Scheme.RadioButton.Check.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.RadioButton.Check.Draw(destPoint); + } + + SetControlFontColor(radiobutton); + + destPoint.X += surf.DisplayWidth + Scheme.RadioButton.Spacing; + + Scheme.WidgetFont.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.WidgetFont.DrawText(destPoint, radiobutton.Text); + } + + private Size CalcMinRadioButtonSize(RadioButton radiobutton) + { + Size text = Scheme.WidgetFont.StringDisplaySize(radiobutton.Text); + Size box = Scheme.RadioButton.Image.SurfaceSize; + + return new Size( + box.Width + Scheme.RadioButton.Spacing + text.Width, + Math.Max(box.Height, text.Height)); + } + + + private bool HitTestRadioButton(RadioButton radioButton, Point screenLocation) + { + Point local = radioButton.PointToClient(screenLocation); + + int right = Scheme.RadioButton.Image.SurfaceWidth + + Scheme.WidgetFont.StringDisplayWidth(radioButton.Text) + Scheme.RadioButton.Spacing * 2; + + if (local.X > right) + return false; + + return true; + } + + + #endregion + #region --- Label --- + + private void DrawLabel(Label label) + { + Point location = new Point(); + + location = DisplayLib.Origin.Calc(label.TextAlignment, label.Size); + location.X += label.ScreenLocation.X; + location.Y += label.ScreenLocation.Y; + + SetControlFontColor(label); + + Scheme.WidgetFont.DisplayAlignment = label.TextAlignment; + Scheme.WidgetFont.DrawText(location, label.Text); + } + + private Size CalcMinLabelSize(Label label) + { + Size retval = Scheme.WidgetFont.StringDisplaySize(label.Text); + + return retval; + } + + #endregion + #region --- Button --- + + private void DrawButton(Button button) + { + Surface image = Scheme.Button.Image; + + bool isDefault = button.IsDefaultButton; + + if (button.Enabled == false) + image = Scheme.Button.Disabled; + else if (button.DrawActivated) + image = Scheme.Button.Pressed; + else if (isDefault) + image = Scheme.Button.Default; + + Point location = button.PointToScreen(Point.Empty); + Size size = new Size(button.Width, button.Height); + + DrawStretchImage(location, size, + image, Scheme.Button.StretchRegion); + + if (button.Enabled) + { + if (button.MouseIn) + { + DrawStretchImage(location, size, + Scheme.Button.Hover, Scheme.Button.StretchRegion); + } + if (button.HasFocus) + { + DrawStretchImage(location, size, + Scheme.Button.Focus, Scheme.Button.StretchRegion); + } + } + + + // Draw button text + SetControlFontColor(button); + + Scheme.WidgetFont.DisplayAlignment = OriginAlignment.Center; + location = Origin.Calc(OriginAlignment.Center, button.Size); + + // drop the text down a bit if the button is being pushed. + if (button.DrawActivated) + { + location.X++; + location.Y++; + } + + Scheme.WidgetFont.DrawText( + button.PointToScreen(location), + button.Text); + } + + private Size CalcMinButtonSize(Button button) + { + Size textSize = Scheme.WidgetFont.StringDisplaySize(button.Text); + Size buttonBorder = new Size( + Scheme.Button.Image.SurfaceWidth - Scheme.Button.StretchRegion.Width, + Scheme.Button.Image.SurfaceHeight - Scheme.Button.StretchRegion.Height); + + textSize.Width += Scheme.Button.TextPadding * 2; + textSize.Height += Scheme.Button.TextPadding * 2; + + return new Size( + textSize.Width + buttonBorder.Width, + textSize.Height + buttonBorder.Height); + } + + private bool HitTestButton(Button button, Point screenLocation) + { + Point local = button.PointToClient(screenLocation); + + return true; + } + + #endregion + #region --- Window --- + + public void DrawWindow(Window window) + { + DrawWindowBackground(window); + DrawWindowTitle(window); + DrawWindowDecorations(window); + } + + // TODO: fix this + public int WindowTitlebarSize + { + get { return Scheme.TitleFont.FontHeight + 6; } + } + + protected virtual void DrawWindowBackground(Window window) + { + if (window.ShowTitleBar) + { + DrawStretchImage(window.Parent.PointToScreen( + new Point(window.Location.X, window.Location.Y + this.WindowTitlebarSize)), + window.Size, Scheme.Window.WithTitle, Scheme.Window.WithTitleStretchRegion); + + } + else + throw new NotImplementedException(); + } + + private void DrawDropShadow(Rectangle rect) + { + for (int i = 0; i <= Scheme.DropShadowSize; i++) + { + Color fadeColor = Color.Red;// Scheme.WindowBorderColor; + fadeColor.A = (byte)( + fadeColor.A * (Scheme.DropShadowSize - i) / (2 * Scheme.DropShadowSize)); + + Display.DrawRect(rect, fadeColor); + + rect.X--; + rect.Y--; + rect.Width += 2; + rect.Height += 2; + } + } + protected virtual void DrawWindowTitle(Window window) + { + Point windowLocation = window.ScreenLocation; + + DrawStretchImage(windowLocation, + new Size(window.Width, WindowTitlebarSize), Scheme.Window.TitleBar, + Scheme.Window.TitleBarStretchRegion); + + Point fontPosition = new Point(windowLocation.X + 8, windowLocation.Y + 3); + if (Scheme.Window.CenterTitle) + { + fontPosition.X = windowLocation.X + window.Width / 2; + fontPosition.Y = windowLocation.Y + WindowTitlebarSize / 2; + Scheme.TitleFont.DisplayAlignment = OriginAlignment.Center; + } + + Scheme.TitleFont.Color = Scheme.FontColor; + + Scheme.TitleFont.DrawText( + fontPosition, + window.Text); + + Scheme.TitleFont.DisplayAlignment = OriginAlignment.TopLeft; + } + protected virtual void DrawWindowDecorations(Window window) + { + Scheme.Window.CloseButton.DisplayAlignment = OriginAlignment.TopRight; + Scheme.Window.CloseButton.Draw( + new Point(window.ScreenLocation.X + window.Size.Width, + window.ScreenLocation.Y)); + } + + #endregion + + + //private bool PointInMargin(Widget widget, Point localPoint, int margin) + //{ + // if (localPoint.X < margin) return true; + // if (localPoint.Y < margin) return true; + // if (localPoint.X >= widget.Width - margin) return true; + // if (localPoint.Y >= widget.Height - margin) return true; + + // return false; + //} + + + private void DrawStretchImage(Point loc, Size size, + Surface surface, Rectangle stretchRegion) + { + Rectangle scaled = new Rectangle( + loc.X + stretchRegion.X, + loc.Y + stretchRegion.Y, + size.Width - (surface.SurfaceWidth - stretchRegion.Right) - stretchRegion.X, + size.Height - (surface.SurfaceHeight - stretchRegion.Bottom) - stretchRegion.Y); + + // draw top left + surface.Draw( + new Rectangle(0, 0, stretchRegion.Left, stretchRegion.Top), + new Rectangle(loc.X, loc.Y, stretchRegion.Left, stretchRegion.Top)); + + // draw top middle + surface.Draw( + new Rectangle(stretchRegion.Left, 0, stretchRegion.Width, stretchRegion.Top), + new Rectangle(loc.X + stretchRegion.Left, loc.Y, + scaled.Width, stretchRegion.Top)); + + // draw top right + surface.Draw( + new Rectangle(stretchRegion.Right, 0, surface.SurfaceWidth - stretchRegion.Right, stretchRegion.Top), + new Rectangle(scaled.Right, loc.Y, surface.SurfaceWidth - stretchRegion.Right, stretchRegion.Top)); + + // draw middle left + surface.Draw( + new Rectangle(0, stretchRegion.Top, stretchRegion.Left, stretchRegion.Height), + new Rectangle(loc.X, loc.Y + stretchRegion.Top, stretchRegion.Left, scaled.Height)); + + // draw middle + surface.Draw( + stretchRegion, + scaled); + + // draw middle right + surface.Draw( + new Rectangle(stretchRegion.Right, stretchRegion.Top, surface.SurfaceWidth - stretchRegion.Right, stretchRegion.Height), + new Rectangle(scaled.Right, scaled.Top, surface.SurfaceWidth - stretchRegion.Right, scaled.Height)); + + // draw bottom left + surface.Draw( + new Rectangle(0, stretchRegion.Bottom, stretchRegion.Left, surface.SurfaceHeight - stretchRegion.Bottom), + new Rectangle(loc.X, scaled.Bottom, stretchRegion.Left, surface.SurfaceHeight - stretchRegion.Bottom)); + + // draw bottom middle + surface.Draw( + new Rectangle(stretchRegion.Left, stretchRegion.Bottom, stretchRegion.Width, surface.SurfaceHeight - stretchRegion.Bottom), + new Rectangle(scaled.Left, scaled.Bottom, scaled.Width, surface.SurfaceHeight - stretchRegion.Bottom)); + + // draw bottom right + surface.Draw( + new Rectangle(stretchRegion.Right, stretchRegion.Bottom, surface.SurfaceWidth - stretchRegion.Right, surface.SurfaceHeight - stretchRegion.Bottom), + new Rectangle(scaled.Right, scaled.Bottom, surface.SurfaceWidth - stretchRegion.Right, surface.SurfaceHeight - stretchRegion.Bottom)); + + } + + public Rectangle GetClientArea(Container widget) + { + if (widget is Window) return GetWindowClientArea((Window)widget); + + return new Rectangle(Point.Empty, widget.Size); + } + public Rectangle GetWindowClientArea(Window widget) + { + if (widget.ShowTitleBar) + { + return new Rectangle( + Scheme.Window.WithTitleStretchRegion.Left, + Scheme.Window.WithTitleStretchRegion.Top + WindowTitlebarSize, + widget.Width - (Scheme.Window.WithTitle.SurfaceWidth - Scheme.Window.WithTitleStretchRegion.Width), + widget.Height - (Scheme.Window.WithTitle.SurfaceHeight - Scheme.Window.WithTitleStretchRegion.Height)); + } + else + { + throw new NotImplementedException(); + } + } + + + private void SetControlFontColor(Widget widget) + { + if (widget.Enabled) + Scheme.WidgetFont.Color = Scheme.FontColor; + else + Scheme.WidgetFont.Color = Scheme.FontColorDisabled; + } + + } +} \ No newline at end of file Copied: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs (from rev 897, branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs) =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs 2009-04-21 03:21:08 UTC (rev 898) @@ -0,0 +1,283 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using AgateLib.Utility; + +namespace AgateLib.Gui.ThemeEngines.Mercury +{ + public class MercuryScheme + { + int mInsertionPointBlinkTime = 500; + MercuryWindow mWindow = new MercuryWindow(); + MercuryButton mButton = new MercuryButton(); + MercuryCheckBox mCheckBox = new MercuryCheckBox(); + MercuryCheckBox mRadioButton = new MercuryCheckBox(); + MercuryTextBox mTextBox = new MercuryTextBox(); + + public MercuryScheme() + { + } + + public static MercuryScheme CreateDefaultScheme() + { + MercuryScheme retval = new MercuryScheme(); + + ZipFileProvider provider = new ZipFileProvider("agate-black-gui", InternalResources.DataResources.agate_black_gui); + retval.SetDefaults(provider); + + return retval; + } + + void SetDefaults(IFileProvider files) + { + WidgetFont = FontSurface.Andika09; + TitleFont = FontSurface.Andika10; + + FontColor = Color.White; + FontColorDisabled = Color.Gray; + DropShadowSize = 10; + + Window.NoTitle = new Surface(files, "window_no_title.png"); + Window.WithTitle = new Surface(files, "window_client.png"); + Window.TitleBar = new Surface(files, "window_titlebar.png"); + Window.TitleBarStretchRegion = new Rectangle(6, 3, 52, 27); + Window.NoTitleStretchRegion = new Rectangle(5, 5, 54, 54); + Window.WithTitleStretchRegion = new Rectangle(7, 4, 50, 53); + + SetButtonImages(new Surface(files, "button.png"), new Size(64, 32)); + Button.StretchRegion = new Rectangle(6, 6, 52, 20); + + + SetCheckBoxImages(new Surface(files, "checkbox.png"), new Size(16, 16)); + SetRadioButtonImages(new Surface(files, "radiobutton.png"), new Size(16, 16)); + + Window.CloseButton = CheckBox.Image; + Window.CloseButtonInactive = CheckBox.Disabled; + Window.CloseButtonHover = CheckBox.Hover; + + SetTextBoxImages(new Surface(files, "textbox.png"), new Size(64, 16)); + TextBox.StretchRegion = new Rectangle(3, 3, 58, 10); + } + + private void SetTextBoxImages(Surface surface, Size boxSize) + { + Surface[] surfs = SplitSurface("textbox", surface, boxSize, 4, 4); + + TextBox.Image = surfs[0]; + TextBox.Disabled = surfs[1]; + TextBox.Hover = surfs[2]; + TextBox.Focus = surfs[3]; + + surface.Dispose(); + } + private void SetCheckBoxImages(Surface surface, Size boxSize) + { + Surface[] surfs = SplitSurface("checkbox", surface, boxSize, 5, 5); + + CheckBox.Image = surfs[0]; + CheckBox.Disabled = surfs[1]; + CheckBox.Check = surfs[2]; + CheckBox.Hover = surfs[3]; + CheckBox.Focus = surfs[4]; + + surface.Dispose(); + } + private void SetRadioButtonImages(Surface surface, Size boxSize) + { + Surface[] surfs = SplitSurface("RadioButton", surface, boxSize, 5, 5); + + RadioButton.Image = surfs[0]; + RadioButton.Disabled = surfs[1]; + RadioButton.Check = surfs[2]; + RadioButton.Hover = surfs[3]; + RadioButton.Focus = surfs[4]; + + surface.Dispose(); + } + private void SetButtonImages(Surface surface, Size buttonSize) + { + Surface[] surfs = SplitSurface("button", surface, buttonSize, 6, 6); + + Button.Image = surfs[0]; + Button.Default = surfs[1]; + Button.Pressed = surfs[2]; + Button.Disabled = surfs[3]; + Button.Hover = surfs[4]; + Button.Focus = surfs[5]; + + surface.Dispose(); + } + + private Surface[] SplitSurface(string name, Surface surface, Size subSurfaceSize, + int requiredImages, int maxImages) + { + Point pt = new Point(); + PixelBuffer pixels = surface.ReadPixels(); + + List<Surface> retval = new List<Surface>(); + + for (int i = 0; i < maxImages; i++) + { + Surface surf = new Surface(subSurfaceSize); + surf.WritePixels(pixels, new Rectangle(pt, subSurfaceSize), Point.Empty); + + retval.Add(surf); + + pt.X += subSurfaceSize.Width; + if (pt.X == surface.SurfaceWidth) + { + pt.X = 0; + pt.Y += subSurfaceSize.Height; + } + else if (pt.X > surface.SurfaceWidth) + { + throw new AgateGuiException( + "Image for " + name + + " does not have a width that is a multiple of " + subSurfaceSize.Width + "."); + } + + if (pt.Y + subSurfaceSize.Height > surface.SurfaceHeight) + { + if (retval.Count < requiredImages) + throw new AgateGuiException( + "There are not enough subimages in the " + name + " image."); + } + } + + return retval.ToArray(); + } + + + public int InsertionPointBlinkTime + { + get { return mInsertionPointBlinkTime; } + set + { + if (value < 1) + throw new ArgumentNullException(); + + mInsertionPointBlinkTime = value; + } + } + public FontSurface WidgetFont { get; set; } + public FontSurface TitleFont { get; set; } + public int DropShadowSize { get; set; } + + public Color FontColor { get; set; } + public Color FontColorDisabled { get; set; } + + public MercuryWindow Window + { + get { return mWindow; } + set + { + if (value == null) throw new ArgumentNullException(); + mWindow = value; + } + } + public MercuryButton Button + { + get { return mButton; } + set + { + if (value == null) throw new ArgumentNullException(); + mButton = value; + } + } + public MercuryTextBox TextBox + { + get { return mTextBox; } + set + { + if (value == null) throw new ArgumentNullException(); + mTextBox = value; + } + } + public MercuryCheckBox CheckBox + { + get { return mCheckBox; } + set + { + if (value == null) throw new ArgumentNullException(); + mCheckBox = value; + } + } + public MercuryCheckBox RadioButton + { + get { return mRadioButton; } + set + { + if (value == null) throw new ArgumentNullException(); + mRadioButton = value; + } + } + + } + + public class MercuryWindow + { + public Surface NoTitle { get; set; } + public Surface WithTitle { get; set; } + public Surface TitleBar { get; set; } + public Rectangle NoTitleStretchRegion { get; set; } + public Rectangle WithTitleStretchRegion { get; set; } + public Rectangle TitleBarStretchRegion { get; set; } + + public bool CenterTitle { get; set; } + + public Surface CloseButton { get; set; } + public Surface CloseButtonHover { get; set; } + public Surface CloseButtonInactive { get; set; } + + public MercuryWindow() + { + CenterTitle = true; + } + } + public class MercuryButton + { + public Rectangle StretchRegion { get; set; } + public Surface Image { get; set; } + public Surface Default { get; set; } + public Surface Pressed { get; set; } + public Surface Disabled { get; set; } + public Surface Hover { get; set; } + public Surface Focus { get; set; } + public int TextPadding { get; set; } + public int Margin { get; set; } + } + public class MercuryTextBox + { + public Surface Image { get; set; } + public Surface Disabled { get; set; } + public Surface Hover { get; set; } + public Surface Focus { get; set; } + public Rectangle StretchRegion { get; set; } + public int Margin { get; set; } + + public MercuryTextBox() + { + Margin = 3; + } + + } + public class MercuryCheckBox + { + public Surface Image { get; set; } + public Surface Disabled { get; set; } + public Surface Check { get; set; } + public Surface Hover { get; set; } + public Surface Focus { get; set; } + public int Spacing { get; set; } + public int Margin { get; set; } + + public MercuryCheckBox() + { + Spacing = 5; + Margin = 2; + } + } +} Deleted: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs 2009-04-20 06:18:37 UTC (rev 897) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs 2009-04-21 03:21:08 UTC (rev 898) @@ -1,613 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using AgateLib.DisplayLib; -using AgateLib.Geometry; -using System.Diagnostics; - -namespace AgateLib.Gui.ThemeEngines -{ - public class Mercury : IGuiThemeEngine - { - public Mercury() - : this(MercuryScheme.CreateDefaultScheme()) - { } - public Mercury(MercuryScheme scheme) - { - this.Scheme = scheme; - } - - public MercuryScheme Scheme { get; set; } - public static bool DebugOutlines { get; set; } - - #region --- Interface Dispatchers --- - - public void DrawWidget(Widget widget) - { - if (widget is GuiRoot) - return; - - if (DebugOutlines) - { - Display.DrawRect(new Rectangle(widget.ScreenLocation, widget.Size), - Color.Red); - } - - if (widget is Window) DrawWindow((Window)widget); - if (widget is Label) DrawLabel((Label)widget); - if (widget is Button) DrawButton((Button)widget); - if (widget is CheckBox) DrawCheckbox((CheckBox)widget); - if (widget is RadioButton) DrawRadioButton((RadioButton)widget); - if (widget is TextBox) DrawTextBox((TextBox)widget); - } - - - public Size RequestClientAreaSize(Container widget, Size clientSize) - { - throw new NotImplementedException(); - } - public Size CalcMinSize(Widget widget) - { - if (widget is Label) return CalcMinLabelSize((Label)widget); - if (widget is Button) return CalcMinButtonSize((Button)widget); - if (widget is CheckBox) return CalcMinCheckBoxSize((CheckBox)widget); - if (widget is TextBox) return CalcMinTextBoxSize((TextBox)widget); - if (widget is RadioButton) return CalcMinRadioButtonSize((RadioButton)widget); - - return Size.Empty; - } - public Size CalcMaxSize(Widget widget) - { - if (widget is TextBox) return CalcTextBoxMaxSize((TextBox)widget); - - return new Size(9000, 9000); - } - public bool HitTest(Widget widget, Point screenLocation) - { - if (widget is Button) return HitTestButton((Button)widget, screenLocation); - if (widget is CheckBox) return HitTestCheckBox((CheckBox)widget, screenLocation); - if (widget is TextBox) return HitTestTextBox((TextBox)widget, screenLocation); - - return true; - } - - public int ThemeMargin(Widget widget) - { - if (widget is Button) return Scheme.ButtonMargin; - if (widget is CheckBox) return Scheme.CheckBoxMargin; - if (widget is TextBox) return Scheme.TextBoxMargin; - - return 0; - } - - #endregion - - #region --- TextBox --- - - private void DrawTextBox(TextBox textBox) - { - Surface image = Scheme.TextBox; - - if (textBox.Enabled == false) - image = Scheme.TextBoxDisabled; - - Point location = textBox.PointToScreen(new Point(0, 0)); - Size size = textBox.Size; - - DrawStretchImage(location, size, - image, Scheme.TextBoxStretchRegion); - - if (textBox.Enabled) - { - if (textBox.HasFocus) - { - DrawStretchImage(location, size, - Scheme.TextBoxFocus, Scheme.TextBoxStretchRegion); - } - if (textBox.MouseIn) - { - DrawStretchImage(location, size, - Scheme.TextBoxHover, Scheme.TextBoxStretchRegion); - } - } - - Scheme.WidgetFont.DisplayAlignment = OriginAlignment.TopLeft; - - SetControlFontColor(textBox); - - location.X += Scheme.TextBoxStretchRegion.X; - location.Y += Scheme.TextBoxStretchRegion.Y; - - Scheme.WidgetFont.DrawText( - location, - textBox.Text); - - if (textBox.HasFocus) - { - size = Scheme.WidgetFont.StringDisplaySize( - textBox.Text.Substring(0, textBox.InsertionPoint)); - - Point loc = new Point( - size.Width + Scheme.TextBoxStretchRegion.X, - Scheme.TextBoxStretchRegion.Y); - - loc = textBox.PointToScreen(loc); - loc.Y++; - - DrawInsertionPoint(textBox, loc, Scheme.WidgetFont.FontHeight - 2, - Timing.TotalMilliseconds - textBox.IPTime); - } - } - - private void DrawInsertionPoint(Widget widget, Point location, int size, double time) - { - int val = (int)time / Scheme.InsertionPointBlinkTime; - //Debug.Print("{0} {1}", time, val); - - if (val % 2 == 1) - return; - - Display.DrawLine(location, - new Point(location.X, location.Y + size), - Scheme.WidgetFont.Color); - } - - private Size CalcMinTextBoxSize(TextBox textBox) - { - Size retval = new Size(); - - retval.Width = 40; - retval.Height = Scheme.WidgetFont.FontHeight; - retval.Height += Scheme.TextBox.SurfaceHeight - Scheme.TextBoxStretchRegion.Height; - - return retval; - } - private Size CalcTextBoxMaxSize(TextBox textBox) - { - Size retval = CalcMinTextBoxSize(textBox); - - retval.Width = 9000; - - return retval; - } - - private bool HitTestTextBox(TextBox textBox, Point screenLocation) - { - Point local = textBox.PointToClient(screenLocation); - - return true; - } - - #endregion - #region --- CheckBox --- - - private void DrawCheckbox(CheckBox checkbox) - { - Surface surf; - - if (checkbox.Enabled == false) - surf = Scheme.CheckBoxDisabled; - else - surf = Scheme.CheckBox; - - Point destPoint = checkbox.PointToScreen( - Origin.Calc(OriginAlignment.CenterLeft, checkbox.Size)); - - surf.DisplayAlignment = OriginAlignment.CenterLeft; - surf.Draw(destPoint); - - if (checkbox.Enabled) - { - if (checkbox.HasFocus) - { - Scheme.CheckBoxFocus.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.CheckBoxFocus.Draw(destPoint); - } - if (checkbox.MouseIn) - { - Scheme.CheckBoxHover.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.CheckBoxHover.Draw(destPoint); - } - if (checkbox.Checked) - { - Scheme.CheckBoxCheck.Color = Color.White; - Scheme.CheckBoxCheck.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.CheckBoxCheck.Draw(destPoint); - } - } - else if (checkbox.Checked) - { - Scheme.CheckBoxCheck.Color = Color.Gray; - Scheme.CheckBoxCheck.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.CheckBoxCheck.Draw(destPoint); - } - - SetControlFontColor(checkbox); - - destPoint.X += surf.DisplayWidth + Scheme.CheckBoxSpacing; - - Scheme.WidgetFont.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.WidgetFont.DrawText(destPoint, checkbox.Text); - } - private Size CalcMinCheckBoxSize(CheckBox checkbox) - { - Size text = Scheme.WidgetFont.StringDisplaySize(checkbox.Text); - Size box = Scheme.CheckBox.SurfaceSize; - - return new Size( - box.Width + Scheme.CheckBoxSpacing + text.Width, - Math.Max(box.Height, text.Height)); - } - private bool HitTestCheckBox(CheckBox checkBox, Point screenLocation) - { - Point local = checkBox.PointToClient(screenLocation); - - int right = Scheme.CheckBox.SurfaceWidth + - Scheme.WidgetFont.StringDisplayWidth(checkBox.Text) + Scheme.CheckBoxSpacing * 2; - - if (local.X > right) - return false; - - return true; - } - - #endregion - #region --- Radio Button --- - - private void DrawRadioButton(RadioButton radiobutton) - { - Surface surf; - - if (radiobutton.Enabled == false) - surf = Scheme.RadioButtonDisabled; - else - surf = Scheme.RadioButton; - - Point destPoint = radiobutton.PointToScreen( - Origin.Calc(OriginAlignment.CenterLeft, radiobutton.Size)); - - surf.DisplayAlignment = OriginAlignment.CenterLeft; - surf.Draw(destPoint); - - if (radiobutton.Enabled) - { - if (radiobutton.HasFocus) - { - Scheme.RadioButtonFocus.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.RadioButtonFocus.Draw(destPoint); - } - if (radiobutton.MouseIn) - { - Scheme.RadioButtonHover.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.RadioButtonHover.Draw(destPoint); - } - if (radiobutton.Checked) - { - Scheme.RadioButtonCheck.Color = Color.White; - Scheme.RadioButtonCheck.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.RadioButtonCheck.Draw(destPoint); - } - } - else if (radiobutton.Checked) - { - Scheme.RadioButtonCheck.Color = Scheme.FontColorDisabled; - Scheme.RadioButtonCheck.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.RadioButtonCheck.Draw(destPoint); - } - - SetControlFontColor(radiobutton); - - destPoint.X += surf.DisplayWidth + Scheme.RadioButtonSpacing; - - Scheme.WidgetFont.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.WidgetFont.DrawText(destPoint, radiobutton.Text); - } - - private Size CalcMinRadioButtonSize(RadioButton radiobutton) - { - Size text = Scheme.WidgetFont.StringDisplaySize(radiobutton.Text); - Size box = Scheme.RadioButton.SurfaceSize; - - return new Size( - box.Width + Scheme.RadioButtonSpacing + text.Width, - Math.Max(box.Height, text.Height)); - } - - - private bool HitTestRadioButton(RadioButton radioButton, Point screenLocation) - { - Point local = radioButton.PointToClient(screenLocation); - - int right = Scheme.RadioButton.SurfaceWidth + - Scheme.WidgetFont.StringDisplayWidth(radioButton.Text) + Scheme.RadioButtonSpacing * 2; - - if (local.X > right) - return false; - - return true; - } - - - #endregion - #region --- Label --- - - private void DrawLabel(Label label) - { - Point location = new Point(); - - location = DisplayLib.Origin.Calc(label.TextAlignment, label.Size); - location.X += label.ScreenLocation.X; - location.Y += label.ScreenLocation.Y; - - SetControlFontColor(label); - - Scheme.WidgetFont.DisplayAlignment = label.TextAlignment; - Scheme.WidgetFont.DrawText(location, label.Text); - } - - private Size CalcMinLabelSize(Label label) - { - Size retval = Scheme.WidgetFont.StringDisplaySize(label.Text); - - return retval; - } - - #endregion - #region --- Button --- - - private void DrawButton(Button button) - { - Surface image = Scheme.Button; - - bool isDefault = button.IsDefaultButton; - - if (button.Enabled == false) - image = Scheme.ButtonDisabled; - else if (button.DrawActivated) - image = Scheme.ButtonPressed; - else if (isDefault) - image = Scheme.ButtonDefault; - - Point location = button.PointToScreen(Point.Empty); - Size size = new Size(button.Width, button.Height); - - DrawStretchImage(location, size, - image, Scheme.ButtonStretchRegion); - - if (button.Enabled) - { - if (button.MouseIn) - { - DrawStretchImage(location, size, - Scheme.ButtonHover, Scheme.ButtonStretchRegion); - } - if (button.HasFocus) - { - DrawStretchImage(location, size, - Scheme.ButtonFocus, Scheme.ButtonStretchRegion); - } - } - - - // Draw button text - SetControlFontColor(button); - - Scheme.WidgetFont.DisplayAlignment = OriginAlignment.Center; - location = Origin.Calc(OriginAlignment.Center, button.Size); - - // drop the text down a bit if the button is being pushed. - if (button.DrawActivated) - { - location.X++; - location.Y++; - } - - Scheme.WidgetFont.DrawText( - button.PointToScreen(location), - button.Text); - } - - private Size CalcMinButtonSize(Button button) - { - Size textSize = Scheme.WidgetFont.StringDisplaySize(button.Text); - Size buttonBorder = new Size( - Scheme.Button.SurfaceWidth - Scheme.ButtonStretchRegion.Width, - Scheme.Button.SurfaceHeight - Scheme.ButtonStretchRegion.Height); - - textSize.Width += Scheme.ButtonTextPadding * 2; - textSize.Height += Scheme.ButtonTextPadding * 2; - - return new Size( - textSize.Width + buttonBorder.Width, - textSize.Height + buttonBorder.Height); - } - - private bool HitTestButton(Button button, Point screenLocation) - { - Point local = button.PointToClient(screenLocation); - - return true; - } - - #endregion - #region --- Window --- - - public void DrawWindow(Window window) - { - DrawWindowBackground(window); - DrawWindowTitle(window); - DrawWindowDecorations(window); - } - - // TODO: fix this - public int WindowTitlebarSize - { - get { return Scheme.TitleFont.FontHeight + 6; } - } - - protected virtual void DrawWindowBackground(Window window) - { - if (window.ShowTitleBar) - { - DrawStretchImage(window.Parent.PointToScreen( - new Point(window.Location.X, window.Location.Y + this.WindowTitlebarSize)), - window.Size, Scheme.WindowWithTitle, Scheme.WindowWithTitleStretchRegion); - - } - else - throw new NotImplementedException(); - } - - private void DrawDropShadow(Rectangle rect) - { - for (int i = 0; i <= Scheme.DropShadowSize; i++) - { - Color fadeColor = Color.Red;// Scheme.WindowBorderColor; - fadeColor.A = (byte)( - fadeColor.A * (Scheme.DropShadowSize - i) / (2 * Scheme.DropShadowSize)); - - Display.DrawRect(rect, fadeColor); - - rect.X--; - rect.Y--; - rect.Width += 2; - rect.Height += 2; - } - } - protected virtual void DrawWindowTitle(Window window) - { - Point windowLocation = window.ScreenLocation; - - DrawStretchImage(windowLocation, - new Size(window.Width, WindowTitlebarSize), Scheme.WindowTitleBar, - Scheme.WindowTitleBarStretchRegion); - - Point fontPosition = new Point(windowLocation.X + 8, windowLocation.Y + 3); - if (Scheme.CenterTitle) - { - fontPosition.X = windowLocation.X + window.Width / 2; - fontPosition.Y = windowLocation.Y + WindowTitlebarSize / 2; - Scheme.TitleFont.DisplayAlignment = OriginAlignment.Center; - } - - Scheme.TitleFont.Color = Scheme.FontColor; - - Scheme.TitleFont.DrawText( - fontPosition, - window.Text); - - Scheme.TitleFont.DisplayAlignment = OriginAlignment.TopLeft; - } - protected virtual void DrawWindowDecorations(Window window) - { - Scheme.CloseButton.DisplayAlignment = OriginAlignment.TopRight; - Scheme.CloseButton.Draw( - new Point(window.ScreenLocation.X + window.Size.Width, - window.ScreenLocation.Y)); - } - - #endregion - - - //private bool PointInMargin(Widget widget, Point localPoint, int margin) - //{ - // if (localPoint.X < margin) return true; - // if (localPoint.Y < margin) return true; - // if (localPoint.X >= widget.Width - margin) return true; - // if (localPoint.Y >= widget.Height - margin) return true; - - // return false; - //} - - - private void DrawStretchImage(Point loc, Size size, - Surface surface, Rectangle stretchRegion) - { - Rectangle scaled = new Rectangle( - loc.X + stretchRegion.X, - loc.Y + stretchRegion.Y, - size.Width - (surface.SurfaceWidth - stretchRegion.Right) - stretchRegion.X, - size.Height - (surface.SurfaceHeight - stretchRegion.Bottom) - stretchRegion.Y); - - // draw top left - surface.Draw( - new Rectangle(0, 0, stretchRegion.Left, stretchRegion.Top), - new Rectangle(loc.X, loc.Y, stretchRegion.Left, stretchRegion.Top)); - - // draw top middle - surface.Draw( - new Rectangle(stretchRegion.Left, 0, stretchRegion.Width, stretchRegion.Top), - new Rectangle(loc.X + stretchRegion.Left, loc.Y, - scaled.Width, stretchRegion.Top)); - - // draw top right - surface.Draw( - new Rectangle(stretchRegion.Right, 0, surface.SurfaceWidth - stretchRegion.Right, stretchRegion.Top), - new Rectangle(scaled.Right, loc.Y, surface.SurfaceWidth - stretchRegion.Right, stretchRegion.Top)); - - // draw middle left - surface.Draw( - new Rectangle(0, stretchRegion.Top, stretchRegion.Left, stretchRegion.Height), - new Rectangle(loc.X, loc.Y + stretchRegion.Top, stretchRegion.Left, scaled.Height)); - - // draw middle - surface.Draw( - stretchRegion, - scaled); - - // draw middle right - surface.Draw( - new Rectangle(stretchRegion.Right, stretchRegion.Top, surface.SurfaceWidth - stretchRegion.Right, stretchRegion.Height), - new Rectangle(scaled.Right, scaled.Top, surface.SurfaceWidth - stretchRegion.Right, scaled.Height)); - - // draw bottom left - surface.Draw( - new Rectangle(0, stretchRegion.Bottom, stretchRegion.Left, surface.SurfaceHeight - stretchRegion.Bottom), - new Rectangle(loc.X, scaled.Bottom, stretchRegion.Left, surface.SurfaceHeight - stretchRegion.Bottom)); - - // draw bottom middle - surface.Draw( - new Rectangle(stretchRegion.Left, stretchRegion.Bottom, stretchRegion.Width, surface.SurfaceHeight - stretchRegion.Bottom), - new Rectangle(scaled.Left, scaled.Bottom, scaled.Width, surface.SurfaceHeight - stretchRegion.Bottom)); - - // draw bottom right - surface.Draw( - new Rectangle(stretchRegion.Right, stretchRegion.Bottom, surface.SurfaceWidth - stretchRegion.Right, surface.SurfaceHeight - stretchRegion.Bottom), - new Rectangle(scaled.Right, scaled.Bottom, surface.SurfaceWidth - stretchRegion.Right, surface.SurfaceHeight - stretchRegion.Bottom)); - - } - - public Rectangle GetClientArea(Container widget) - { - if (widget is Window) return GetWindowClientArea((Window)widget); - - return new Rectangle(Point.Empty, widget.Size); - } - public Rectangle GetWindowClientArea(Window widget) - { - if (widget.ShowTitleBar) - { - return new Rectangle( - Scheme.WindowWithTitleStretchRegion.Left, - Scheme.WindowWithTitleStretchRegion.Top + WindowTitlebarSize, - widget.Width - (Scheme.WindowWithTitle.SurfaceWidth - Scheme.WindowWithTitleStretchRegion.Width), - widget.Height - (Scheme.WindowWithTitle.SurfaceHeight - Scheme.WindowWithTitleStretchRegion.Height)); - } - else - { - throw new NotImplementedException(); - } - } - - - private void SetControlFontColor(Widget widget) - { - if (widget.Enabled) - Scheme.WidgetFont.Color = Scheme.FontColor; - else - Scheme.WidgetFont.Color = Scheme.FontColorDisabled; - } - - } -} \ No newline at end of file Deleted: branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-20 06:18:37 UTC (rev 897) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-21 03:21:08 UTC (rev 898) @@ -1,222 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using AgateLib.DisplayLib; -using AgateLib.Geometry; -using AgateLib.Utility; - -namespace AgateLib.Gui.ThemeEngines -{ - public class MercuryScheme - { - public MercuryScheme() - { - } - - public static MercuryScheme CreateDefaultScheme() - { - MercuryScheme retval = new MercuryScheme(); - - ZipFileProvider provider = new ZipFileProvider("agate-black-gui", InternalResources.DataResources.agate_black_gui); - retval.SetDefaults(provider); - - return retval; - } - - void SetDefaults(IFileProvider files) - { - WidgetFont = FontSurface.Andika09; - TitleFont = FontSurface.Andika10; - CenterTitle = true; - - FontColor = Color.White; - FontColorDisabled = Color.Gray; - DropShadowSize = 10; - - WindowNoTitle = new Surface(files, "window_no_title.png"); - WindowWithTitle = new Surface(files, "window_client.png"); - WindowTitleBar = new Surface(files, "window_titlebar.png"); - WindowTitleBarStretchRegion = new Rectangle(6, 3, 52, 27); - WindowNoTitleStretchRegion = new Rectangle(5, 5, 54, 54); - WindowWithTitleStretchRegion = new Rectangle(7, 4, 50, 53); - - SetButtonImages(new Surface(files, "button.png"), new Size(64, 32)); - ButtonStretchRegion = new Rectangle(6, 6, 52, 20); - ButtonTextPadding = 2; - ButtonMargin = 1; - - SetCheckBoxImages(new Surface(files, "checkbox.png"), new Size(16, 16)); - CheckBoxSpacing = 5; - CheckBoxMargin = 2; - - SetRadioButtonImages(new Surface(files, "radiobutton.png"), new Size(16, 16)); - RadioButtonSpacing = 5; - RadioButtonMargin = 2; - - CloseButton = CheckBox; - CloseButtonInactive = CheckBoxDisabled; - CloseButtonHover = CheckBoxHover; - - SetTextBoxImages(new Surface(files, "textbox.png"), new Size(64, 16)); - TextBoxMargin = 3; - TextBoxStretchRegion = new Rectangle(3, 3, 58, 10); - } - - - private void SetTextBoxImages(Surface surface, Size boxSize) - { - Surface[] surfs = SplitSurface("textbox", surface, boxSize, 4, 4); - - TextBox = surfs[0]; - TextBoxDisabled = surfs[1]; - TextBoxHover = surfs[2]; - TextBoxFocus = surfs[3]; - - surface.Dispose(); - } - - private void SetCheckBoxImages(Surface surface, Size boxSize) - { - Surface[] surfs = SplitSurface("checkbox", surface, boxSize, 5, 5); - - CheckBox = surfs[0]; - CheckBoxDisabled = surfs[1]; - CheckBoxCheck = surfs[2]; - CheckBoxHover = surfs[3]; - CheckBoxFocus = surfs[4]; - - surface.Dispose(); - } - - private void SetRadioButtonImages(Surface surface, Size boxSize) - { - Surface[] surfs = SplitSurface("RadioButton", surface, boxSize, 5, 5); - - RadioButton = surfs[0]; - RadioButtonDisabled = surfs[1]; - RadioButtonCheck = surfs[2]; - RadioButtonHover = surfs[3]; - RadioButtonFocus = surfs[4]; - - surface.Dispose(); - } - private void SetButtonImages(Surface surface, Size buttonSize) - { - Surface[] surfs = SplitSurface("button", surface, buttonSize, 6, 6); - - Button = surfs[0]; - ButtonDefault = surfs[1]; - ButtonPressed = surfs[2]; - ButtonDisabled = surfs[3]; - ButtonHover = surfs[4]; - ButtonFocus = surfs[5]; - - surface.Dispose(); - } - - private Surface[] SplitSurface(string name, Surface surface, Size subSurfaceSize, - int requiredImages, int maxImages) - { - Point pt = new Point(); - PixelBuffer pixels = surface.ReadPixels(); - - List<Surface> retval = new List<Surface>(); - - for (int i = 0; i < maxImages; i++) - { - Surface surf = new Surface(subSurfaceSize); - surf.WritePixels(pixels, new Rectangle(pt, subSurfaceSize), Point.Empty); - - retval.Add(surf); - - pt.X += subSurfaceSize.Width; - if (pt.X == surface.SurfaceWidth) - { - pt.X = 0; - pt.Y += subSurfaceSize.Height; - } - else if (pt.X > surface.SurfaceWidth) - { - throw new AgateGuiException( - "Image for " + name + - " does not have a width that is a multiple of " + subSurfaceSize.Width + "."); - } - - if (pt.Y + subSurfaceSize.Height > surface.SurfaceHeight) - { - if (retval.Count < requiredImages) - throw new AgateGuiException( - "There are not enough subimages in the " + name + " image."); - } - } - - return retval.ToArray(); - } - - int mInsertionPointBlinkTime = 500; - - public int InsertionPointBlinkTime - { - get { return mInsertionPointBlinkTime; } - set - { - if (value < 1) - throw new ArgumentNullException(); - - mInsertionPointBlinkTime = value; - } - } - public FontSurface WidgetFont { get; set; } - public FontSurface TitleFont { get; set; } - public bool CenterTitle { get; set; } - public int DropShadowSize { get; set; } - - public Color FontColor { get; set; } - public Color FontColorDisabled { get; set; } - public Surface WindowNoTitle { get; set; } - public Surface WindowWithTitle { get; set; } - public Surface WindowTitleBar { get; set; } - public Rectangle WindowNoTitleStretchRegion { get; set; } - public Rectangle WindowWithTitleStretchRegion { get; set; } - public Rectangle WindowTitleBarStretchRegion { get; set; } - - public Surface CloseButton { get; set; } - public Surface CloseButtonHover { get; set; } - public Surface CloseButtonInactive { get; set; } - - public Rectangle ButtonStretchRegion { get; set; } - public Surface Button { get; set; } - public Surface ButtonDefault { get; set; } - public Surface ButtonPressed { get; set; } - public Surface ButtonDisabled { get; set; } - public Surface ButtonHover { get; set; } - public Surface ButtonFocus { get; set; } - public int ButtonTextPadding { get; set; } - public int ButtonMargin { get; set; } - - public Surface CheckBox { get; set; } - public Surface CheckBoxDisabled { get; set; } - public Surface CheckBoxCheck { get; set; } - public Surface CheckBoxHover { get; set; } - public Surface CheckBoxFocus { get; set; } - public int CheckBoxSpacing { get; set; } - public int CheckBoxMargin { get; set; } - - public Surface RadioButton { get; set; } - public Surface RadioButtonDisabled { get; set; } - public Surface RadioButtonCheck { get; set; } - public Surface RadioButtonHover { get; set; } - public Surface RadioButtonFocus { get; set; } - public int RadioButtonSpacing { get; set; } - public int RadioButtonMargin { get; set; } - - public Surface TextBox { get; set; } - public Surface TextBoxDisabled { get; set; } - public Surface TextBoxHover { get; set; } - public Surface TextBoxFocus { get; set; } - public Rectangle TextBoxStretchRegion { get; set; } - public int TextBoxMargin { get; set; } - - } -} Modified: branches/gui-3.2/AgateLib/InternalResources/agate-black-gui.zip =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-20 06:18:39
|
Revision: 897 http://agate.svn.sourceforge.net/agate/?rev=897&view=rev Author: kanato Date: 2009-04-20 06:18:37 +0000 (Mon, 20 Apr 2009) Log Message: ----------- Add keyboard interaction with checkbox and radio button. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/CheckBox.cs branches/gui-3.2/AgateLib/Gui/RadioButton.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs Modified: branches/gui-3.2/AgateLib/Gui/CheckBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/CheckBox.cs 2009-04-20 05:52:37 UTC (rev 896) +++ branches/gui-3.2/AgateLib/Gui/CheckBox.cs 2009-04-20 06:18:37 UTC (rev 897) @@ -29,6 +29,13 @@ } } + public override bool CanHaveFocus + { + get + { + return true; + } + } bool mouseDownIn; protected internal override void OnMouseDown(AgateLib.InputLib.InputEventArgs e) @@ -47,6 +54,13 @@ } + protected internal override void SendKeyDown(AgateLib.InputLib.InputEventArgs e) + { + if (e.KeyCode == AgateLib.InputLib.KeyCode.Space) + { + Checked = !Checked; + } + } private void OnCheckChanged() { Modified: branches/gui-3.2/AgateLib/Gui/RadioButton.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/RadioButton.cs 2009-04-20 05:52:37 UTC (rev 896) +++ branches/gui-3.2/AgateLib/Gui/RadioButton.cs 2009-04-20 06:18:37 UTC (rev 897) @@ -45,7 +45,22 @@ } } + public override bool CanHaveFocus + { + get + { + return true; + } + } + protected internal override void SendKeyDown(AgateLib.InputLib.InputEventArgs e) + { + if (e.KeyCode == AgateLib.InputLib.KeyCode.Space) + { + Checked = true; + } + } + bool mouseDownIn; protected internal override void OnMouseDown(AgateLib.InputLib.InputEventArgs e) { @@ -57,7 +72,7 @@ protected internal override void OnMouseUp(AgateLib.InputLib.InputEventArgs e) { if (MouseIn && mouseDownIn) - Checked = !Checked; + Checked = true; mouseDownIn = false; } Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-20 05:52:37 UTC (rev 896) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-20 06:18:37 UTC (rev 897) @@ -48,7 +48,7 @@ SetCheckBoxImages(new Surface(files, "checkbox.png"), new Size(16, 16)); CheckBoxSpacing = 5; - CheckBoxMargin = 6; + CheckBoxMargin = 2; SetRadioButtonImages(new Surface(files, "radiobutton.png"), new Size(16, 16)); RadioButtonSpacing = 5; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-20 05:52:40
|
Revision: 896 http://agate.svn.sourceforge.net/agate/?rev=896&view=rev Author: kanato Date: 2009-04-20 05:52:37 +0000 (Mon, 20 Apr 2009) Log Message: ----------- Update GUI images to be layered. Updated control styles. Added radio button style. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs branches/gui-3.2/AgateLib/InternalResources/agate-black-gui.zip Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs 2009-04-20 05:51:24 UTC (rev 895) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs 2009-04-20 05:52:37 UTC (rev 896) @@ -91,8 +91,6 @@ if (textBox.Enabled == false) image = Scheme.TextBoxDisabled; - else if (textBox.MouseIn) - image = Scheme.TextBoxHover; Point location = textBox.PointToScreen(new Point(0, 0)); Size size = textBox.Size; @@ -100,6 +98,20 @@ DrawStretchImage(location, size, image, Scheme.TextBoxStretchRegion); + if (textBox.Enabled) + { + if (textBox.HasFocus) + { + DrawStretchImage(location, size, + Scheme.TextBoxFocus, Scheme.TextBoxStretchRegion); + } + if (textBox.MouseIn) + { + DrawStretchImage(location, size, + Scheme.TextBoxHover, Scheme.TextBoxStretchRegion); + } + } + Scheme.WidgetFont.DisplayAlignment = OriginAlignment.TopLeft; SetControlFontColor(textBox); @@ -174,11 +186,8 @@ { Surface surf; - if (checkbox.Enabled == false && checkbox.Checked) surf = Scheme.CheckBoxCheckedDisabled; - else if (checkbox.Enabled == false) surf = Scheme.CheckBoxDisabled; - else if (checkbox.Checked && checkbox.MouseIn) surf = Scheme.CheckBoxCheckedHover; - else if (checkbox.Checked) surf = Scheme.CheckBoxChecked; - else if (checkbox.MouseIn) surf = Scheme.CheckBoxHover; + if (checkbox.Enabled == false) + surf = Scheme.CheckBoxDisabled; else surf = Scheme.CheckBox; @@ -188,6 +197,32 @@ surf.DisplayAlignment = OriginAlignment.CenterLeft; surf.Draw(destPoint); + if (checkbox.Enabled) + { + if (checkbox.HasFocus) + { + Scheme.CheckBoxFocus.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.CheckBoxFocus.Draw(destPoint); + } + if (checkbox.MouseIn) + { + Scheme.CheckBoxHover.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.CheckBoxHover.Draw(destPoint); + } + if (checkbox.Checked) + { + Scheme.CheckBoxCheck.Color = Color.White; + Scheme.CheckBoxCheck.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.CheckBoxCheck.Draw(destPoint); + } + } + else if (checkbox.Checked) + { + Scheme.CheckBoxCheck.Color = Color.Gray; + Scheme.CheckBoxCheck.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.CheckBoxCheck.Draw(destPoint); + } + SetControlFontColor(checkbox); destPoint.X += surf.DisplayWidth + Scheme.CheckBoxSpacing; @@ -195,7 +230,6 @@ Scheme.WidgetFont.DisplayAlignment = OriginAlignment.CenterLeft; Scheme.WidgetFont.DrawText(destPoint, checkbox.Text); } - private Size CalcMinCheckBoxSize(CheckBox checkbox) { Size text = Scheme.WidgetFont.StringDisplaySize(checkbox.Text); @@ -205,8 +239,6 @@ box.Width + Scheme.CheckBoxSpacing + text.Width, Math.Max(box.Height, text.Height)); } - - private bool HitTestCheckBox(CheckBox checkBox, Point screenLocation) { Point local = checkBox.PointToClient(screenLocation); @@ -220,53 +252,75 @@ return true; } - #endregion - #region --- CheckBox --- + #region --- Radio Button --- - private void DrawRadioButton(RadioButton checkbox) + private void DrawRadioButton(RadioButton radiobutton) { Surface surf; - if (checkbox.Enabled == false && checkbox.Checked) surf = Scheme.CheckBoxCheckedDisabled; - else if (checkbox.Enabled == false) surf = Scheme.CheckBoxDisabled; - else if (checkbox.Checked && checkbox.MouseIn) surf = Scheme.CheckBoxCheckedHover; - else if (checkbox.Checked) surf = Scheme.CheckBoxChecked; - else if (checkbox.MouseIn) surf = Scheme.CheckBoxHover; + if (radiobutton.Enabled == false) + surf = Scheme.RadioButtonDisabled; else - surf = Scheme.CheckBox; + surf = Scheme.RadioButton; - Point destPoint = checkbox.PointToScreen( - Origin.Calc(OriginAlignment.CenterLeft, checkbox.Size)); + Point destPoint = radiobutton.PointToScreen( + Origin.Calc(OriginAlignment.CenterLeft, radiobutton.Size)); surf.DisplayAlignment = OriginAlignment.CenterLeft; surf.Draw(destPoint); - SetControlFontColor(checkbox); + if (radiobutton.Enabled) + { + if (radiobutton.HasFocus) + { + Scheme.RadioButtonFocus.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.RadioButtonFocus.Draw(destPoint); + } + if (radiobutton.MouseIn) + { + Scheme.RadioButtonHover.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.RadioButtonHover.Draw(destPoint); + } + if (radiobutton.Checked) + { + Scheme.RadioButtonCheck.Color = Color.White; + Scheme.RadioButtonCheck.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.RadioButtonCheck.Draw(destPoint); + } + } + else if (radiobutton.Checked) + { + Scheme.RadioButtonCheck.Color = Scheme.FontColorDisabled; + Scheme.RadioButtonCheck.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.RadioButtonCheck.Draw(destPoint); + } - destPoint.X += surf.DisplayWidth + Scheme.CheckBoxSpacing; + SetControlFontColor(radiobutton); + destPoint.X += surf.DisplayWidth + Scheme.RadioButtonSpacing; + Scheme.WidgetFont.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.WidgetFont.DrawText(destPoint, checkbox.Text); + Scheme.WidgetFont.DrawText(destPoint, radiobutton.Text); } - private Size CalcMinRadioButtonSize(RadioButton checkbox) + private Size CalcMinRadioButtonSize(RadioButton radiobutton) { - Size text = Scheme.WidgetFont.StringDisplaySize(checkbox.Text); - Size box = Scheme.CheckBox.SurfaceSize; + Size text = Scheme.WidgetFont.StringDisplaySize(radiobutton.Text); + Size box = Scheme.RadioButton.SurfaceSize; return new Size( - box.Width + Scheme.CheckBoxSpacing + text.Width, + box.Width + Scheme.RadioButtonSpacing + text.Width, Math.Max(box.Height, text.Height)); } - private bool HitTestRadioButton(RadioButton checkBox, Point screenLocation) + private bool HitTestRadioButton(RadioButton radioButton, Point screenLocation) { - Point local = checkBox.PointToClient(screenLocation); + Point local = radioButton.PointToClient(screenLocation); - int right = Scheme.CheckBox.SurfaceWidth + - Scheme.WidgetFont.StringDisplayWidth(checkBox.Text) + Scheme.CheckBoxSpacing * 2; + int right = Scheme.RadioButton.SurfaceWidth + + Scheme.WidgetFont.StringDisplayWidth(radioButton.Text) + Scheme.RadioButtonSpacing * 2; if (local.X > right) return false; @@ -305,20 +359,15 @@ private void DrawButton(Button button) { Surface image = Scheme.Button; + bool isDefault = button.IsDefaultButton; if (button.Enabled == false) image = Scheme.ButtonDisabled; else if (button.DrawActivated) image = Scheme.ButtonPressed; - else if (isDefault && button.MouseIn) - image = Scheme.ButtonDefaultHover; else if (isDefault) image = Scheme.ButtonDefault; - else if (button.MouseIn) - image = Scheme.ButtonHover; - else if (button.HasFocus) - image = Scheme.ButtonHover; Point location = button.PointToScreen(Point.Empty); Size size = new Size(button.Width, button.Height); @@ -326,6 +375,21 @@ DrawStretchImage(location, size, image, Scheme.ButtonStretchRegion); + if (button.Enabled) + { + if (button.MouseIn) + { + DrawStretchImage(location, size, + Scheme.ButtonHover, Scheme.ButtonStretchRegion); + } + if (button.HasFocus) + { + DrawStretchImage(location, size, + Scheme.ButtonFocus, Scheme.ButtonStretchRegion); + } + } + + // Draw button text SetControlFontColor(button); Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-20 05:51:24 UTC (rev 895) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-20 05:52:37 UTC (rev 896) @@ -50,50 +50,67 @@ CheckBoxSpacing = 5; CheckBoxMargin = 6; + SetRadioButtonImages(new Surface(files, "radiobutton.png"), new Size(16, 16)); + RadioButtonSpacing = 5; + RadioButtonMargin = 2; + CloseButton = CheckBox; CloseButtonInactive = CheckBoxDisabled; CloseButtonHover = CheckBoxHover; SetTextBoxImages(new Surface(files, "textbox.png"), new Size(64, 16)); - TextBoxMargin = 2; + TextBoxMargin = 3; TextBoxStretchRegion = new Rectangle(3, 3, 58, 10); } + private void SetTextBoxImages(Surface surface, Size boxSize) { - Surface[] surfs = SplitSurface("textbox", surface, boxSize, 3, 3); + Surface[] surfs = SplitSurface("textbox", surface, boxSize, 4, 4); TextBox = surfs[0]; - TextBoxHover = surfs[1]; - TextBoxDisabled = surfs[2]; + TextBoxDisabled = surfs[1]; + TextBoxHover = surfs[2]; + TextBoxFocus = surfs[3]; surface.Dispose(); } private void SetCheckBoxImages(Surface surface, Size boxSize) { - Surface[] surfs = SplitSurface("checkbox", surface, boxSize, 6, 6); + Surface[] surfs = SplitSurface("checkbox", surface, boxSize, 5, 5); - CheckBoxDisabled = surfs[0]; - CheckBox = surfs[1]; - CheckBoxHover = surfs[2]; - CheckBoxCheckedDisabled = surfs[3]; - CheckBoxChecked = surfs[4]; - CheckBoxCheckedHover = surfs[5]; + CheckBox = surfs[0]; + CheckBoxDisabled = surfs[1]; + CheckBoxCheck = surfs[2]; + CheckBoxHover = surfs[3]; + CheckBoxFocus = surfs[4]; surface.Dispose(); } + private void SetRadioButtonImages(Surface surface, Size boxSize) + { + Surface[] surfs = SplitSurface("RadioButton", surface, boxSize, 5, 5); + + RadioButton = surfs[0]; + RadioButtonDisabled = surfs[1]; + RadioButtonCheck = surfs[2]; + RadioButtonHover = surfs[3]; + RadioButtonFocus = surfs[4]; + + surface.Dispose(); + } private void SetButtonImages(Surface surface, Size buttonSize) { Surface[] surfs = SplitSurface("button", surface, buttonSize, 6, 6); Button = surfs[0]; - ButtonHover = surfs[1]; - ButtonDefault = surfs[2]; - ButtonDefaultHover = surfs[3]; - ButtonPressed = surfs[4]; - ButtonDisabled = surfs[5]; + ButtonDefault = surfs[1]; + ButtonPressed = surfs[2]; + ButtonDisabled = surfs[3]; + ButtonHover = surfs[4]; + ButtonFocus = surfs[5]; surface.Dispose(); } @@ -171,25 +188,33 @@ public Rectangle ButtonStretchRegion { get; set; } public Surface Button { get; set; } public Surface ButtonDefault { get; set; } - public Surface ButtonDefaultHover { get; set; } - public Surface ButtonHover { get; set; } public Surface ButtonPressed { get; set; } public Surface ButtonDisabled { get; set; } + public Surface ButtonHover { get; set; } + public Surface ButtonFocus { get; set; } public int ButtonTextPadding { get; set; } public int ButtonMargin { get; set; } public Surface CheckBox { get; set; } + public Surface CheckBoxDisabled { get; set; } + public Surface CheckBoxCheck { get; set; } public Surface CheckBoxHover { get; set; } - public Surface CheckBoxDisabled { get; set; } - public Surface CheckBoxChecked { get; set; } - public Surface CheckBoxCheckedHover { get; set; } - public Surface CheckBoxCheckedDisabled { get; set; } + public Surface CheckBoxFocus { get; set; } public int CheckBoxSpacing { get; set; } public int CheckBoxMargin { get; set; } + public Surface RadioButton { get; set; } + public Surface RadioButtonDisabled { get; set; } + public Surface RadioButtonCheck { get; set; } + public Surface RadioButtonHover { get; set; } + public Surface RadioButtonFocus { get; set; } + public int RadioButtonSpacing { get; set; } + public int RadioButtonMargin { get; set; } + public Surface TextBox { get; set; } + public Surface TextBoxDisabled { get; set; } public Surface TextBoxHover { get; set; } - public Surface TextBoxDisabled { get; set; } + public Surface TextBoxFocus { get; set; } public Rectangle TextBoxStretchRegion { get; set; } public int TextBoxMargin { get; set; } Modified: branches/gui-3.2/AgateLib/InternalResources/agate-black-gui.zip =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-20 05:51:25
|
Revision: 895 http://agate.svn.sourceforge.net/agate/?rev=895&view=rev Author: kanato Date: 2009-04-20 05:51:24 +0000 (Mon, 20 Apr 2009) Log Message: ----------- Add ToString method in FileHeader structure. Modified Paths: -------------- branches/gui-3.2/AgateLib/Utility/ZipFileProvider.cs Modified: branches/gui-3.2/AgateLib/Utility/ZipFileProvider.cs =================================================================== --- branches/gui-3.2/AgateLib/Utility/ZipFileProvider.cs 2009-04-20 03:42:39 UTC (rev 894) +++ branches/gui-3.2/AgateLib/Utility/ZipFileProvider.cs 2009-04-20 05:51:24 UTC (rev 895) @@ -27,6 +27,11 @@ public long DataOffset { get; set; } public int DataSize { get; set; } public ZipStorageType StorageType { get; set; } + + public override string ToString() + { + return "Header: " + Filename; + } } class ZipFileEntryStream : Stream { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-20 03:42:41
|
Revision: 894 http://agate.svn.sourceforge.net/agate/?rev=894&view=rev Author: kanato Date: 2009-04-20 03:42:39 +0000 (Mon, 20 Apr 2009) Log Message: ----------- Fixes to fonts. Modified Paths: -------------- branches/gui-3.2/AgateLib/InternalResources/Data.cs Modified: branches/gui-3.2/AgateLib/InternalResources/Data.cs =================================================================== --- branches/gui-3.2/AgateLib/InternalResources/Data.cs 2009-04-20 02:37:40 UTC (rev 893) +++ branches/gui-3.2/AgateLib/InternalResources/Data.cs 2009-04-20 03:42:39 UTC (rev 894) @@ -25,8 +25,11 @@ static void Display_DisposeDisplay() { - mPoweredBy.Dispose(); - mPoweredBy = null; + if (mPoweredBy != null) + { + mPoweredBy.Dispose(); + mPoweredBy = null; + } foreach (var font in mAndika) font.Value.Dispose(); @@ -40,7 +43,10 @@ private static void LoadFonts() { - mFontResources = new AgateResourceCollection(mFontProvider); + if (mFontResources == null) + { + mFontResources = new AgateResourceCollection(mFontProvider); + } } internal static Surface PoweredBy @@ -85,19 +91,19 @@ internal static FontSurface Andika09 { - get { return GetFont(mGentium, 9, "Andika-09"); } + get { return GetFont(mAndika, 9, "Andika-09"); } } internal static FontSurface Andika10 { - get { return GetFont(mGentium, 10, "Andika-10"); } + get { return GetFont(mAndika, 10, "Andika-10"); } } internal static FontSurface Andika12 { - get { return GetFont(mGentium, 12, "Andika-12"); } + get { return GetFont(mAndika, 12, "Andika-12"); } } internal static FontSurface Andika14 { - get { return GetFont(mGentium, 14, "Andika-14"); } + get { return GetFont(mAndika, 14, "Andika-14"); } } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-20 02:37:41
|
Revision: 893 http://agate.svn.sourceforge.net/agate/?rev=893&view=rev Author: kanato Date: 2009-04-20 02:37:40 +0000 (Mon, 20 Apr 2009) Log Message: ----------- Use Andika 9/10 for widget/title fonts. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-20 02:37:10 UTC (rev 892) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-20 02:37:40 UTC (rev 893) @@ -27,7 +27,7 @@ void SetDefaults(IFileProvider files) { WidgetFont = FontSurface.Andika09; - TitleFont = FontSurface.Andika12; + TitleFont = FontSurface.Andika10; CenterTitle = true; FontColor = Color.White; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-20 02:37:12
|
Revision: 892 http://agate.svn.sourceforge.net/agate/?rev=892&view=rev Author: kanato Date: 2009-04-20 02:37:10 +0000 (Mon, 20 Apr 2009) Log Message: ----------- Refactor font data so it is properly disposed when display is disposed. Modified Paths: -------------- branches/gui-3.2/AgateLib/InternalResources/Data.cs Modified: branches/gui-3.2/AgateLib/InternalResources/Data.cs =================================================================== --- branches/gui-3.2/AgateLib/InternalResources/Data.cs 2009-04-20 02:36:37 UTC (rev 891) +++ branches/gui-3.2/AgateLib/InternalResources/Data.cs 2009-04-20 02:37:10 UTC (rev 892) @@ -15,9 +15,29 @@ static AgateResourceCollection mFontResources; static Surface mPoweredBy; - static FontSurface mGentium10,mGentium12,mGentium14; - static FontSurface mAndika09, mAndika10, mAndika12, mAndika14; + static Dictionary<int, FontSurface> mGentium = new Dictionary<int, FontSurface>(); + static Dictionary<int, FontSurface> mAndika = new Dictionary<int, FontSurface>(); + static Data() + { + Display.DisposeDisplay += new Display.DisposeDisplayHandler(Display_DisposeDisplay); + } + + static void Display_DisposeDisplay() + { + mPoweredBy.Dispose(); + mPoweredBy = null; + + foreach (var font in mAndika) + font.Value.Dispose(); + + foreach (var font in mGentium) + font.Value.Dispose(); + + mAndika.Clear(); + mGentium.Clear(); + } + private static void LoadFonts() { mFontResources = new AgateResourceCollection(mFontProvider); @@ -36,92 +56,48 @@ } } - - internal static FontSurface Gentium10 + private static FontSurface GetFont(Dictionary<int, FontSurface> dictionary, int size, string resourceName) { - get + LoadFonts(); + + if (dictionary.ContainsKey(size) == false) { - LoadFonts(); + FontSurface font = new FontSurface(mFontResources, resourceName); + dictionary[size] = font; + } - if (mGentium10 == null) - mGentium10 = new FontSurface(mFontResources, "Gentium-10"); + return dictionary[size]; + } - return mGentium10; - } + internal static FontSurface Gentium10 + { + get { return GetFont(mGentium, 10, "Gentium-10"); } } + internal static FontSurface Gentium12 { - get - { - LoadFonts(); - - if (mGentium12 == null) - mGentium12 = new FontSurface(mFontResources, "Gentium-12"); - - return mGentium12; - } + get { return GetFont(mGentium, 12, "Gentium-12"); } } internal static FontSurface Gentium14 { - get - { - LoadFonts(); - - if (mGentium14 == null) - mGentium14 = new FontSurface(mFontResources, "Gentium-14"); - - return mGentium14; - } + get { return GetFont(mGentium, 14, "Gentium-14"); } } internal static FontSurface Andika09 { - get - { - LoadFonts(); - - if (mAndika09 == null) - mAndika09 = new FontSurface(mFontResources, "Andika-09"); - - return mAndika09; - } + get { return GetFont(mGentium, 9, "Andika-09"); } } internal static FontSurface Andika10 { - get - { - LoadFonts(); - - if (mAndika10 == null) - mAndika10 = new FontSurface(mFontResources, "Andika-10"); - - return mAndika10; - } + get { return GetFont(mGentium, 10, "Andika-10"); } } internal static FontSurface Andika12 { - get - { - LoadFonts(); - - if (mAndika12 == null) - mAndika12 = new FontSurface(mFontResources, "Andika-12"); - - return mAndika12; - } + get { return GetFont(mGentium, 12, "Andika-12"); } } internal static FontSurface Andika14 { - get - { - LoadFonts(); - - if (mAndika14 == null) - mAndika14 =new FontSurface(mFontResources, "Andika-14"); - - - return mAndika14; - } + get { return GetFont(mGentium, 14, "Andika-14"); } } } -} +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-20 02:36:45
|
Revision: 891 http://agate.svn.sourceforge.net/agate/?rev=891&view=rev Author: kanato Date: 2009-04-20 02:36:37 +0000 (Mon, 20 Apr 2009) Log Message: ----------- Fix StringDisplaySize to not crash when a glyph that doesn't exist in the font is entered. Modified Paths: -------------- branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs Modified: branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs =================================================================== --- branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-19 18:59:20 UTC (rev 890) +++ branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-20 02:36:37 UTC (rev 891) @@ -182,6 +182,9 @@ for (int j = 0; j < line.Length; j++) { + if (mFontMetrics.ContainsKey(line[j]) == false) + continue; + lineWidth += mFontMetrics[line[j]].Width; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-19 18:59:29
|
Revision: 890 http://agate.svn.sourceforge.net/agate/?rev=890&view=rev Author: kanato Date: 2009-04-19 18:59:20 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Include serif/sans serif in font comments. Modified Paths: -------------- branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs Modified: branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs =================================================================== --- branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-04-19 18:52:40 UTC (rev 889) +++ branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-04-19 18:59:20 UTC (rev 890) @@ -333,7 +333,7 @@ #region --- Built-in Fonts --- /// <summary> - /// This bitmap font was generated from Andika at 9 points. + /// This sans serif bitmap font was generated from Andika at 9 points. /// </summary> /// <remarks> /// Andika is Copyright (c) 2004-2008, SIL International and @@ -345,7 +345,7 @@ get { return InternalResources.Data.Andika09; } } /// <summary> - /// This bitmap font was generated from Andika at 10 points. + /// This sans serif bitmap font was generated from Andika at 10 points. /// </summary> /// <remarks> /// Andika is Copyright (c) 2004-2008, SIL International and @@ -357,7 +357,7 @@ get { return InternalResources.Data.Andika10; } } /// <summary> - /// This bitmap font was generated from Andika at 12 points. + /// This sans serif bitmap font was generated from Andika at 12 points. /// </summary> /// <remarks> /// Andika is Copyright (c) 2004-2008, SIL International and @@ -369,7 +369,7 @@ get { return InternalResources.Data.Andika12; } } /// <summary> - /// This bitmap font was generated from Andika at 14 points. + /// This sans serif bitmap font was generated from Andika at 14 points. /// </summary> /// <remarks> /// Andika is Copyright (c) 2004-2008, SIL International and @@ -382,7 +382,7 @@ } /// <summary> - /// This bitmap font was generated from Gentium at 10 points. + /// This serif bitmap font was generated from Gentium at 10 points. /// </summary> /// <remarks> /// Gentium is Copyright (c) 2004-2008, SIL International and @@ -394,7 +394,7 @@ get { return InternalResources.Data.Gentium10; } } /// <summary> - /// This bitmap font was generated from Gentium at 12 points. + /// This serif bitmap font was generated from Gentium at 12 points. /// </summary> /// <remarks> /// Gentium is Copyright (c) 2004-2008, SIL International and @@ -406,7 +406,7 @@ get { return InternalResources.Data.Gentium12; } } /// <summary> - /// This bitmap font was generated from Gentium at 14 points. + /// This serif bitmap font was generated from Gentium at 14 points. /// </summary> /// <remarks> /// Gentium is Copyright (c) 2004-2008, SIL International and This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-19 18:52:49
|
Revision: 889 http://agate.svn.sourceforge.net/agate/?rev=889&view=rev Author: kanato Date: 2009-04-19 18:52:40 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Add built-in font test. Added Paths: ----------- branches/gui-3.2/Tests/Fonts/Builtin.cs Added: branches/gui-3.2/Tests/Fonts/Builtin.cs =================================================================== --- branches/gui-3.2/Tests/Fonts/Builtin.cs (rev 0) +++ branches/gui-3.2/Tests/Fonts/Builtin.cs 2009-04-19 18:52:40 UTC (rev 889) @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib; +using AgateLib.DisplayLib; +using AgateLib.Geometry; + +namespace Tests.Fonts +{ + class Builtin : AgateApplication, IAgateTest + { + #region IAgateTest Members + + public string Name + { + get { return "Built-in font tests"; } + } + + public string Category + { + get { return "Fonts"; } + } + + public void Main(string[] args) + { + Run(args); + } + + #endregion + + List<FontSurface> fonts = new List<FontSurface>(); + string nonenglish; + + protected override AppInitParameters GetAppInitParameters() + { + var retval = base.GetAppInitParameters(); + + retval.AllowResize = true; + retval.ShowSplashScreen = false; + + return retval; + } + + protected override void Initialize() + { + base.Initialize(); + + fonts.Add(FontSurface.Andika09); + fonts.Add(FontSurface.Andika10); + fonts.Add(FontSurface.Andika12); + fonts.Add(FontSurface.Andika14); + + fonts.Add(FontSurface.Gentium10); + fonts.Add(FontSurface.Gentium12); + fonts.Add(FontSurface.Gentium14); + + for (char i = (char)128; i < 255; i++) + { + nonenglish += i; + } + } + protected override void Render() + { + Display.Clear(Color.Black); + + int y = 0; + foreach(var font in fonts) + { + font.Color = Color.White; + + font.DrawText(0, y, font.FontName); + int x = font.StringDisplayWidth(font.FontName) + 40; + + font.DrawText(x, y, "The quick brown fox jumped over the lazy dogs."); + y += font.FontHeight; + + font.DrawText(x, y, "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS."); + y += font.FontHeight; + + font.DrawText(x, y, nonenglish); + y += font.FontHeight; + + y += font.FontHeight; + } + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-19 18:51:43
|
Revision: 888 http://agate.svn.sourceforge.net/agate/?rev=888&view=rev Author: kanato Date: 2009-04-19 18:51:33 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Dump Prociono in favor of Gentium and Andika. Modified Paths: -------------- branches/gui-3.2/AgateLib/AgateApplication.cs branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs branches/gui-3.2/AgateLib/InternalResources/Data.cs branches/gui-3.2/AgateLib/InternalResources/DataResources.Designer.cs branches/gui-3.2/AgateLib/InternalResources/DataResources.resx branches/gui-3.2/Drivers/AgateLib.WinForms/BitmapFontUtil.cs Added Paths: ----------- branches/gui-3.2/AgateLib/InternalResources/Fonts.zip Removed Paths: ------------- branches/gui-3.2/AgateLib/InternalResources/Prociono.zip Modified: branches/gui-3.2/AgateLib/AgateApplication.cs =================================================================== --- branches/gui-3.2/AgateLib/AgateApplication.cs 2009-04-19 18:08:08 UTC (rev 887) +++ branches/gui-3.2/AgateLib/AgateApplication.cs 2009-04-19 18:51:33 UTC (rev 888) @@ -79,7 +79,7 @@ CreateDisplayWindow(); - font = FontSurface.Prociono11; + font = FontSurface.Gentium12; if (InitParams.ShowSplashScreen) { Modified: branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs =================================================================== --- branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-19 18:08:08 UTC (rev 887) +++ branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-19 18:51:33 UTC (rev 888) @@ -50,6 +50,7 @@ /// <param name="characterSize"></param> public BitmapFontImpl(string filename, Size characterSize) { + FontName = System.IO.Path.GetFileNameWithoutExtension(filename); mFontMetrics = new FontMetrics(); mSurface = new Surface(filename); @@ -65,8 +66,9 @@ /// <param name="surface">Surface which contains the image data for the font glyphs.</param> /// <param name="fontMetrics">FontMetrics structure which describes how characters /// are laid out.</param> - public BitmapFontImpl(Surface surface, FontMetrics fontMetrics) + public BitmapFontImpl(Surface surface, FontMetrics fontMetrics, string name) { + FontName = name; mFontMetrics = (FontMetrics)((ICloneable)fontMetrics).Clone(); float maxHeight = 0; @@ -266,6 +268,10 @@ break; default: + if (mFontMetrics.ContainsKey(text[i]) == false) + { + break; + } GlyphMetrics glyph = mFontMetrics[text[i]]; destX = Math.Max(0, destX - glyph.LeftOverhang * ScaleWidth); Modified: branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs =================================================================== --- branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-04-19 18:08:08 UTC (rev 887) +++ branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-04-19 18:51:33 UTC (rev 888) @@ -107,7 +107,7 @@ { Surface surf = new Surface(resources.FileProvider, bmpFont.Image); - impl = new BitmapFontImpl(surf, bmpFont.FontMetrics); + impl = new BitmapFontImpl(surf, bmpFont.FontMetrics, resourceName); } else throw new AgateResourceException(string.Format( @@ -126,6 +126,10 @@ Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose); } + public string FontName + { + get { return impl.FontName; } + } /// <summary> /// Private initializer to tell it what impl to use. /// </summary> @@ -328,15 +332,92 @@ #region --- Built-in Fonts --- - public static FontSurface Prociono11 + /// <summary> + /// This bitmap font was generated from Andika at 9 points. + /// </summary> + /// <remarks> + /// Andika is Copyright (c) 2004-2008, SIL International and + /// distributed under the Open Font License. + /// http://scripts.sil.org/OFL + /// </remarks> + public static FontSurface Andika09 { - get { return InternalResources.Data.Prociono11; } + get { return InternalResources.Data.Andika09; } } - public static FontSurface Prociono14 + /// <summary> + /// This bitmap font was generated from Andika at 10 points. + /// </summary> + /// <remarks> + /// Andika is Copyright (c) 2004-2008, SIL International and + /// distributed under the Open Font License. + /// http://scripts.sil.org/OFL + /// </remarks> + public static FontSurface Andika10 { - get { return InternalResources.Data.Prociono14; } + get { return InternalResources.Data.Andika10; } } + /// <summary> + /// This bitmap font was generated from Andika at 12 points. + /// </summary> + /// <remarks> + /// Andika is Copyright (c) 2004-2008, SIL International and + /// distributed under the Open Font License. + /// http://scripts.sil.org/OFL + /// </remarks> + public static FontSurface Andika12 + { + get { return InternalResources.Data.Andika12; } + } + /// <summary> + /// This bitmap font was generated from Andika at 14 points. + /// </summary> + /// <remarks> + /// Andika is Copyright (c) 2004-2008, SIL International and + /// distributed under the Open Font License. + /// http://scripts.sil.org/OFL + /// </remarks> + public static FontSurface Andika14 + { + get { return InternalResources.Data.Andika14; } + } + /// <summary> + /// This bitmap font was generated from Gentium at 10 points. + /// </summary> + /// <remarks> + /// Gentium is Copyright (c) 2004-2008, SIL International and + /// distributed under the Open Font License. + /// http://scripts.sil.org/OFL + /// </remarks> + public static FontSurface Gentium10 + { + get { return InternalResources.Data.Gentium10; } + } + /// <summary> + /// This bitmap font was generated from Gentium at 12 points. + /// </summary> + /// <remarks> + /// Gentium is Copyright (c) 2004-2008, SIL International and + /// distributed under the Open Font License. + /// http://scripts.sil.org/OFL + /// </remarks> + public static FontSurface Gentium12 + { + get { return InternalResources.Data.Gentium12; } + } + /// <summary> + /// This bitmap font was generated from Gentium at 14 points. + /// </summary> + /// <remarks> + /// Gentium is Copyright (c) 2004-2008, SIL International and + /// distributed under the Open Font License. + /// http://scripts.sil.org/OFL + /// </remarks> + public static FontSurface Gentium14 + { + get { return InternalResources.Data.Gentium14; } + } + #endregion } } Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-19 18:08:08 UTC (rev 887) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-19 18:51:33 UTC (rev 888) @@ -26,8 +26,8 @@ void SetDefaults(IFileProvider files) { - WidgetFont = new FontSurface("Prociono", 8); - TitleFont = new FontSurface("Sans Serif", 10); + WidgetFont = FontSurface.Andika09; + TitleFont = FontSurface.Andika12; CenterTitle = true; FontColor = Color.White; Modified: branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs =================================================================== --- branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs 2009-04-19 18:08:08 UTC (rev 887) +++ branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs 2009-04-19 18:51:33 UTC (rev 888) @@ -34,6 +34,7 @@ private Color mColor = Color.White; private double mScaleWidth = 1.0; private double mScaleHeight = 1.0; + private string mFontName = "Unknown"; /// <summary> /// Measures the width of the given string. @@ -55,6 +56,15 @@ public abstract Size StringDisplaySize(string text); /// <summary> + /// Returns the name/size of the font. + /// </summary> + public string FontName + { + get { return mFontName; } + protected internal set { mFontName = value; } + } + + /// <summary> /// Gets the height of a single line of text. /// </summary> public virtual int FontHeight Modified: branches/gui-3.2/AgateLib/InternalResources/Data.cs =================================================================== --- branches/gui-3.2/AgateLib/InternalResources/Data.cs 2009-04-19 18:08:08 UTC (rev 887) +++ branches/gui-3.2/AgateLib/InternalResources/Data.cs 2009-04-19 18:51:33 UTC (rev 888) @@ -11,15 +11,16 @@ internal static class Data { static TgzFileProvider mProvider = new TgzFileProvider("images", DataResources.images); - static ZipFileProvider mProcionoProvider = new ZipFileProvider("Prociono", DataResources.Prociono); + static ZipFileProvider mFontProvider = new ZipFileProvider("Fonts", DataResources.Fonts); static AgateResourceCollection mFontResources; static Surface mPoweredBy; - static FontSurface mProciono11, mProciono14; + static FontSurface mGentium10,mGentium12,mGentium14; + static FontSurface mAndika09, mAndika10, mAndika12, mAndika14; private static void LoadFonts() { - mFontResources = new AgateResourceCollection(mProcionoProvider); + mFontResources = new AgateResourceCollection(mFontProvider); } internal static Surface PoweredBy @@ -35,31 +36,92 @@ } } - internal static FontSurface Prociono11 + + internal static FontSurface Gentium10 { get { LoadFonts(); - if (mProciono11 == null) - mProciono11 = new FontSurface(mFontResources, "Prociono-11"); + if (mGentium10 == null) + mGentium10 = new FontSurface(mFontResources, "Gentium-10"); - return mProciono11; + return mGentium10; } } + internal static FontSurface Gentium12 + { + get + { + LoadFonts(); - internal static FontSurface Prociono14 + if (mGentium12 == null) + mGentium12 = new FontSurface(mFontResources, "Gentium-12"); + + return mGentium12; + } + } + internal static FontSurface Gentium14 { get { LoadFonts(); - if (mProciono14 == null) - mProciono14 = new FontSurface(mFontResources, "Prociono-14"); + if (mGentium14 == null) + mGentium14 = new FontSurface(mFontResources, "Gentium-14"); - return mProciono14; + return mGentium14; } } + internal static FontSurface Andika09 + { + get + { + LoadFonts(); + + if (mAndika09 == null) + mAndika09 = new FontSurface(mFontResources, "Andika-09"); + + return mAndika09; + } + } + internal static FontSurface Andika10 + { + get + { + LoadFonts(); + + if (mAndika10 == null) + mAndika10 = new FontSurface(mFontResources, "Andika-10"); + + return mAndika10; + } + } + internal static FontSurface Andika12 + { + get + { + LoadFonts(); + + if (mAndika12 == null) + mAndika12 = new FontSurface(mFontResources, "Andika-12"); + + return mAndika12; + } + } + internal static FontSurface Andika14 + { + get + { + LoadFonts(); + + if (mAndika14 == null) + mAndika14 =new FontSurface(mFontResources, "Andika-14"); + + + return mAndika14; + } + } } } Modified: branches/gui-3.2/AgateLib/InternalResources/DataResources.Designer.cs =================================================================== --- branches/gui-3.2/AgateLib/InternalResources/DataResources.Designer.cs 2009-04-19 18:08:08 UTC (rev 887) +++ branches/gui-3.2/AgateLib/InternalResources/DataResources.Designer.cs 2009-04-19 18:51:33 UTC (rev 888) @@ -67,16 +67,16 @@ } } - internal static byte[] images { + internal static byte[] Fonts { get { - object obj = ResourceManager.GetObject("images", resourceCulture); + object obj = ResourceManager.GetObject("Fonts", resourceCulture); return ((byte[])(obj)); } } - internal static byte[] Prociono { + internal static byte[] images { get { - object obj = ResourceManager.GetObject("Prociono", resourceCulture); + object obj = ResourceManager.GetObject("images", resourceCulture); return ((byte[])(obj)); } } Modified: branches/gui-3.2/AgateLib/InternalResources/DataResources.resx =================================================================== --- branches/gui-3.2/AgateLib/InternalResources/DataResources.resx 2009-04-19 18:08:08 UTC (rev 887) +++ branches/gui-3.2/AgateLib/InternalResources/DataResources.resx 2009-04-19 18:51:33 UTC (rev 888) @@ -124,7 +124,7 @@ <data name="images" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>images.tar.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </data> - <data name="Prociono" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>Prociono.zip;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + <data name="Fonts" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>Fonts.zip;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </data> </root> \ No newline at end of file Added: branches/gui-3.2/AgateLib/InternalResources/Fonts.zip =================================================================== (Binary files differ) Property changes on: branches/gui-3.2/AgateLib/InternalResources/Fonts.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: branches/gui-3.2/AgateLib/InternalResources/Prociono.zip =================================================================== (Binary files differ) Modified: branches/gui-3.2/Drivers/AgateLib.WinForms/BitmapFontUtil.cs =================================================================== --- branches/gui-3.2/Drivers/AgateLib.WinForms/BitmapFontUtil.cs 2009-04-19 18:08:08 UTC (rev 887) +++ branches/gui-3.2/Drivers/AgateLib.WinForms/BitmapFontUtil.cs 2009-04-19 18:51:33 UTC (rev 888) @@ -174,7 +174,9 @@ Surface surf = new Surface(tempFile); System.IO.File.Delete(tempFile); - return new BitmapFontImpl(surf, glyphs); + return new BitmapFontImpl(surf, glyphs, + string.Format("{0} {1}{2}", options.FontFamily, options.SizeInPoints, + (options.FontStyle != FontStyle.None) ? " " + options.FontStyle.ToString():string.Empty )); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |