Exemplo n.º 1
0
        public unsafe static BOOL SetViewportExtEx(IHandle hdc, int x, int y, Size *lpsz)
        {
            BOOL result = SetViewportExtEx((HDC)hdc.Handle, x, y, lpsz);

            GC.KeepAlive(hdc);
            return(result);
        }
Exemplo n.º 2
0
 public GpRect([NativeTypeName("const Gdiplus::Point &")] GpPoint *location, [NativeTypeName("const Gdiplus::Size &")] Size *size)
 {
     X      = location->X;
     Y      = location->Y;
     Width  = size->Width;
     Height = size->Height;
 }
Exemplo n.º 3
0
        unsafe void MeasureContentSizes(SpecialInputTab e, Font font, Size *sizes)
        {
            DrawTextArgs args = new DrawTextArgs(null, font, false);

            for (int i = 0; i < e.Contents.Length; i += e.CharsPerItem)
            {
                args.Text = e.Contents.Substring(i, e.CharsPerItem);
                sizes[i / e.CharsPerItem] = game.Drawer2D.MeasureText(ref args);
            }
        }
        unsafe Size CalculateContentSize(SpecialInputTab e, Size *sizes, out Size elemSize)
        {
            elemSize = Size.Empty;
            for (int i = 0; i < e.Contents.Length; i += e.CharsPerItem)
            {
                elemSize.Width = Math.Max(elemSize.Width, sizes[i / e.CharsPerItem].Width);
            }

            elemSize.Width += contentSpacing;
            elemSize.Height = sizes[0].Height + contentSpacing;
            int rows = Utils.CeilDiv(e.Contents.Length / e.CharsPerItem, e.ItemsPerRow);

            return(new Size(elemSize.Width * e.ItemsPerRow, elemSize.Height * rows));
        }
        unsafe void MeasureContentSizes(SpecialInputTab e, Font font, Size *sizes)
        {
            string       s    = new String('\0', e.CharsPerItem);
            DrawTextArgs args = new DrawTextArgs(s, font, false);

            // avoid allocating temporary strings here
            fixed(char *ptr = s)
            {
                for (int i = 0; i < e.Contents.Length; i += e.CharsPerItem)
                {
                    for (int j = 0; j < e.CharsPerItem; j++)
                    {
                        ptr[j] = e.Contents[i + j];
                    }
                    sizes[i / e.CharsPerItem] = game.Drawer2D.MeasureSize(ref args);
                }
            }
        }
Exemplo n.º 6
0
        unsafe void Make(Element e, Font font)
        {
            Size *sizes = stackalloc Size[e.Contents.Length / e.CharsPerItem];

            MeasureContentSizes(e, font, sizes);
            Size bodySize = CalculateContentSize(e, sizes, out elementSize);
            int  titleWidth = MeasureTitles(font), titleHeight = elements[0].TitleSize.Height;
            Size size = new Size(Math.Max(bodySize.Width, titleWidth), bodySize.Height + titleHeight);

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    DrawTitles(drawer, font);
                    drawer.Clear(new FastColour(30, 30, 30, 200), 0, titleHeight,
                                 size.Width, bodySize.Height);

                    DrawContent(drawer, font, e, titleHeight);
                    texture = drawer.Make2DTexture(bmp, size, X, Y);
                }
        }
Exemplo n.º 7
0
        unsafe Texture DrawAdvanced(ref DrawTextArgs args, int index, string text)
        {
            LinkData data      = Split(index, text);
            Size     total     = Size.Empty;
            Size *   partSizes = stackalloc Size[data.parts.Length];

            linkData[index] = data;

            for (int i = 0; i < data.parts.Length; i++)
            {
                args.Text    = data.parts[i];
                args.Font    = (i & 1) == 0 ? font : underlineFont;
                partSizes[i] = game.Drawer2D.MeasureChatSize(ref args);
                total.Height = Math.Max(partSizes[i].Height, total.Height);
                total.Width += partSizes[i].Width;
            }

            using (IDrawer2D drawer = game.Drawer2D)
                using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(total))
                {
                    drawer.SetBitmap(bmp);
                    int x = 0;

                    for (int i = 0; i < data.parts.Length; i++)
                    {
                        args.Text = data.parts[i];
                        args.Font = (i & 1) == 0 ? font : underlineFont;
                        Size size = partSizes[i];

                        drawer.DrawChatText(ref args, x, 0);
                        data.bounds[i].X     = x;
                        data.bounds[i].Width = size.Width;
                        x += size.Width;
                    }
                    return(drawer.Make2DTexture(bmp, total, 0, 0));
                }
        }
Exemplo n.º 8
0
        unsafe Texture DrawAdvanced(ref DrawTextArgs args, int index, string text)
        {
            char *   chars         = stackalloc char[lines.Length * 96];
            Portion *portions      = stackalloc Portion[(96 / httpLen) * 2];
            int      portionsCount = Reduce(chars, index, portions);

            Size  total     = Size.Empty;
            Size *partSizes = stackalloc Size[portionsCount];

            for (int i = 0; i < portionsCount; i++)
            {
                Portion bit = portions[i];
                args.Text = text.Substring(bit.LineBeg, bit.LineLen);
                args.Font = (bit.Len & 0x8000) == 0 ? font : underlineFont;

                partSizes[i] = game.Drawer2D.MeasureText(ref args);
                total.Height = Math.Max(partSizes[i].Height, total.Height);
                total.Width += partSizes[i].Width;
            }

            using (IDrawer2D drawer = game.Drawer2D)
                using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(total))
                {
                    drawer.SetBitmap(bmp);
                    for (int i = 0, x = 0; i < portionsCount; i++)
                    {
                        Portion bit = portions[i];
                        args.Text = text.Substring(bit.LineBeg, bit.LineLen);
                        args.Font = (bit.Len & 0x8000) == 0 ? font : underlineFont;

                        drawer.DrawText(ref args, x, 0);
                        x += partSizes[i].Width;
                    }
                    return(drawer.Make2DTexture(bmp, total, 0, 0));
                }
        }
Exemplo n.º 9
0
 public static unsafe extern bool SetWindowExtEx(IntPtr hDC, int x, int y, Size *size);
Exemplo n.º 10
0
 public static unsafe extern bool SetViewportExtEx(IntPtr hDC, int x, int y, Size *size);
Exemplo n.º 11
0
 public unsafe static partial BOOL SetViewportExtEx(HDC hdc, int x, int y, Size *lpsz);
Exemplo n.º 12
0
Arquivo: Value.cs Projeto: ynkbt/moon
        public static unsafe object ToObject(Type type, Value *value)
        {
            if (value == null || value->IsNull)
            {
                return(null);
            }

            if (value->boxed_valuetype.IsAllocated)
            {
                return(value->boxed_valuetype.Target);
            }

            if (value->IsGCHandle)
            {
                IntPtr   managed_object = value->u.p;
                GCHandle handle         = GCHandle.FromIntPtr(managed_object);
                return(handle.Target);
            }

            switch (value->Kind)
            {
            case Kind.INVALID:
                return(null);

            case Kind.DEPENDENCYPROPERTY:
                return(DependencyProperty.Lookup(value->u.p));

            case Kind.BOOL:
                return(value->u.i32 != 0);

            case Kind.DOUBLE:
                return(value->u.d);

            case Kind.FLOAT:
                return(value->u.f);

            case Kind.UINT64:
                return(value->u.ui64);

            case Kind.INT64:
                return(value->u.i64);

            case Kind.TIMESPAN:
                return(new TimeSpan(value->u.i64));

            case Kind.CURSORTYPE:
                return(Cursors.FromEnum((CursorType)value->u.i32));

            case Kind.TEXTDECORATIONS:
                return((value->u.i32 == (int)TextDecorationKind.Underline) ? TextDecorations.Underline : null);

            case Kind.INT32:
                return(value->u.i32);

            case Kind.UINT32:
                return(value->u.ui32);

            case Kind.CHAR:
                return((char)value->u.ui32);

            case Kind.SURFACE:
                return(NativeDependencyObjectHelper.FromIntPtr(value->u.p));

            case Kind.STRING: {
                return(Marshal.PtrToStringAuto(value->u.p));
            }

            case Kind.URI:
                return(UriHelper.FromNativeUri(value->u.p));

            case Kind.XMLLANGUAGE: {
                string str = Marshal.PtrToStringAuto(value->u.p);
                return(XmlLanguage.GetLanguage(str));
            }

            case Kind.FONTFAMILY: {
                UnmanagedFontFamily *family = (UnmanagedFontFamily *)value->u.p;
                return(new FontFamily(family == null ? null : Marshal.PtrToStringAuto(family->source)));
            }

            case Kind.FONTSTRETCH: {
                UnmanagedFontStretch *stretch = (UnmanagedFontStretch *)value->u.p;
                return(new FontStretch(stretch == null ? FontStretchKind.Normal : stretch->stretch));
            }

            case Kind.FONTSTYLE: {
                UnmanagedFontStyle *style = (UnmanagedFontStyle *)value->u.p;
                return(new FontStyle(style == null ? FontStyleKind.Normal : style->style));
            }

            case Kind.FONTWEIGHT: {
                UnmanagedFontWeight *weight = (UnmanagedFontWeight *)value->u.p;
                return(new FontWeight(weight == null ? FontWeightKind.Normal : weight->weight));
            }

            case Kind.FONTSOURCE: {
                UnmanagedFontSource *  fs = (UnmanagedFontSource *)value->u.p;
                ManagedStreamCallbacks callbacks;
                GlyphTypeface          typeface;
                StreamWrapper          wrapper;

                switch (fs->type)
                {
                case FontSourceType.ManagedStream:
                    callbacks = (ManagedStreamCallbacks)Marshal.PtrToStructure(fs->source.stream, typeof(ManagedStreamCallbacks));

                    wrapper = (StreamWrapper)GCHandle.FromIntPtr(callbacks.handle).Target;

                    return(new FontSource(wrapper.stream));

                case FontSourceType.GlyphTypeface:
                    typeface = new GlyphTypeface(fs->source.typeface);
                    return(new FontSource(typeface));

                default:
                    throw new Exception(String.Format("Do not know how to create a FontSource of type {0}",
                                                      fs->type.ToString()));
                }
            }

            case Kind.GLYPHTYPEFACE: {
                return(new GlyphTypeface(value->u.p));
            }

            case Kind.PROPERTYPATH: {
                UnmanagedPropertyPath *propertypath = (UnmanagedPropertyPath *)value->u.p;
                if (propertypath == null)
                {
                    return(new PropertyPath(null));
                }
                if (propertypath->property != IntPtr.Zero)
                {
                    return(null);
                }
                return(new PropertyPath(Marshal.PtrToStringAuto(propertypath->pathString), Marshal.PtrToStringAuto(propertypath->expandedPathString)));
            }

            case Kind.POINT: {
                Point *point = (Point *)value->u.p;
                return((point == null) ? new Point(0, 0) : *point);
            }

            case Kind.RECT: {
                Rect *rect = (Rect *)value->u.p;
                return((rect == null) ? new Rect(0, 0, 0, 0) : *rect);
            }

            case Kind.SIZE: {
                Size *size = (Size *)value->u.p;
                return((size == null) ? new Size(0, 0) : *size);
            }

            case Kind.CORNERRADIUS: {
                CornerRadius *corner = (CornerRadius *)value->u.p;
                return((corner == null) ? new CornerRadius(0) : *corner);
            }

            case Kind.AUDIOFORMAT: {
                UnmanagedAudioFormat *format = (UnmanagedAudioFormat *)value->u.p;
                return((format == null) ? new AudioFormat() : format->ToAudioFormat());
            }

            case Kind.VIDEOFORMAT: {
                UnmanagedVideoFormat *format = (UnmanagedVideoFormat *)value->u.p;
                return((format == null) ? new VideoFormat() : format->ToVideoFormat());
            }

            case Kind.THICKNESS: {
                Thickness *thickness = (Thickness *)value->u.p;
                return((thickness == null) ? new Thickness(0) : *thickness);
            }

            case Kind.COLOR: {
                UnmanagedColor *color = (UnmanagedColor *)value->u.p;
                if (color == null)
                {
                    return(new Color());
                }
                return(color->ToColor());
            }

            case Kind.MATRIX:
            case Kind.UNMANAGEDMATRIX: {
                return(new Matrix(value->u.p));
            }

            case Kind.MATRIX3D:
            case Kind.UNMANAGEDMATRIX3D: {
                return(new Matrix3D(value->u.p));
            }

            case Kind.STYLUSPOINT:
            case Kind.UNMANAGEDSTYLUSPOINT: {
                var kind     = value->Kind;
                var ptr      = value->u.p;
                var x        = (double)Value.ToObject(typeof(double), NativeMethods.dependency_object_get_value(ptr, UnmanagedStylusPoint.XProperty.Native));
                var y        = (double)Value.ToObject(typeof(double), NativeMethods.dependency_object_get_value(ptr, UnmanagedStylusPoint.YProperty.Native));
                var pressure = (double)Value.ToObject(typeof(double), NativeMethods.dependency_object_get_value(ptr, UnmanagedStylusPoint.PressureFactorProperty.Native));
                return(new StylusPoint {
                        X = x, Y = y, PressureFactor = (float)pressure
                    });
            }

            case Kind.DURATION: {
                Duration *duration = (Duration *)value->u.p;
                return((duration == null) ? Duration.Automatic : *duration);
            }

            case Kind.KEYTIME: {
                KeyTime *keytime = (KeyTime *)value->u.p;
                return((keytime == null) ? KeyTime.FromTimeSpan(TimeSpan.Zero) : *keytime);
            }

            case Kind.GRIDLENGTH: {
                GridLength *gridlength = (GridLength *)value->u.p;
                return((gridlength == null) ? new GridLength() : *gridlength);
            }

            case Kind.REPEATBEHAVIOR: {
                RepeatBehavior *repeat = (RepeatBehavior *)value->u.p;
                return((repeat == null) ? new RepeatBehavior() : *repeat);
            }

            case Kind.MEDIAATTRIBUTE_COLLECTION: {
                IntPtr p = value->u.p;
                if (p == IntPtr.Zero)
                {
                    return(null);
                }

                int count = NativeMethods.collection_get_count(p);
                var dict  = new Dictionary <string, string> ();
                for (int i = 0; i < count; i++)
                {
                    IntPtr map = NativeMethods.collection_get_value_at(p, i);
                    if (map == IntPtr.Zero)
                    {
                        continue;
                    }
                    Value *attribute = (Value *)map;
                    if (attribute->Kind != Kind.MEDIAATTRIBUTE || attribute->u.p == IntPtr.Zero)
                    {
                        continue;
                    }
                    string name = NativeMethods.media_attribute_get_name(attribute->u.p);
                    string val  = NativeMethods.media_attribute_get_value(attribute->u.p);

                    dict.Add(name, val);
                }
                return(dict);
            }

            case Kind.MANAGEDTYPEINFO: {
                ManagedTypeInfo *type_info = (ManagedTypeInfo *)value->u.p;
                if (type_info == null)
                {
                    return(null);
                }
                return(Deployment.Current.Types.KindToType(type_info->Kind));
            }

            default:
                Type tt = Deployment.Current.Types.KindToType(value->Kind);
                if (tt != null && tt.IsEnum)
                {
                    return(Enum.ToObject(tt, value->u.i32));
                }
                break;
            }

            if (NativeMethods.type_is_event_object(value->Kind))
            {
                if (value->u.p == IntPtr.Zero)
                {
                    return(null);
                }

                return(NativeDependencyObjectHelper.Lookup(value->u.p));
            }

            throw new Exception(String.Format("Do not know how to convert {0}  {1}. Managed type: {2}",
                                              value->Kind, (int)value->Kind, Deployment.Current.Types.KindToType(value->Kind)));
        }
Exemplo n.º 13
0
 unsafe HRESULT IOleObject.GetExtent(DVASPECT dwDrawAspect, Size *pSizel)
 {
     return(HRESULT.S_OK);
 }
Exemplo n.º 14
0
 public GpPoint([NativeTypeName("const Gdiplus::Size &")] Size *size)
 {
     X = size->Width;
     Y = size->Height;
 }
 public unsafe static extern BOOL SetViewportExtEx(IntPtr hdc, int x, int y, Size *lpsz);
Exemplo n.º 16
0
 public unsafe static partial BOOL SetWindowExtEx(HDC hdc, int x, int y, Size *lpsz);
Exemplo n.º 17
0
 public void GetSize([NativeTypeName("Gdiplus::Size *")] Size *size)
 {
     size->Width  = Width;
     size->Height = Height;
 }
 public unsafe static extern BOOL SetWindowExtEx(IntPtr hdc, int x, int y, Size *lpsz);
Exemplo n.º 19
0
 public BOOL Equals([NativeTypeName("const Gdiplus::Size &")] Size *sz)
 {
     return(((Width == sz->Width) && (Height == sz->Height)) ? 1 : 0);
 }
Exemplo n.º 20
0
 public Size([NativeTypeName("const Gdiplus::Size &")] Size *size)
 {
     Width  = size->Width;
     Height = size->Height;
 }