Mercurial > octave-nkf
comparison src/graphics.cc @ 11576:8ac9687dbe9f
rename backend to graphics_toolkit
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 02:29:57 -0500 |
parents | 7d6d8c1e471f |
children | 12df7854fa7c |
comparison
equal
deleted
inserted
replaced
11575:d6619410e79c | 11576:8ac9687dbe9f |
---|---|
763 base_property::set (const octave_value& v, bool do_run ) | 763 base_property::set (const octave_value& v, bool do_run ) |
764 { | 764 { |
765 if (do_set (v)) | 765 if (do_set (v)) |
766 { | 766 { |
767 | 767 |
768 // notify backend | 768 // Notify graphics toolkit. |
769 if (id >= 0) | 769 if (id >= 0) |
770 { | 770 { |
771 graphics_object go = gh_manager::get_object (parent); | 771 graphics_object go = gh_manager::get_object (parent); |
772 if (go) | 772 if (go) |
773 { | 773 { |
774 graphics_backend backend = go.get_backend(); | 774 graphics_toolkit toolkit = go.get_toolkit (); |
775 if (backend) | 775 if (toolkit) |
776 backend.update (go, id); | 776 toolkit.update (go, id); |
777 } | 777 } |
778 } | 778 } |
779 | 779 |
780 // run listeners | 780 // run listeners |
781 if (do_run && ! error_state) | 781 if (do_run && ! error_state) |
1869 | 1869 |
1870 octave_value val = bp.get_deletefcn (); | 1870 octave_value val = bp.get_deletefcn (); |
1871 | 1871 |
1872 bp.execute_deletefcn (); | 1872 bp.execute_deletefcn (); |
1873 | 1873 |
1874 // notify backend | 1874 // Notify graphics toolkit. |
1875 graphics_backend backend = p->second.get_backend (); | 1875 graphics_toolkit toolkit = p->second.get_toolkit (); |
1876 if (backend) | 1876 if (toolkit) |
1877 backend.finalize (p->second); | 1877 toolkit.finalize (p->second); |
1878 | 1878 |
1879 // Note: this will be valid only for first explicitly | 1879 // Note: this will be valid only for first explicitly |
1880 // deleted object. All its children will then have an | 1880 // deleted object. All its children will then have an |
1881 // unknown backend. | 1881 // unknown graphics toolkit. |
1882 | 1882 |
1883 // Graphics handles for non-figure objects are negative | 1883 // Graphics handles for non-figure objects are negative |
1884 // integers plus some random fractional part. To avoid | 1884 // integers plus some random fractional part. To avoid |
1885 // running out of integers, we recycle the integer part | 1885 // running out of integers, we recycle the integer part |
1886 // but tack on a new random part each time. | 1886 // but tack on a new random part each time. |
2049 } | 2049 } |
2050 | 2050 |
2051 // --------------------------------------------------------------------- | 2051 // --------------------------------------------------------------------- |
2052 | 2052 |
2053 void | 2053 void |
2054 base_graphics_backend::update (const graphics_handle& h, int id) | 2054 base_graphics_toolkit::update (const graphics_handle& h, int id) |
2055 { | 2055 { |
2056 graphics_object go = gh_manager::get_object (h); | 2056 graphics_object go = gh_manager::get_object (h); |
2057 | 2057 |
2058 update (go, id); | 2058 update (go, id); |
2059 } | 2059 } |
2060 | 2060 |
2061 void | 2061 void |
2062 base_graphics_backend::initialize (const graphics_handle& h) | 2062 base_graphics_toolkit::initialize (const graphics_handle& h) |
2063 { | 2063 { |
2064 graphics_object go = gh_manager::get_object (h); | 2064 graphics_object go = gh_manager::get_object (h); |
2065 | 2065 |
2066 initialize (go); | 2066 initialize (go); |
2067 } | 2067 } |
2068 | 2068 |
2069 void | 2069 void |
2070 base_graphics_backend::finalize (const graphics_handle& h) | 2070 base_graphics_toolkit::finalize (const graphics_handle& h) |
2071 { | 2071 { |
2072 graphics_object go = gh_manager::get_object (h); | 2072 graphics_object go = gh_manager::get_object (h); |
2073 | 2073 |
2074 finalize (go); | 2074 finalize (go); |
2075 } | 2075 } |
2242 | 2242 |
2243 if (obj) | 2243 if (obj) |
2244 obj.update_axis_limits (axis_type, h); | 2244 obj.update_axis_limits (axis_type, h); |
2245 } | 2245 } |
2246 | 2246 |
2247 graphics_backend | 2247 graphics_toolkit |
2248 base_properties::get_backend (void) const | 2248 base_properties::get_toolkit (void) const |
2249 { | 2249 { |
2250 graphics_object go = gh_manager::get_object (get_parent ()); | 2250 graphics_object go = gh_manager::get_object (get_parent ()); |
2251 | 2251 |
2252 if (go) | 2252 if (go) |
2253 return go.get_backend (); | 2253 return go.get_toolkit (); |
2254 else | 2254 else |
2255 return graphics_backend (); | 2255 return graphics_toolkit (); |
2256 } | 2256 } |
2257 | 2257 |
2258 void | 2258 void |
2259 base_properties::update_boundingbox (void) | 2259 base_properties::update_boundingbox (void) |
2260 { | 2260 { |
2289 p.delete_listener (v, mode); | 2289 p.delete_listener (v, mode); |
2290 } | 2290 } |
2291 | 2291 |
2292 // --------------------------------------------------------------------- | 2292 // --------------------------------------------------------------------- |
2293 | 2293 |
2294 class gnuplot_backend : public base_graphics_backend | 2294 class gnuplot_toolkit : public base_graphics_toolkit |
2295 { | 2295 { |
2296 public: | 2296 public: |
2297 gnuplot_backend (void) | 2297 gnuplot_toolkit (void) |
2298 : base_graphics_backend ("gnuplot") { } | 2298 : base_graphics_toolkit ("gnuplot") { } |
2299 | 2299 |
2300 ~gnuplot_backend (void) { } | 2300 ~gnuplot_toolkit (void) { } |
2301 | 2301 |
2302 bool is_valid (void) const { return true; } | 2302 bool is_valid (void) const { return true; } |
2303 | 2303 |
2304 void finalize (const graphics_object& go) | 2304 void finalize (const graphics_object& go) |
2305 { | 2305 { |
2400 } | 2400 } |
2401 } | 2401 } |
2402 } | 2402 } |
2403 }; | 2403 }; |
2404 | 2404 |
2405 graphics_backend | 2405 graphics_toolkit |
2406 graphics_backend::default_backend (void) | 2406 graphics_toolkit::default_toolkit (void) |
2407 { | 2407 { |
2408 if (available_backends.size () == 0) | 2408 if (available_toolkits.size () == 0) |
2409 register_backend (new gnuplot_backend ()); | 2409 register_toolkit (new gnuplot_toolkit ()); |
2410 | 2410 |
2411 return available_backends["gnuplot"]; | 2411 return available_toolkits["gnuplot"]; |
2412 } | 2412 } |
2413 | 2413 |
2414 std::map<std::string, graphics_backend> graphics_backend::available_backends; | 2414 std::map<std::string, graphics_toolkit> graphics_toolkit::available_toolkits; |
2415 | 2415 |
2416 // --------------------------------------------------------------------- | 2416 // --------------------------------------------------------------------- |
2417 | 2417 |
2418 void | 2418 void |
2419 base_graphics_object::update_axis_limits (const std::string& axis_type) | 2419 base_graphics_object::update_axis_limits (const std::string& axis_type) |
3814 { | 3814 { |
3815 double af; | 3815 double af; |
3816 | 3816 |
3817 // FIXME -- was this really needed? When compared to Matlab, it | 3817 // FIXME -- was this really needed? When compared to Matlab, it |
3818 // does not seem to be required. Need investigation with concrete | 3818 // does not seem to be required. Need investigation with concrete |
3819 // backend to see results visually. | 3819 // graphics toolkit to see results visually. |
3820 if (false && dowarp) | 3820 if (false && dowarp) |
3821 af = 1.0 / (xM > yM ? xM : yM); | 3821 af = 1.0 / (xM > yM ? xM : yM); |
3822 else | 3822 else |
3823 { | 3823 { |
3824 if ((bb(2)/bb(3)) > (xM/yM)) | 3824 if ((bb(2)/bb(3)) > (xM/yM)) |
5505 : handle_map (), handle_free_list (), | 5505 : handle_map (), handle_free_list (), |
5506 next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) | 5506 next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) |
5507 { | 5507 { |
5508 handle_map[0] = graphics_object (new root_figure ()); | 5508 handle_map[0] = graphics_object (new root_figure ()); |
5509 | 5509 |
5510 // Make sure the default backend is registered. | 5510 // Make sure the default graphics toolkit is registered. |
5511 graphics_backend::default_backend (); | 5511 graphics_toolkit::default_toolkit (); |
5512 } | 5512 } |
5513 | 5513 |
5514 graphics_handle | 5514 graphics_handle |
5515 gh_manager::do_make_graphics_handle (const std::string& go_name, | 5515 gh_manager::do_make_graphics_handle (const std::string& go_name, |
5516 const graphics_handle& p, bool do_createfcn) | 5516 const graphics_handle& p, bool do_createfcn) |
5527 | 5527 |
5528 handle_map[h] = obj; | 5528 handle_map[h] = obj; |
5529 if (do_createfcn) | 5529 if (do_createfcn) |
5530 go->get_properties ().execute_createfcn (); | 5530 go->get_properties ().execute_createfcn (); |
5531 | 5531 |
5532 // notify backend | 5532 // Notify graphics toolkit. |
5533 graphics_backend backend = go->get_backend (); | 5533 graphics_toolkit toolkit = go->get_toolkit (); |
5534 if (backend) | 5534 if (toolkit) |
5535 backend.initialize (obj); | 5535 toolkit.initialize (obj); |
5536 } | 5536 } |
5537 else | 5537 else |
5538 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", | 5538 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
5539 go_name.c_str ()); | 5539 go_name.c_str ()); |
5540 | 5540 |
5549 base_graphics_object* go = new figure (h, 0); | 5549 base_graphics_object* go = new figure (h, 0); |
5550 graphics_object obj (go); | 5550 graphics_object obj (go); |
5551 | 5551 |
5552 handle_map[h] = obj; | 5552 handle_map[h] = obj; |
5553 | 5553 |
5554 // notify backend | 5554 // Notify graphics toolkit. |
5555 graphics_backend backend = go->get_backend (); | 5555 graphics_toolkit toolkit = go->get_toolkit (); |
5556 if (backend) | 5556 if (toolkit) |
5557 backend.initialize (obj); | 5557 toolkit.initialize (obj); |
5558 | 5558 |
5559 return h; | 5559 return h; |
5560 } | 5560 } |
5561 | 5561 |
5562 void | 5562 void |
6732 print_usage (); | 6732 print_usage (); |
6733 | 6733 |
6734 return retval; | 6734 return retval; |
6735 } | 6735 } |
6736 | 6736 |
6737 DEFUN (available_backends, , , | 6737 DEFUN (available_graphics_toolkits, , , |
6738 "-*- texinfo -*-\n\ | 6738 "-*- texinfo -*-\n\ |
6739 @deftypefn {Built-in Function} {} available_backends ()\n\ | 6739 @deftypefn {Built-in Function} {} available_graphiscs_toolkits ()\n\ |
6740 Return a cell array of registered graphics backends.\n\ | 6740 Return a cell array of registered graphics toolkits.\n\ |
6741 @end deftypefn") | 6741 @end deftypefn") |
6742 { | 6742 { |
6743 gh_manager::autolock guard; | 6743 gh_manager::autolock guard; |
6744 | 6744 |
6745 return octave_value (graphics_backend::available_backends_list ()); | 6745 return octave_value (graphics_toolkit::available_toolkits_list ()); |
6746 } | 6746 } |
6747 | 6747 |
6748 DEFUN (drawnow, args, , | 6748 DEFUN (drawnow, args, , |
6749 "-*- texinfo -*-\n\ | 6749 "-*- texinfo -*-\n\ |
6750 @deftypefn {Built-in Function} {} drawnow ()\n\ | 6750 @deftypefn {Built-in Function} {} drawnow ()\n\ |
6796 { | 6796 { |
6797 if (fprops.is_visible ()) | 6797 if (fprops.is_visible ()) |
6798 { | 6798 { |
6799 gh_manager::unlock (); | 6799 gh_manager::unlock (); |
6800 | 6800 |
6801 fprops.get_backend ().redraw_figure (go); | 6801 fprops.get_toolkit ().redraw_figure (go); |
6802 | 6802 |
6803 gh_manager::lock (); | 6803 gh_manager::lock (); |
6804 } | 6804 } |
6805 | 6805 |
6806 fprops.set_modified (false); | 6806 fprops.set_modified (false); |
6877 { | 6877 { |
6878 graphics_object go = gh_manager::get_object (h); | 6878 graphics_object go = gh_manager::get_object (h); |
6879 | 6879 |
6880 gh_manager::unlock (); | 6880 gh_manager::unlock (); |
6881 | 6881 |
6882 go.get_backend () | 6882 go.get_toolkit () |
6883 .print_figure (go, term, file, mono, debug_file); | 6883 .print_figure (go, term, file, mono, debug_file); |
6884 | 6884 |
6885 gh_manager::lock (); | 6885 gh_manager::lock (); |
6886 } | 6886 } |
6887 else | 6887 else |