- Widgets now will be shown. Still some problem with their background
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@820 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
b76756c2a8
commit
56d7ddbc5a
|
@ -38,6 +38,14 @@
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
using Gnome::Glade::Xml;
|
using Gnome::Glade::Xml;
|
||||||
|
|
||||||
|
void
|
||||||
|
test_me()
|
||||||
|
{
|
||||||
|
// A test for widget display:
|
||||||
|
Simulation& sim = Simulation::get_instance();
|
||||||
|
sim.get_history().add_process("goofy", 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GuiBuilder::GuiBuilder(const std::string& gladefile)
|
GuiBuilder::GuiBuilder(const std::string& gladefile)
|
||||||
: _refXml(Xml::create(gladefile))
|
: _refXml(Xml::create(gladefile))
|
||||||
|
@ -58,7 +66,8 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
||||||
_refXml->get_widget("MenuItem.Help.About", help_about);
|
_refXml->get_widget("MenuItem.Help.About", help_about);
|
||||||
AboutDialog* about_dialog = NULL;
|
AboutDialog* about_dialog = NULL;
|
||||||
_refXml->get_widget("AboutDialog", about_dialog);
|
_refXml->get_widget("AboutDialog", about_dialog);
|
||||||
help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
|
//help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
|
||||||
|
help_about->signal_activate().connect(sigc::ptr_fun(test_me));
|
||||||
|
|
||||||
// Temporary code to test the Schedulables custom widget
|
// Temporary code to test the Schedulables custom widget
|
||||||
Expander* scheds_expander = NULL;
|
Expander* scheds_expander = NULL;
|
||||||
|
@ -68,9 +77,6 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
||||||
// we have to remember to manually show custom added widgets:
|
// we have to remember to manually show custom added widgets:
|
||||||
scheds_widget->show();
|
scheds_widget->show();
|
||||||
|
|
||||||
// A test for widget display:
|
|
||||||
Simulation& sim = Simulation::get_instance();
|
|
||||||
sim.get_history().add_process("goofy", 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,16 +26,19 @@
|
||||||
|
|
||||||
#include <gdkmm/window.h>
|
#include <gdkmm/window.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
SchedulablesWidget::SchedulablesWidget()
|
SchedulablesWidget::SchedulablesWidget()
|
||||||
: Glib::ObjectBase("sgpem_CairoWidget"),
|
: Glib::ObjectBase("sgpem_CairoWidget"),
|
||||||
Gtk::Widget(), _h(1), _buf(NULL)
|
Gtk::Widget(), _h(1), _buf(NULL)
|
||||||
{
|
{
|
||||||
|
set_flags(Gtk::NO_WINDOW);
|
||||||
// Register this observer:
|
// Register this observer:
|
||||||
Simulation::get_instance().get_history().attach(*this);
|
Simulation::get_instance().get_history().attach(*this);
|
||||||
}
|
}
|
||||||
|
@ -51,24 +54,27 @@ void
|
||||||
SchedulablesWidget::update(const History& history)
|
SchedulablesWidget::update(const History& history)
|
||||||
{
|
{
|
||||||
if(!is_realized())
|
if(!is_realized())
|
||||||
return; // Nowhere to draw to.
|
return; // Nowhere to draw to.
|
||||||
|
|
||||||
// Determine the final height before to start drawing
|
// Determine the final height before to start drawing
|
||||||
unsigned int w = get_allocation().get_width();
|
unsigned int w = get_allocation().get_width();
|
||||||
_h = calc_height(history);
|
_h = calc_height(history);
|
||||||
|
|
||||||
// get_window() returns a null pointer
|
// get_window() returns a null pointer
|
||||||
// if the widget has not been realized
|
// if the widget has not been realized
|
||||||
_buf = Gdk::Pixmap::create(get_window(), w, _h);
|
_buf = Gdk::Pixmap::create(get_window(), w, _h);
|
||||||
|
|
||||||
cairo_t* ctx = gdk_cairo_create(_buf->gobj());
|
cairo_t* ctx = gdk_cairo_create(_buf->gobj());
|
||||||
|
|
||||||
// do the drawing...
|
// do the drawing...
|
||||||
draw_widget(ctx);
|
draw_widget(ctx);
|
||||||
|
|
||||||
cairo_scale(ctx, w, _h);
|
cairo_scale(ctx, w, _h);
|
||||||
|
|
||||||
// manually force an expose_event?
|
// manually force an expose_event?
|
||||||
cairo_destroy(ctx);
|
cairo_destroy(ctx);
|
||||||
|
|
||||||
|
queue_draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,13 +101,13 @@ SchedulablesWidget::calc_height(const History& history) const
|
||||||
void
|
void
|
||||||
SchedulablesWidget::on_realize()
|
SchedulablesWidget::on_realize()
|
||||||
{
|
{
|
||||||
set_flags(Gtk::REALIZED);
|
if(is_realized()) return;
|
||||||
|
|
||||||
// Add other events we want to manage (as mouse clicks)
|
|
||||||
// when needed
|
|
||||||
add_events(Gdk::EXPOSURE_MASK);
|
|
||||||
|
|
||||||
GdkWindowAttr attributes;
|
Gtk::Widget::on_realize();
|
||||||
|
ensure_style();
|
||||||
|
|
||||||
|
GdkWindowAttr attributes;
|
||||||
|
memset(&attributes, 0, sizeof(attributes));
|
||||||
|
|
||||||
Gtk::Allocation alloc = get_allocation();
|
Gtk::Allocation alloc = get_allocation();
|
||||||
|
|
||||||
|
@ -110,20 +116,23 @@ SchedulablesWidget::on_realize()
|
||||||
attributes.width = alloc.get_width();
|
attributes.width = alloc.get_width();
|
||||||
attributes.height = alloc.get_height();
|
attributes.height = alloc.get_height();
|
||||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||||
attributes.visual = get_visual()->gobj();
|
attributes.event_mask = get_events() | GDK_EXPOSURE_MASK;
|
||||||
attributes.colormap = get_colormap()->gobj();
|
attributes.window_type = GDK_WINDOW_CHILD;
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(),
|
Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(),
|
||||||
&attributes,
|
&attributes,
|
||||||
GDK_WA_X | GDK_WA_Y | GDK_WA_COLORMAP |
|
Gdk::WA_X | Gdk::WA_Y |
|
||||||
GDK_WA_VISUAL | GDK_WA_WMCLASS);
|
Gdk::WA_WMCLASS);
|
||||||
|
unset_flags(Gtk::NO_WINDOW);
|
||||||
|
|
||||||
set_window(window);
|
set_window(window);
|
||||||
// get_style()->attach(window);
|
|
||||||
window->set_user_data(gobj());
|
window->set_user_data(gobj());
|
||||||
get_style()->set_background(window, Gtk::STATE_ACTIVE);
|
get_style()->set_background(window, Gtk::STATE_ACTIVE);
|
||||||
|
|
||||||
|
_refGC = Gdk::GC::create(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SchedulablesWidget::on_size_request(Gtk::Requisition* requisition)
|
SchedulablesWidget::on_size_request(Gtk::Requisition* requisition)
|
||||||
{
|
{
|
||||||
// FIXME: take correct measures, consider also using a viewport(?)
|
// FIXME: take correct measures, consider also using a viewport(?)
|
||||||
|
@ -147,28 +156,29 @@ SchedulablesWidget::on_size_allocate(const Gtk::Allocation& allocation)
|
||||||
bool
|
bool
|
||||||
SchedulablesWidget::on_expose_event(GdkEventExpose* event)
|
SchedulablesWidget::on_expose_event(GdkEventExpose* event)
|
||||||
{
|
{
|
||||||
if(!event || event->count > 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// calculated dinamically:
|
// calculated dinamically:
|
||||||
set_size_request(get_allocation().get_width(), _h);
|
int w = get_allocation().get_width();
|
||||||
|
set_size_request(w, _h);
|
||||||
|
|
||||||
// Clip to redraw only the smallest possible area
|
// Clip to redraw only the smallest possible area
|
||||||
std::auto_ptr<Gdk::Rectangle> clip_area;
|
std::auto_ptr<Gdk::Rectangle> clip_area;
|
||||||
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(event->area.x, event->area.y,
|
if(event)
|
||||||
event->area.width, event->area.height));
|
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(event->area.x, event->area.y,
|
||||||
|
event->area.width, event->area.height));
|
||||||
|
else
|
||||||
|
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(0, 0, w, _h));
|
||||||
|
|
||||||
// Use double buffering or we're CPU-dead
|
// Use double buffering or we're CPU-dead
|
||||||
// Copy from the buffer to the screen
|
// Copy from the buffer to the screen
|
||||||
if(_buf)
|
if(_buf)
|
||||||
get_window()->draw_drawable(Gdk::GC::create(get_window()), _buf,
|
get_window()->draw_drawable(_refGC, _buf,
|
||||||
clip_area->get_x(), clip_area->get_y(),
|
clip_area->get_x(), clip_area->get_y(),
|
||||||
clip_area->get_x(), clip_area->get_y(),
|
clip_area->get_x(), clip_area->get_y(),
|
||||||
clip_area->get_width(), clip_area->get_height());
|
clip_area->get_width(), clip_area->get_height());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SchedulablesWidget::on_button_press_event(GdkEventButton* event)
|
SchedulablesWidget::on_button_press_event(GdkEventButton* event)
|
||||||
|
|
|
@ -59,6 +59,7 @@ namespace sgpem
|
||||||
typedef std::vector<area_callback_t> areas_vect_t;
|
typedef std::vector<area_callback_t> areas_vect_t;
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Pixmap> _buf;
|
Glib::RefPtr<Gdk::Pixmap> _buf;
|
||||||
|
Glib::RefPtr<Gdk::GC> _refGC;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //~ namespace sgpem
|
} //~ namespace sgpem
|
||||||
|
|
Loading…
Reference in New Issue