static void run_starfish (struct state *st, struct starfish *s) { throb_starfish (s); spin_starfish (s); draw_starfish (st, st->window, st->gc, s, False); if (mono_p) { if (!st->initted) { #if 1 st->black = load_color(st->dpy, st->cmap, background); st->white = load_color(st->dpy, st->cmap, foreground); #else st->black = get_pixel_resource (st->dpy, st->cmap, "background", "Background"); st->white = get_pixel_resource (st->dpy, st->cmap, "foreground", "Foreground"); #endif st->initted = True; st->fg_index = st->white; XSetForeground (st->dpy, st->gc, st->fg_index); } else if (!s->blob_p) { st->fg_index = (st->fg_index == st->black ? st->white : st->black); XSetForeground (st->dpy, st->gc, st->fg_index); } } else { st->fg_index = (st->fg_index + 1) % st->ncolors; XSetForeground (st->dpy, st->gc, st->colors [st->fg_index].pixel); } }
static int load_land(scene_t *scene,FILE *file,char *path,int texture_mode) { char buffer[128]; land_config_t config; memset(&config,0,sizeof(land_config_t)); config.num_base = 1; config.num_detail = 1; config.texture_mode = texture_mode; fscanf(file,"%s",buffer); while(fscanf(file,"%s",buffer) != EOF) { if(buffer[0] == '#') skeep_comment(file); else if(!strcmp(buffer,"land")) load_name(file,path,config.heightmap); else if(!strcmp(buffer,"step")) config.step = load_float(file); else if(!strcmp(buffer,"altitude")) config.altitude = load_float(file); else if(!strcmp(buffer,"lod")) config.lod = load_float(file); else if(!strcmp(buffer,"ambient")) load_color(file,config.ambient); else if(!strcmp(buffer,"diffuse")) load_color(file,config.diffuse); else if(!strcmp(buffer,"specular")) load_color(file,config.specular); else if(!strcmp(buffer,"base")) load_name(file,path,config.base); else if(!strcmp(buffer,"num_base")) config.num_base = load_int(file); else if(!strcmp(buffer,"detail")) load_name(file,path,config.detail); else if(!strcmp(buffer,"num_detail")) config.num_detail = load_int(file); else if(!strcmp(buffer,"}")) { scene->land = land_create(&config); break; } else return 0; } if(!scene->land) return 0; return 1; }
static eraser_state * eraser_init (Display *dpy, Window window) { eraser_state *st = (eraser_state *) calloc (1, sizeof(*st)); XWindowAttributes xgwa; XGCValues gcv; unsigned long fg, bg; double duration; int which; char *s; st->dpy = dpy; st->window = window; XGetWindowAttributes (dpy, window, &xgwa); st->width = xgwa.width; st->height = xgwa.height; //bg = get_pixel_resource (dpy, xgwa.colormap, "background", "Background"); //fg = get_pixel_resource (dpy, xgwa.colormap, "foreground", "Foreground"); bg = load_color(dpy, xgwa.colormap, background); fg = load_color(dpy, xgwa.colormap, foreground); gcv.foreground = fg; gcv.background = bg; st->fg_gc = XCreateGC (dpy, window, GCForeground|GCBackground, &gcv); gcv.foreground = bg; gcv.background = fg; st->bg_gc = XCreateGC (dpy, window, GCForeground|GCBackground, &gcv); # ifdef HAVE_COCOA /* Pretty much all of these leave turds if AA is on. */ jwxyz_XSetAntiAliasing (st->dpy, st->fg_gc, False); jwxyz_XSetAntiAliasing (st->dpy, st->bg_gc, False); # endif //s = get_string_resource (dpy, "eraseMode", "Integer"); s = eraseMode; if (!s || !*s) which = -1; else //which = get_integer_resource(dpy, "eraseMode", "Integer"); which = atoi(eraseMode); if (which < 0 || which >= countof(erasers)) which = random() % countof(erasers); st->fn = erasers[which]; //duration = get_float_resource (dpy, "eraseSeconds", "Float"); duration = eraseSeconds; if (duration < 0.1 || duration > 10) duration = 1; st->start_time = double_time(); st->stop_time = st->start_time + duration; XSync (st->dpy, False); return st; }
static void setup_random_colormap (struct state *st, XWindowAttributes *xgwa) { XGCValues gcv; int lose = 0; int ncolors = st->count - 1; int n; XColor *colors = (XColor *) calloc (sizeof(*colors), st->count*2); //colors[0].pixel = get_pixel_resource (st->dpy, xgwa->colormap, // "background", "Background"); colors[0].pixel = load_color(st->dpy, xgwa->colormap, background); make_random_colormap (xgwa->screen, xgwa->visual, xgwa->colormap, colors+1, &ncolors, True, True, 0, True); if (ncolors < 1) { fprintf (stderr, "%s: couldn't allocate any colors\n", progname); exit (-1); } ncolors++; st->count = ncolors; memcpy (colors + st->count, colors, st->count * sizeof(*colors)); //colors[st->count].pixel = get_pixel_resource (st->dpy, xgwa->colormap, // "foreground", "Foreground"); colors[st->count].pixel = load_color(st->dpy, xgwa->colormap, foreground); for (n = 1; n < st->count; n++) { int m = n + st->count; colors[n].red = colors[m].red / 2; colors[n].green = colors[m].green / 2; colors[n].blue = colors[m].blue / 2; if (!XAllocColor (st->dpy, xgwa->colormap, &colors[n])) { lose++; colors[n] = colors[m]; } } if (lose) { fprintf (stderr, "%s: unable to allocate %d half-intensity colors.\n", progname, lose); } for (n = 0; n < st->count*2; n++) { gcv.foreground = colors[n].pixel; st->coloredGCs[n] = XCreateGC (st->dpy, st->window, GCForeground, &gcv); } free (colors); }
static void setup_original_colormap (struct state *st, XWindowAttributes *xgwa) { XGCValues gcv; int lose = 0; int n; XColor *colors = (XColor *) calloc (sizeof(*colors), st->count*2); //colors[0].pixel = get_pixel_resource (st->dpy, xgwa->colormap, // "background", "Background"); colors[0].pixel = load_color(st->dpy, xgwa->colormap, background); //colors[st->count].pixel = get_pixel_resource (st->dpy, xgwa->colormap, // "foreground", "Foreground"); colors[st->count].pixel = load_color(st->dpy, xgwa->colormap, foreground); for (n = 1; n < st->count; n++) { int m = n + st->count; colors[n].red = ((n & 0x01) != 0) * 0x8000; colors[n].green = ((n & 0x02) != 0) * 0x8000; colors[n].blue = ((n & 0x04) != 0) * 0x8000; if (!XAllocColor (st->dpy, xgwa->colormap, &colors[n])) { lose++; colors[n] = colors[0]; } colors[m].red = colors[n].red + 0x4000; colors[m].green = colors[n].green + 0x4000; colors[m].blue = colors[n].blue + 0x4000; if (!XAllocColor (st->dpy, xgwa->colormap, &colors[m])) { lose++; colors[m] = colors[st->count]; } } if (lose) { fprintf (stderr, "%s: unable to allocate %d colors.\n", progname, lose); } for (n = 0; n < st->count*2; n++) { gcv.foreground = colors[n].pixel; st->coloredGCs[n] = XCreateGC (st->dpy, st->window, GCForeground, &gcv); } free (colors); }
static int load_sky_sun(scene_t *scene,FILE *file,char *path,int texture_mode) { char buffer[128],pathname[256]; float length = 0; sky_sun_config_t config; memset(&config,0,sizeof(sky_sun_config_t)); config.texture_mode = texture_mode; fscanf(file,"%s",buffer); while(fscanf(file,"%s",buffer) != EOF) { if(buffer[0] == '#') skeep_comment(file); else if(!strcmp(buffer,"pos")) load_pos(file,config.pos); else if(!strcmp(buffer,"color")) load_color(file,config.color); else if(!strcmp(buffer,"num_flare")) config.num_flare = load_int(file); else if(!strcmp(buffer,"flare")) load_sky_sun_flare(&config,file,path); else if(!strcmp(buffer,"length")) length = load_float(file); else if(!strcmp(buffer,"path")) { load_name(file,path,pathname); if(length <= scene->end - scene->start) scene->pathsun = spline_close_load(pathname,length,0,0,0); else scene->pathsun = spline_load(pathname,length,0,0,0); if(!scene->pathsun) return 0; } else if(!strcmp(buffer,"}")) { scene->sun = sky_sun_load(&config); break; } else return 0; } if(!scene->sun) return 0; return 1; }
int main(int argc, char *argv[]) { if (argc < 2) { cout << "Enter the image path as argument." << endl; } auto image = load_color(argv[1]); display_and_block(image); return 0; }
static int load_camera(scene_t *scene,FILE *file,char *path) { char buffer[128],pathname[256]; float length = 0; camera_config_t config; memset(&config,0,sizeof(camera_config_t)); config.aspect = 4.0 / 3.0; fscanf(file,"%s",buffer); while(fscanf(file,"%s",buffer) != EOF) { if(buffer[0] == '#') skeep_comment(file); else if(!strcmp(buffer,"start")) scene->start = load_float(file); else if(!strcmp(buffer,"end")) scene->end = load_float(file); else if(!strcmp(buffer,"length")) length = load_float(file); else if(!strcmp(buffer,"pathpos")) { load_name(file,path,pathname); if(length <= scene->end - scene->start) scene->pathpos = spline_close_load(pathname,length,0,0,0); else scene->pathpos = spline_load(pathname,length,0,0,0); if(!scene->pathpos) return 0; } else if(!strcmp(buffer,"pathdir")) { load_name(file,path,pathname); if(length <= scene->end - scene->start) scene->pathdir = spline_close_load(pathname,length,0,0,0); else scene->pathdir = spline_load(pathname,length,0,0,0); if(!scene->pathdir) return 0; } else if(!strcmp(buffer,"fov")) config.fov = load_float(file); else if(!strcmp(buffer,"aspect")) config.aspect = load_float(file); else if(!strcmp(buffer,"clipnear")) config.clipnear = load_float(file); else if(!strcmp(buffer,"clipfar")) config.clipfar = load_float(file); else if(!strcmp(buffer,"fogcolor")) load_color(file,config.fogcolor); else if(!strcmp(buffer,"fogstart")) config.fogstart = load_float(file); else if(!strcmp(buffer,"fogend")) config.fogend = load_float(file); else if(!strcmp(buffer,"}")) { scene->camera = camera_create(&config); break; } else return 0; } if(!scene->camera) return 0; return 1; }
static void * whirlygig_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); st->dpy = dpy; st->window = window; st->ncolors = NCOLORS; //st->dbuf = get_boolean_resource (st->dpy, "doubleBuffer", "Boolean"); st->dbuf = doubleBuffer; # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ st->dbuf = False; # endif st->start_time = st->current_time; st->info = (struct info *)malloc(sizeof(struct info)); st->screen = DefaultScreen(st->dpy); XGetWindowAttributes (st->dpy, st->window, &st->xgwa); if (st->dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION //if (get_boolean_resource(st->dpy,"useDBE","Boolean")) if (True) { //st->dbeclear_p = get_boolean_resource (st->dpy, "useDBEClear", // "Boolean"); st->dbeclear_p = True; if (st->dbeclear_p) st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeBackground); else st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeUndefined); st->backb = st->b; } #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (!st->b) { st->ba = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height,st->xgwa.depth); st->b = st->ba; } } else { st->b = st->window; } //st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, "foreground", "Foreground"); st->gcv.foreground = load_color(st->dpy, st->xgwa.colormap, foreground); st->fgc = XCreateGC (st->dpy, st->b, GCForeground, &st->gcv); //st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, "background", "Background"); st->gcv.foreground = load_color(st->dpy, st->xgwa.colormap, background); st->bgc = XCreateGC (st->dpy, st->b, GCForeground, &st->gcv); #ifdef HAVE_COCOA /* #### should turn off double-buffering instead */ jwxyz_XSetAntiAliasing (dpy, st->fgc, False); jwxyz_XSetAntiAliasing (dpy, st->bgc, False); #endif { Bool writable_p = False; make_uniform_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, &writable_p, True); } if (st->ba) XFillRectangle (st->dpy, st->ba, st->bgc, 0, 0, st->xgwa.width, st->xgwa.height); /* info is a structure holding all the random pieces of information I may want to pass to my baby functions -- much of it I may never use, but it is nice to have around just in case I want it to make a funky function funkier */ /* info->writable = get_boolean_resource (dpy, "cycle", "Boolean"); */ #if 1 st->info->xspeed = xspeed; st->info->yspeed = yspeed; st->info->xamplitude = xamplitude; st->info->yamplitude = yamplitude; st->info->offset_period = offset_period; st->info->whirlies = whirlies; st->info->nlines = nlines; #else st->info->xspeed = get_float_resource(st->dpy, "xspeed" , "Float"); st->info->yspeed = get_float_resource(st->dpy, "yspeed" , "Float"); st->info->xamplitude = get_float_resource(st->dpy, "xamplitude", "Float"); st->info->yamplitude = get_float_resource(st->dpy, "yamplitude", "Float"); st->info->offset_period = get_float_resource(st->dpy, "offset_period", "Float"); st->info->whirlies = get_integer_resource(st->dpy, "whirlies", "Integer"); st->info->nlines = get_integer_resource(st->dpy, "nlines", "Integer"); #endif st->info->half_width = st->xgwa.width / 2; st->info->half_height = st->xgwa.height / 2; #if 1 st->info->speed = speed; st->info->trail = trail; st->info->color_modifier = color_modifier; st->info->xoffset = xoffset; st->info->yoffset = yoffset; st->xmode_str = xmode; st->ymode_str = ymode; st->wrap = wrap; #else st->info->speed = get_integer_resource(st->dpy, "speed" , "Integer"); st->info->trail = get_boolean_resource(st->dpy, "trail", "Integer"); st->info->color_modifier = get_integer_resource(st->dpy, "color_modifier", "Integer"); st->info->xoffset = get_float_resource(st->dpy, "xoffset", "Float"); st->info->yoffset = get_float_resource(st->dpy, "yoffset", "Float"); st->xmode_str = get_string_resource(st->dpy, "xmode", "Mode"); st->ymode_str = get_string_resource(st->dpy, "ymode", "Mode"); st->wrap = get_boolean_resource(st->dpy, "wrap", "Boolean"); #endif st->modifier = 3000.0 + frand(1500.0); if (! st->xmode_str) st->xmode = spin_mode; else if (! strcmp (st->xmode_str, "spin")) st->xmode = spin_mode; else if (! strcmp (st->xmode_str, "funky")) st->xmode = funky_mode; else if (! strcmp (st->xmode_str, "circle")) st->xmode = circle_mode; else if (! strcmp (st->xmode_str, "linear")) st->xmode = linear_mode; else if (! strcmp (st->xmode_str, "test")) st->xmode = test_mode; else if (! strcmp (st->xmode_str, "fun")) st->xmode = fun_mode; else if (! strcmp (st->xmode_str, "innie")) st->xmode = innie_mode; else if (! strcmp (st->xmode_str, "lissajous")) st->xmode = lissajous_mode; else { st->xmode = random() % (int) lissajous_mode; } if (! st->ymode_str) st->ymode = spin_mode; else if (! strcmp (st->ymode_str, "spin")) st->ymode = spin_mode; else if (! strcmp (st->ymode_str, "funky")) st->ymode = funky_mode; else if (! strcmp (st->ymode_str, "circle")) st->ymode = circle_mode; else if (! strcmp (st->ymode_str, "linear")) st->ymode = linear_mode; else if (! strcmp (st->ymode_str, "test")) st->ymode = test_mode; else if (! strcmp (st->ymode_str, "fun")) st->ymode = fun_mode; else if (! strcmp (st->ymode_str, "innie")) st->ymode = innie_mode; else if (! strcmp (st->ymode_str, "lissajous")) st->ymode = lissajous_mode; else { st->ymode = random() % (int) lissajous_mode; } #if 1 if (start_time == -1) st->current_time = (unsigned long int)(random()); else st->current_time = start_time; #else if (get_integer_resource(st->dpy, "start_time", "Integer") == -1) st->current_time = (unsigned long int)(random()); else st->current_time = get_integer_resource(st->dpy, "start_time", "Integer"); #endif if (st->info->whirlies == -1) st->info->whirlies = 1 + (random() % 15); if (st->info->nlines == -1) st->info->nlines = 1 + (random() % 5); if (st->info->color_modifier == -1) st->info->color_modifier = 1 + (random() % 25); //if (get_boolean_resource(st->dpy, "explain", "Integer")) if (explain) st->explaining = 1; st->current_color = 1 + (random() % NCOLORS); return st; }
static void initLMorph(struct state *st) { int steps; XGCValues gcv; XWindowAttributes wa; Colormap cmap; char *ft; int i; st->maxGamma = 1.0; #if 1 st->numPoints = points; steps = steps_; st->delay = delay; ft = figtype; #else st->numPoints = get_integer_resource(st->dpy, "points", "Integer"); steps = get_integer_resource(st->dpy, "steps", "Integer"); st->delay = get_integer_resource(st->dpy, "delay", "Integer"); ft = get_string_resource(st->dpy, "figtype", "String"); #endif if (strcmp(ft, "all") == 0) st->figType = FT_ALL; else if (strcmp(ft, "open") == 0) st->figType = FT_OPEN; else if (strcmp(ft, "closed") == 0) st->figType = FT_CLOSED; else { fprintf(stderr, "figtype should be `all', `open' or `closed'.\n"); st->figType = FT_ALL; } if (steps <= 0) steps = (random() % 400) + 100; st->deltaGamma = 1.0 / steps; XGetWindowAttributes(st->dpy, st->window, &wa); st->scrWidth = wa.width; st->scrHeight = wa.height; cmap = wa.colormap; //gcv.foreground = get_pixel_resource(st->dpy, cmap, "foreground", "Foreground"); gcv.foreground = load_color(st->dpy, cmap, foreground); st->gcDraw = XCreateGC(st->dpy, st->window, GCForeground, &gcv); XSetForeground(st->dpy, st->gcDraw, gcv.foreground); //gcv.foreground = get_pixel_resource(st->dpy, cmap, "background", "Background"); gcv.foreground = load_color(st->dpy, cmap, background); st->gcClear = XCreateGC(st->dpy, st->window, GCForeground, &gcv); XClearWindow(st->dpy, st->window); initPointArrays(st); st->aCurr = st->aWork[st->nWork = 0]; st->aPrev = NULL; st->currGamma = st->maxGamma + 1.0; /* force creation of new figure at startup */ st->nTo = RND(st->numFigs); do { st->nNext = RND(st->numFigs); } while (st->nNext == st->nTo); st->aSlopeTo = (XPoint *) xmalloc(st->numPoints * sizeof(XPoint)); st->aSlopeFrom = (XPoint *) xmalloc(st->numPoints * sizeof(XPoint)); st->aNext = (XPoint *) xmalloc(st->numPoints * sizeof(XPoint)); for (i = 0; i < st->numPoints ; i++) { st->aSlopeTo[i].x = 0.0; st->aSlopeTo[i].y = 0.0; } { /* jwz for version 2.11 */ /* int width = random() % 10;*/ //int width = get_integer_resource(st->dpy, "linewidth", "Integer"); int width = linewidth; int style = LineSolid; int cap = (width > 1 ? CapRound : CapButt); int join = (width > 1 ? JoinRound : JoinBevel); if (width == 1) width = 0; XSetLineAttributes(st->dpy, st->gcDraw, width, style, cap, join); XSetLineAttributes(st->dpy, st->gcClear, width, style, cap, join); } }
static void moire_init_1 (struct state *st) { int oncolors; int i; int fgh, bgh; double fgs, fgv, bgs, bgv; XWindowAttributes xgwa; XColor fgc, bgc; XGCValues gcv; XGetWindowAttributes (st->dpy, st->window, &xgwa); //st->delay = get_integer_resource (st->dpy, "delay", "Integer"); //st->offset = get_integer_resource (st->dpy, "offset", "Integer"); st->delay = delay; st->offset = offset; if (st->offset < 2) st->offset = 2; #ifdef HAVE_XSHM_EXTENSION st->use_shm = get_boolean_resource(st->dpy, "useSHM", "Boolean"); #endif /* HAVE_XSHM_EXTENSION */ MONO: if (st->colors) { for (i = 0; i < st->ncolors; i++) XFreeColors (st->dpy, xgwa.colormap, &st->colors[i].pixel, 1, 0); free(st->colors); st->colors = 0; } if (mono_p) { st->fg_pixel = WhitePixelOfScreen (DefaultScreenOfDisplay(st->dpy)); st->bg_pixel = BlackPixelOfScreen (DefaultScreenOfDisplay(st->dpy)); } else { #if 1 st->fg_pixel = load_color(st->dpy, xgwa.colormap, foreground); st->bg_pixel = load_color(st->dpy, xgwa.colormap, background); #else st->fg_pixel = get_pixel_resource (st->dpy, xgwa.colormap, "foreground", "Foreground"); st->bg_pixel = get_pixel_resource (st->dpy, xgwa.colormap, "background", "Background"); #endif } if (mono_p) { st->offset *= 20; /* compensate for lack of shading */ gcv.foreground = st->fg_pixel; } else { //st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer"); st->ncolors = ncolors; if (st->ncolors < 2) st->ncolors = 2; oncolors = st->ncolors; fgc.flags = bgc.flags = DoRed|DoGreen|DoBlue; //if (get_boolean_resource(st->dpy, "random","Boolean")) if (random_) { fgc.red = random() & 0xFFFF; fgc.green = random() & 0xFFFF; fgc.blue = random() & 0xFFFF; bgc.red = random() & 0xFFFF; bgc.green = random() & 0xFFFF; bgc.blue = random() & 0xFFFF; } else { fgc.pixel = st->fg_pixel; bgc.pixel = st->bg_pixel; XQueryColor (st->dpy, xgwa.colormap, &fgc); XQueryColor (st->dpy, xgwa.colormap, &bgc); } rgb_to_hsv (fgc.red, fgc.green, fgc.blue, &fgh, &fgs, &fgv); rgb_to_hsv (bgc.red, bgc.green, bgc.blue, &bgh, &bgs, &bgv); st->colors = (XColor *) malloc (sizeof (XColor) * (st->ncolors+2)); memset(st->colors, 0, (sizeof (XColor) * (st->ncolors+2))); make_color_ramp (xgwa.screen, xgwa.visual, xgwa.colormap, fgh, fgs, fgv, bgh, bgs, bgv, st->colors, &st->ncolors, True, True, False); if (st->ncolors != oncolors) fprintf(stderr, "%s: got %d of %d requested colors.\n", progname, st->ncolors, oncolors); if (st->ncolors <= 2) { mono_p = True; goto MONO; } gcv.foreground = st->colors[0].pixel; } st->gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv); }
static int setmode(GrxVideoMode *mp,int noclear) { int res; GrxVideoModeExt *ep = mp->extended_info; int fullscreen = mp->user_data & SDL_FULLSCREEN; #if defined (__WIN32__) SDL_SysWMinfo info; #endif SDL_PixelFormat *vfmt; GRX_ENTER(); res = FALSE; if(mp->mode != 0) { if(!detect()) { DBGPRINTF(DBG_DRIVER, ("SDL re-detect() failed\n")); goto done; } _SGrScreen = SDL_SetVideoMode(mp->width, mp->height, mp->bpp, mp->user_data); if(_SGrScreen == NULL) { DBGPRINTF(DBG_DRIVER, ("SDL_SetVideoMode() failed\n")); goto done; } if((_SGrScreen->flags & SDL_FULLSCREEN) != fullscreen) { DBGPRINTF(DBG_DRIVER, ("SDL_FULLSCREEN mismatch\n")); goto done; } SDL_ShowCursor(SDL_DISABLE); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_SetEventFilter(filter); if(SDL_MUSTLOCK(_SGrScreen)) { if(!fullscreen) { DBGPRINTF(DBG_DRIVER, ("hardware windows not supported\n")); goto done; } if(SDL_LockSurface(_SGrScreen)) { DBGPRINTF(DBG_DRIVER, ("SDL_LockSurface() failed\n")); goto done; } #if defined(__WIN32__) SDL_VERSION(&info.version); if(!SDL_GetWMInfo(&info)) { DBGPRINTF(DBG_DRIVER, ("SDL_GetWMInfo() failed\n")); goto done; } window = info.window; wndproc = (WNDPROC)GetWindowLong(window, GWL_WNDPROC); SetWindowLong(window, GWL_WNDPROC, (LONG) WndProc); _SGrActive = TRUE; #endif } mp->line_offset = _SGrScreen->pitch; ep->frame = _SGrScreen->pixels; if(mp->bpp >= 15 && fullscreen) { vfmt = _SGrScreen->format; ep->cprec[0] = 8 - vfmt->Rloss; ep->cprec[1] = 8 - vfmt->Gloss; ep->cprec[2] = 8 - vfmt->Bloss; ep->cpos[0] = vfmt->Rshift; ep->cpos[1] = vfmt->Gshift; ep->cpos[2] = vfmt->Bshift; if(mp->bpp == 32 && vfmt->Rshift == 24) ep->mode = GRX_FRAME_MODE_LFB_32BPP_HIGH; } if(!noclear) { if(mp->bpp == 8) load_color(0, 0, 0, 0); SDL_FillRect(_SGrScreen, NULL, 0); SDL_UpdateRect(_SGrScreen, 0, 0, 0, 0); } res = TRUE; } done: if (res != TRUE) { reset(); res = mp->mode == 0; } GRX_RETURN(res); }
BOOL InitPixelFormat(SCREENSAVER *ss) { ModeInfo *mi; int i; ss->modeinfo.gc = XCreateGC(ss->hdc, 0, 0, NULL); assert(ss->modeinfo.gc != NULL); if (hack_ncolors <= 0) hack_ncolors = 64; else if (hack_ncolors > MAX_COLORCELLS) hack_ncolors = MAX_COLORCELLS; mi = &ss->modeinfo; mi->install_p = fChildPreview; mi->writable_p = True; mi->black_pixel = 0; mi->white_pixel = 255; mi->npixels = hack_ncolors; mi->colors = NULL; mi->pixels = NULL; mi->threed = False; mi->threed_delta = 1.5; mi->threed_right_color = load_color(NULL, 0, "red"); mi->threed_left_color = load_color(NULL, 0, "blue"); mi->threed_both_color = load_color(NULL, 0, "magenta"); mi->threed_none_color = load_color(NULL, 0, "black"); if (hack_ncolors_enabled) { mi->colors = (XColor *) calloc(mi->npixels, sizeof(*mi->colors)); if (mi->colors == NULL) return FALSE; switch (hack_color_scheme) { case color_scheme_uniform: make_uniform_colormap(mi->xgwa.screen, mi->xgwa.visual, mi->xgwa.colormap, mi->colors, &mi->npixels, True, &mi->writable_p, True); break; case color_scheme_smooth: make_smooth_colormap(mi->xgwa.screen, mi->xgwa.visual, mi->xgwa.colormap, mi->colors, &mi->npixels, True, &mi->writable_p, True); break; case color_scheme_bright: case color_scheme_default: make_random_colormap(mi->xgwa.screen, mi->xgwa.visual, mi->xgwa.colormap, mi->colors, &mi->npixels, (hack_color_scheme == color_scheme_bright), True, &mi->writable_p, True); break; default: fprintf(stderr, "Bad color scheme\n"); abort(); } mi->pixels = (unsigned long *)calloc(mi->npixels, sizeof(*mi->pixels)); if (mi->pixels == NULL) { free(mi->colors); return FALSE; } for (i = 0; i < mi->npixels; i++) mi->pixels[i] = mi->colors[i].pixel; } return TRUE; }
static void * truchet_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); st->dpy = dpy; st->window = window; #if 1 st->maxlinewidth = maxLineWidth; st->minlinewidth = minLineWidth; st->minwidth = minWidth; st->minheight = minHeight; st->max_width = max_Width; st->max_height = max_Height; st->delay = delay; st->eraseCount = eraseCount; st->square = square; st->curves = curves; st->angles = angles; st->erase = erase; st->scroll = scroll; st->overlap = scroll_overlap; st->anim_delay = anim_delay; st->anim_step_size = anim_step_size; #else st->maxlinewidth = maxLineWidth", "Integer"); st->minlinewidth = get_integer_resource (st->dpy, "minLineWidth", "Integer"); st->minwidth = get_integer_resource (st->dpy, "minWidth", "Integer"); st->minheight = get_integer_resource (st->dpy, "minHeight", "Integer"); st->max_width = get_integer_resource (st->dpy, "max-Width", "Integer"); st->max_height = get_integer_resource (st->dpy, "max-Height", "Integer" ); st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->eraseCount = get_integer_resource (st->dpy, "eraseCount", "Integer"); st->square = get_boolean_resource (st->dpy, "square", "Boolean"); st->curves = get_boolean_resource (st->dpy, "curves", "Boolean"); st->angles = get_boolean_resource (st->dpy, "angles", "Boolean"); st->erase = get_boolean_resource (st->dpy, "erase", "Boolean"); st->scroll = get_boolean_resource (st->dpy, "scroll", "Boolean"); st->overlap = get_integer_resource (st->dpy, "scroll-overlap", "Integer"); st->anim_delay = get_integer_resource (st->dpy, "anim-delay", "Integer"); st->anim_step_size = get_integer_resource (st->dpy, "anim-step-size", "Integer"); #endif //if (get_boolean_resource(st->dpy, "randomize", "Randomize")) if (randomize) { int i = (random() % 12); switch(i) { case 0: break; case 1: st->curves = False; break; case 2: st->curves = False; st->square = True; st->erase = False; break; case 3: st->square = True; st->erase = False; st->eraseCount = 5; break; case 4: st->scroll = True; break; case 5: st->scroll = True; st->erase = False; st->anim_step_size = 9; break; case 6: st->angles = False; st->minwidth = st->max_width = 36; break; case 7: st->curves = False; st->minwidth = st->max_width = 12; break; case 8: st->curves = False; st->erase = False; st->minwidth = st->max_width = 36; break; case 9: st->erase = False; st->minwidth = 256; st->max_width = 512; st->minlinewidth = 96; break; case 10: st->angles = False; st->minwidth = 64; st->max_width = 128; st->maxlinewidth = 4; break; case 11: st->curves = False; st->minwidth = 64; st->max_width = 128; st->maxlinewidth = 4; break; default: abort(); break; } } XGetWindowAttributes (st->dpy, st->window, &st->xgwa); st->gcv.foreground = BlackPixel(st->dpy,0); st->gcv.background = WhitePixel(st->dpy,0); st->gcv.line_width = 25; st->cmap = st->xgwa.colormap; //st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, // "background", "Background"); st->gcv.foreground = load_color(st->dpy, st->xgwa.colormap, background); st->bgc = XCreateGC (st->dpy, st->window, GCForeground, &st->gcv); st->agc = XCreateGC(st->dpy, st->window, GCForeground, &st->gcv); XFillRectangle(st->dpy, st->window, st->bgc, 0, 0, st->xgwa.width, st->xgwa.height); st->width=60; st->height=60; st->linewidth=1; st->count=0; XSetForeground(st->dpy, st->agc, st->gcv.background); st->frame = XCreatePixmap(st->dpy,st->window, st->xgwa.width+st->overlap, st->xgwa.height+st->overlap, st->xgwa.depth); XFillRectangle(st->dpy, st->frame, st->bgc, 0, 0, st->xgwa.width + st->overlap, st->xgwa.height + st->overlap); return st; }
static void * deco_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; //st->delay = get_integer_resource (dpy, "delay", "Integer"); st->delay = delay; //st->smoothColors = get_boolean_resource(dpy, "smoothColors", "Boolean"); st->smoothColors = smoothColors; st->old_line_width = 1; //st->goldenRatio = get_boolean_resource (dpy, "goldenRatio", "Boolean"); st->goldenRatio = goldenRatio; //st->max_depth = get_integer_resource (dpy, "maxDepth", "Integer"); st->max_depth = maxDepth; if (st->max_depth < 1) st->max_depth = 1; else if (st->max_depth > 1000) st->max_depth = 1000; //st->min_width = get_integer_resource (dpy, "minWidth", "Integer"); st->min_width = minWidth; if (st->min_width < 2) st->min_width = 2; //st->min_height = get_integer_resource (dpy, "minHeight", "Integer"); st->min_height = minHeight; if (st->min_height < 2) st->min_height = 2; //st->line_width = get_integer_resource (dpy, "lineWidth", "Integer"); st->line_width = lineWidth; XGetWindowAttributes (dpy, window, &st->xgwa); //st->ncolors = get_integer_resource (dpy, "ncolors", "Integer"); st->ncolors = ncolors; //gcv.foreground = get_pixel_resource(dpy, st->xgwa.colormap, // "foreground", "Foreground"); gcv.foreground = load_color(dpy, st->xgwa.colormap, foreground); st->fgc = XCreateGC (dpy, window, GCForeground, &gcv); //gcv.foreground = get_pixel_resource(dpy, st->xgwa.colormap, // "background", "Background"); gcv.foreground = load_color(dpy, st->xgwa.colormap, background); st->bgc = XCreateGC (dpy, window, GCForeground, &gcv); if (st->ncolors <= 2) mono_p = True; if (!mono_p) { GC tmp = st->fgc; st->fgc = st->bgc; st->bgc = tmp; } //st->mondrian = get_boolean_resource(dpy, "mondrian", "Boolean"); st->mondrian = mondrian; if (st->mondrian) { /* Mondrian, if true, overrides several other options. */ mondrian_set_sizes(st, st->xgwa.width, st->xgwa.height); /** set up red-yellow-blue-black-white colormap and fgc **/ make_mondrian_colormap(st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, 0, True); /** put white in several cells **/ /** set min-height and min-width to about 10% of total w/h **/ } else if (st->smoothColors) make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, 0, True); else make_random_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, False, True, 0, True); gcv.line_width = st->old_line_width = st->line_width; XChangeGC(dpy, st->fgc, GCLineWidth, &gcv); return st; }
static void setup_dialog_load_config (SetupDialog *dialog) { GVariant *values; GdkColor defcol; GtkCellRenderer *renderer; values = ibus_config_get_values (dialog->config, dialog->section); /* ibus_config_get_values may return NULL on failure */ if (values == NULL) { GVariantType *child_type = g_variant_type_new ("{sv}"); values = g_variant_new_array (child_type, NULL, 0); g_variant_type_free (child_type); } /* General -> Pre-edit Appearance */ /* foreground color of pre-edit buffer */ _gdk_color_from_uint (PREEDIT_FOREGROUND, &defcol); load_color (values, GTK_TOGGLE_BUTTON (dialog->checkbutton_foreground), GTK_COLOR_BUTTON (dialog->colorbutton_foreground), "preedit_foreground", &defcol); g_signal_connect (dialog->checkbutton_foreground, "toggled", G_CALLBACK (on_foreground_toggled), dialog); /* background color of pre-edit buffer */ _gdk_color_from_uint (PREEDIT_BACKGROUND, &defcol); load_color (values, GTK_TOGGLE_BUTTON (dialog->checkbutton_background), GTK_COLOR_BUTTON (dialog->colorbutton_background), "preedit_background", &defcol); g_signal_connect (dialog->checkbutton_background, "toggled", G_CALLBACK (on_background_toggled), dialog); /* underline of pre-edit buffer */ load_choice (values, GTK_COMBO_BOX (dialog->combobox_underline), "preedit_underline", IBUS_ATTR_UNDERLINE_NONE); /* General -> Other */ /* lookup table orientation */ load_choice (values, GTK_COMBO_BOX (dialog->combobox_orientation), "lookup_table_orientation", IBUS_ORIENTATION_SYSTEM); /* Advanced -> m17n-lib configuration */ dialog->store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); insert_m17n_items (dialog->store, dialog->lang, dialog->name); gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview), GTK_TREE_MODEL (dialog->store)); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (dialog->treeview), -1, "Key", renderer, "text", COLUMN_KEY, NULL); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (dialog->treeview), -1, "Value", renderer, "text", COLUMN_VALUE, NULL); g_object_set (renderer, "editable", TRUE, NULL); g_signal_connect (renderer, "edited", G_CALLBACK (on_edited), dialog); g_signal_connect (dialog->treeview, "query-tooltip", G_CALLBACK (on_query_tooltip), NULL); g_variant_unref (values); }
/* Update the background colour. */ void update_background_color (gchar* rgba) { set_background_color (rgba); load_color (); }
static void * deluxe_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; int i; st->dpy = dpy; st->window = window; #if 1 st->count = count; st->delay = delay; st->ncolors = ncolors; st->dbuf = doubleBuffer; #else st->count = get_integer_resource (st->dpy, "count", "Integer"); st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer"); st->dbuf = get_boolean_resource (st->dpy, "doubleBuffer", "Boolean"); #endif # ifdef HAVE_DOUBLE_BUFFER_EXTENSION //st->dbeclear_p = get_boolean_resource (st->dpy, "useDBEClear", "Boolean"); st->dbeclear_p = True; #endif # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ st->dbuf = False; # endif XGetWindowAttributes (st->dpy, st->window, &st->xgwa); //st->transparent_p = get_boolean_resource(st->dpy, "transparent", "Transparent"); st->transparent_p = transparent; st->colors = (XColor *) calloc (sizeof(*st->colors), st->ncolors); //if (get_boolean_resource(st->dpy, "mono", "Boolean")) if (False) { MONO: st->ncolors = 1; //st->colors[0].pixel = get_pixel_resource(st->dpy, st->xgwa.colormap, // "foreground", "Foreground"); st->colors[0].pixel = load_color(st->dpy, st->xgwa.colormap, foreground); } #ifndef HAVE_COCOA else if (st->transparent_p) { //st->nplanes = get_integer_resource (st->dpy, "planes", "Planes"); st->nplanes = 1; if (st->nplanes <= 0) st->nplanes = (random() % (st->xgwa.depth-2)) + 2; allocate_alpha_colors (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, &st->nplanes, True, &st->plane_masks, &st->base_pixel); if (st->nplanes <= 1) { # if 0 fprintf (stderr, "%s: couldn't allocate any color planes; turning transparency off.\n", progname); # endif st->transparent_p = False; goto COLOR; } } #endif /* !HAVE_COCOA */ else { #ifndef HAVE_COCOA COLOR: #endif make_random_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, True, 0, True); if (st->ncolors < 2) goto MONO; } if (st->dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (st->dbeclear_p) st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeBackground); else st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeUndefined); st->backb = st->b; #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (!st->b) { st->ba = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height,st->xgwa.depth); st->bb = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height,st->xgwa.depth); st->b = st->ba; } } else { st->b = st->window; } st->throbbers = (struct throbber **) calloc (st->count, sizeof(struct throbber *)); for (i = 0; i < st->count; i++) st->throbbers[i] = make_throbber (st, st->b, st->xgwa.width, st->xgwa.height, st->colors[random() % st->ncolors].pixel); //gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap, // "background", "Background"); gcv.foreground = load_color(st->dpy, st->xgwa.colormap, background); st->erase_gc = XCreateGC (st->dpy, st->b, GCForeground, &gcv); if (st->ba) XFillRectangle (st->dpy, st->ba, st->erase_gc, 0, 0, st->xgwa.width, st->xgwa.height); if (st->bb) XFillRectangle (st->dpy, st->bb, st->erase_gc, 0, 0, st->xgwa.width, st->xgwa.height); return st; }