Наследование: MpqResource
Пример #1
0
		public LabelElement (UIScreen screen, byte[] palette, Fnt font, ushort x, ushort y)
			: base (screen, x, y)
		{
			this.Palette = palette;
			this.Font = font;
			calc_width = true;
		}
Пример #2
0
		public static void RenderGlyphToContext (CGContext context, PointF position, Glyph g, Fnt font, byte[] palette, int offset)
		{
			byte[] buf = new byte[g.Width * g.Height * 4];
			int i = 0;

			for (int y = g.Height - 1; y >= 0; y--) {
				for (int x = g.Width - 1; x >= 0; x--) {
					if (g.Bitmap[y,x] == 0)
						buf [i + 0] = 0;
					else if (g.Bitmap[y,x] == 1)
						buf [i + 0] = 255;
					else
						buf [i + 0] = 128;

					buf[i + 1] = palette[ (g.Bitmap[y,x]) * 3 + offset + 0];
					buf[i + 2] = palette[ (g.Bitmap[y,x]) * 3 + offset + 1];
					buf[i + 3] = palette[ (g.Bitmap[y,x]) * 3 + offset + 2];

					if (buf[i+1] == 252 && buf[i+2] == 0 && buf[i+3] == 252)
						buf[i + 0] = 0;

					i += 4;
				}
			}

			CGImage glyphImage = CreateImage (buf, (ushort)g.Width, (ushort)g.Height, 32, g.Width * 4);
			
			context.DrawImage (new RectangleF (position, new SizeF (g.Width, g.Height)), glyphImage);
		}
Пример #3
0
			public MarkupPage (PageLocation loc, Fnt font, byte[] palette)
			{
				location = loc;
				lines = new List<string> ();
				fnt = font;
				pal = palette;
			}
Пример #4
0
		public static CALayer ComposeText (string text, Fnt font, byte[] palette, int width, int height, int offset)
		{
			if (font == null)
				Console.WriteLine ("aiiiieeee");

			int i;
			
			/* create a run of text, for now ignoring any control codes in the string */
			StringBuilder run = new StringBuilder ();
			if (text != null) {
				for (i = 0; i < text.Length; i ++)
					if (text[i] == 0x0a /* allow newlines */||
				    	!Char.IsControl (text[i]))
						run.Append (text[i]);
			}

			string rs = run.ToString ();
			byte[] r = Encoding.ASCII.GetBytes (rs);

			int x, y;
			int text_height, text_width;

			/* measure the text first, optionally wrapping at width */
			text_width = text_height = 0;
			x = y = 0;

			for (i = 0; i < r.Length; i ++) {
				int glyph_width = 0;

				if (r[i] != 0x0a) /* newline */ {
					if (r[i] == 0x20) /* space */
						glyph_width = font.SpaceSize;
					else {
						Glyph g = font[r[i]-1];

						glyph_width = g.Width + g.XOffset;
					}
				}

				if (r[i] == 0x0a ||
				    (width != -1 && x + glyph_width > width)) {
					if (x > text_width)
						text_width = x;
					x = 0;
					text_height += font.LineSize;
				}
					
				x += glyph_width;
			}

			if (x > text_width)
				text_width = x;
			text_height += font.LineSize;
			
			CALayer layer = CALayer.Create ();
			layer.AnchorPoint = new PointF (0, 0);
			layer.Bounds = new RectangleF (0, 0, text_width, text_height);

			/* the draw it */
			x = 0;
			y = text_height;
			for (i = 0; i < r.Length; i ++) {
				int glyph_width = 0;
				Glyph g = null;

				if (r[i] != 0x0a) /* newline */ {
					if (r[i] == 0x20)  /* space */{
						glyph_width = font.SpaceSize;
					}
					else {
						g = font[r[i]-1];
						glyph_width = g.Width + g.XOffset;

						CALayer gl = RenderGlyph (font, g, palette, offset);
						gl.AnchorPoint = new PointF (0,0);
						gl.Position = new PointF (x, y - g.Height - g.YOffset);
						layer.AddSublayer (gl);
					}
				}

				if (r[i] == 0x0a ||
				    x + glyph_width > text_width) {
					x = 0;
					y -= font.LineSize;
				}
					
				x += glyph_width;
			}

			return layer;
		}	
Пример #5
0
		public static SizeF MeasureText (string text, Fnt font)
		{
			int i;
			/* create a run of text, for now ignoring any control codes in the string */
			StringBuilder run = new StringBuilder ();
			for (i = 0; i < text.Length; i ++)
				if (text[i] == 0x0a /* allow newlines */||
				    !Char.IsControl (text[i]))
					run.Append (text[i]);

			string rs = run.ToString ();
			byte[] r = Encoding.ASCII.GetBytes (rs);

			int x, y;
			int text_height, text_width;

			/* measure the text first, optionally wrapping at width */
			text_width = text_height = 0;
			x = y = 0;

			for (i = 0; i < r.Length; i ++) {
				int glyph_width = 0;

				if (r[i] != 0x0a) /* newline */ {
					if (r[i] == 0x20) /* space */
						glyph_width = font.SpaceSize;
					else {
						Glyph g = font[r[i]-1];

						glyph_width = g.Width + g.XOffset;
					}
				}

				if (r[i] == 0x0a) {
					if (x > text_width)
						text_width = x;
					x = 0;
					text_height += font.LineSize;
				}
					
				x += glyph_width;
			}

			if (x > text_width)
				text_width = x;
			text_height += font.LineSize;

			return new SizeF (text_width, text_height);
		}
Пример #6
0
		public static CALayer ComposeText (string text, Fnt font, byte[] palette, int offset)
		{
			return ComposeText (text, font, palette, -1, -1, offset);
		}
Пример #7
0
		public static CALayer RenderGlyph (Fnt font, Glyph g, byte[] palette, int offset)
		{
			byte[] buf = new byte[g.Width * g.Height * 4];
			int i = 0;

			for (int y = g.Height - 1; y >= 0; y--) {
				for (int x = g.Width - 1; x >= 0; x--) {
					if (g.Bitmap[y,x] == 0)
						buf [i + 0] = 0;
					else if (g.Bitmap[y,x] == 1)
						buf [i + 0] = 255;
					else
						buf [i + 0] = 128;

					buf[i + 1] = palette[ (g.Bitmap[y,x]) * 3 + offset + 0];
					buf[i + 2] = palette[ (g.Bitmap[y,x]) * 3 + offset + 1];
					buf[i + 3] = palette[ (g.Bitmap[y,x]) * 3 + offset + 2];

					if (buf[i+1] == 252 && buf[i+2] == 0 && buf[i+3] == 252)
						buf[i + 0] = 0;

					i += 4;
				}
			}
				
			return CreateLayerFromRGBAData (buf, (ushort)g.Width, (ushort)g.Height, 32, g.Width * 4);
		}
Пример #8
0
		public static void RenderTextToContext (CGContext context, PointF position, string text, Fnt font, byte[] palette, int offset)
		{
			int i;
			
			/* create a run of text, for now ignoring any control codes in the string */
			StringBuilder run = new StringBuilder ();
			for (i = 0; i < text.Length; i ++) {
				if ((text[i] == 0x0a /* allow newlines */||
				    !Char.IsControl (text[i])) &&
					(text[i] >= font.LowIndex && text[i] <= font.HighIndex)) {
					run.Append (text[i]);
				}
			}

			string rs = run.ToString ();
			byte[] r = Encoding.ASCII.GetBytes (rs);

			/* the draw it */
			for (i = 0; i < r.Length; i ++) {
				int glyph_width = 0;
				Glyph g = null;

				if (r[i] == 0x20)  /* space */{
					glyph_width = font.SpaceSize;
				}
				else {
					g = font[r[i]-1];
					glyph_width = g.Width + g.XOffset;

					RenderGlyphToContext (context, position, g, font, palette, offset);
				}

				position.X += glyph_width;
			}
		}
Пример #9
0
		protected override void ResourceLoader ()
		{
			Console.WriteLine ("loading font palette");
			Stream palStream = (Stream)mpq.GetResource ("glue\\Palmm\\tFont.pcx");
			Pcx pcx = new Pcx ();
			pcx.ReadFromStream (palStream, -1, -1);
				
			pal = pcx.RGBData;

			Console.WriteLine ("loading font");
			fnt = GuiUtil.GetFonts(mpq)[3];

			Console.WriteLine ("loading markup");
			LoadMarkup ();

			/* set things up so we're ready to go */
			millisDelay = 4000;
			pageEnumerator = pages.GetEnumerator();
			AdvanceToNextPage ();
		}