remove width and height arguments from configure callback; call configure callback after instantiating a new mode
This commit is contained in:
parent
e2dc328996
commit
d87a116957
@ -1,6 +1,8 @@
|
||||
|
||||
#include "GnomeScreensaver.h"
|
||||
|
||||
#define MAX_ASPECT (16.0/9.0*1.02)
|
||||
|
||||
static gboolean
|
||||
expose (GtkWidget *da, GdkEventExpose *event, GnomeScreensaver *gs)
|
||||
{
|
||||
@ -20,7 +22,7 @@ update (void *gs)
|
||||
}
|
||||
|
||||
GnomeScreensaver::GnomeScreensaver(int *argc, char ***argv,
|
||||
bool (*configure_callback)(GnomeScreensaver &, int, int),
|
||||
bool (*configure_callback)(GnomeScreensaver &),
|
||||
bool (*expose_callback)(GnomeScreensaver &),
|
||||
bool (*update_callback)(GnomeScreensaver &),
|
||||
int32_t interval_msec)
|
||||
@ -96,6 +98,8 @@ GnomeScreensaver::GnomeScreensaver(int *argc, char ***argv,
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
m_start_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
|
||||
m_n_monitors = 1;
|
||||
}
|
||||
|
||||
uint32_t GnomeScreensaver::getTicks()
|
||||
@ -138,8 +142,16 @@ gboolean GnomeScreensaver::configureCB(GtkWidget *da, GdkEventConfigure *event)
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
gboolean rc = m_configure_callback(*this,
|
||||
da->allocation.width, da->allocation.height);
|
||||
m_width = da->allocation.width;
|
||||
m_height = da->allocation.height;
|
||||
m_aspect_ratio = (float)m_width / (float)m_height;
|
||||
|
||||
for (m_n_monitors = 1;
|
||||
(double)m_width/(double)m_n_monitors/(double)m_height > MAX_ASPECT;
|
||||
m_n_monitors++)
|
||||
;
|
||||
|
||||
gboolean rc = m_configure_callback(*this);
|
||||
|
||||
gdk_gl_drawable_gl_end(gldrawable);
|
||||
|
||||
|
@ -24,7 +24,7 @@ class GnomeScreensaver
|
||||
{
|
||||
public:
|
||||
GnomeScreensaver(int *argc, char ***argv,
|
||||
bool (*configure_callback)(GnomeScreensaver &, int, int),
|
||||
bool (*configure_callback)(GnomeScreensaver &),
|
||||
bool (*expose_callback)(GnomeScreensaver &),
|
||||
bool (*update_callback)(GnomeScreensaver &),
|
||||
int32_t interval_msec);
|
||||
@ -33,13 +33,19 @@ class GnomeScreensaver
|
||||
gboolean configureCB(GtkWidget *da, GdkEventConfigure *event);
|
||||
gboolean exposeCB(GtkWidget *da, GdkEventExpose *event);
|
||||
gboolean updateCB();
|
||||
int getWidth() { return m_width; }
|
||||
int getHeight() { return m_height; }
|
||||
float getAspectRatio() { return m_aspect_ratio; }
|
||||
|
||||
protected:
|
||||
GtkWidget *m_drawing_area;
|
||||
uint64_t m_start_msec;
|
||||
bool (*m_configure_callback)(GnomeScreensaver &, int, int);
|
||||
bool (*m_configure_callback)(GnomeScreensaver &);
|
||||
bool (*m_expose_callback)(GnomeScreensaver &);
|
||||
bool (*m_update_callback)(GnomeScreensaver &);
|
||||
int m_width, m_height;
|
||||
float m_aspect_ratio;
|
||||
int m_n_monitors;
|
||||
};
|
||||
|
||||
#endif /* GNOMESCREENSAVER_H */
|
||||
|
20
dwss.cc
20
dwss.cc
@ -13,9 +13,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define MAX_ASPECT (16.0/9.0*1.02)
|
||||
|
||||
static int n_monitors = 1;
|
||||
static Mode *current_mode = NULL;
|
||||
|
||||
static bool expose (GnomeScreensaver & gs)
|
||||
@ -23,16 +20,9 @@ static bool expose (GnomeScreensaver & gs)
|
||||
return current_mode != NULL ? current_mode->expose(gs) : true;
|
||||
}
|
||||
|
||||
static bool configure (GnomeScreensaver & gs, int width, int height)
|
||||
static bool configure (GnomeScreensaver & gs)
|
||||
{
|
||||
for (n_monitors = 1;
|
||||
(double)width/(double)n_monitors/(double)height > MAX_ASPECT;
|
||||
n_monitors++)
|
||||
;
|
||||
|
||||
return current_mode != NULL
|
||||
? current_mode->configure(gs, width, height)
|
||||
: true;
|
||||
return current_mode != NULL ? current_mode->configure(gs) : true;
|
||||
}
|
||||
|
||||
static bool update (GnomeScreensaver & gs)
|
||||
@ -48,7 +38,13 @@ int main (int argc, char *argv[])
|
||||
new Spin()
|
||||
};
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
current_mode = modes[0];
|
||||
current_mode->configure(gs);
|
||||
|
||||
gs.mainloop();
|
||||
|
||||
|
@ -8,8 +8,7 @@ class Mode
|
||||
{
|
||||
public:
|
||||
virtual bool expose (GnomeScreensaver & gs) = 0;
|
||||
virtual bool configure (GnomeScreensaver & gs, int width,
|
||||
int height) = 0;
|
||||
virtual bool configure (GnomeScreensaver & gs) = 0;
|
||||
virtual bool update (GnomeScreensaver & gs) = 0;
|
||||
};
|
||||
|
||||
|
@ -9,39 +9,26 @@ bool Spin::expose (GnomeScreensaver & gs)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(0, 0, -3.0);
|
||||
|
||||
glRotatef(gs.getTicks() / 1000.0 * 360.0 / 4.0, 0, 1, 0);
|
||||
m_logobox.draw();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(1, 0.6, 0);
|
||||
glNormal3f(0, 0, 1);
|
||||
glVertex2f(1, 1);
|
||||
glVertex2f(-1, 1);
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f(1, 0);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Spin::configure (GnomeScreensaver & gs, int width, int height)
|
||||
bool Spin::configure (GnomeScreensaver & gs)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
glViewport(0, 0, gs.getWidth(), gs.getHeight());
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(60.0, (double)width/(double)height, 0.01, 1000.0);
|
||||
gluPerspective(60.0, gs.getAspectRatio(), 0.01, 1000.0);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
// gluLookAt(0, 0, 0, 0, 0, 4, 0, 1, 0);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -10,8 +10,7 @@ class Spin : public Mode
|
||||
{
|
||||
public:
|
||||
bool expose (GnomeScreensaver & gs);
|
||||
bool configure (GnomeScreensaver & gs, int width,
|
||||
int height);
|
||||
bool configure (GnomeScreensaver & gs);
|
||||
bool update (GnomeScreensaver & gs);
|
||||
protected:
|
||||
LogoBox m_logobox;
|
||||
|
Loading…
x
Reference in New Issue
Block a user