示例#1
0
  static gint cb_expose (GtkWidget * ww,
			 GdkEventExpose * ee,
			 gpointer data)
  {
    if (dbgos) {
      *dbgos << __func__ << "\n";
    }
      
    cairo = gdk_cairo_create (ee->window);
  
    cairo_set_source_rgb (cairo, 1.0, 1.0, 1.0);
    cairo_rectangle (cairo, 0, 0, canvas_width, canvas_height);
    cairo_fill (cairo);
      
    /*
      The round line cap style is required for drawing points. It
      may be better to have that switched to and from square
      depending on what we draw, but for now it is easier to just
      globally have round line caps everywhere.
    */
    cairo_set_line_cap (cairo, CAIRO_LINE_CAP_ROUND);
      
    draw_cb ();
  
    cairo_destroy (cairo);
    cairo = 0;
  
    return TRUE;
  }
示例#2
0
文件: st.c 项目: gattschardo/tetris
static void key_cb(SDL_Keycode k, int shift, struct game_state *gs)
{
	switch (k)
	{
	case SDLK_r: init_game_state(gs); break;
	case SDLK_q: if (shift) end_cb(gs); break;
	case SDLK_j:
	case SDLK_s: drop_block(gs); break;
	case SDLK_h:
	case SDLK_a: move_x(gs, -1); break;
	case SDLK_l:
	case SDLK_d: move_x(gs, 1); break;
	case SDLK_k:
	case SDLK_w: rot_block(gs); break;
	}

	draw_cb(gs);
}
示例#3
0
文件: iup_cells.c 项目: Vulcanior/IUP
/* Function used to call the client; is used when a cell must be repainted. */
static void iCellsCallDrawCb(Ihandle* ih, int xmin, int xmax, int ymin, int ymax, int i, int j)
{
  int oldxmin, oldxmax, oldymin, oldymax, oldclip;
  int w = ih->data->w;
  int h = ih->data->h;
  IFniiiiiiC draw_cb;
  cdCanvas* old_cnv = cdActiveCanvas();

  /* Getting clipping area for post restore */
  oldclip = cdCanvasClip(ih->data->cd_canvas, CD_QUERY);
  cdCanvasGetClipArea(ih->data->cd_canvas, &oldxmin, &oldxmax, &oldymin, &oldymax);

  if (ih->data->clipped)  /* Clipping the cell area */
  { 
    int cxmin, cxmax, cymin, cymax;
    cdCanvasClip(ih->data->cd_canvas, CD_CLIPAREA);
    cxmin = xmin < 0 ? 0 : xmin;
    cymin = ymin < 0 ? 0 : ymin;
    cxmax = xmax > w ? w : xmax;
    cymax = ymax > h ? h : ymax;
    cdCanvasClipArea(ih->data->cd_canvas, cxmin, cxmax, cymin, cymax);
  }

  draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB");
  if (draw_cb)
  {
    if (old_cnv != ih->data->cd_canvas) /* backward compatibility code */
      cdActivate(ih->data->cd_canvas);

    draw_cb(ih, i, j, xmin, xmax, ymin, ymax, ih->data->cd_canvas);

    if (old_cnv && old_cnv != ih->data->cd_canvas)
    {
      cdActivate(old_cnv);
      cdCanvasActivate(ih->data->cd_canvas);
    }
  }

  cdCanvasClip(ih->data->cd_canvas, oldclip);
  cdCanvasClipArea(ih->data->cd_canvas, oldxmin, oldxmax, oldymin, oldymax);
}
示例#4
0
文件: st.c 项目: gattschardo/tetris
int main(int argc, char **argv)
{
	struct game_state *gs = init_window(125000);
	SDL_Event ev;
	int mods;
	
	draw_cb(gs);
	while (1) {
		SDL_RenderPresent(gs->surface);
		SDL_WaitEvent(&ev);

		switch (ev.type) {
		case SDL_QUIT:
			end_cb(gs);
			break;
		case SDL_KEYDOWN:
			mods = SDL_GetModState();
			key_cb(ev.key.keysym.sym, mods & KMOD_SHIFT, gs);
			break;
		}
	}

	return 0;
}