Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

context.h

Go to the documentation of this file.
00001 /* Copyright (C) 2005 The cairomm Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Library General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2 of the License, or (at your option) any later version.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Library General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Library General Public
00014  * License along with this library; if not, write to the Free
00015  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018 #ifndef __CAIROMM_CONTEXT_H
00019 #define __CAIROMM_CONTEXT_H
00020 
00021 #include <cairomm/surface.h>
00022 #include <cairomm/fontface.h>
00023 #include <cairomm/pattern.h>
00024 #include <cairomm/path.h>
00025 #include <valarray>
00026 #include <vector>
00027 #include <cairo.h>
00028 
00029 
00030 namespace Cairo
00031 {
00032 
00033 typedef cairo_operator_t Operator;
00034 typedef cairo_fill_rule_t FillRule;
00035 typedef cairo_line_cap_t LineCap;
00036 typedef cairo_line_join_t LineJoin;
00037 typedef cairo_font_slant_t FontSlant;
00038 typedef cairo_font_weight_t FontWeight;
00039 
00040 typedef cairo_glyph_t Glyph; //A simple struct.
00041 typedef cairo_font_extents_t FontExtents; //A simple struct.
00042 typedef cairo_text_extents_t TextExtents; //A simple struct.
00043 typedef cairo_matrix_t Matrix; //A simple struct. //TODO: Derive and add operator[] and operator. matrix multiplication?
00044 
00055 class Context
00056 {
00057 protected:
00058   explicit Context(const RefPtr<Surface>& target);
00059 
00060 public:
00061 
00069   explicit Context(cairo_t* cobject, bool has_reference = false);
00070 
00071   static RefPtr<Context> create(const RefPtr<Surface>& target);
00072 
00073   virtual ~Context();
00074 
00086   void save();
00087 
00093   void restore();
00094 
00101   void set_operator(Operator op);
00102 
00120   void set_source(const RefPtr<const Pattern>& source);
00121 
00136   void set_source_rgb(double red, double green, double blue);
00137 
00154   void set_source_rgba(double red, double green, double blue, double alpha);
00155 
00175   void set_source(const RefPtr<Surface>& surface, double x, double y);
00176 
00186   void set_tolerance(double tolerance);
00187 
00198   void set_antialias(Antialias antialias);
00199 
00208   void set_fill_rule(FillRule fill_rule);
00209 
00219   void set_line_width(double width);
00220   
00230   void set_line_cap(LineCap line_cap);
00231 
00241   void set_line_join(LineJoin line_join);
00242 
00260   void set_dash(std::valarray<double>& dashes, double offset);
00261 
00264   void unset_dash();
00265   void set_miter_limit(double limit);
00266 
00276   void translate(double tx, double ty);
00277 
00285   void scale(double sx, double sy);
00286 
00296   void rotate(double angle_radians);
00297 
00303   void rotate_degrees(double angle_degres);
00304 
00311   void transform(const Matrix& matrix);
00312 
00318   void set_matrix(const Matrix& matrix);
00319 
00324   void set_identity_matrix();
00325 
00332   void user_to_device(double& x, double& y);
00333 
00341   void user_to_device_distance(double& dx, double& dy);
00342 
00349   void device_to_user(double& x, double& y);
00350 
00358   void device_to_user_distance(double& dx, double& dy);
00359 
00360   // FIXME: why is this named clear_path instead of new_path?
00363   void clear_path();
00364 
00371   void move_to(double x, double y);
00372 
00379   void line_to(double x, double y);
00380 
00392   void curve_to(double x1, double y1, double x2, double y2, double x3, double y3);
00393 
00433   void arc(double xc, double yc, double radius, double angle1, double angle2);
00434 
00449   void arc_negative(double xc, double yc, double radius, double angle1, double angle2);
00450 
00466   void rel_move_to(double dx, double dy);
00467 
00485   void rel_line_to(double dx, double dy);
00486 
00509   void rel_curve_to(double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
00510 
00529   void rectangle(double x, double y, double width, double height);
00530 
00541   void close_path();
00542 
00546   void paint();
00547 
00555   void paint_with_alpha(double alpha);
00556 
00563   void mask(const RefPtr<Pattern>& pattern);
00564 
00573   void mask(const RefPtr<Surface>& surface, double surface_x, double surface_y);
00574 
00585   void stroke();
00586 
00597   void stroke_preserve();
00598 
00606   void fill();
00607 
00616   void fill_preserve();
00617   void copy_page();
00618   void show_page();
00619   bool in_stroke(double x, double y) const;
00620   bool in_fill(double x, double y) const;
00621   void get_stroke_extents(double& x1, double& y1, double& x2, double& y2) const;
00622   void get_fill_extents(double& x1, double& y1, double& x2, double& y2) const;
00623 
00634   void reset_clip();
00635 
00654   void clip();
00655 
00666   void clip_preserve();
00667   void select_font_face(const std::string& family, FontSlant slant, FontWeight weight);
00668   void set_font_size(double size);
00669   void set_font_matrix(const Matrix& matrix);
00670   void get_font_matrix(Matrix& matrix) const;
00671   void set_font_options(const FontOptions& options);
00672   void show_text(const std::string& utf8);
00673   void show_glyphs(const std::vector<Glyph>& glyphs);
00674   RefPtr<FontFace> get_font_face();
00675   RefPtr<const FontFace> get_font_face() const;
00676   void get_font_extents(FontExtents& extents) const;
00677   void set_font_face(const RefPtr<const FontFace>& font_face);
00678   void get_text_extents(const std::string& utf8, TextExtents& extents) const;
00679   void get_glyph_extents(const std::vector<Glyph>& glyphs, TextExtents& extents) const;
00680   void text_path(const std::string& utf8);
00681   void glyph_path(const std::vector<Glyph>& glyphs);
00682 
00685   Operator get_operator() const;
00686 
00689   RefPtr<Pattern> get_source();
00690   RefPtr<const Pattern> get_source() const;
00691 
00694   double get_tolerance() const;
00695 
00698   Antialias get_antialias() const;
00699 
00714   void get_current_point (double& x, double& y) const;
00715 
00718   FillRule get_fill_rule() const;
00719 
00722   double get_line_width() const;
00723 
00726   LineCap get_line_cap() const;
00727 
00730   LineJoin get_line_join() const;
00731 
00734   double get_miter_limit() const;
00735 
00740   void get_matrix(Matrix& matrix);
00741 
00746   RefPtr<Surface> get_target();
00747 
00752   RefPtr<const Surface> get_target() const;
00753   
00754   //TODO: Copy or reference-count a Path somethow instead of asking the caller to delete it?
00755   Path* copy_path() const;
00756   Path* copy_path_flat() const;
00757 
00764   void append_path(const Path& path);
00765 
00768   typedef cairo_t cobject;
00769 
00772   inline cobject* cobj() { return m_cobject; }
00773 
00776   inline const cobject* cobj() const { return m_cobject; }
00777  
00778   #ifndef DOXYGEN_IGNORE_THIS
00779 
00780   inline ErrorStatus get_status() const
00781   { return cairo_status(const_cast<cairo_t*>(cobj())); }
00782 
00783   void reference() const;
00784   void unreference() const;
00785   #endif //DOXYGEN_IGNORE_THIS
00786 
00787 protected:
00788 
00789  
00790   cobject* m_cobject;
00791 };
00792 
00793 } // namespace Cairo
00794 
00795 #endif //__CAIROMM_CONTEXT_H
00796 

Generated on Thu Feb 9 12:47:13 2006 for cairomm by  doxygen 1.4.4