00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef RULER_HPP
00044 #define RULER_HPP 1
00045
00046
00047 #include <cairo.h>
00048 #include <vector>
00049 #include <string>
00050 #include <stdio.h>
00051 #include <iostream>
00052 #include "color.hpp"
00053 #include "label.hpp"
00054 #include "coordmapper.hpp"
00055
00056
00062 class Ruler {
00063
00066 struct Tic {
00067 double _x;
00068 Label _label;
00072 Tic( double x, const std::string &label ) : _x(x), _label(label) {}
00073 };
00074
00075 Color _color;
00076 double _ticlen_in;
00077 double _ticlen_out;
00078 double _labelspace;
00080 double _range[2];
00081 bool _autorange[2];
00083 double _endpt[4];
00085 double _fontsize;
00086 Label _axislabel;
00088 bool _label_enabled;
00089 bool _indir;
00090 std::vector<Tic> _tic;
00092 int _cind;
00095 static bool tic_labels_bbox_crash_x( const double bbox[4], const double obbox[4] );
00096 static bool tic_labels_bbox_crash_y( const double bbox[4], const double obbox[4] );
00097 bool add_tic( double x, cairo_t *cairo, const Coordmapper1D &cm,
00098 bool ruler_tic_bbox_test, double &maxsize, double obbox[4] );
00099
00100 public:
00101
00104 Ruler();
00105
00108 Ruler( int cind );
00109
00112 Ruler( const Ruler &ruler );
00113
00116 Ruler &operator=( const Ruler &ruler );
00117
00120 ~Ruler() {}
00121
00124 void copy_tics( const Ruler &ruler );
00125
00128 void set_font_size( double size );
00129
00132 void set_color( const Color &color );
00133
00136 void set_ticlen( double inlen, double outlen );
00137
00140 void set_autorange( bool autorange_min, bool autorange_max );
00141
00144 void get_autorange( bool &autorange_min, bool &autorange_max ) const;
00145
00153 void set_ranges( double min, double max );
00154
00159 void get_ranges( double &min, double &max ) const;
00160
00163 void set_endpoints( double x1, double y1, double x2, double y2 );
00164
00167 void set_axis_label( const std::string &label );
00168
00171 void enable_labels( bool enable );
00172
00177 void set_coord_index( int cind );
00178
00181 void set_indir( bool ccw );
00182
00189 void calculate( cairo_t *cairo, Coordmapper1D &cm, bool ruler_tic_bbox_test );
00190
00197 void draw( cairo_t *cairo, Coordmapper1D &cm, bool recalculate = true );
00198
00205 void get_bbox( cairo_t *cairo, double bbox[4], Coordmapper1D &cm, bool recalculate = true );
00206
00209 void debug_print( std::ostream &os ) const ;
00210 };
00211
00212
00213 #endif
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231