ScrolledWindow and Layout
- From: "Rose Cumming" <rose_alice_cumming hotmail com>
- To: gtkmm-list gnome org
- Subject: ScrolledWindow and Layout
- Date: Thu, 22 Sep 2005 18:19:08 +0000
I'd like to have a vertical scroll bar that can scroll a Gtk::Layout that
can potentially be larger than the screen.
should I call:
m_ScrolledWindow.set_vadjustment(*m_Layout.get_vadjustment());
or
m_Layout.set_vadjustment(*m_Scrolled.get_vadjustment());
I tried both, they did not seem to work.
Can anyone tell me what's wrong in the attached code?
_________________________________________________________________
Powerful Parental Controls Let your child discover the best the Internet has
to offer.
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN® Premium right now and get the
first two months FREE*.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cmath>
#include <gtkmm/layout.h>
#include <gtkmm.h>
class GearsScene : public Gtk::Layout
{
public:
GearsScene(bool is_sync = true);
virtual ~GearsScene();
protected:
void gear();
protected:
// signal handlers:
virtual void on_realize();
virtual bool on_configure_event(GdkEventConfigure* event);
virtual bool on_expose_event(GdkEventExpose* event);
virtual bool on_motion_notify_event(GdkEventMotion* event);
virtual bool on_map_event(GdkEventAny* event);
virtual bool on_unmap_event(GdkEventAny* event);
virtual bool on_visibility_notify_event(GdkEventVisibility* event);
virtual bool on_idle();
public:
// Invalidate whole window.
void invalidate() {
GtkAllocation allocation = get_allocation();
get_bin_window()->invalidate_rect(Gdk::Rectangle(&allocation), false);
}
// Update window synchronously (fast).
void update()
{ get_bin_window()->process_updates(false); }
protected:
// idle signal connection:
SigC::Connection m_ConnectionIdle;
public:
// get & set view rotation values.
protected:
bool m_IsSync;
protected:
// frame rate evaluation stuff:
Glib::Timer m_Timer;
int m_Frames;
Glib::RefPtr<Gdk::GC> gc_;
Glib::RefPtr<Gdk::GC> gc_xor_;
Gdk::Color black_;
Gdk::Color green_;
Glib::RefPtr<Gdk::Pixmap> pixmap_;
int x_;
int y_;
};
GearsScene::GearsScene(bool is_sync)
: m_IsSync(is_sync),
m_Frames(0)
{
x_=500;
y_=500;
// Add events.
add_events(Gdk::VISIBILITY_NOTIFY_MASK);
add_events(Gdk::POINTER_MOTION_MASK);
}
GearsScene::~GearsScene()
{
}
void GearsScene::gear()
{
}
void GearsScene::on_realize()
{
// We need to call the base on_realize()
Gtk::Layout::on_realize();
Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
black_ = Gdk::Color("black");
green_ = Gdk::Color("green");
colormap->alloc_color(black_);
colormap->alloc_color(green_);
Glib::RefPtr<Gdk::Window> window = get_bin_window();
gc_ = Gdk::GC::create(window);
gc_xor_ = Gdk::GC::create(window);
gc_->set_foreground(black_);
gc_->set_line_attributes(2,
Gdk::LINE_SOLID,
Gdk::CAP_NOT_LAST,
Gdk::JOIN_MITER);
// testing
pixmap_ = Gdk::Pixmap::create(window,
1000,
2000,
-1);
pixmap_->draw_rectangle (gc_,
true,
0, 0,
1000,
1000);
window->draw_drawable (gc_,
pixmap_,
0,0,0,0,1000,2000);
// Start timer.
m_Timer.start();
}
bool GearsScene::on_configure_event(GdkEventConfigure* event)
{
return true;
}
bool GearsScene::on_expose_event(GdkEventExpose* event)
{
Glib::RefPtr<Gdk::Window> window = get_bin_window();
window->draw_drawable (gc_,
pixmap_,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
//
// Print frame rate.
//
++m_Frames;
double seconds = m_Timer.elapsed();
if (seconds >= 5.0)
{
std::cout.setf(std::ios::fixed, std::ios::floatfield);
std::cout.precision(3);
std::cout << m_Frames << " frames in "
<< seconds << " seconds = "
<< (m_Frames / seconds) << " FPS\n";
m_Timer.reset();
m_Frames = 0;
}
return true;
}
bool GearsScene::on_motion_notify_event(GdkEventMotion* event)
{
return true;
}
bool GearsScene::on_map_event(GdkEventAny* event)
{
if (!m_ConnectionIdle.connected())
m_ConnectionIdle = Glib::signal_idle().connect(
SigC::slot(*this, &GearsScene::on_idle), GDK_PRIORITY_REDRAW);
return true;
}
bool GearsScene::on_unmap_event(GdkEventAny* event)
{
if (m_ConnectionIdle.connected())
m_ConnectionIdle.disconnect();
return true;
}
bool GearsScene::on_visibility_notify_event(GdkEventVisibility* event)
{
if (event->state == GDK_VISIBILITY_FULLY_OBSCURED)
{
if (m_ConnectionIdle.connected())
m_ConnectionIdle.disconnect();
}
else
{
if (!m_ConnectionIdle.connected())
m_ConnectionIdle = Glib::signal_idle().connect(
SigC::slot(*this, &GearsScene::on_idle), GDK_PRIORITY_REDRAW);
}
return true;
}
bool GearsScene::on_idle()
{
// Invalidate the whole window.
invalidate();
// Update window synchronously (fast).
if (m_IsSync)
update();
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// The application class.
//
///////////////////////////////////////////////////////////////////////////////
class Gears : public Gtk::Window
{
public:
explicit Gears(bool is_sync = true);
virtual ~Gears();
protected:
// signal handlers:
void on_button_quit_clicked();
virtual bool on_key_press_event(GdkEventKey* event);
protected:
// member widgets:
Gtk::VBox m_VBox;
Gtk::ScrolledWindow m_Window;
GearsScene m_GearsScene;
Gtk::Button m_ButtonQuit;
};
Gears::Gears(bool is_sync)
: m_VBox(false, 0), m_GearsScene(is_sync), m_ButtonQuit("Quit")
{
//
// Top-level window.
//
set_title("Test");
//set_decorated(false);
// Get automatically redrawn if any of their children changed allocation.
set_reallocate_redraws(true);
add(m_VBox);
//
// Gears scene.
//
m_VBox.pack_start(m_Window);
m_Window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
m_Window.add(m_GearsScene);
m_Window.set_size_request(1000, 1000);
m_GearsScene.set_size_request(1000, 2000);
//m_GearsScene.set_vadjustment(*m_Window.get_vadjustment());
m_Window.set_vadjustment(*m_GearsScene.get_vadjustment());
//
// Simple quit button.
//
m_ButtonQuit.signal_clicked().connect(
SigC::slot(*this, &Gears::on_button_quit_clicked));
m_VBox.pack_start(m_ButtonQuit, Gtk::PACK_SHRINK, 0);
//
// Show window.
//
show_all();
}
Gears::~Gears()
{
}
void Gears::on_button_quit_clicked()
{
Gtk::Main::quit();
}
bool Gears::on_key_press_event(GdkEventKey* event)
{
m_GearsScene.invalidate();
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// Main.
//
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char** argv)
{
Gtk::Main kit(argc, argv);
bool is_sync = true;
Gears gears(is_sync);
kit.run(gears);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]