예제 #1
0
/**
 * @function GUI_AddGenericObject
 * @brief Allocate & initialize a new generic object
 * @param none
 * @return g_obj_st*: pointer to the object if success, NULL otherwise
 */
g_obj_st /*@null@*/ *GUI_AddGenericObject(void) {

  g_obj_st *obj = NULL;

  /*try to allocate memory for the new object*/
  obj = salloc(sizeof(g_obj_st));
  if(obj != NULL) {

    /*set default content for the new object*/
    gmemset(obj, 0, sizeof(g_obj_st));
    GUI_ObjSetNeedRefresh(obj, true);
    obj->group = group;

    /*insert object in the linked list (base or top layer)*/
    if(bTopLayerActive == false) {
      if(headBase == NULL) headBase = obj;
      else if(lastAddedObj != NULL) lastAddedObj->next = obj;
      else { /*cannot happen*/ }
    }
    else {
      if(headTop == NULL) headTop = obj;
      else if(lastAddedObj != NULL) lastAddedObj->next = obj;
      else { /*cannot happen*/ }
    }

    lastAddedObj = obj;
  }

  return obj;
}
예제 #2
0
/**
 * @function GUI_W_ListAddFieldToLastItem
 * @brief add a field to the last added item, after the last added field
 * @param g_obj_st *obj: pointer to list
 * @param const void *str: content of the field
 * @return int8_t: 0 success, -1 error
 */
int8_t GUI_W_ListAddFieldToLastItem(g_obj_st /*@null@*/ *obj, const void *str) {

  int8_t res = -1;
  uint8_t field_cnt;
  list_st *list = NULL;
  field_st *field = NULL, **seek = NULL;

  /*retrieve the list corresponding to the generic object*/
  list = GetList(obj);
  if(list != NULL && list->pLastItem != NULL) {

    /*retrieve the pointer to the current field and its position*/
    seek = &(list->pLastItem->pHn);
    field_cnt = 0;
    while(*seek != NULL) {
      seek = &((*seek)->pHn);
      field_cnt++;
    }

    /*check if the current item has less fields than the number of categories*/
    if(field_cnt < list->categoryCount) {

      /*allocate memory for the item's field*/
      field = (field_st *) salloc(sizeof(field_st));
      if(field != NULL) {

        /*init. the field*/
        gmemset( (void *)field, 0, sizeof(field_st));
        field->pItem = list->pLastItem;
        field->str = AllocateAndCopyStr(str);
        if(str == NULL || field->str != NULL) {

          /*insert in the horizontal list (i.e. linked to the item)*/
          *seek = field;

          /*insert in the vertical list (i.e. linked to the category)*/
          InsertInCategory(list, field_cnt, field);

          /*if all fields are defined, bLastItemDefined becomes true*/
          field_cnt++;
          if(field_cnt == list->categoryCount) list->bLastItemDefined = true;

          res = 0;
        }
      }
    }
  }

  return res;
}
예제 #3
0
/**
 * @function GUI_W_ListAddCategoryToList
 * @brief add a new category into a list
 * @param g_obj_st *obj: pointer to list
 * @param length_t w: width (in pixel)
 * @param const void *name: name of the category
 * @return int8_t: 0 success, -1 error
 */
int8_t GUI_W_ListAddCategoryToList(g_obj_st /*@null@*/ *obj, length_t w, const void *name) {

  int8_t res = -1;
  list_st *list = NULL;
  category_st *category = NULL, **seek = NULL;

  /*retrieve the list corresponding to the generic object*/
  list = GetList(obj);
  if(list != NULL) {

    /*a new category can be added only if the list does not contains any item*/
    if(list->vScroll.totSize == 0 && list->categoryCount < 255) {

      /*allocate memory for the new field header*/
      category = (category_st *) salloc(sizeof(category_st));
      if(category != NULL) {

        /*init. the category*/
        gmemset( (void *)category, 0, sizeof(category_st));
        category->w = w;
        category->name = AllocateAndCopyStr(name);

        if(name == NULL || category->name != NULL) {

          /*insert the category into its list*/
          seek = &(list->pCategory);
          while(*seek != NULL) seek = &((*seek)->next);
          *seek = category;

          /*update the category counter & the selected category (user for sort)*/
          list->categoryCount++;
          if(list->pSelectedCategory == NULL) list->pSelectedCategory = category;

          /*update the horizontal scroll size*/
          list->hScroll.totSize += w;

          res = 0;
        }
      }
    }
  }
  return res;
}
예제 #4
0
/**
 * @function GUI_W_ListAddItemToList
 * @brief add a new item into a list
 * @param g_obj_st *obj: pointer to list
 * @param gui_img_t sprite: sprite of the item
 * @param uint16_t *uid: if non null, the uid of the new item will be written into it
 * @return int8_t: 0 success, -1 error
 */
int8_t GUI_W_ListAddItemToList(g_obj_st /*@null@*/ *obj, gui_img_t sprite, uint16_t /*@null@*/ *uid) {

  int8_t res = -1;
  item_st *item = NULL;
  list_st *list = NULL;
  length_t wSprite;

  /*retrieve the list corresponding to the generic object*/
  list = GetList(obj);

  /*add item if: no item OR last item fully defined*/
  if(list != NULL && (list->pLastItem == NULL || list->bLastItemDefined == true)) {

    /*allocate memory for the new item*/
    item = (item_st *) salloc(sizeof(item_st));
    if(item != NULL) {

      /*init. the item & export uid*/
      gmemset( (void *) item, 0, sizeof(item_st));
      item->uid = list->vScroll.totSize;
      item->sprite = sprite;
      if(uid != NULL) *uid = item->uid;

      /*update the V scroll size*/
      list->vScroll.totSize++;

      /*just added, so item's fields are not yet defined*/
      list->bLastItemDefined = false;

      /*update the maximal sprite width*/
      wSprite = SpriteGetWidth(sprite);
      if(list->wSpriteMax < wSprite) list->wSpriteMax = wSprite;

      res = 0;
    }

    /*save the address of the last added item*/
    list->pLastItem = item;
  }

  return res;
}
예제 #5
0
파일: intro.c 프로젝트: Joexv/OakTutorial
void fadeInProfBg(u8 index) {
	if (check_a_pressed(0)) return;
	
	audio_play(0x124);

	/*
	 * Tilemap dimensions
	 */
	u8 *tilemap;
	u16 i, j, k;
	u32 size;
	void *data;
	BUP config = { 0 };

	/*
	 * Allocated enough space for a full screen tilemap
	 */
	tilemap = (u8*) malloc_and_clear(SCREEN_SIZE);
	gmemset(tilemap, 0xFF, SCREEN_SIZE);

	/*
	 * Generate the tilemap on the fly
	 */
	for (k = PROF_MAP_BASE, i = PROF_Y; i < PROF_Y + PROF_HEIGHT; ++i) {
		for (j = PROF_X; j < PROF_X + PROF_WIDTH; ++j)
			tilemap[i * SCREEN_WIDTH + j] = k++;
	}

	/*
	 * Unpack the professor graphics
	 */
	data = malloc_and_LZ77UnComp((void *) profTiles, &size);
	config.SrcNum = size;

	/*
	 * Upscale 4bpp to 8bpp
	 */
	config.SrcBitNum = 4;
	config.DestBitNum = 8;

	/*
	 * Select palette 4
	 */
	config.DestOffset = 64;

	/*
	 * Copy professor graphics to the map base of BG2
	 */
	bitUnPack(data, (void *) 0x06000600, &config);
	gpu_pal_apply((void *) profPal, 0x40, 0x40);
	free(data);

	bgid_set_tilemap(2, tilemap);
	bgid_send_tilemap(2);

	/*
	 * Slow unfade
	 */
	fadescreen(0xFFFFFFFF, 0x10, 0x10, 0x0, 0x0000);
	gpu_sync_bg_show(1);
	gpu_sync_bg_show(2);
	textbox_close();

	tasks[index].args[6] = 0xA0;
	tasks[index].function = (u32) profIntroduce;
}
예제 #6
0
/**
 * @function GUI_W_ListCreate
 * @brief add list container
 * @param const rect_st *rec: list dimension
 * @param bool bHeader: if true, categories will be displayed (*rec will be shared between list & its header)
 * @param scroll_param_st **pvScroll: if non null, will recieve the addr of the internal vertical scroll struct
 * @param scroll_param_st **phScroll: if non null, will recieve the addr of the internal horizontal scroll struct
 * @return g_obj_st *: pointer to the associated generic object if succedeed, NULL if error.
 */
g_obj_st /*@null@*/ *GUI_W_ListCreate(const rect_st *rec, bool bHeader, scroll_param_st /*@null@*/ **pvScroll, scroll_param_st /*@null@*/ **phScroll) {

  g_obj_st *g_obj = NULL, *g_obj_header = NULL, *res = NULL;
  list_st *list = NULL;
  list_header_st *header = NULL;
  length_t hItem = P2D_GetTextHeight();
  rect_st lrec;

  /*create the generic object for the list's header; configure it later*/
  if(bHeader) {
    g_obj_header = GUI_AddGenericObject();
    if(g_obj_header != NULL) {
      header = (list_header_st *) salloc(sizeof(list_header_st));
    }
  }

  /*check parameters*/
  if(rec != NULL && rec->w >= LIST_W_MIN && hItem > 0 && rec->h >= hItem * LIST_H_MIN && (header != NULL || bHeader == false)) {

    /*allocate a generic object*/
    g_obj = GUI_AddGenericObject();
    if(g_obj != NULL) {

      /*allocate and init the list*/
      list = (list_st *) salloc(sizeof(list_st));
      if(list != NULL) {

        /* *rec may be shared between list & its header*/
        lrec = *rec;
        if(bHeader) {
          lrec.y += hItem + 2;
          lrec.h -= hItem + 2;
        }

        /*ensures that all internal links are NULL & var = 0*/
        gmemset( (void *) list, 0, sizeof(list_st));

        /*init. the list*/
        list->font = GetCurrentFont();
        list->hItem = hItem;
        list->colBackOdd = GetColor(G_COL_E_BACKGROUND);
        list->colBackEven = P2D_Alpha_a_on_b(GetColor(G_COL_SPECIAL), list->colBackOdd, 32);
        list->vScroll.wndSize = lrec.h / hItem;
        list->hScroll.wndSize = lrec.w;
        list->g_obj_header = g_obj_header;

        /*return scroller addresses*/
        if(pvScroll != NULL) *pvScroll = &(list->vScroll);
        if(phScroll != NULL) *phScroll = &(list->hScroll);

        /*linkage between generic obj & list*/
        g_obj->rec = lrec;
        g_obj->draw = ListDraw;
        g_obj->task = ListRefresh;
        g_obj->obj = list;
        GUI_ObjSetStatic(g_obj, true);  /*list_st handle refresh event itself*/

        /*header linkage, if any*/
        if(header != NULL) {
          lrec.y = rec->y;
          lrec.h = hItem + 2;
          header->xt = -1;
          header->g_obj_list = g_obj;
          g_obj_header->rec = lrec;
          g_obj_header->draw = HeaderDraw;
          g_obj_header->task = HeaderRefresh;
          g_obj_header->obj = header;
          GUI_ObjSetStatic(g_obj, true);  /*header handles refresh event itself*/
        }

        res = g_obj;
      }
    }
  }

  return res;
}