コード例 #1
0
ファイル: radial-gradient.c プロジェクト: 499940913/moon
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    int i, j, k;
    cairo_extend_t extend[NUM_EXTEND] = {
	CAIRO_EXTEND_NONE,
	CAIRO_EXTEND_REPEAT,
	CAIRO_EXTEND_REFLECT,
	CAIRO_EXTEND_PAD
    };

    cairo_test_paint_checkered (cr);

    for (j = 0; j < NUM_EXTEND; j++) {
	for (i = 0; i < NUM_GRADIENTS; i++) {
	    double r1_offset = i % 2 ? SIZE / 12.0 : 0.0;
	    double r1_radius = i >= NUM_GRADIENTS / 2 ? SIZE / 6.0 : 0.0;
	    for (k = 0; k < NUM_GRADIENTS; k++) {
		double r2_offset = k % 2 ? SIZE / 12.0 : 0.0;
		double r2_radius = k >= NUM_GRADIENTS / 2 ? SIZE / 3.0 : SIZE / 12.;
		draw_gradient (cr,
			       i * SIZE * NUM_GRADIENTS + k * SIZE, j * SIZE, SIZE,
			       r1_offset, r1_radius,
			       r2_offset, r2_radius,
			       extend[j]);
	    }
	}
    }

    return CAIRO_TEST_SUCCESS;
}
コード例 #2
0
ファイル: SampleDitherBitmap.cpp プロジェクト: ghub/NVprSDK
    virtual void onDrawContent(SkCanvas* canvas) {
        canvas->translate(SkIntToScalar(20), SkIntToScalar(20));

        draw2(canvas, fBM8);
        canvas->translate(0, SkIntToScalar(fBM8.height() *3));
        draw2(canvas, fBM32);

        canvas->translate(0, SkIntToScalar(fBM8.height() *3));
        draw_gradient(canvas);
    }
コード例 #3
0
ファイル: cairo.c プロジェクト: volkanh/baresip
static void process(struct vidsrc_st *st)
{
	struct vidframe f;

	draw_gradient(st->cr, st->step, st->size.w, st->size.h);
	st->step += 0.02 / st->prm.fps;

	vidframe_init_buf(&f, VID_FMT_RGB32, &st->size,
			  cairo_image_surface_get_data(st->surface));

	st->frameh(&f, st->arg);
}
コード例 #4
0
ファイル: window.c プロジェクト: tommie/xppaut
Window make_unmapped_window(Window root, int x, int y, int width, int height,
                            int bw) {
  Window win = make_plain_unmapped_window(root, x, y, width, height, bw);

  if (UserGradients == 1) {
    Pixmap pmap = XCreatePixmap(display, root, width, height,
                                DefaultDepth(display, DefaultScreen(display)));

    draw_gradient(pmap, width, height);
    XSetWindowBackgroundPixmap(display, win, pmap);
    XFreePixmap(display, pmap);
  }

  return win;
}
コード例 #5
0
    virtual void onDrawContent(SkCanvas* canvas) {
        canvas->translate(SkIntToScalar(20), SkIntToScalar(20));

        draw2(canvas, fBM8);
        canvas->translate(0, SkIntToScalar(fBM8.height() *3));
        draw2(canvas, fBM32);

        canvas->translate(0, SkIntToScalar(fBM8.height() *3));
        draw_gradient(canvas);

        char resultTrue[] = "SkRegion::setPath returned true";
        char resultFalse[] = "SkRegion::setPath returned false";
        SkPaint p;
        if (fResult)
            canvas->drawText(resultTrue, sizeof(resultTrue) - 1, 0, 50, p);
        else
            canvas->drawText(resultFalse, sizeof(resultFalse) - 1, 0, 50, p);
    }
コード例 #6
0
ファイル: sdltest.c プロジェクト: joshdekock/jim-psp
int main(int argc, char *argv[])
{
	SDL_Joystick *joystick = NULL;
	SDL_Event event;
	SDL_TimerID t1, t2, t3;
	int done = 0;

	/* Initialize SDL. */
	if (SDL_Init(SDL_INIT_VIDEO |
		     SDL_INIT_JOYSTICK | 
		     SDL_INIT_TIMER) < 0) {
		fprintf(stderr, "init: '%s'\n", SDL_GetError());
		return 1;
	}

	if((color_mutex = SDL_CreateMutex()) == NULL) {
		fprintf(stderr, "mutex: '%s'\n", SDL_GetError());
		return 1;
	}

	/* Set video mode.  Any pixel format should work. */
	if((screen = SDL_SetVideoMode(W, H, 32, 0)) == NULL)
	{
		fprintf(stderr, "SetVideoMode: %s\n", SDL_GetError());
		return 1;
	}

	/* Draw background */
	draw_gradient();

	/* Wait 1 second */
	SDL_Delay(1000);

	/* Set up three callbacks to change color and signal drawing */
	t1 = SDL_AddTimer(200, color_square, (void*)1); 
	t2 = SDL_AddTimer(350, color_square, (void*)2);
	t3 = SDL_AddTimer(500, color_square, (void*)3);
	
	/* Open the joystick */
	if(SDL_NumJoysticks()) {
		joystick = SDL_JoystickOpen(0);
	} else {
		printf("No joystick detected\n");
	}

	/* Main event loop */
	done = 0;
	while (!done) {
		while (SDL_PollEvent(&event)) {
			switch (event.type) {
			case SDL_MOUSEBUTTONDOWN:
				if(event.button.button == SDL_BUTTON_LEFT)
					draw_gradient();
				else if(event.button.button == SDL_BUTTON_RIGHT)
					done = 1;
				break;
			case SDL_JOYBUTTONDOWN:
				if(event.jbutton.button == 0)
					draw_gradient();
				else if(event.jbutton.button == 1)
					done = 1;
				break;
			case SDL_KEYDOWN:
				if(event.key.keysym.sym == SDLK_SPACE)
					draw_gradient();
				else if(event.key.keysym.sym == SDLK_ESCAPE)
					done = 1;
				break;
			case SDL_QUIT:
				done = 1;
				break;
			default:
				break;
			}
		}
		SDL_mutexP(color_mutex);
		if(color_draw) {
			SDL_Rect rect;

			color_draw = 0;			

			rect.x = rand()%(W-50);
			rect.y = rand()%(H-50);
			rect.w = 50;
			rect.h = 50;

			SDL_FillRect(screen, &rect, color);
			SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h);
		}
		SDL_mutexV(color_mutex);
	}

	/* Cleanup */
	SDL_RemoveTimer(t1);
	SDL_RemoveTimer(t2);
	SDL_RemoveTimer(t3);

	if(joystick)
		SDL_JoystickClose(joystick);


	SDL_DestroyMutex(color_mutex);
	SDL_Quit();

	return(0);
}
コード例 #7
0
ファイル: MwAnimator.c プロジェクト: UlricE/Mowitz
Pixmap MwAnimatorPixmap(Widget w, int ani_now)
{
	MwAnimatorWidget aw = (MwAnimatorWidget)w;
	GC ani_gc = aw->animator.gc;
	Display *display = XtDisplay(w);
	Window ani_win = XtWindow(w);
	MwFmt fmt;
	XColor color;

	int x, y, x1, y1, x2, y2;
	unsigned int b1, d1;
	Window root;
	int width, height;
	unsigned int w1, h1;
	int visible;
	int angle1, angle2;
	MwAniObject *actor;
	ani_image *img, *bg_image;
	Pixmap scribble;
	unsigned int ani_width, ani_height, ani_depth;
	MwRichchar *p;
	char *bg_pixmap = aw->animator.bg_pixmap;

	if (!XtIsRealized(w)) return None;

	ani_width = aw->core.width;
	ani_height = aw->core.height;
	ani_depth = aw->core.depth;
	if (ani_width > 2000 || ani_height > 2000) return None;

	scribble = XCreatePixmap(display, ani_win,
		ani_width, ani_height, ani_depth);

	draw_gradient(w, scribble);

	/* tile the background */
	bg_image = name2image(w, bg_pixmap);

	if (bg_image) {
		int bg_x, bg_y;
		unsigned int bg_width, bg_height, bg_border, bg_depth;

		XSetClipMask(display, ani_gc, bg_image->mask);

		XGetGeometry(display, bg_image->pixmap, &root, &bg_x, &bg_y,
				&bg_width, &bg_height, &bg_border, &bg_depth);
		for (y = 0; y < ani_height; y += bg_height) {
			for (x = 0; x < ani_width; x += bg_width) {
				XSetClipOrigin(display, ani_gc, x, y);
				XCopyArea(display, bg_image->pixmap, scribble,
					ani_gc, 0, 0,
					bg_width, bg_height, x, y);
			}
		}
	}

	/* now loop over the objects, drawing each in the right place */
	for (actor = aw->animator.cast; actor; actor = actor->next) {
		/* find the tick before and after ani_now and
		   interpolate to find position and size.
		   the script always contains a tick for time=0 */
		MwAniScript *before, *after;

		before = actor->script;		/* this is never NULL */
		while (before->next) {
			if (before->next->time > ani_now) break;
			before = before->next;
		}
		after = before->next;
		visible = before->visible;
		if (!visible) continue;

		/* set color */
		MwDecodeFormat(actor->fmt, MW_FMT_FG, &fmt);
		/* fmt.fg is now the color name */
		MwAllocNamedColor(display, fmt.fg, &color);
		XSetForeground(display, ani_gc, color.pixel);

		XSetClipMask(display, ani_gc, None);

		if (!after) {	/* object remains at before */
			x = before->x;
			y = before->y;
			width = before->width;
			height = before->height;
		} else {	/* interpolate */
			x = INTERPOLATE(before->x, after->x,
				ani_now, before->time, after->time);
			y = INTERPOLATE(before->y, after->y,
				ani_now, before->time, after->time);
			width = INTERPOLATE(before->width, after->width,
				ani_now, before->time, after->time);
			height = INTERPOLATE(before->height, after->height,
				ani_now, before->time, after->time);
		}

		switch (actor->type) {
		case MW_ANI_NONE:
			break;
		case MW_ANI_LINE:
			x2 = x+width;
			y2 = y+height;
			XDrawLine(display, scribble,
				ani_gc, x, y, x2, y2);
			break;
		case MW_ANI_RECTANGLE:
			XDrawRectangle(display, scribble,
				ani_gc, x, y, width, height);
			break;
		case MW_ANI_ARC:
			angle1 = 64*90;		/* bogus!!! */
			angle2 = 64*180;
			XDrawArc(display, scribble,
				ani_gc, x, y, width, height,
				angle1, angle2);
			break;
		case MW_ANI_ELLIPSE:
			XDrawArc(display, scribble,
				ani_gc, x, y, width, height,
				0, 64*360);
			break;
		case MW_ANI_PIXMAP:
			img = name2image(w, actor->string);
			if (!img) break;

			XGetGeometry(display, img->pixmap, &root, &x1, &y1,
				&w1, &h1, &b1, &d1);
			XSetClipOrigin(display, ani_gc, x, y);
			XSetClipMask(display, ani_gc, img->mask);

			XCopyArea(display, img->pixmap,
				scribble, ani_gc,
				0, 0, w1, h1, x, y);
			break;
		case MW_ANI_STRING:
			/* set font */
			if (!actor->string) break;	/* sanity */
			p = MwRcMakerich(actor->string, actor->fmt);
			MwRcStrdraw(scribble, ani_gc, 0, 0, x, y, p, -1, 1.0);
			MwFree(p);
			break;
		case MW_ANI_POINT:
			XDrawPoint(display, scribble,
				ani_gc, x, y);
			break;
		case MW_ANI_FILLRECT:
			XFillRectangle(display, scribble,
				ani_gc, x, y, width, height);
			break;
		case MW_ANI_FILLARC:
			angle1 = 64*90;		/* bogus!!! */
			angle2 = 64*180;
			XFillArc(display, scribble,
				ani_gc, x, y, width, height,
				angle1, angle2);
			break;
		case MW_ANI_FILLELLIPSE:
			XFillArc(display, scribble,
				ani_gc, x, y, width, height,
				0, 64*360);
			break;
		default:
			fprintf(stderr, "bzz\n");
		}
	}

	return scribble;
}
コード例 #8
0
ファイル: window.c プロジェクト: tommie/xppaut
/*Convenience function for making buttons with icons on them*/
Window make_unmapped_icon_window(Window root, int x, int y, int width,
                                 int height, int bw, int icx, int icy,
                                 unsigned char *icdata) {
  Window win = make_plain_unmapped_window(root, x, y, width, height, bw);
  Pixmap pmap = XCreatePixmap(display, root, width, height,
                              DefaultDepth(display, DefaultScreen(display)));
  Colormap cmap = DefaultColormap(display, DefaultScreen(display));

  if (UserGradients == 1) {
    draw_gradient(pmap, width, height);
  } else {
    XColor bcolor;

    XParseColor(display, cmap, UserWhite, &bcolor);
    XAllocColor(display, cmap, &bcolor);
    XSetForeground(display, gc, bcolor.pixel);
    XDrawRectangle(display, pmap, gc, 0, 0, width, height);
  }

  int z = 0, row = 0, col = 0;

  if (icdata != NULL) {
    XColor diffcol;

    XParseColor(display, cmap, UserBlack, &diffcol);
    XAllocColor(display, cmap, &diffcol);
    XSetForeground(display, gc, diffcol.pixel);

    unsigned char *ps = icdata;

    int intstack[8];

    col = 0;
    row = -1;
    z = 0;
    while (row < height) {
      col = 0;
      row++;
      while (1) {
        bin_prnt_byte(*ps, intstack);
        ps++;

        int q = 0;
        for (q = 0; q < 8; q++) /*8 bits per byte*/
        {
          if (col >= width) {
            /*myint[z] = 0;*/
          } else {
            if (intstack[q] == 1) {
              XDrawPoint(display, pmap, gc, col, row);
            }
          }
          z++;
          col++;
        }

        if (col >= width) {

          break;
        }
      }
    }
  }

  XSetWindowBackgroundPixmap(display, win, pmap);
  XFreePixmap(display, pmap);

  return win;
}