Beispiel #1
0
static void cb_in_received_handler(DictionaryIterator *iter, void *context) {
  // Get the bitmap
  Tuple *image_tuple = dict_find(iter, KEY_IMAGE);
  Tuple *index_tuple = dict_find(iter, KEY_INDEX);
  if (index_tuple && image_tuple) {
    int32_t index = index_tuple->value->int32;

    APP_LOG(APP_LOG_LEVEL_DEBUG, "image received index=%ld size=%d", index, image_tuple->length);
    memcpy(data_image + index,&image_tuple->value->uint8,image_tuple->length);

    if(image_tuple->length < CHUNK_SIZE){
      if(image){
        gbitmap_destroy(image);
        image = NULL;
      }
      image = gbitmap_create_with_data(data_image);
      bitmap_layer_set_bitmap(image_layer, image);
      text_layer_set_text(text_layer, "");
      layer_mark_dirty(bitmap_layer_get_layer(image_layer));
    }
  }

  Tuple *message_tuple = dict_find(iter, KEY_MESSAGE);
  if(message_tuple){
    text_layer_set_text(text_layer, message_tuple->value->cstring);
  }
}
Beispiel #2
0
GBitmap* gbitmap_create_with_resource (uint32_t resource_id) {
    printf ("[DEBUG] Load resource ID:%d as image\n",resource_id);
    char name[MAX_RESOURCE_NAME];
    copyResName(name,resource_id);
    FILE* f=fopen(name,"rb");
    if (!f) {
        printf("[ERROR] Couldn't load \"%s\"(%s)!\n",name,SDL_GetError());
        return 0;
    }
    fseek(f,0,SEEK_END);
    size_t len=ftell(f);
    fseek(f,0,SEEK_SET);
    void* data=malloc(len);
    if (!data) {
        printf("[ERROR] Couldn't load \"%s\"(Memory allocation failed)!\n",name);
        return 0;
    }
    size_t readLen=fread(data,1,len,f);
    fclose(f);
    if (len!=readLen) {
        printf ("[ERROR] Read error!\n");
        free(data);
        return 0;
    }
    return gbitmap_create_with_data (data);
}
static void cb_draw_row(GContext *g_ctx, const Layer *l_cell, MenuIndex *i_cell, void *ctx) {
  ActionMenu *menu = ctx;
  GRect bounds = layer_get_bounds(l_cell);

  if(menu_layer_get_selected_index(menu->menulayer).row == i_cell->row) {
    graphics_context_set_fill_color(g_ctx, GColorWhite);
    graphics_fill_rect(g_ctx, bounds, 0, GCornerNone);
  }

  bounds.origin.x += 4;
  bounds.size.w -= 2*4;

  graphics_context_set_fill_color(g_ctx, GColorBlack);
  graphics_fill_rect(g_ctx, bounds, 4, GCornersAll);

  bounds.size.w -= 2*4;
  bounds.origin.x += 4;

  bounds.origin.y += 4;
  bounds.size.h -= 2*4;

  graphics_draw_text(g_ctx,
    menu->current_level->items[i_cell->row]->label,
    fonts_get_system_font(ACTION_MENU_FONT),
    bounds,
    GTextOverflowModeWordWrap,
    GTextAlignmentLeft,
    0);

  if(menu->current_level->items[i_cell->row]->child && menu_layer_get_selected_index(menu->menulayer).row == i_cell->row) {
    if(menu->arrow_image == NULL){
      menu->arrow_image = gbitmap_create_with_data(ARROW_IMAGE_DATA);
    }
    graphics_draw_bitmap_in_rect(g_ctx, menu->arrow_image, (GRect){.origin={116, bounds.origin.y + (bounds.size.h - 4) / 2},.size={7,5}});
Beispiel #4
0
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  image = gbitmap_create_with_data(data_image);

  image_layer = bitmap_layer_create(bounds);
  bitmap_layer_set_bitmap(image_layer, image);
  bitmap_layer_set_alignment(image_layer, GAlignCenter);
  layer_add_child(window_layer, bitmap_layer_get_layer(image_layer));

  text_layer = text_layer_create(GRect(0, bounds.size.h - 16, bounds.size.w, 16));
  text_layer_set_text(text_layer, "Welcome to PayFace $)");
  text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
  text_layer_set_background_color(text_layer, GColorClear);
  layer_add_child(window_layer, text_layer_get_layer(text_layer));
}
Beispiel #5
0
void load_background_image(int affiliation) {
    int logo_resource_id = c_affiliation_logos[affiliation];
    ASSERT(logo_resource_id != 0);
    
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Loading logo resource %i for affiliation %i", logo_resource_id, affiliation);
    
    ResHandle logo_resource_handle = resource_get_handle(logo_resource_id);
    ASSERT(resource_size(logo_resource_handle) == sizeof(g_background_blob));
    if (resource_load(logo_resource_handle, g_background_blob, sizeof(g_background_blob)) != sizeof(g_background_blob)) {
        APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to load background logo resource %u", (unsigned) logo_resource_id);
    } else if (logoBitmap == NULL) {
        const uint8_t* data = prezr_load_image_data(g_background_blob);
        logoBitmap = gbitmap_create_with_data(data);
        if (logoBitmap == NULL) {
            APP_LOG(APP_LOG_LEVEL_ERROR, "Loaded background logo resource %u but gbitmap create failed", (unsigned) logo_resource_id);
        }
    }
}
static void prv_image_received_handler(DictionaryIterator *iter, void *context) {
  // Get the bitmap
 
  Tuple *size_tuple  = dict_find(iter, MESSAGE_KEY_size);
  if(size_tuple){
    if(data_image)
      free(data_image);
    data_size = size_tuple->value->uint32;
    data_image = malloc(data_size);
  }

  Tuple *image_tuple = dict_find(iter, MESSAGE_KEY_chunk);
  Tuple *index_tuple = dict_find(iter, MESSAGE_KEY_index);
  if (index_tuple && image_tuple) {
    int32_t index = index_tuple->value->int32;

    APP_LOG(APP_LOG_LEVEL_DEBUG, "image received index=%ld size=%d", index, image_tuple->length);
    memcpy(data_image + index,&image_tuple->value->uint8,image_tuple->length);

    if(image_tuple->length < CHUNK_SIZE){
      if(image){
        gbitmap_destroy(image);
        image = NULL;
      }
#ifdef PBL_COLOR
      image = gbitmap_create_from_png_data(data_image, data_size);
#else
      image = gbitmap_create_with_data(data_image);
#endif
      bitmap_layer_set_bitmap(image_layer, image);
      text_layer_set_text(text_layer, "");
      layer_mark_dirty(bitmap_layer_get_layer(image_layer));
    }
  }

  Tuple *message_tuple = dict_find(iter, MESSAGE_KEY_message);
  if(message_tuple){
    text_layer_set_text(text_layer, message_tuple->value->cstring);
  }
}
Beispiel #7
0
static void cb_in_received_handler(DictionaryIterator *iter, void *context) {

	APP_LOG(APP_LOG_LEVEL_DEBUG, "Incoming data");

	// Reset
	ErrorExists = 0;
    text_layer_set_text(error_text_layer, "");

	// Set any messages
    Tuple *message_tuple = dict_find(iter, KEY_MESSAGE);
    if(message_tuple){
        strcpy(msg_str, message_tuple->value->cstring);
        text_layer_set_text(message_text_layer, msg_str);
        layer_mark_dirty(text_layer_get_layer(message_text_layer));
    }

    // Get the bitmap
    Tuple *size_tuple  = dict_find(iter, KEY_SIZE);
    if(size_tuple){
        if(data_image)
            free(data_image);
            data_size = size_tuple->value->uint32;
            data_image = malloc(data_size);
    }

	// Set the image
    Tuple *image_tuple = dict_find(iter, KEY_IMAGE);
    Tuple *index_tuple = dict_find(iter, KEY_INDEX);
    if (index_tuple && image_tuple) {
        int32_t index = index_tuple->value->int32;
        //APP_LOG(APP_LOG_LEVEL_DEBUG, "image received index=%ld size=%d", index, image_tuple->length);
        memcpy(data_image + index,&image_tuple->value->uint8,image_tuple->length);
        if(image_tuple->length < CHUNK_SIZE){

			// Clear the image
			if(image){
				gbitmap_destroy(image);
				image = NULL;
			}

            #ifdef PBL_COLOR
            	image = gbitmap_create_from_png_data(data_image, data_size);
            #else
            	image = gbitmap_create_with_data(data_image);
            #endif

            bitmap_layer_set_bitmap(image_layer, image);
            layer_mark_dirty(bitmap_layer_get_layer(image_layer));
			text_layer_set_text(message_text_layer,"");
            layer_mark_dirty(text_layer_get_layer(message_text_layer));

            vibes_short_pulse();
            light_enable_interaction();

            ImgLoaded = 1;
            Loading = 0;

            text_layer_set_text(username_text_layer, usr_str);
    		text_layer_set_background_color(username_text_layer, GColorWhite);
    		if(ErrorExists == 1){
    			text_layer_set_background_color(username_text_layer, GColorClear);
    		}
            layer_mark_dirty(text_layer_get_layer(username_text_layer));
        }
    }

	// Set any errors
    Tuple *error_tuple = dict_find(iter, KEY_ERROR);
    if(error_tuple){
        text_layer_set_text(message_text_layer,"");
        layer_mark_dirty(text_layer_get_layer(message_text_layer));

		// Clear the image
		if(image){
    		gbitmap_destroy(image);
            if(data_image){
                free(data_image);
            }
			image = NULL;
    		bitmap_layer_set_bitmap(image_layer, image);
		}

        Loading = 0;
		ErrorExists = 1;
		#ifdef PBL_COLOR
			image = gbitmap_create_with_resource(RESOURCE_ID_ERROR_B);
            text_layer_set_text_color(error_text_layer, GColorBlack);
		#else
			image = gbitmap_create_with_resource(RESOURCE_ID_ERROR_A);
		#endif
		bitmap_layer_set_bitmap(image_layer, image);
        layer_mark_dirty(bitmap_layer_get_layer(image_layer));
        text_layer_set_text(error_text_layer, error_tuple->value->cstring);
        layer_mark_dirty(text_layer_get_layer(error_text_layer));
        vibes_short_pulse();
        light_enable_interaction();
    }

	// Prepare the username
    Tuple *username_tuple = dict_find(iter, KEY_USERNAME);
    if(username_tuple){
        strcpy(usr_str, username_tuple->value->cstring);
		prepend(usr_str, " ");
        //text_layer_set_text(username_text_layer, usr_str);
    }

	// Set the likes
	Tuple *likes_tuple = dict_find(iter, KEY_LIKES);
    if(likes_tuple){
        strcpy(likes_str, likes_tuple->value->cstring);
		update_likes(likes_str);
    }

	// Set the comments
	Tuple *comments_tuple = dict_find(iter, KEY_COMMENTS);
    if(comments_tuple){
        strcpy(comments_str, comments_tuple->value->cstring);
		update_comments(comments_str);
    }

	// Set the caption
	Tuple *caption_tuple = dict_find(iter, KEY_CAPTION);
    if(caption_tuple){
        strcpy(capt_str, caption_tuple->value->cstring);
		update_caption(capt_str);
    }

}
Beispiel #8
0
void netimage_receive(DictionaryIterator *iter)
{
	NetImageContext *ctx = get_netimage_context();

	Tuple *tuple = dict_read_first(iter);
	if (!tuple)
	{
		DEBUG_MSG("Got a message with no first key! Size of message: %li", (uint32_t)iter->end - (uint32_t)iter->dictionary);
		return;
	}

	switch (tuple->key)
	{
		case NETIMAGE_DATA:
			if (ctx->index + tuple->length <= ctx->length)
			{
				memcpy(ctx->data + ctx->index, tuple->value->data, tuple->length);
				ctx->index += tuple->length;
			}
			else
			{
				DEBUG_MSG("Not overriding rx buffer. Bufsize=%li BufIndex=%li DataLen=%i",
						ctx->length, ctx->index, tuple->length);
			}
			break;
		case NETIMAGE_BEGIN:
			DEBUG_MSG("Start transmission. Size=%lu", tuple->value->uint32);
			if (ctx->data != NULL)
			{
				nt_Free(ctx->data);
			}
			if(tuple->value->uint32 == 0)
			{
				ctx->data = NULL;
				break;
			}
			ctx->data = nt_Malloc(tuple->value->uint32);
			if (ctx->data != NULL)
			{
				ctx->length = tuple->value->uint32;
				ctx->index = 0;
			}
			else
			{
				DEBUG_MSG("Unable to allocate memory to receive image.");
				ctx->length = 0;
				ctx->index = 0;
			}
			break;
		case NETIMAGE_END:
			if (ctx->data && ctx->length > 0 && ctx->index > 0)
			{
				GBitmap *bitmap = gbitmap_create_with_data(ctx->data);
				nt_Free(ctx->data);
				if (bitmap)
				{
					ctx->callback(bitmap);
				}
				else
				{
					ctx->callback(NULL);
					DEBUG_MSG("Unable to create GBitmap. Is this a valid PBI?");
				}
				ctx->data = NULL;
				ctx->index = ctx->length = 0;
			}
			else
			{
				ctx->callback(NULL);
				DEBUG_MSG("Got End message but we have no image...");
			}
			break;
		default:
			DEBUG_MSG("Unknown key in dict: %lu", tuple->key);
			break;
	}
}