External/OxyPlot/OxyPlot/Render/IRenderContext.cs
author moel.mich
Sat, 08 Jun 2013 16:53:22 +0000
changeset 391 5be8f2773237
permissions -rw-r--r--
Added the source code of OxyPlot as of commit d190d7748a73 (6.5.2013).
     1 // --------------------------------------------------------------------------------------------------------------------
     2 // <copyright file="IRenderContext.cs" company="OxyPlot">
     3 //   The MIT License (MIT)
     4 //
     5 //   Copyright (c) 2012 Oystein Bjorke
     6 //
     7 //   Permission is hereby granted, free of charge, to any person obtaining a
     8 //   copy of this software and associated documentation files (the
     9 //   "Software"), to deal in the Software without restriction, including
    10 //   without limitation the rights to use, copy, modify, merge, publish,
    11 //   distribute, sublicense, and/or sell copies of the Software, and to
    12 //   permit persons to whom the Software is furnished to do so, subject to
    13 //   the following conditions:
    14 //
    15 //   The above copyright notice and this permission notice shall be included
    16 //   in all copies or substantial portions of the Software.
    17 //
    18 //   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    19 //   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    20 //   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    21 //   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    22 //   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    23 //   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    24 //   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    25 // </copyright>
    26 // <summary>
    27 //   Render context interface.
    28 // </summary>
    29 // --------------------------------------------------------------------------------------------------------------------
    30 namespace OxyPlot
    31 {
    32     using System.Collections.Generic;
    33 
    34     /// <summary>
    35     /// Defines rendering functionality.
    36     /// </summary>
    37     public interface IRenderContext
    38     {
    39         /// <summary>
    40         /// Gets a value indicating whether the context renders to screen.
    41         /// </summary>
    42         /// <value>
    43         ///   <c>true</c> if the context renders to screen; otherwise, <c>false</c>.
    44         /// </value>
    45         bool RendersToScreen { get; }
    46 
    47         /// <summary>
    48         /// Draws an ellipse.
    49         /// </summary>
    50         /// <param name="rect">
    51         /// The rectangle.
    52         /// </param>
    53         /// <param name="fill">
    54         /// The fill color.
    55         /// </param>
    56         /// <param name="stroke">
    57         /// The stroke color.
    58         /// </param>
    59         /// <param name="thickness">
    60         /// The thickness.
    61         /// </param>
    62         void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness = 1.0);
    63 
    64         /// <summary>
    65         /// Draws the collection of ellipses, where all have the same stroke and fill.
    66         /// This performs better than calling DrawEllipse multiple times.
    67         /// </summary>
    68         /// <param name="rectangles">
    69         /// The rectangles.
    70         /// </param>
    71         /// <param name="fill">
    72         /// The fill color.
    73         /// </param>
    74         /// <param name="stroke">
    75         /// The stroke color.
    76         /// </param>
    77         /// <param name="thickness">
    78         /// The stroke thickness.
    79         /// </param>
    80         void DrawEllipses(IList<OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness = 1.0);
    81 
    82         /// <summary>
    83         /// Draws the polyline from the specified points.
    84         /// </summary>
    85         /// <param name="points">
    86         /// The points.
    87         /// </param>
    88         /// <param name="stroke">
    89         /// The stroke color.
    90         /// </param>
    91         /// <param name="thickness">
    92         /// The stroke thickness.
    93         /// </param>
    94         /// <param name="dashArray">
    95         /// The dash array.
    96         /// </param>
    97         /// <param name="lineJoin">
    98         /// The line join type.
    99         /// </param>
   100         /// <param name="aliased">
   101         /// if set to <c>true</c> the shape will be aliased.
   102         /// </param>
   103         void DrawLine(
   104             IList<ScreenPoint> points,
   105             OxyColor stroke,
   106             double thickness = 1.0,
   107             double[] dashArray = null,
   108             OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
   109             bool aliased = false);
   110 
   111         /// <summary>
   112         /// Draws the multiple line segments defined by points (0,1) (2,3) (4,5) etc.
   113         /// This should have better performance than calling DrawLine for each segment.
   114         /// </summary>
   115         /// <param name="points">
   116         /// The points.
   117         /// </param>
   118         /// <param name="stroke">
   119         /// The stroke color.
   120         /// </param>
   121         /// <param name="thickness">
   122         /// The stroke thickness.
   123         /// </param>
   124         /// <param name="dashArray">
   125         /// The dash array.
   126         /// </param>
   127         /// <param name="lineJoin">
   128         /// The line join type.
   129         /// </param>
   130         /// <param name="aliased">
   131         /// if set to <c>true</c> the shape will be aliased.
   132         /// </param>
   133         void DrawLineSegments(
   134             IList<ScreenPoint> points,
   135             OxyColor stroke,
   136             double thickness = 1.0,
   137             double[] dashArray = null,
   138             OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
   139             bool aliased = false);
   140 
   141         /// <summary>
   142         /// Draws the polygon from the specified points. The polygon can have stroke and/or fill.
   143         /// </summary>
   144         /// <param name="points">
   145         /// The points.
   146         /// </param>
   147         /// <param name="fill">
   148         /// The fill color.
   149         /// </param>
   150         /// <param name="stroke">
   151         /// The stroke color.
   152         /// </param>
   153         /// <param name="thickness">
   154         /// The stroke thickness.
   155         /// </param>
   156         /// <param name="dashArray">
   157         /// The dash array.
   158         /// </param>
   159         /// <param name="lineJoin">
   160         /// The line join type.
   161         /// </param>
   162         /// <param name="aliased">
   163         /// if set to <c>true</c> the shape will be aliased.
   164         /// </param>
   165         void DrawPolygon(
   166             IList<ScreenPoint> points,
   167             OxyColor fill,
   168             OxyColor stroke,
   169             double thickness = 1.0,
   170             double[] dashArray = null,
   171             OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
   172             bool aliased = false);
   173 
   174         /// <summary>
   175         /// Draws a collection of polygons, where all polygons have the same stroke and fill.
   176         /// This performs better than calling DrawPolygon multiple times.
   177         /// </summary>
   178         /// <param name="polygons">
   179         /// The polygons.
   180         /// </param>
   181         /// <param name="fill">
   182         /// The fill color.
   183         /// </param>
   184         /// <param name="stroke">
   185         /// The stroke color.
   186         /// </param>
   187         /// <param name="thickness">
   188         /// The stroke thickness.
   189         /// </param>
   190         /// <param name="dashArray">
   191         /// The dash array.
   192         /// </param>
   193         /// <param name="lineJoin">
   194         /// The line join type.
   195         /// </param>
   196         /// <param name="aliased">
   197         /// if set to <c>true</c> the shape will be aliased.
   198         /// </param>
   199         void DrawPolygons(
   200             IList<IList<ScreenPoint>> polygons,
   201             OxyColor fill,
   202             OxyColor stroke,
   203             double thickness = 1.0,
   204             double[] dashArray = null,
   205             OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
   206             bool aliased = false);
   207 
   208         /// <summary>
   209         /// Draws the rectangle.
   210         /// </summary>
   211         /// <param name="rect">
   212         /// The rectangle.
   213         /// </param>
   214         /// <param name="fill">
   215         /// The fill color.
   216         /// </param>
   217         /// <param name="stroke">
   218         /// The stroke color.
   219         /// </param>
   220         /// <param name="thickness">
   221         /// The stroke thickness.
   222         /// </param>
   223         void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness = 1.0);
   224 
   225         /// <summary>
   226         /// Draws a collection of rectangles, where all have the same stroke and fill.
   227         /// This performs better than calling DrawRectangle multiple times.
   228         /// </summary>
   229         /// <param name="rectangles">
   230         /// The rectangles.
   231         /// </param>
   232         /// <param name="fill">
   233         /// The fill color.
   234         /// </param>
   235         /// <param name="stroke">
   236         /// The stroke color.
   237         /// </param>
   238         /// <param name="thickness">
   239         /// The stroke thickness.
   240         /// </param>
   241         void DrawRectangles(IList<OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness = 1.0);
   242 
   243         /// <summary>
   244         /// Draws the text.
   245         /// </summary>
   246         /// <param name="p">
   247         /// The position.
   248         /// </param>
   249         /// <param name="text">
   250         /// The text.
   251         /// </param>
   252         /// <param name="fill">
   253         /// The fill color.
   254         /// </param>
   255         /// <param name="fontFamily">
   256         /// The font family.
   257         /// </param>
   258         /// <param name="fontSize">
   259         /// Size of the font.
   260         /// </param>
   261         /// <param name="fontWeight">
   262         /// The font weight.
   263         /// </param>
   264         /// <param name="rotate">
   265         /// The rotation angle.
   266         /// </param>
   267         /// <param name="halign">
   268         /// The horizontal alignment.
   269         /// </param>
   270         /// <param name="valign">
   271         /// The vertical alignment.
   272         /// </param>
   273         /// <param name="maxSize">
   274         /// The maximum size of the text.
   275         /// </param>
   276         void DrawText(
   277             ScreenPoint p,
   278             string text,
   279             OxyColor fill,
   280             string fontFamily = null,
   281             double fontSize = 10,
   282             double fontWeight = 500,
   283             double rotate = 0,
   284             HorizontalAlignment halign = HorizontalAlignment.Left,
   285             VerticalAlignment valign = VerticalAlignment.Top,
   286             OxySize? maxSize = null);
   287 
   288         /// <summary>
   289         /// Measures the text.
   290         /// </summary>
   291         /// <param name="text">
   292         /// The text.
   293         /// </param>
   294         /// <param name="fontFamily">
   295         /// The font family.
   296         /// </param>
   297         /// <param name="fontSize">
   298         /// Size of the font.
   299         /// </param>
   300         /// <param name="fontWeight">
   301         /// The font weight.
   302         /// </param>
   303         /// <returns>
   304         /// The text size.
   305         /// </returns>
   306         OxySize MeasureText(string text, string fontFamily = null, double fontSize = 10, double fontWeight = 500);
   307 
   308         /// <summary>
   309         /// Sets the tool tip for the following items.
   310         /// </summary>
   311         /// <params>
   312         /// This is only used in the plot controls.
   313         /// </params>
   314         /// <param name="text">
   315         /// The text in the tooltip.
   316         /// </param>
   317         void SetToolTip(string text);
   318 
   319         /// <summary>
   320         /// Cleans up resources not in use.
   321         /// </summary>
   322         /// <remarks>
   323         /// This method is called at the end of each rendering.
   324         /// </remarks>
   325         void CleanUp();
   326 
   327         /// <summary>
   328         /// Gets the size of the specified image.
   329         /// </summary>
   330         /// <param name="source">The image source.</param>
   331         /// <returns>The image info.</returns>
   332         OxyImageInfo GetImageInfo(OxyImage source);
   333 
   334         /// <summary>
   335         /// Draws the specified portion of the specified <see cref="OxyImage"/> at the specified location and with the specified size.
   336         /// </summary>
   337         /// <param name="source">The source.</param>
   338         /// <param name="srcX">The x-coordinate of the upper-left corner of the portion of the source image to draw.</param>
   339         /// <param name="srcY">The y-coordinate of the upper-left corner of the portion of the source image to draw.</param>
   340         /// <param name="srcWidth">Width of the portion of the source image to draw.</param>
   341         /// <param name="srcHeight">Height of the portion of the source image to draw.</param>
   342         /// <param name="destX">The x-coordinate of the upper-left corner of drawn image.</param>
   343         /// <param name="destY">The y-coordinate of the upper-left corner of drawn image.</param>
   344         /// <param name="destWidth">The width of the drawn image.</param>
   345         /// <param name="destHeight">The height of the drawn image.</param>
   346         /// <param name="opacity">The opacity.</param>
   347         /// <param name="interpolate">interpolate if set to <c>true</c>.</param>
   348         void DrawImage(OxyImage source, uint srcX, uint srcY, uint srcWidth, uint srcHeight, double destX, double destY, double destWidth, double destHeight, double opacity, bool interpolate);
   349 
   350         /// <summary>
   351         /// Sets the clip rectangle.
   352         /// </summary>
   353         /// <param name="rect">The clip rectangle.</param>
   354         /// <returns>True if the clip rectangle was set.</returns>
   355         bool SetClip(OxyRect rect);
   356 
   357         /// <summary>
   358         /// Resets the clip rectangle.
   359         /// </summary>
   360         void ResetClip();
   361     }
   362 
   363     /// <summary>
   364     /// Provides information about the size of an image.
   365     /// </summary>
   366     public class OxyImageInfo
   367     {
   368         /// <summary>
   369         /// Gets or sets the width in pixels.
   370         /// </summary>
   371         /// <value>
   372         /// The width.
   373         /// </value>
   374         public uint Width { get; set; }
   375 
   376         /// <summary>
   377         /// Gets or sets the height in pixels.
   378         /// </summary>
   379         /// <value>
   380         /// The height.
   381         /// </value>
   382         public uint Height { get; set; }
   383 
   384         /// <summary>
   385         /// Gets or sets the horizontal resolution in dpi.
   386         /// </summary>
   387         /// <value>
   388         /// The dpi X.
   389         /// </value>
   390         public double DpiX { get; set; }
   391 
   392         /// <summary>
   393         /// Gets or sets the vertical resolution in dpi.
   394         /// </summary>
   395         /// <value>
   396         /// The dpi Y.
   397         /// </value>
   398         public double DpiY { get; set; }
   399     }
   400 }