"*count: -30 \n" \
"*showFPS: False \n" \
"*cycles: 20 \n" \
- "*size: -6 \n"
+ "*size: -6 \n" \
+ "*suppressRotationAnimation: True\n" \
+
# define refresh_rubik 0
+# define release_rubik 0
# include "xlockmore.h" /* from the xscreensaver distribution */
#else /* !STANDALONE */
# include "xlock.h" /* from the xlockmore distribution */
#ifdef USE_MODULES
ModStruct rubik_description =
-{"rubik", "init_rubik", "draw_rubik", "release_rubik",
+{"rubik", "init_rubik", "draw_rubik", (char *) NULL,
"draw_rubik", "change_rubik", (char *) NULL, &rubik_opts,
10000, -30, 5, -6, 64, 1.0, "",
"Shows an auto-solving Rubik's Cube", 0, NULL};
*sizeOfRow = MAXSIZEX;
*sizeOfColumn = MAXSIZEY;
break;
+ default: abort();
}
}
}
#ifdef DEBUG
-void
+static void
printCube(rubikstruct * rp)
{
int face, position, sizeOfRow, sizeOfColumn;
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0);
glMatrixMode(GL_MODELVIEW);
-
}
ENTRYPOINT Bool
{
rubikstruct *rp = &rubik[MI_SCREEN(mi)];
- if (event->xany.type == ButtonPress &&
- event->xbutton.button == Button1)
+ if (gltrackball_event_handler (event, rp->trackball,
+ MI_WIDTH (mi), MI_HEIGHT (mi),
+ &rp->button_down_p))
+ return True;
+ else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
{
- rp->button_down_p = True;
- gltrackball_start (rp->trackball,
- event->xbutton.x, event->xbutton.y,
- MI_WIDTH (mi), MI_HEIGHT (mi));
- return True;
- }
- else if (event->xany.type == ButtonRelease &&
- event->xbutton.button == Button1)
- {
- rp->button_down_p = False;
- return True;
- }
- else if (event->xany.type == ButtonPress &&
- (event->xbutton.button == Button4 ||
- event->xbutton.button == Button5 ||
- event->xbutton.button == Button6 ||
- event->xbutton.button == Button7))
- {
- gltrackball_mousewheel (rp->trackball, event->xbutton.button, 10,
- !!event->xbutton.state);
- return True;
- }
- else if (event->xany.type == MotionNotify &&
- rp->button_down_p)
- {
- gltrackball_track (rp->trackball,
- event->xmotion.x, event->xmotion.y,
- MI_WIDTH (mi), MI_HEIGHT (mi));
+ rp->done = 1;
return True;
}
}
static void
-free_rubik(rubikstruct *rp)
+free_rubik(ModeInfo *mi)
{
+ rubikstruct *rp = &rubik[MI_SCREEN(mi)];
int i;
for (i = 0; i < MAXFACES; i++)
}
}
-ENTRYPOINT void
-release_rubik(ModeInfo * mi)
-{
- if (rubik != NULL) {
- int screen;
-
- for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
- rubikstruct *rp = &rubik[screen];
-
- free_rubik(rp);
- }
- (void) free((void *) rubik);
- rubik = (rubikstruct *) NULL;
- }
- FreeAllGL(mi);
-}
-
ENTRYPOINT void
init_rubik(ModeInfo * mi)
{
rubikstruct *rp;
- if (rubik == NULL) {
- if ((rubik = (rubikstruct *) calloc(MI_NUM_SCREENS(mi),
- sizeof (rubikstruct))) == NULL)
- return;
- }
+ MI_INIT (mi, rubik, free_rubik);
rp = &rubik[MI_SCREEN(mi)];
rp->step = NRAND(90);
rp->PX = ((float) LRAND() / (float) MAXRAND) * 2.0 - 1.0;
rp->PY = ((float) LRAND() / (float) MAXRAND) * 2.0 - 1.0;
- rp->trackball = gltrackball_init ();
+ rp->trackball = gltrackball_init (True);
if ((rp->glx_context = init_GL(mi)) != NULL) {
reshape_rubik(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
glDrawBuffer(GL_BACK);
if (!pinit(mi)) {
- free_rubik(rp);
+ free_rubik(mi);
if (MI_IS_VERBOSE(mi)) {
(void) fprintf(stderr,
"Could not allocate memory for rubik\n");
glScalef(Scale4Iconic * rp->WindH / rp->WindW, Scale4Iconic, Scale4Iconic);
}
- /* Do it twice because we don't track the device's orientation. */
- glRotatef( current_device_rotation(), 0, 0, 1);
+# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */
+ {
+ GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
+ int o = (int) current_device_rotation();
+ if (o != 0 && o != 180 && o != -180) {
+ glScalef (1/h, h, 1); /* #### not quite right */
+ h = 1.8;
+ glScalef (h, h, h);
+ }
+ }
+# endif
+
gltrackball_rotate (rp->trackball);
- glRotatef(-current_device_rotation(), 0, 0, 1);
glRotatef(rp->step * 100, 1, 0, 0);
glRotatef(rp->step * 95, 0, 1, 0);
glRotatef(rp->step * 90, 0, 0, 1);
if (!draw_cube(mi)) {
- release_rubik(mi);
+ MI_ABORT(mi);
return;
}
if (MI_IS_FPS(mi)) do_fps (mi);
rp->rotatestep += rp->anglestep;
if (rp->rotatestep > rp->degreeTurn) {
if (!evalmovement(mi, rp->movement)) {
- free_rubik(rp);
+ free_rubik(mi);
if (MI_IS_VERBOSE(mi)) {
(void) fprintf(stderr,
"Could not allocate memory for rubik\n");
if (rp->done) {
if (++rp->rotatestep > DELAY_AFTER_SOLVING)
if (!shuffle(mi)) {
- free_rubik(rp);
+ free_rubik(mi);
if (MI_IS_VERBOSE(mi)) {
(void) fprintf(stderr,
"Could not allocate memory for rubik\n");
rp->rotatestep += rp->anglestep;
if (rp->rotatestep > rp->degreeTurn) {
if (!evalmovement(mi, rp->movement)) {
- free_rubik(rp);
+ free_rubik(mi);
if (MI_IS_VERBOSE(mi)) {
(void) fprintf(stderr,
"Could not allocate memory for rubik\n");
if (!rp->glx_context)
return;
if (!pinit(mi)) {
- free_rubik(rp);
+ free_rubik(mi);
if (MI_IS_VERBOSE(mi)) {
(void) fprintf(stderr,
"Could not allocate memory for rubik\n");