本文整理汇总了C#中gbrainy.Core.Main.CairoContextEx.Save方法的典型用法代码示例。如果您正苦于以下问题:C# CairoContextEx.Save方法的具体用法?C# CairoContextEx.Save怎么用?C# CairoContextEx.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gbrainy.Core.Main.CairoContextEx
的用法示例。
在下文中一共展示了CairoContextEx.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(CairoContextEx gr, int area_width, int area_height, bool rtl)
{
double x = X, y = Y;
this.rtl = rtl;
#if DESIGN_MODE
gr.Save ();
gr.Color = new Cairo.Color (0, 0, 1);
gr.Rectangle (X, Y, Width, Height);
gr.Stroke ();
gr.Restore ();
double width = 0;
foreach (Widget child in children)
{
width += child.Width;
if (Height < child.Height)
throw new InvalidOperationException (String.Format ("Container height too small {0} < {1}", Height, child.Height));
}
if (Width < width)
throw new InvalidOperationException (String.Format ("Container witdh too small {0} < {1}", Width, width));
#endif
//
// Coordinates are stored right to left
//
if (rtl == false) {
for (int i = 0; i < children.Count; i++)
{
gr.Save ();
gr.Translate (x, y);
children[i].Draw (gr, area_width, area_height, rtl);
gr.Restore ();
x += children[i].Width;
}
} else {
x += Width;
for (int i = 0; i < children.Count; i++)
{
x -= children[i].Width;
gr.Save ();
gr.Translate (x, y);
children[i].Draw (gr, area_width, area_height, rtl);
gr.Restore ();
}
}
}
示例2: Draw
public override void Draw(CairoContextEx gr, int area_width, int area_height, bool rtl)
{
#if DESIGN_MODE
gr.Save ();
gr.Color = new Cairo.Color (1, 0, 0);
gr.Rectangle (0, 0, Width, Height);
gr.Stroke ();
gr.Restore ();
#endif
if (hoover == true)
{
double lw = gr.LineWidth;
double [] dashes = {0.01, /* ink */
0.01, /* skip */ };
gr.Save ();
gr.Color = new Cairo.Color (0.5, 0.5, 0.5, 1);
gr.SetDash (dashes, 0);
if (SelectedArea.Width == 0 && SelectedArea.Height == 0)
gr.Rectangle (-lw, -lw, Width + lw * 2, Height + lw * 2);
else
gr.Rectangle (SelectedArea.X -lw, SelectedArea.Y -lw, SelectedArea.Width + lw * 2, SelectedArea.Height + lw * 2);
gr.Stroke ();
gr.Restore ();
}
if (DrawEventHandler == null)
return;
DrawEventHandler (this, new DrawEventArgs (gr, Width, Height, rtl, Data));
}
示例3: Draw
public override void Draw(CairoContextEx gr, int area_width, int area_height, bool rtl)
{
double x = X, y = Y;
this.rtl = rtl;
#if DESIGN_MODE
gr.Save ();
gr.Color = new Cairo.Color (0, 0, 1);
gr.Rectangle (X, Y, Width, Height);
gr.Stroke ();
gr.Restore ();
ValidateDimensions ();
#endif
//
// Coordinates are stored right to left
//
if (rtl == false) {
for (int i = 0; i < children.Count; i++)
{
gr.Save ();
gr.Translate (x, y);
children[i].Draw (gr, area_width, area_height, rtl);
gr.Restore ();
x += children[i].Width;
}
} else {
x += Width;
for (int i = 0; i < children.Count; i++)
{
x -= children[i].Width;
gr.Save ();
gr.Translate (x, y);
children[i].Draw (gr, area_width, area_height, rtl);
gr.Restore ();
}
}
}
示例4: DrawBar
static void DrawBar(CairoContextEx gr, double x, double y, double w, double h, double percentage)
{
double per = percentage / 100;
gr.Rectangle (x, y - h * per, w, h * per);
gr.FillGradient (x, y - h * per, w, h * per, new Cairo.Color (0, 0, 1));
gr.DrawTextCentered (x + w / 2, (y - 0.03) - h * per, String.Format ("{0}", percentage));
gr.Save ();
gr.Color = new Cairo.Color (0, 0, 0);
gr.MoveTo (x, y);
gr.LineTo (x, y - h * per);
gr.LineTo (x + w, y - h * per);
gr.LineTo (x + w, y);
gr.LineTo (x, y);
gr.Stroke ();
gr.Restore ();
}
示例5: GenerateQuestions
static void GenerateQuestions(CairoContextEx cr, Game [] games, int columns, int rows)
{
int x, y, page;
Game puzzle;
string str;
x = y = page = 0;
for (int i = 0; i < games.Length; i++)
{
puzzle = games [i];
puzzle.Begin ();
page++;
cr.Save ();
cr.Translate (x, y);
cr.Rectangle (0, 0, width, height + question_height);
cr.Clip ();
// Translators: {0} is the game number and {1} the game question or answer
// The number is used as reference when looking for the game solution in the PDF
str = String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Game #{0}. {1}"), i + 1, puzzle.Question);
// Draw question
cr.SetPangoFontSize (12);
cr.UseMarkup = true;
cr.DrawStringWithWrapping (margin, 10, str, width - margin);
cr.Stroke ();
cr.UseMarkup = false;
// Draw from question_height up height since from 0 to question_height is the question
// Translate adds always to previous matrix's transformation
cr.Translate (0, question_height);
puzzle.DrawPreview (cr, width, height, false);
if (i == 0) {
cr.Save ();
cr.SetPangoFontSize (0.02);
cr.MoveTo (0.05, 0.95);
cr.ShowPangoText (String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Created by gbrainy {0}"), Defines.VERSION));
cr.Stroke ();
cr.Restore ();
}
x += width + margin;
if (x > width + margin) {
x = 0;
y += height + margin + question_height;
}
cr.Restore ();
cr.Stroke ();
if (page >= columns * rows) {
cr.ShowPage ();
page = x = y = 0;
}
}
if (y > 0)
cr.ShowPage ();
}
示例6: DrawTimeBar
public void DrawTimeBar(CairoContextEx gr, double x, double y, double percentage)
{
double width = 0.04, height = 0.6;
const double w = 0.003, h = 0.003;
gr.DrawTextCentered (x + (width / 2), y + height + 0.05, Translations.GetString ("Time left"));
gr.Stroke ();
gr.Save ();
gr.Color = new Color (0, 0, 0);
gr.MoveTo (x, y);
gr.LineTo (x, y + height);
gr.LineTo (x + width, y + height);
gr.LineTo (x + width, y);
gr.LineTo (x, y);
gr.Stroke ();
x+= w;
y+= h;
width -= w * 2;
height -= h * 2;
y += height * (100 - percentage) / 100;
height *= percentage / 100;
if (gradient == null) {
gradient = new LinearGradient (x, y, x + width, y + height);
gradient.AddColorStop (0, new Color (1, 0, 0, 1));
gradient.AddColorStop (1, new Color (0.2, 0, 0, 1));
}
gr.Source = gradient;
gr.MoveTo (x, y);
gr.LineTo (x, y + height);
gr.LineTo (x + width, y + height);
gr.LineTo (x + width, y);
gr.LineTo (x, y);
gr.FillPreserve ();
gr.Stroke ();
gr.Restore ();
}
示例7: DrawBand
static void DrawBand(CairoContextEx gr, double x, double y)
{
gr.Save ();
gr.Rectangle (x, y, 1 - 0.06, 0.06);
gr.Color = new Cairo.Color (0, 0, 0.2, 0.2);
gr.Fill ();
gr.Restore ();
}
示例8: Draw
public override void Draw(CairoContextEx gr, int area_width, int area_height, bool rtl)
{
int element;
double x = DrawAreaX;
double y = 0.05, pos_y;
base.Draw (gr, area_width, area_height, rtl);
for (int i = 0; i < (Answer.Draw ? question_columns : question_columns - 1); i++)
{
element = question_indices [i];
pos_y = y;
for (int n = 0; n < figures_column; n++)
{
DrawFigure (gr, x, pos_y, figures [(n * question_columns) + element]);
pos_y+= figure_size + space_height;
}
x+= figure_size + space_width;
}
if (Answer.Draw == false) {
gr.Save ();
gr.SetPangoFontSize (figure_size);
for (int n = 0; n < figures_column; n++) {
gr.MoveTo (x, y - 0.02);
gr.ShowPangoText ("?");
gr.Stroke ();
y+= figure_size + space_height;
}
gr.SetPangoNormalFontSize ();
gr.Restore ();
}
gr.MoveTo (0.08, 0.45);
gr.ShowPangoText (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Choose one of the following:"));
gr.Stroke ();
}
示例9: DrawAnswer
void DrawAnswer(CairoContextEx gr, double x, double y)
{
ColorPalette palette = new ColorPalette (Translations);
gr.Save ();
// A full sized square of paper
gr.Color = palette.Cairo (ColorPalette.Id.Yellow);
gr.Rectangle (x, y, width, height);
gr.Fill ();
gr.Stroke ();
// 3/4 of the whole size square of paper in the bottom right corner
gr.Color = palette.Cairo (ColorPalette.Id.Blue);
double w = 3d/4d * width;
double h = 3d/4d * height;
gr.Rectangle (x + (width - w), y + (height - h), w, h);
gr.Fill ();
gr.Stroke ();
// 3/4 square of paper in the top left corner
gr.Color = palette.Cairo (ColorPalette.Id.Green);
gr.Rectangle (x, y, 3d/4d * width, 3d/4d * height);
gr.Fill ();
gr.Stroke ();
// 1/4 square of paper in the top left corner
gr.Color = palette.Cairo (ColorPalette.Id.Red);
gr.Rectangle (x, y, 1d/4d * width, 1d/4d * height);
gr.Fill ();
gr.Stroke ();
gr.Restore ();
}
示例10: DrawAxisDescription
void DrawAxisDescription(CairoContextEx cr, double x, double y, string description)
{
cr.Save ();
cr.Color = desc_color;
cr.MoveTo (x, y);
cr.ShowPangoText (description);
cr.Stroke ();
cr.Restore ();
}
示例11: DrawGrid
void DrawGrid(CairoContextEx cr, double x, double y)
{
// Draw Axis
cr.MoveTo (x, y);
cr.LineTo (x, y + grid_height);
cr.LineTo (x + grid_width, y + grid_height);
cr.Stroke ();
cr.Save ();
cr.Color = axis_color;
cr.LineWidth = 0.001;
for (double line_y = y; line_y < grid_height + y; line_y += grid_height / 10) {
cr.MoveTo (x, line_y);
cr.LineTo (x + grid_width, line_y);
cr.Stroke ();
}
cr.Restore ();
// Draw score scale
int pos = 100;
for (double line_y = y; line_y < grid_height + y; line_y += grid_height / 10) {
cr.DrawTextAlignedRight (x- 0.01, line_y, String.Format ("{0}", pos));
pos -= 10;
}
}
示例12: DrawSection
private void DrawSection(CairoContextEx gr, double x, double y)
{
double w = width / 2, h = height / 2;
double pos_x = x, pos_y = y;
for (int i = 0; i < 5; i++) {
gr.MoveTo (pos_x, pos_y + h / 5);
gr.LineTo (pos_x + w, pos_y + h / 5);
gr.Stroke ();
pos_y += h / 5;
}
gr.MoveTo (x + w / 2, y);
gr.LineTo (x + w / 2, y + h);
gr.Stroke ();
gr.Save ();
gr.Color = new Cairo.Color (0.90, 0.90, 0.90);
for (int i = 0; i < partial_zones; i++) {
Fill (gr, x + line_width, line_width + y,
(w / 2) - (line_width * 2) , (h / 5) - (line_width * 2));
Fill (gr, x + (w / 2) + line_width * 2, line_width + y,
(w / 2) - (line_width * 4) , (h / 5) - (line_width * 2));
y += h / 5;
}
gr.Restore ();
}
示例13: DrawSquare
private void DrawSquare(CairoContextEx gr, double x, double y, SquareColor []colours, int index)
{
gr.Save ();
for (int column = 0; column < columns; column++) {
for (int row = 0; row < rows; row++) {
// if you want 2 schemes (primary or secundary colors)
Color c = palette.Cairo(ColorPalette.Id.First+ color_sheme*3 + (int)colours[index+(columns * row) + column]);
gr.Rectangle (x + row * rect_w, y + column * rect_h, rect_w, rect_h);
gr.FillGradient (x + row * rect_w, y + column * rect_h, rect_w, rect_h, c);
}
}
gr.Restore ();
for (int column = 0; column < columns; column++) {
for (int row = 0; row < rows; row++) {
gr.Rectangle (x + row * rect_w, y + column * rect_h, rect_w, rect_h);
gr.Stroke ();
}
}
}
示例14: DrawSolution
void DrawSolution(CairoContextEx cr, int height, double max_width)
{
if (UseSolutionArea == false || String.IsNullOrEmpty (Solution) == true)
return;
double width_str, height_str, x_text, icon_x, icon_w, icon_h, box_height_scaled;
cr.Save ();
cr.LineWidth = 0.001;
icon_w = icon_size * (cr.Matrix.Xx > cr.Matrix.Yy ? cr.Matrix.Yy / cr.Matrix.Xx : 1);
icon_h = icon_size * (cr.Matrix.Yy > cr.Matrix.Xx ? cr.Matrix.Xx / cr.Matrix.Yy : 1);
cr.MeasureString (Solution, max_width - icon_w, true, out width_str, out height_str);
// In case that the string to show is longer than the space reserved (long translations for example)
// allow the box to grow taking part of the lower part of the graphic
box_height_scaled = Math.Max (height_str, (double) solution_high / (double) height);
// Draw black box
cr.Color = new Color (0.1, 0.1, 0.1);
cr.Rectangle (text_margin,
1 - box_height_scaled - text_margin,
max_width,
box_height_scaled);
cr.Fill ();
cr.Stroke ();
// Draw text and icon
cr.Color = new Color (1, 1, 1);
if (Direction == Gtk.TextDirection.Rtl)
{
x_text = 0;
icon_x = max_width - icon_w;
}
else
{
x_text = icon_w + text_margin;
icon_x = 0;
}
cr.DrawStringWithWrapping (x_text,
(1 - box_height_scaled - text_margin) + ((box_height_scaled - height_str) / 2),
Solution, max_width - icon_w);
cr.Stroke ();
DrawSolutionIcon (cr, icon_x,
(1 - box_height_scaled - text_margin) + ((box_height_scaled - icon_h) / 2),
icon_w, icon_h);
cr.Restore ();
}
示例15: OnExposeEvent
protected override bool OnExposeEvent(Gdk.EventExpose args)
{
if (!IsRealized)
return false;
int w, h, total_w, total_h;
Cairo.Context cc = Gdk.CairoHelper.Create (args.Window);
CairoContextEx cr = new CairoContextEx (cc.Handle, this);
args.Window.GetSize (out total_w, out total_h);
h = total_h - question_high;
if (UseSolutionArea)
h -= solution_high;
w = total_w;
// We want a square drawing area for the puzzles then the figures are shown as designed.
// For example, squares are squares. This also makes sure that proportions are kept when resizing
DrawingSquare = Math.Min (w, h);
if (DrawingSquare < w)
OffsetX = (w - DrawingSquare) / 2d;
else
OffsetX = 0;
if (DrawingSquare < h)
OffsetY = (h - DrawingSquare) / 2d;
else
OffsetY = 0;
OffsetY += question_high;
// Draw a background taking all the window area
cr.Save ();
cr.Scale (total_w, total_h);
cr.DrawBackground ();
if (Paused == false) {
DrawQuestionAndAnswer (cr, total_h);
} else {
cr.SetPangoFontSize (0.08);
cr.DrawTextCentered (0.5, 0.5, Catalog.GetString ("Paused"));
cr.Stroke ();
}
cr.Restore ();
if (Paused == false) {
// Draw the game area
cr.Translate (OffsetX, OffsetY);
cr.SetPangoNormalFontSize ();
cr.Color = new Color (1, 1, 1, 0.5);
Drawable.Draw (cr, DrawingSquare, DrawingSquare, Direction == Gtk.TextDirection.Rtl);
cr.Stroke ();
}
((IDisposable)cc).Dispose();
((IDisposable)cr).Dispose();
return true;
}