예제 #1
0
void create_planet()
{
  Uint32 x, y;
  Uint32 i;
  char *image = NULL;

  /* Get random coordinates. */
  x = ( rand() % screen_width() );
  y = -( rand() % 1000) + 100;

  /* Get random image name. */
  i = ( rand() % PLANET_IMAGE_NUM ) + 1; 
  switch( i ) {
  case 1: image = get_data( MOON_1_IMAGE, DATA_IMAGES ); break;
  default: image = NULL;
  }

  /* Make the planet sprite. */
  planet = new_sprite( x, y, 1, image, 0 );
  set_speed( planet, PLANET_SPEED ); 
  if( planet == NULL ) {
    fprintf( stderr, "Error creating new sprite: %s.\n",
              SDL_GetError() );
    exit(-1);
  }
}
예제 #2
0
파일: stage.cpp 프로젝트: aonorin/KGLT
SpriteID Stage::new_sprite_from_file(const unicode& filename, uint32_t frame_width, uint32_t frame_height, uint32_t margin, uint32_t spacing, std::pair<uint32_t, uint32_t> padding) {
    SpriteID s = new_sprite();
    TextureID t = new_texture_from_file(
        filename,
        kglt::TEXTURE_OPTION_CLAMP_TO_EDGE | kglt::TEXTURE_OPTION_DISABLE_MIPMAPS | kglt::TEXTURE_OPTION_NEAREST_FILTER
    );
    try {
        sprite(s)->set_spritesheet(t, frame_width, frame_height, margin, spacing, padding);
    } catch(...) {
        delete_sprite(s);
        throw;
    }

    return s;
}
예제 #3
0
파일: sprite.c 프로젝트: johnh530/electro
void recv_create_sprite(void)
{
    int i = new_sprite();
    int j = recv_index();

    struct sprite *s = get_sprite(i);

    s->brush = j;
    s->count = 1;
    s->s0 = 0.0f;
    s->t0 = 0.0f;
    s->s1 = 1.0f;
    s->t1 = 1.0f;

    recv_create_entity();
}
예제 #4
0
파일: sprite.c 프로젝트: johnh530/electro
int send_create_sprite(int j)
{
    int i;

    if ((i = new_sprite()) >= 0)
    {
        struct sprite *s = get_sprite(i);

        s->brush = j;
        s->count = 1;
        s->s0 = 0.0f;
        s->t0 = 0.0f;
        s->s1 = 1.0f;
        s->t1 = 1.0f;

        send_event(EVENT_CREATE_SPRITE);
        send_index(s->brush);

        return send_create_entity(TYPE_SPRITE, i);
    }
    return -1;
}
예제 #5
0
파일: panelbar.c 프로젝트: UIKit0/picogui
void panelbar_trigger_sprite(struct widget *self,s32 type,union trigparam *param) {
  bool force = 0;
  struct widget *boundwidget;
  int s;

  switch (type) {

  case PG_TRIGGER_ENTER:
    DATA->over = 1;
    break;

  case PG_TRIGGER_LEAVE:
    /* If we're dragging, the mouse didn't REALLY leave */
    if (DATA->on) return;
    DATA->over=0;
    break;

  case PG_TRIGGER_DOWN:
    if (param->mouse.chbtn != 1) return;

    /* If we're bound to another widget (we should be) save its current size */
    if (!iserror(rdhandle((void**)&boundwidget,PG_TYPE_WIDGET,self->owner,
			  DATA->bindto)) && boundwidget) {
      DATA->oldsize = widget_get(boundwidget,PG_WP_SIZE);

      /* If we're not rolled up, save this as the unrolled split */
      if (DATA->oldsize > DATA->minimum)
	DATA->unrolled = DATA->oldsize;
    }

    DATA->on = 1;
    DATA->x = param->mouse.x;
    DATA->y = param->mouse.y;
    DATA->draglen = 0;
     
    /* Update the screen now, so we have an up-to-date picture
       of the panelbar stored in DATA->s */
    themeify_panelbar(self,1);

    VID(sprite_hideall) ();   /* This line combined with the zero flag on */
    update(NULL,0);             /*  the next gets a clean spriteless grab */

    /* In case there was no release trigger (bug in input driver) */
    if (DATA->s) {
       free_sprite(DATA->s);
       DATA->s = NULL;
    }
    if (DATA->sbit) {
       VID(bitmap_free) (DATA->sbit);
       DATA->sbit = NULL;
    }
     
    /* Allocate the new sprite */
    if(iserror(new_sprite(&DATA->s,self->dt,DATA->panelbar->r.w,DATA->panelbar->r.h))) {
       DATA->s = NULL;
       return;
    }
    if (iserror(VID(bitmap_new) (&DATA->sbit,DATA->panelbar->r.w,DATA->panelbar->r.h,vid->bpp))) {
       free_sprite(DATA->s);
       DATA->s = NULL;
       DATA->sbit = NULL;
       return;
    }
    DATA->s->bitmap = &DATA->sbit;
    
    /* Grab a bitmap of the panelbar to use as the sprite */
    VID(blit) (DATA->sbit,0,0,DATA->panelbar->r.w,DATA->panelbar->r.h,
	       self->dt->display,DATA->s->x = DATA->panelbar->r.x,DATA->s->y = DATA->panelbar->r.y,
	       PG_LGOP_NONE);

    /* Clip the sprite to the travel allowed by boundwidget's parent */
    if (!iserror(rdhandle((void**)&boundwidget,PG_TYPE_WIDGET,self->owner,
			  DATA->bindto)) && boundwidget) {
      DATA->s->clip_to = boundwidget->in;
    }

    return;

  case PG_TRIGGER_UP:
  case PG_TRIGGER_RELEASE:
    if (!DATA->on) return;
    if (!(param->mouse.chbtn & 1)) return;

    if (!iserror(rdhandle((void**)&boundwidget,PG_TYPE_WIDGET,self->owner,
			  DATA->bindto)) && boundwidget) {

      s = panel_calcsplit(self,param->mouse.x,param->mouse.y,
			  widget_get(boundwidget,PG_WP_SIDE));
      
      if (DATA->draglen < MINDRAGLEN) {
	/* This was a click, not a drag */
	DATA->over = 0;
	
	widget_set(boundwidget,PG_WP_SIZEMODE,PG_SZMODE_PIXEL);
	if (DATA->oldsize > DATA->minimum)
	  /* Roll up the panel */
	  widget_set(boundwidget,PG_WP_SIZE,DATA->minimum);
	else
	  /* Unroll the panel */
	  widget_set(boundwidget,PG_WP_SIZE,DATA->unrolled);
      }
      else {
	s += panel_effective_split(boundwidget->in);

	/* Save this as the new unrolled split,
	 * Unless the user manually rolled up the panel */
	if ((s-DATA->minimum) > MAXROLLUP) 
	  DATA->unrolled = s;
	else
	  s = DATA->minimum;
	
	widget_set(boundwidget,PG_WP_SIZEMODE,PG_SZMODE_PIXEL);
	widget_set(boundwidget,PG_WP_SIZE,s);

	DATA->over = 1;
      }
    }

    VID(bitmap_free) (DATA->sbit);
    free_sprite(DATA->s);
    DATA->s = NULL;
    DATA->sbit = NULL;
    force = 1;           /* Definitely draw the new position */
     
    DATA->on = 0;
    break;

  case PG_TRIGGER_MOVE:
  case PG_TRIGGER_DRAG:
    if (!DATA->on) return;
     /* Ok, button 1 is dragging through our widget... */
     
    if (panel_throttle(self))
      return;
     
     /* Race condition prevention?
      * Without this, sometimes segfaults because DATA->s is NULL.
      * Possibly events_pending() triggered another event? */
     if (!DATA->s) return;
      
     /* Determine where to blit the bar to... */
     switch (self->in->flags & (~SIDEMASK)) {
     case PG_S_TOP:
     case PG_S_BOTTOM:
       DATA->s->x = DATA->panelbar->r.x;
       DATA->draglen += abs(param->mouse.y - DATA->y + DATA->panelbar->r.y - DATA->s->y);
       DATA->s->y = param->mouse.y - DATA->y + DATA->panelbar->r.y;
       break;
     case PG_S_LEFT:
     case PG_S_RIGHT:
       DATA->s->y = DATA->panelbar->r.y;
       DATA->draglen += abs(param->mouse.x - DATA->x + DATA->panelbar->r.x - DATA->s->x);
       DATA->s->x = param->mouse.x - DATA->x + DATA->panelbar->r.x;
       break;
     }

    /* Reposition sprite */
    VID(sprite_update) (DATA->s);
    return;
  }

  themeify_panelbar(self,force);
}
예제 #6
0
/*
 *	Because Jaguar games are in ROM, 
 *  there are no directories or what so ever.
*/
void Load_Image(unsigned short a, phrase directory, int w, int h)
{
	// Black is the transparent colour
	sprites_img[a] = new_sprite( w , h , -640 , -480 , DEPTH16 , &directory); /* Set X and Y outside so we can't see it */
	attach_sprite_to_display_at_layer(sprites_img[a] , d , a );
}
예제 #7
0
ENTRYPOINT void
draw_slideshow (ModeInfo *mi)
{
  slideshow_state *ss = &sss[MI_SCREEN(mi)];
  int i;

  if (!ss->glx_context)
    return;

  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(ss->glx_context));

  if (ss->awaiting_first_image_p)
    {
      image *img = ss->images[0];
      if (!img) abort();
      if (!img->loaded_p)
        return;

      ss->awaiting_first_image_p = False;
      ss->dawn_of_time = double_time();

      /* start the very first sprite fading in */
      new_sprite (mi);
    }

  ss->now = double_time();

  /* Each sprite has three states: fading in, full, fading out.
     The in/out states overlap like this:

     iiiiiiFFFFFFFFFFFFoooooo  . . . . . . . . . . . . . . . . . 
     . . . . . . . . . iiiiiiFFFFFFFFFFFFoooooo  . . . . . . . .
     . . . . . . . . . . . . . . . . . . iiiiiiFFFFFFFFFFFFooooo

     So as soon as a sprite goes into the "out" state, we create
     a new sprite (in the "in" state.)
   */

  if (ss->nsprites > 2) abort();

  /* If a sprite is just entering the fade-out state,
     then add a new sprite in the fade-in state.
   */
  for (i = 0; i < ss->nsprites; i++)
    {
      sprite *sp = ss->sprites[i];
      if (sp->state != sp->prev_state &&
          sp->state == (fade_seconds == 0 ? DEAD : OUT))
        new_sprite (mi);
    }

  tick_sprites (mi);

  /* Now garbage collect the dead sprites.
   */
  for (i = 0; i < ss->nsprites; i++)
    {
      sprite *sp = ss->sprites[i];
      if (sp->state == DEAD)
        {
          destroy_sprite (mi, sp);
          i--;
        }
    }

  /* We can only ever end up with no sprites at all if the machine is
     being really slow and we hopped states directly from FULL to DEAD
     without passing OUT... */
  if (ss->nsprites == 0)
    new_sprite (mi);

  if (!ss->redisplay_needed_p)
    return;

  if (debug_p && ss->now - ss->prev_frame_time > 1)
    fprintf (stderr, "%s: static screen for %.1f secs\n",
             blurb(), ss->now - ss->prev_frame_time);

  draw_sprites (mi);

  if (mi->fps_p) do_fps (mi);

  glFinish();
  glXSwapBuffers (MI_DISPLAY (mi), MI_WINDOW(mi));
  ss->prev_frame_time = ss->now;
  ss->redisplay_needed_p = False;
  check_fps (mi);
}
예제 #8
0
파일: cursor.c 프로젝트: UIKit0/picogui
g_error cursor_set_theme(struct cursor *crsr, int thobj) {
  hwrbitmap *bitmap,*mask;
  s16 w,h;
  bool redisplay;
  g_error e;

  crsr->thobj = thobj;
  
  /* Read the cursor bitmap and bitmask. Note that if the cursor is rectangular
   * or it uses an alpha channel the mask will be NULL.
   */

  e = rdhandlep((void***)&bitmap,PG_TYPE_BITMAP,-1,theme_lookup(thobj,PGTH_P_CURSORBITMAP));
  errorcheck;

  mask = NULL;
  e = rdhandlep((void***)&mask,PG_TYPE_BITMAP,-1,theme_lookup(thobj,PGTH_P_CURSORBITMASK));
  errorcheck;

  if (crsr->sprite && bitmap==crsr->sprite->bitmap && mask==crsr->sprite->mask)
    return success;

  /* If there's no bitmap yet, it's early in init and the default cursor
   * hasn't been created yet. Skip this all.
   */
  if (!bitmap)
    return success;

  VID(bitmap_getsize) (*bitmap,&w,&h);
  
  /* Insert the new bitmaps, resize/create the sprite if necessary */

  redisplay = crsr->sprite && crsr->sprite->onscreen;
  if (redisplay)
    VID(sprite_hide) (crsr->sprite);

  /* Update the hotspot before cursor_move */
  crsr->hotspot_x = theme_lookup(thobj,PGTH_P_CRSRHOTSPOT_X);
  crsr->hotspot_y = theme_lookup(thobj,PGTH_P_CRSRHOTSPOT_Y);

  if (!crsr->sprite) {
    int x,y;
    struct divtree *dt;

    /* Get the default position */
    cursor_getposition(crsr,&x,&y,&dt);

    /* Create a new sprite (default hidden, as per description in input.h) */
    e = new_sprite(&crsr->sprite,dt,w,h);
    errorcheck;
    crsr->sprite->visible = 0;
    
    /* Set the bitmap up, and move it */
    crsr->sprite->bitmap = bitmap;
    crsr->sprite->mask = mask;
    cursor_move(crsr, x,y, dt);
  }
  else {

    /* Since we're not creating a new sprite, we might need to move the hotspot
     */
    crsr->sprite->x = crsr->x - crsr->hotspot_x;
    crsr->sprite->y = crsr->y - crsr->hotspot_y;

    if ( (w!=crsr->sprite->w) || (h!=crsr->sprite->h) ) {
      /* Resize an existing sprite 
       */
      VID(bitmap_free) (crsr->sprite->backbuffer);
      e = VID(bitmap_new) (&crsr->sprite->backbuffer,w,h,vid->bpp);
      errorcheck;
      crsr->sprite->w = w;
      crsr->sprite->h = h;
    }

    crsr->sprite->bitmap = bitmap;
    crsr->sprite->mask = mask;
  }    

  /* If the cursor has an alpha channel, set the LGOP accordingly */
  if (w && h && (VID(getpixel)(*bitmap,0,0) & PGCF_ALPHA))
    crsr->sprite->lgop = PG_LGOP_ALPHA;
  else
    crsr->sprite->lgop = PG_LGOP_NONE;
  
  if (redisplay)
    VID(sprite_show)(crsr->sprite);
  
  /* Whether it was onscreen or not, show it at the next convenient opportunity */
  crsr->sprite->visible = 1;

  return success;
}