comparison src/graphics.h.in @ 10402:9f2bf537a651

Implement text extent property
author Michael Goffioul <michael.goffioul@gmail.com>
date Sun, 07 Mar 2010 21:00:07 +0000
parents 42d098307c30
children 82ee24bf783c
comparison
equal deleted inserted replaced
10401:6d1e49abf95f 10402:9f2bf537a651
2702 2702
2703 class OCTINTERP_API graphics_xform 2703 class OCTINTERP_API graphics_xform
2704 { 2704 {
2705 public: 2705 public:
2706 graphics_xform (void) 2706 graphics_xform (void)
2707 : xform (xform_eye ()), xform_inv (xform_eye ()) 2707 : xform (xform_eye ()), xform_inv (xform_eye ()), zlim (1, 2, 0.0)
2708 { 2708 {
2709 sx = sy = sz = "linear"; 2709 sx = sy = sz = "linear";
2710 zlim(1) = 1.0;
2710 } 2711 }
2711 2712
2712 graphics_xform (const Matrix& xm, const Matrix& xim, 2713 graphics_xform (const Matrix& xm, const Matrix& xim,
2713 const scaler& x, const scaler& y, const scaler& z) 2714 const scaler& x, const scaler& y, const scaler& z,
2714 : xform (xm), xform_inv (xim), sx (x), sy (y), sz (z) { } 2715 const Matrix& zl)
2716 : xform (xm), xform_inv (xim), sx (x), sy (y), sz (z), zlim (zl) { }
2715 2717
2716 graphics_xform (const graphics_xform& g) 2718 graphics_xform (const graphics_xform& g)
2717 : xform (g.xform), xform_inv (g.xform_inv), sx (g.sx), 2719 : xform (g.xform), xform_inv (g.xform_inv), sx (g.sx),
2718 sy (g.sy), sz (g.sz) { } 2720 sy (g.sy), sz (g.sz), zlim (g.zlim) { }
2719 2721
2720 ~graphics_xform (void) { } 2722 ~graphics_xform (void) { }
2721 2723
2722 graphics_xform& operator = (const graphics_xform& g) 2724 graphics_xform& operator = (const graphics_xform& g)
2723 { 2725 {
2724 xform = g.xform; 2726 xform = g.xform;
2725 xform_inv = g.xform_inv; 2727 xform_inv = g.xform_inv;
2726 sx = g.sx; 2728 sx = g.sx;
2727 sy = g.sy; 2729 sy = g.sy;
2728 sz = g.sz; 2730 sz = g.sz;
2731 zlim = g.zlim;
2729 2732
2730 return *this; 2733 return *this;
2731 } 2734 }
2732 2735
2733 static ColumnVector xform_vector (double x, double y, double z); 2736 static ColumnVector xform_vector (double x, double y, double z);
2737 ColumnVector transform (double x, double y, double z, 2740 ColumnVector transform (double x, double y, double z,
2738 bool scale = true) const; 2741 bool scale = true) const;
2739 2742
2740 ColumnVector untransform (double x, double y, double z, 2743 ColumnVector untransform (double x, double y, double z,
2741 bool scale = true) const; 2744 bool scale = true) const;
2745
2746 ColumnVector untransform (double x, double y, bool scale = true) const
2747 { return untransform (x, y, (zlim(0)+zlim(1))/2, scale); }
2742 2748
2743 Matrix xscale (const Matrix& m) const { return sx.scale (m); } 2749 Matrix xscale (const Matrix& m) const { return sx.scale (m); }
2744 Matrix yscale (const Matrix& m) const { return sy.scale (m); } 2750 Matrix yscale (const Matrix& m) const { return sy.scale (m); }
2745 Matrix zscale (const Matrix& m) const { return sz.scale (m); } 2751 Matrix zscale (const Matrix& m) const { return sz.scale (m); }
2746 2752
2769 2775
2770 private: 2776 private:
2771 Matrix xform; 2777 Matrix xform;
2772 Matrix xform_inv; 2778 Matrix xform_inv;
2773 scaler sx, sy, sz; 2779 scaler sx, sy, sz;
2780 Matrix zlim;
2774 }; 2781 };
2775 2782
2776 class OCTINTERP_API axes : public base_graphics_object 2783 class OCTINTERP_API axes : public base_graphics_object
2777 { 2784 {
2778 public: 2785 public:
2805 update_aspectratios (); 2812 update_aspectratios ();
2806 update_camera (); 2813 update_camera ();
2807 } 2814 }
2808 2815
2809 graphics_xform get_transform (void) const 2816 graphics_xform get_transform (void) const
2810 { return graphics_xform (x_render, x_render_inv, sx, sy, sz); } 2817 { return graphics_xform (x_render, x_render_inv, sx, sy, sz, x_zlim); }
2811 2818
2812 Matrix get_transform_matrix (void) const { return x_render; } 2819 Matrix get_transform_matrix (void) const { return x_render; }
2813 Matrix get_inverse_transform_matrix (void) const { return x_render_inv; } 2820 Matrix get_inverse_transform_matrix (void) const { return x_render_inv; }
2814 Matrix get_opengl_matrix_1 (void) const { return x_gl_mat1; } 2821 Matrix get_opengl_matrix_1 (void) const { return x_gl_mat1; }
2815 Matrix get_opengl_matrix_2 (void) const { return x_gl_mat2; } 2822 Matrix get_opengl_matrix_2 (void) const { return x_gl_mat2; }
3231 public: 3238 public:
3232 // See the genprops.awk script for an explanation of the 3239 // See the genprops.awk script for an explanation of the
3233 // properties declarations. 3240 // properties declarations.
3234 3241
3235 BEGIN_PROPERTIES (text) 3242 BEGIN_PROPERTIES (text)
3236 string_property string , "" 3243 string_property string u , ""
3237 radio_property units , "{data}|pixels|normalized|inches|centimeters|points" 3244 radio_property units u , "{data}|pixels|normalized|inches|centimeters|points"
3238 array_property position u , Matrix (1, 3, 0.0) 3245 array_property position u , Matrix (1, 3, 0.0)
3239 double_property rotation , 0 3246 double_property rotation u , 0
3240 radio_property horizontalalignment , "{left}|center|right" 3247 radio_property horizontalalignment , "{left}|center|right"
3241 color_property color , color_values (0, 0, 0) 3248 color_property color , color_values (0, 0, 0)
3242 string_property fontname , OCTAVE_DEFAULT_FONTNAME 3249 string_property fontname u , OCTAVE_DEFAULT_FONTNAME
3243 double_property fontsize , 10 3250 double_property fontsize u , 10
3244 radio_property fontangle , "{normal}|italic|oblique" 3251 radio_property fontangle u , "{normal}|italic|oblique"
3245 radio_property fontweight , "light|{normal}|demi|bold" 3252 radio_property fontweight u , "light|{normal}|demi|bold"
3246 radio_property interpreter , "{tex}|none|latex" 3253 radio_property interpreter u , "{tex}|none|latex"
3247 color_property backgroundcolor , "{none}" 3254 color_property backgroundcolor , "{none}"
3248 string_property displayname , "" 3255 string_property displayname , ""
3249 color_property edgecolor , "{none}" 3256 color_property edgecolor , "{none}"
3250 radio_property erasemode , "{normal}|none|xor|background" 3257 radio_property erasemode , "{normal}|none|xor|background"
3251 bool_property editing , "off" 3258 bool_property editing , "off"
3252 radio_property fontunits , "inches|centimeters|normalized|{points}|pixels" 3259 radio_property fontunits , "inches|centimeters|normalized|{points}|pixels"
3253 radio_property linestyle , "{-}|--|:|-.|none" 3260 radio_property linestyle , "{-}|--|:|-.|none"
3254 double_property linewidth , 0.5 3261 double_property linewidth , 0.5
3255 double_property margin , 1 3262 double_property margin , 1
3256 radio_property verticalalignment , "top|cap|{middle}|baseline|bottom" 3263 radio_property verticalalignment , "top|cap|{middle}|baseline|bottom"
3264 array_property extent rG , Matrix (1, 4, 0.0)
3257 // hidden properties for limit computation 3265 // hidden properties for limit computation
3258 row_vector_property xlim hlr , Matrix () 3266 row_vector_property xlim hlr , Matrix ()
3259 row_vector_property ylim hlr , Matrix () 3267 row_vector_property ylim hlr , Matrix ()
3260 row_vector_property zlim hlr , Matrix () 3268 row_vector_property zlim hlr , Matrix ()
3261 bool_property xliminclude hl , "on" 3269 bool_property xliminclude hl , "on"
3262 bool_property yliminclude hl , "on" 3270 bool_property yliminclude hl , "on"
3263 bool_property zliminclude hl , "off" 3271 bool_property zliminclude hl , "off"
3264 END_PROPERTIES 3272 END_PROPERTIES
3265 3273
3274 Matrix get_data_position (void) const;
3275
3266 protected: 3276 protected:
3267 void init (void) 3277 void init (void)
3268 { 3278 {
3279 position.add_constraint (dim_vector (1, 2));
3269 position.add_constraint (dim_vector (1, 3)); 3280 position.add_constraint (dim_vector (1, 3));
3281 cached_units = get_units ();
3270 } 3282 }
3271 3283
3272 private: 3284 private:
3273 void update_position (void) 3285 void update_position (void)
3274 { 3286 {
3275 Matrix pos = get_position ().matrix_value (); 3287 Matrix pos = get_data_position ();
3276 Matrix lim; 3288 Matrix lim;
3277 3289
3278 lim = Matrix (1, 3, pos(0)); 3290 lim = Matrix (1, 3, pos(0));
3279 lim(2) = (lim(2) <= 0 ? octave_Inf : lim(2)); 3291 lim(2) = (lim(2) <= 0 ? octave_Inf : lim(2));
3280 set_xlim (lim); 3292 set_xlim (lim);
3291 set_zlim (lim); 3303 set_zlim (lim);
3292 } 3304 }
3293 else 3305 else
3294 set_zliminclude ("off"); 3306 set_zliminclude ("off");
3295 } 3307 }
3308
3309 void update_text_extent (void);
3310
3311 void update_string (void) { update_text_extent (); }
3312 void update_rotation (void) { update_text_extent (); }
3313 void update_fontname (void) { update_text_extent (); }
3314 void update_fontsize (void) { update_text_extent (); }
3315 void update_fontangle (void) { update_text_extent (); }
3316 void update_fontweight (void) { update_text_extent (); }
3317 void update_interpreter (void) { update_text_extent (); }
3318
3319 void update_units (void);
3320
3321 private:
3322 std::string cached_units;
3296 }; 3323 };
3297 3324
3298 private: 3325 private:
3299 properties xproperties; 3326 properties xproperties;
3300 3327