"Fossies" - the Fresh Open Source Software Archive

Member "google-gadgets-for-linux-0.11.2/ggadget/gtk/cairo_canvas.h" (15 Mar 2009, 5711 Bytes) of package /linux/misc/old/google-gadgets-for-linux-0.11.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2   Copyright 2008 Google Inc.
    3 
    4   Licensed under the Apache License, Version 2.0 (the "License");
    5   you may not use this file except in compliance with the License.
    6   You may obtain a copy of the License at
    7 
    8        http://www.apache.org/licenses/LICENSE-2.0
    9 
   10   Unless required by applicable law or agreed to in writing, software
   11   distributed under the License is distributed on an "AS IS" BASIS,
   12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13   See the License for the specific language governing permissions and
   14   limitations under the License.
   15 */
   16 
   17 #ifndef GGADGET_GTK_CAIRO_CANVAS_H__
   18 #define GGADGET_GTK_CAIRO_CANVAS_H__
   19 
   20 #include <cairo.h>
   21 #include <stack>
   22 
   23 #include <ggadget/common.h>
   24 #include <ggadget/logger.h>
   25 #include <ggadget/canvas_interface.h>
   26 
   27 namespace ggadget {
   28 
   29 class ClipRegion;
   30 
   31 namespace gtk {
   32 
   33 class CairoGraphics;
   34 
   35 /**
   36  * This class realizes the CanvasInterface using the Cairo graphics library.
   37  * Internally, the graphics state is represented by a Cairo context object.
   38  * The owner of this object should set any necessary Cairo properties before
   39  * passing the cairo_t to the constructor. This may include operator, clipping,
   40  * set initial matrix settings, and clear the drawing surface.
   41  */
   42 class CairoCanvas : public CanvasInterface {
   43  public:
   44   /** Creates a CairoCanvas object which uses the zoom factor of a specified
   45    * CairoGraphics object.
   46    */
   47   CairoCanvas(const CairoGraphics *graphics, double w, double h,
   48               cairo_format_t fmt);
   49 
   50   /**
   51    * Creates a CairoCanvas object which uses a fixed zoom factor.
   52    */
   53   CairoCanvas(double zoom, double w, double h, cairo_format_t fmt);
   54 
   55   /**
   56    * Creates a CairoCanvas object with specified cairo context and zoom factor.
   57    * The zoom factor will be applied to the cairo context.
   58    */
   59   CairoCanvas(cairo_t *cr, double zoom, double w, double h);
   60 
   61   virtual ~CairoCanvas();
   62 
   63   virtual void Destroy();
   64 
   65   virtual double GetWidth() const;
   66   virtual double GetHeight() const;
   67 
   68   virtual bool PushState();
   69   virtual bool PopState();
   70 
   71   virtual bool MultiplyOpacity(double opacity);
   72   virtual void RotateCoordinates(double radians);
   73   virtual void TranslateCoordinates(double dx, double dy);
   74   virtual void ScaleCoordinates(double cx, double cy);
   75 
   76   virtual bool ClearCanvas();
   77   virtual bool ClearRect(double x, double y, double w, double h);
   78 
   79   virtual bool DrawLine(double x0, double y0, double x1, double y1,
   80                         double width, const Color &c);
   81   virtual bool DrawFilledRect(double x, double y,
   82                               double w, double h, const Color &c);
   83 
   84   virtual bool DrawCanvas(double x, double y, const CanvasInterface *img);
   85   virtual bool DrawRawImage(double x, double y,
   86                             const char *data, RawImageFormat format,
   87                             int width, int height, int stride);
   88   virtual bool DrawFilledRectWithCanvas(double x, double y,
   89                                         double w, double h,
   90                                         const CanvasInterface *img);
   91   /**
   92    * Note: This function currently doesn't support the opacity setting of
   93    * target canvas. Fortunately, it won't cause problem for now. Because this
   94    * function will only be called by Elements::Draw() to compose the children's
   95    * canvases with their masks onto a newly created canvas, which will always
   96    * have opacity=1. Then the canvas containning all children's content will be
   97    * composed onto the parent's canvas by BasicElement::Draw() with its opacity
   98    * setting honoured.
   99    */
  100   virtual bool DrawCanvasWithMask(double x, double y,
  101                                   const CanvasInterface *img,
  102                                   double mx, double my,
  103                                   const CanvasInterface *mask);
  104 
  105   virtual bool DrawText(double x, double y, double width, double height,
  106                         const char *text, const FontInterface *f,
  107                         const Color &c, Alignment align, VAlignment valign,
  108                         Trimming trimming, int text_flags);
  109   virtual bool DrawTextWithTexture(double x, double y, double width,
  110                                    double height, const char *text,
  111                                    const FontInterface *f,
  112                                    const CanvasInterface *texture,
  113                                    Alignment align, VAlignment valign,
  114                                    Trimming trimming, int text_flags);
  115 
  116   virtual bool IntersectRectClipRegion(double x, double y, double w, double h);
  117 
  118   virtual bool IntersectGeneralClipRegion(const ClipRegion &region);
  119 
  120   virtual bool GetTextExtents(const char *text, const FontInterface *f,
  121                               int text_flags, double in_width,
  122                               double *width, double *height);
  123 
  124   virtual bool GetPointValue(double x, double y,
  125                              Color *color, double *opacity) const;
  126 
  127 
  128  public:
  129   /**
  130    * Get the surface contained within this class for use elsewhere.
  131    * Will flush the surface before returning so it is ready to be read.
  132    */
  133   cairo_surface_t *GetSurface() const;
  134 
  135   /**
  136    * Get the cairo context contained within this class for use elsewhere.
  137    */
  138   cairo_t *GetContext() const;
  139 
  140   /**
  141    * Multiplies a specified color to every pixel in the canvas.
  142    * Color(0.5, 0.5, 0.5) is middle color.
  143    */
  144   void MultiplyColor(const Color &color);
  145 
  146   /** Checks if the canvas is valid */
  147   bool IsValid() const;
  148 
  149   /** Get the zoom factor. */
  150   double GetZoom() const;
  151 
  152  private:
  153   class Impl;
  154   Impl *impl_;
  155 
  156   DISALLOW_EVIL_CONSTRUCTORS(CairoCanvas);
  157 };
  158 
  159 } // namespace gtk
  160 } // namespace ggadget
  161 
  162 #endif // GGADGET_GTK_CAIRO_CANVAS_H__