Beispiel #1
0
        public void SetInfo(IHasInfo info)
        {
            content.IsReadOnly = false;

            var header = info.Header;
            var infos  = info.GetInfos().ToList();

            int  indent = 0;
            var  hls    = new List <Tuple <long, long, int> >();
            long prev   = 0;
            var  ms     = new MemoryStream();

            using (var bFont = new Font(content.Font, FontStyle.Bold))
                using (var writer = new StreamWriter(ms, Encoding.UTF8)) {
                    writer.AutoFlush = true;

                    writer.Write(header);
                    hls.Add(Tuple.Create(prev, ms.Position, 1));
                    prev = ms.Position;

                    foreach (var entry in infos)
                    {
                        writer.WriteLine();
                        prev = ms.Position;

                        writer.Write(entry.Key + ":\t");
                        hls.Add(Tuple.Create(prev, ms.Position, 2));
                        prev = ms.Position;

                        writer.Write(entry.Value);
                        hls.Add(Tuple.Create(prev, ms.Position, 3));

                        var nameWidth = TextRenderer.MeasureText(entry.Key, bFont).Width;
                        if (nameWidth > indent)
                        {
                            indent = nameWidth;
                        }
                    }
                }
            content.Text = Encoding.UTF8.GetString(ms.ToArray());

            for (int i = 0; i < infos.Count; i++)
            {
                const int SCI_CLEARTABSTOPS = 2675;
                const int SCI_ADDTABSTOP    = 2676;
                content.NativeInterface.SendMessageDirect(SCI_CLEARTABSTOPS, i + 1);
                content.NativeInterface.SendMessageDirect(SCI_ADDTABSTOP, i + 1, indent + 20);
            }

            foreach (var hlEntry in hls)
            {
                content.GetRange((int)hlEntry.Item1, (int)hlEntry.Item2).SetStyle(hlEntry.Item3);
            }

            var width = TextRenderer.MeasureText(content.Text, content.Font).Width;

            content.Scrolling.HorizontalScrollWidth = width + 10;

            content.IsReadOnly = true;
        }
Beispiel #2
0
        public static IntPtr GetSize <KeyType>(IHasInfo <KeyType> obj, KeyType param_name)
        {
            IntPtr result = IntPtr.Zero;

            unsafe {
                Native.Call(obj.GetInfo(param_name, (IntPtr)0, IntPtr.Zero, &result));
            }
            return(result);
        }
Beispiel #3
0
        public static ImageFormat Get_ImageFormat <KeyType>(IHasInfo <KeyType> obj, KeyType param_name)
        {
            ImageFormat result = new ImageFormat();

            unsafe {
                Native.Call(obj.GetInfo(param_name, (IntPtr)sizeof(ImageFormat), (IntPtr)(&result), null));
            }
            return(result);
        }
Beispiel #4
0
        public static ulong Get_ulong <KeyType>(IHasInfo <KeyType> obj, KeyType param_name)
        {
            ulong result = 0;

            unsafe {
                Native.Call(obj.GetInfo(param_name, (IntPtr)sizeof(ulong), (IntPtr)(&result), null));
            }
            return(result);
        }
Beispiel #5
0
        public static int Get_int <KeyType>(IHasInfo <KeyType> obj, KeyType param_name)
        {
            int result = 0;

            unsafe {
                Native.Call(obj.GetInfo(param_name, (IntPtr)sizeof(int), (IntPtr)(&result), null));
            }
            return(result);
        }
Beispiel #6
0
        public static IntPtr Get_IntPtr <KeyType>(IHasInfo <KeyType> obj, KeyType param_name)
        {
            IntPtr result = IntPtr.Zero;

            unsafe {
                Native.Call(obj.GetInfo(param_name, (IntPtr)sizeof(IntPtr), (IntPtr)(&result), null));
            }
            return(result);
        }
Beispiel #7
0
		public void SetInfo(IHasInfo info) {
			content.IsReadOnly = false;

			var header = info.Header;
			var infos = info.GetInfos().ToList();

			int indent = 0;
			var hls = new List<Tuple<long, long, int>>();
			long prev = 0;
			var ms = new MemoryStream();
			using (var bFont = new Font(content.Font, FontStyle.Bold))
			using (var writer = new StreamWriter(ms, Encoding.UTF8)) {
				writer.AutoFlush = true;

				writer.Write(header);
				hls.Add(Tuple.Create(prev, ms.Position, 1));
				prev = ms.Position;

				foreach (var entry in infos) {
					writer.WriteLine();
					prev = ms.Position;

					writer.Write(entry.Key + ":\t");
					hls.Add(Tuple.Create(prev, ms.Position, 2));
					prev = ms.Position;

					writer.Write(entry.Value);
					hls.Add(Tuple.Create(prev, ms.Position, 3));

					var nameWidth = TextRenderer.MeasureText(entry.Key, bFont).Width;
					if (nameWidth > indent)
						indent = nameWidth;
				}
			}
			content.Text = Encoding.UTF8.GetString(ms.ToArray());

			for (int i = 0; i < infos.Count; i++) {
				const int SCI_CLEARTABSTOPS = 2675;
				const int SCI_ADDTABSTOP = 2676;
				content.NativeInterface.SendMessageDirect(SCI_CLEARTABSTOPS, i + 1);
				content.NativeInterface.SendMessageDirect(SCI_ADDTABSTOP, i + 1, indent + 20);
			}

			foreach (var hlEntry in hls)
				content.GetRange((int)hlEntry.Item1, (int)hlEntry.Item2).SetStyle(hlEntry.Item3);

			var width = TextRenderer.MeasureText(content.Text, content.Font).Width;
			content.Scrolling.HorizontalScrollWidth = width + 10;

			content.IsReadOnly = true;
		}
Beispiel #8
0
        public static uint[] Get_uintArray <KeyType>(IHasInfo <KeyType> obj, KeyType param_name)
        {
            unsafe {
                IntPtr size   = GetSize(obj, param_name);
                uint   count  = (uint)size / sizeof(uint);
                uint[] result = new uint[count];
                fixed(uint *p_result = result)
                {
                    Native.Call(obj.GetInfo(param_name, size, (IntPtr)p_result, null));
                }

                return(result);
            }
        }
Beispiel #9
0
        public static string Get_string <KeyType>(IHasInfo <KeyType> obj, KeyType param_name)
        {
            string result = null;

            unsafe {
                IntPtr size   = GetSize(obj, param_name);
                IntPtr strBuf = Marshal.AllocHGlobal((int)size + 1);                 //leave room for a null terminator
                try{
                    Native.Call(obj.GetInfo(param_name, size, strBuf, null));
                    ((byte *)strBuf)[(int)size] = 0;                    //make sure the string is null terminated
                    result = Marshal.PtrToStringAnsi(strBuf);
                }
                finally{
                    Marshal.FreeHGlobal(strBuf);
                }
            }
            return(result);
        }
Beispiel #10
0
 public static bool Get_bool <KeyType>(IHasInfo <KeyType> obj, KeyType param_name)
 {
     return(Get_int(obj, param_name) != 0);
 }
Beispiel #11
0
 public void CheckInfo(IHasInfo hasInfo)  // С помощью такой реализации мы можем через класс Player вызвать информацию о любом обьекте, наследованном от IHasInfo
 {
     hasInfo.ShowInfo();
 }