comparison src/graphics.cc @ 7828:4739b6a1925c

Implement resize handler mechanism (call resizefcn on figure resize and notify children). * * * Fix figure boundingbox <-> position conversion bug.
author Michael Goffioul <michael.goffioul@gmail.com>
date Wed, 13 Feb 2008 17:06:22 +0100
parents 3584f37eac69
children 8ca8e97e8c0a
comparison
equal deleted inserted replaced
7827:3584f37eac69 7828:4739b6a1925c
1299 return go.get_backend (); 1299 return go.get_backend ();
1300 else 1300 else
1301 return graphics_backend (); 1301 return graphics_backend ();
1302 } 1302 }
1303 1303
1304 void
1305 base_properties::update_boundingbox (void)
1306 {
1307 Matrix kids = get_children ();
1308
1309 for (int i = 0; i < kids.numel (); i++)
1310 {
1311 graphics_object go = gh_manager::get_object (kids(i));
1312
1313 if (go.valid_object ())
1314 go.get_properties ().update_boundingbox ();
1315 }
1316 }
1317
1304 // --------------------------------------------------------------------- 1318 // ---------------------------------------------------------------------
1305 1319
1306 class gnuplot_backend : public base_graphics_backend 1320 class gnuplot_backend : public base_graphics_backend
1307 { 1321 {
1308 public: 1322 public:
1499 pos(0)--; 1513 pos(0)--;
1500 pos(1)--; 1514 pos(1)--;
1501 pos(1) = screen_size(1) - pos(1) - pos(3); 1515 pos(1) = screen_size(1) - pos(1) - pos(3);
1502 1516
1503 return pos; 1517 return pos;
1518 }
1519
1520 void
1521 figure::properties::set_boundingbox (const Matrix& bb)
1522 {
1523 graphics_backend b = get_backend ();
1524 // FIXME: screen size should be obtained from root object
1525 Matrix screen_size = b.get_screen_size ();
1526 Matrix pos = bb;
1527
1528 pos(1) = screen_size(1) - pos(1) - pos(3);
1529 pos(1)++;
1530 pos(0)++;
1531 pos = convert_position (pos, "pixels", get_units (), screen_size, b);
1532
1533 set_position (pos);
1534 }
1535
1536 void
1537 figure::properties::set_position (const octave_value& v)
1538 {
1539 if (! error_state)
1540 {
1541 Matrix old_bb, new_bb;
1542
1543 old_bb = get_boundingbox ();
1544 position = v;
1545 new_bb = get_boundingbox ();
1546
1547 if (old_bb != new_bb)
1548 {
1549 // FIXME: maybe this should be converted into a more generic
1550 // call like "update_gui (this)"
1551 get_backend ().set_figure_position (__myhandle__, new_bb);
1552 if (old_bb(2) != new_bb(2) || old_bb(3) != new_bb(3))
1553 {
1554 execute_resizefcn ();
1555 update_boundingbox ();
1556 }
1557 }
1558
1559 mark_modified ();
1560 }
1504 } 1561 }
1505 1562
1506 octave_value 1563 octave_value
1507 figure::get_default (const caseless_str& name) const 1564 figure::get_default (const caseless_str& name) const
1508 { 1565 {