- 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 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)
|
||||
: _refXml(Xml::create(gladefile))
|
||||
|
@ -58,7 +66,8 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
|||
_refXml->get_widget("MenuItem.Help.About", help_about);
|
||||
AboutDialog* about_dialog = NULL;
|
||||
_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
|
||||
Expander* scheds_expander = NULL;
|
||||
|
@ -68,9 +77,6 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
|||
// we have to remember to manually show custom added widgets:
|
||||
scheds_widget->show();
|
||||
|
||||
// A test for widget display:
|
||||
Simulation& sim = Simulation::get_instance();
|
||||
sim.get_history().add_process("goofy", 0, 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,9 +26,11 @@
|
|||
|
||||
#include <gdkmm/window.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
|
||||
|
@ -36,6 +38,7 @@ SchedulablesWidget::SchedulablesWidget()
|
|||
: Glib::ObjectBase("sgpem_CairoWidget"),
|
||||
Gtk::Widget(), _h(1), _buf(NULL)
|
||||
{
|
||||
set_flags(Gtk::NO_WINDOW);
|
||||
// Register this observer:
|
||||
Simulation::get_instance().get_history().attach(*this);
|
||||
}
|
||||
|
@ -51,7 +54,7 @@ void
|
|||
SchedulablesWidget::update(const History& history)
|
||||
{
|
||||
if(!is_realized())
|
||||
return; // Nowhere to draw to.
|
||||
return; // Nowhere to draw to.
|
||||
|
||||
// Determine the final height before to start drawing
|
||||
unsigned int w = get_allocation().get_width();
|
||||
|
@ -60,6 +63,7 @@ SchedulablesWidget::update(const History& history)
|
|||
// get_window() returns a null pointer
|
||||
// if the widget has not been realized
|
||||
_buf = Gdk::Pixmap::create(get_window(), w, _h);
|
||||
|
||||
cairo_t* ctx = gdk_cairo_create(_buf->gobj());
|
||||
|
||||
// do the drawing...
|
||||
|
@ -69,6 +73,8 @@ SchedulablesWidget::update(const History& history)
|
|||
|
||||
// manually force an expose_event?
|
||||
cairo_destroy(ctx);
|
||||
|
||||
queue_draw();
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,13 +101,13 @@ SchedulablesWidget::calc_height(const History& history) const
|
|||
void
|
||||
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);
|
||||
Gtk::Widget::on_realize();
|
||||
ensure_style();
|
||||
|
||||
GdkWindowAttr attributes;
|
||||
GdkWindowAttr attributes;
|
||||
memset(&attributes, 0, sizeof(attributes));
|
||||
|
||||
Gtk::Allocation alloc = get_allocation();
|
||||
|
||||
|
@ -110,17 +116,20 @@ SchedulablesWidget::on_realize()
|
|||
attributes.width = alloc.get_width();
|
||||
attributes.height = alloc.get_height();
|
||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||
attributes.visual = get_visual()->gobj();
|
||||
attributes.colormap = get_colormap()->gobj();
|
||||
attributes.event_mask = get_events() | GDK_EXPOSURE_MASK;
|
||||
attributes.window_type = GDK_WINDOW_CHILD;
|
||||
|
||||
Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(),
|
||||
&attributes,
|
||||
GDK_WA_X | GDK_WA_Y | GDK_WA_COLORMAP |
|
||||
GDK_WA_VISUAL | GDK_WA_WMCLASS);
|
||||
Gdk::WA_X | Gdk::WA_Y |
|
||||
Gdk::WA_WMCLASS);
|
||||
unset_flags(Gtk::NO_WINDOW);
|
||||
|
||||
set_window(window);
|
||||
// get_style()->attach(window);
|
||||
window->set_user_data(gobj());
|
||||
get_style()->set_background(window, Gtk::STATE_ACTIVE);
|
||||
|
||||
_refGC = Gdk::GC::create(window);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -147,24 +156,25 @@ SchedulablesWidget::on_size_allocate(const Gtk::Allocation& allocation)
|
|||
bool
|
||||
SchedulablesWidget::on_expose_event(GdkEventExpose* event)
|
||||
{
|
||||
if(!event || event->count > 0)
|
||||
return false;
|
||||
|
||||
// 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
|
||||
std::auto_ptr<Gdk::Rectangle> clip_area;
|
||||
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(event->area.x, event->area.y,
|
||||
event->area.width, event->area.height));
|
||||
if(event)
|
||||
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
|
||||
// Copy from the buffer to the screen
|
||||
if(_buf)
|
||||
get_window()->draw_drawable(Gdk::GC::create(get_window()), _buf,
|
||||
clip_area->get_x(), clip_area->get_y(),
|
||||
clip_area->get_x(), clip_area->get_y(),
|
||||
clip_area->get_width(), clip_area->get_height());
|
||||
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_width(), clip_area->get_height());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ namespace sgpem
|
|||
typedef std::vector<area_callback_t> areas_vect_t;
|
||||
|
||||
Glib::RefPtr<Gdk::Pixmap> _buf;
|
||||
Glib::RefPtr<Gdk::GC> _refGC;
|
||||
};
|
||||
|
||||
} //~ namespace sgpem
|
||||
|
|
Loading…
Reference in New Issue