Permalink
Browse files

Merge branch 'upstream'

Conflicts:
	twiddle.c
  • Loading branch information...
2 parents 3a2a5cc + 7c05b09 commit 5d565f02f83b9d398c414f27c428d7bb6d92e0e1 @chrisboyle committed Nov 21, 2010
Showing with 71 additions and 64 deletions.
  1. +14 −8 PuzzleApplet.java
  2. +43 −48 gtk.c
  3. +4 −1 nestedvm.c
  4. +7 −7 twiddle.c
  5. +3 −0 unfinished/slide.c
View
@@ -297,16 +297,22 @@ public int call(int cmd, int arg1, int arg2, int arg3) {
String text = runtime.cstring(arg2);
if (text.equals("")) text = " ";
System.out.println("status '" + text + "'");
- statusBar.setText(text); break;
+ statusBar.setText(text);
+ break;
case 1:
gg = pp.backBuffer.createGraphics();
- if (arg2 != 0 || arg3 != 0) {
- gg.setColor(Color.black);
- gg.fillRect(0, 0, arg2, getHeight());
- gg.fillRect(0, 0, getWidth(), arg3);
- gg.fillRect(getWidth() - arg2, 0, arg2, getHeight());
- gg.fillRect(0, getHeight() - arg3, getWidth(), arg3);
- gg.setClip(arg2, arg3, getWidth()-2*arg2, getHeight()-2*arg3);
+ if (arg2 != 0 || arg3 != 0 ||
+ arg2 + xarg2 != getWidth() ||
+ arg3 + xarg3 != getHeight()) {
+ int left = arg2, right = arg2 + xarg2;
+ int top = arg3, bottom = arg3 + xarg3;
+ int width = getWidth(), height = getHeight();
+ gg.setColor(colors != null ? colors[0] : Color.black);
+ gg.fillRect(0, 0, left, height);
+ gg.fillRect(right, 0, width-right, height);
+ gg.fillRect(0, 0, width, top);
+ gg.fillRect(0, bottom, width, height-bottom);
+ gg.setClip(left, top, right-left, bottom-top);
}
break;
case 2: gg.dispose(); pp.repaint(); break;
View
91 gtk.c
@@ -125,11 +125,13 @@ struct frontend {
cairo_t *cr;
cairo_surface_t *image;
GdkPixmap *pixmap;
+ GdkColor background; /* for painting outside puzzle area */
#else
GdkPixmap *pixmap;
GdkGC *gc;
GdkColor *colours;
GdkColormap *colmap;
+ int backgroundindex; /* which of colours[] is background */
#endif
int ncolours;
int bbox_l, bbox_r, bbox_u, bbox_d;
@@ -238,18 +240,18 @@ static void set_colour(frontend *fe, int colour)
static void set_window_background(frontend *fe, int colour)
{
GdkColormap *colmap;
- GdkColor backg;
colmap = gdk_colormap_get_system();
- backg.red = fe->colours[3*colour + 0] * 65535;
- backg.green = fe->colours[3*colour + 1] * 65535;
- backg.blue = fe->colours[3*colour + 2] * 65535;
- if (!gdk_colormap_alloc_color(colmap, &backg, FALSE, FALSE)) {
+ fe->background.red = fe->colours[3*colour + 0] * 65535;
+ fe->background.green = fe->colours[3*colour + 1] * 65535;
+ fe->background.blue = fe->colours[3*colour + 2] * 65535;
+ if (!gdk_colormap_alloc_color(colmap, &fe->background, FALSE, FALSE)) {
g_error("couldn't allocate background (#%02x%02x%02x)\n",
- backg.red >> 8, backg.green >> 8, backg.blue >> 8);
+ fe->background.red >> 8, fe->background.green >> 8,
+ fe->background.blue >> 8);
}
- gdk_window_set_background(fe->area->window, &backg);
- gdk_window_set_background(fe->window->window, &backg);
+ gdk_window_set_background(fe->area->window, &fe->background);
+ gdk_window_set_background(fe->window->window, &fe->background);
}
static PangoLayout *make_pango_layout(frontend *fe)
@@ -408,41 +410,6 @@ static void teardown_backing_store(frontend *fe)
fe->image = NULL;
}
-static void repaint_rectangle(frontend *fe, GtkWidget *widget,
- int x, int y, int w, int h)
-{
- if (x < fe->ox) {
- gdk_draw_rectangle(widget->window,
- widget->style->bg_gc[GTK_WIDGET_STATE(fe->area)],
- TRUE, x, y, fe->ox - x, h);
- w -= (fe->ox - x);
- x = fe->ox;
- }
- if (y < fe->oy) {
- gdk_draw_rectangle(widget->window,
- widget->style->bg_gc[GTK_WIDGET_STATE(fe->area)],
- TRUE, x, y, w, fe->oy - y);
- h -= (fe->oy - y);
- y = fe->oy;
- }
- if (w > fe->pw) {
- gdk_draw_rectangle(widget->window,
- widget->style->bg_gc[GTK_WIDGET_STATE(fe->area)],
- TRUE, x + fe->pw, y, w - fe->pw, h);
- w = fe->pw;
- }
- if (h > fe->ph) {
- gdk_draw_rectangle(widget->window,
- widget->style->bg_gc[GTK_WIDGET_STATE(fe->area)],
- TRUE, x, y + fe->ph, w, h - fe->ph);
- h = fe->ph;
- }
- gdk_draw_pixmap(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(fe->area)],
- fe->pixmap,
- x - fe->ox, y - fe->oy, x, y, w, h);
-}
-
#endif
/* ----------------------------------------------------------------------
@@ -492,6 +459,7 @@ static void snaffle_colours(frontend *fe)
static void set_window_background(frontend *fe, int colour)
{
+ fe->backgroundindex = colour;
gdk_window_set_background(fe->area->window, &fe->colours[colour]);
gdk_window_set_background(fe->window->window, &fe->colours[colour]);
}
@@ -690,17 +658,44 @@ static void teardown_backing_store(frontend *fe)
fe->pixmap = NULL;
}
+#endif
+
static void repaint_rectangle(frontend *fe, GtkWidget *widget,
int x, int y, int w, int h)
{
- gdk_draw_pixmap(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(fe->area)],
- fe->pixmap,
+ GdkGC *gc = gdk_gc_new(widget->window);
+#ifdef USE_CAIRO
+ gdk_gc_set_foreground(gc, &fe->background);
+#else
+ gdk_gc_set_foreground(gc, &fe->colours[fe->backgroundindex]);
+#endif
+ if (x < fe->ox) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x, y, fe->ox - x, h);
+ w -= (fe->ox - x);
+ x = fe->ox;
+ }
+ if (y < fe->oy) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x, y, w, fe->oy - y);
+ h -= (fe->oy - y);
+ y = fe->oy;
+ }
+ if (w > fe->pw) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x + fe->pw, y, w - fe->pw, h);
+ w = fe->pw;
+ }
+ if (h > fe->ph) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x, y + fe->ph, w, h - fe->ph);
+ h = fe->ph;
+ }
+ gdk_draw_pixmap(widget->window, gc, fe->pixmap,
x - fe->ox, y - fe->oy, x, y, w, h);
+ gdk_gc_unref(gc);
}
-#endif
-
/* ----------------------------------------------------------------------
* Pango font functions.
*/
View
@@ -35,7 +35,7 @@ struct frontend {
struct timeval last_time;
config_item *cfg;
int cfg_which, cfgret;
- int ox, oy;
+ int ox, oy, w, h;
};
static frontend *_fe;
@@ -61,6 +61,7 @@ void nestedvm_status_bar(void *handle, char *text)
void nestedvm_start_draw(void *handle)
{
frontend *fe = (frontend *)handle;
+ _call_java(5, 0, fe->w, fe->h);
_call_java(4, 1, fe->ox, fe->oy);
}
@@ -219,6 +220,8 @@ int jcallback_resize(int width, int height)
midend_size(fe->me, &x, &y, TRUE);
fe->ox = (width - x) / 2;
fe->oy = (height - y) / 2;
+ fe->w = x;
+ fe->h = y;
midend_force_redraw(fe->me);
return 0;
}
View
@@ -21,7 +21,7 @@
#define COORD(x) ( (x) * TILE_SIZE + BORDER )
#define FROMCOORD(x) ( ((x) - BORDER + TILE_SIZE) / TILE_SIZE - 1 )
-#define ANIM_PER_RADIUS_UNIT 0.13F
+#define ANIM_PER_BLKSIZE_UNIT 0.13F
#define FLASH_FRAME 0.13F
enum {
@@ -88,9 +88,9 @@ static int game_fetch_preset(int i, char **name, game_params **params)
{ "3x3 orientable", { 3, 3, 2, FALSE, TRUE } },
{ "4x4 normal", { 4, 4, 2, FALSE } },
{ "4x4 orientable", { 4, 4, 2, FALSE, TRUE } },
- { "4x4 radius 3", { 4, 4, 3, FALSE } },
- { "5x5 radius 3", { 5, 5, 3, FALSE } },
- { "6x6 radius 4", { 6, 6, 4, FALSE } },
+ { "4x4, rotating 3x3 blocks", { 4, 4, 3, FALSE } },
+ { "5x5, rotating 3x3 blocks", { 5, 5, 3, FALSE } },
+ { "6x6, rotating 4x4 blocks", { 6, 6, 4, FALSE } },
};
/* _("3x3 rows only"), _("3x3 normal"), _("3x3 orientable"), _("4x4 normal"), _("4x4 orientable"), _("4x4 radius 3"), _("5x5 radius 3"), _("6x6 radius 4") */
@@ -166,7 +166,7 @@ static config_item *game_configure(game_params *params)
ret[1].sval = dupstr(buf);
ret[1].ival = 0;
- ret[2].name = _("Rotation radius");
+ ret[2].name = _("Rotating block size");
ret[2].type = C_STRING;
sprintf(buf, "%d", params->n);
ret[2].sval = dupstr(buf);
@@ -213,7 +213,7 @@ static game_params *custom_params(config_item *cfg)
static char *validate_params(game_params *params, int full)
{
if (params->n < 2)
- return _("Rotation radius must be at least two");
+ return _("Rotating block size must be at least two");
if (params->w < params->n)
return _("Width must be at least the rotation radius");
if (params->h < params->n)
@@ -1061,7 +1061,7 @@ static int highlight_colour(float angle)
static float game_anim_length(game_state *oldstate, game_state *newstate,
int dir, game_ui *ui)
{
- return (float)(ANIM_PER_RADIUS_UNIT * sqrt(newstate->n-1));
+ return (float)(ANIM_PER_BLKSIZE_UNIT * sqrt(newstate->n-1));
}
static float game_flash_length(game_state *oldstate, game_state *newstate,
View
@@ -821,6 +821,9 @@ static void generate_board(int w, int h, int *rtx, int *rty, int *minmoves,
}
}
+ sfree(dsf);
+ sfree(list);
+ sfree(tried_merge);
sfree(board2);
*rtx = tx;

0 comments on commit 5d565f0

Please sign in to comment.