예제 #1
0
파일: window.c 프로젝트: sub77-bkp/libaroma
/*
 * Function    : libaroma_window_measure
 * Return Value: byte
 * Descriptions: measure control size
 */
byte libaroma_window_measure(LIBAROMA_WINDOWP win, LIBAROMA_CONTROLP ctl){
  if (win&&ctl){
    if (_libaroma_window_measurement_dp){
      ctl->x = libaroma_dp(ctl->rx);
      ctl->y = libaroma_dp(ctl->ry);
      ctl->w = libaroma_dp(ctl->rw);
      ctl->h = libaroma_dp(ctl->rh);
    }
    else{
      ctl->x = ctl->rx;
      ctl->y = ctl->ry;
      ctl->w = ctl->rw;
      ctl->h = ctl->rh;
    }
    
    ctl->x=libaroma_window_measure_calculate(
      ctl->x, ctl->rx, win->w, 0, 0
    );
    ctl->y=libaroma_window_measure_calculate(
      ctl->y, ctl->ry, win->h, 0, 0
    );
    ctl->w=libaroma_window_measure_calculate(
      ctl->w,ctl->rw, win->w, 1, ctl->x
    );
    ctl->h=libaroma_window_measure_calculate(
      ctl->h,ctl->rh, win->h, 1, ctl->y
    );
    
    if (ctl->w+ctl->x>win->w){
      ctl->w = win->w-ctl->x;
    }
    if (ctl->h+ctl->y>win->h){
      ctl->h = win->h-ctl->y;
    }
    if (ctl->w<ctl->minw){
      ctl->w=ctl->minw;
    }
    if (ctl->h<ctl->minh){
      ctl->h=ctl->minh;
    }
    _libaroma_window_measure_save(NULL,ctl);
    if (ctl->handler->message){
      LIBAROMA_MSG _msg;
      ctl->handler->message(ctl, libaroma_wm_compose(
        &_msg, LIBAROMA_MSG_WIN_MEASURED, NULL, 0, 0)
      );
      return 1;
    }
  }
  return 0;
} /* End of libaroma_window_measure */
예제 #2
0
파일: svg.c 프로젝트: Ever-Never/libaroma
LIBAROMA_CANVASP libaroma_svg_ex(
    LIBAROMA_STREAMP stream,
    byte freeStream,
    byte use_px) {

  LIBAROMA_CANVASP cv = NULL;
  if (!stream) {
    return NULL;
  }
  
  char * data = libaroma_stream_to_string(stream,0);
  if (data){
    NSVGimage *image = NULL;
    if (!use_px){
      image=nsvgParse(data, "dp", ((float) libaroma_fb()->dpi));
    }
    else{
      image=nsvgParse(data, "px", ((float) libaroma_fb()->dpi));
    }
    free(data);
    if (image == NULL) {
  		ALOGW("libaroma_svg: Could not open SVG image.");
  		goto exit;
  	}
  	
  	
  	NSVGrasterizer *rast =nsvgCreateRasterizer();
  	if (rast == NULL) {
  		printf("libaroma_svg: Could not init rasterizer.");
  		nsvgDelete(image);
  		goto exit;
  	}
  	if (!use_px){
  	  cv = libaroma_canvas_ex(libaroma_dp(image->width),libaroma_dp(image->height),1);
  	}
  	else{
  	  cv = libaroma_canvas_ex(image->width,image->height,1);
  	}
  	libaroma_canvas_setcolor(cv,0,0);
  	nsvgRasterize(rast,image,0,0,1,cv);
  	nsvgDelete(image);
  	nsvgDeleteRasterizer(rast);
  }
  
exit:
  if (freeStream) {
    libaroma_stream_close(stream);
  }
  return cv;
}
예제 #3
0
/*
 * Function    : libaroma_font_size_px
 * Return Value: short
 * Descriptions: font size in px
 */
short libaroma_font_size_px(byte size) {
  if (size > 15) {
    size = 15;
  }
  else if (size < 1) {
    size = 1;
  }
  /* more than size 8 */
  if (size>8){
  	size-=8;
  	return libaroma_dp(8 + 16 + (size * 4));
  }
  return libaroma_dp(8 + size * 2);
} /* End of libaroma_font_size_px */
예제 #4
0
/*
 * Function    : libaroma_window_measure_size
 * Return Value: byte
 * Descriptions: measure window size
 */
byte libaroma_window_measure_size(LIBAROMA_WINDOWP win){
  if (win){
    if (win->parent!=NULL){
      ALOGW("window_resize cannot be used for child window");
      return 0;
    }
    if (_libaroma_window_measurement_dp){
      win->x = libaroma_dp(win->rx);
      win->y = libaroma_dp(win->ry);
      win->w = libaroma_dp(win->rw);
      win->h = libaroma_dp(win->rh);
    }
    else{
      win->x = win->rx;
      win->y = win->ry;
      win->w = win->rw;
      win->h = win->rh;
    }
    win->ax=win->x;
    win->ay=win->y;
    
    win->x=libaroma_window_measure_calculate(
      win->x, win->rx, libaroma_wm()->w, 0, 0
    );
    win->y=libaroma_window_measure_calculate(
      win->y, win->ry, libaroma_wm()->h, 0, 0
    );
    win->w=libaroma_window_measure_calculate(
      win->w, win->rw, libaroma_wm()->w, 1, win->x
    );
    win->h=libaroma_window_measure_calculate(
      win->h, win->rh, libaroma_wm()->h, 1, win->y
    );
    
    if (win->w+win->x>libaroma_wm()->w){
      win->w = libaroma_wm()->w-win->x;
    }
    if (win->h+win->y>libaroma_wm()->h){
      win->h = libaroma_wm()->h-win->y;
    }
    _libaroma_window_measure_save(win,NULL);
    LIBAROMA_MSG _msg;
    libaroma_window_process_event(win,libaroma_wm_compose(
      &_msg, LIBAROMA_MSG_WIN_MEASURED, NULL, 0, 0)
    );
    return 1;
  }
  return 0;
} /* End of libaroma_window_measure */
예제 #5
0
/*
 * Function    : libaroma_font_size_px
 * Return Value: short
 * Descriptions: font size in px
 */
short libaroma_font_size_px(byte size) {
  if (size > 15) {
    size = 15;
  }
  else if (size < 1) {
    size = 1;
  }
  return libaroma_dp(8 + size * 2);
} /* End of libaroma_font_size_px */
예제 #6
0
LIBAROMA_CONTROLP libaroma_control_label(
  LIBAROMA_WINDOWP win, word id, char * text,
  int x, int y, int w, int h
){
  _LIBAROMA_CONTROL_LABELP me = (_LIBAROMA_CONTROL_LABELP)
    calloc(sizeof(_LIBAROMA_CONTROL_LABEL),1);
  if (!me){
    ALOGW("libaroma_control_label alloc label memory failed");
    return NULL;
  }
  me->text = strdup(text);
  me->textp = libaroma_text(
    me->text,
    libaroma_wm_get_color("control_text"),
    w - libaroma_dp(8),
    LIBAROMA_FONT(0,4)|LIBAROMA_TEXT_SINGLELINE,
    100
  );
  
  LIBAROMA_CONTROLP ctl =
    libaroma_control_new(
      id,
      x, y, w, h,
      libaroma_dp(28),libaroma_dp(32), /* min size */
      me,
      &_libaroma_control_label_handler,
      win
    );
  
  if (!ctl){
    if (me->text){
      free(me->text);
    }
    if (me->textp){
      libaroma_text_free(me->textp);
    }
    free(me);
  }
  return ctl;
}
예제 #7
0
/* init recovery */
byte recovery_init(){
  /* 
    snprintf(libaroma_config()->fb_shm_name,64,"recovery-mainfb");
    libaroma_config()->runtime_monitor = LIBAROMA_START_UNSAFE;
  */
  
  /* disable shared fb */
  libaroma_config()->runtime_monitor = LIBAROMA_START_UNSAFE;
  libaroma_config()->fb_shm_name[0]=0;
  
  /* start libaroma */
  if (!libaroma_start()){
    RLOG("recovery_init: libaroma_start failed");
    return 0;
  }
  
  /*
  LIBAROMA_CANVASP svg1=libaroma_image(
    libaroma_stream(
      "file:///sdcard/23.svg"
    ),
    1
  );
  if (svg1){
    libaroma_draw(libaroma_fb()->canvas,svg1,0,0,1);
    libaroma_sync();
    sleep(4);
  }
  else{
    printf("\n\nSVG RENDER ERROR\n\n\n");
  }
  */
  
  /* set workspace size */
  libaroma_wm_set_workspace(
    0,
    libaroma_dp(24),
    libaroma_fb()->w,
    libaroma_fb()->h-libaroma_dp(24)
  );
  
  /* clean display */
  libaroma_canvas_blank(libaroma_fb()->canvas);
  
  /* create statusbar canvas area */
  _recovery.status_canvas=libaroma_canvas_area(
    libaroma_fb()->canvas,
    0, 0, libaroma_fb()->w, libaroma_dp(24)
  );
  if (!_recovery.status_canvas){
    RLOG("recovery_init: _recovery.status_canvas failed");
    libaroma_end();
    return 0;
  }
  
  /* set wm ui thread */
  libaroma_wm_set_ui_thread(recovery_statusbar_ui_thread);
  recovery_statusbar_setcolor(0);
  
  /* load zip resource */
  _recovery.zip = libaroma_zip("/sdcard/recovery.zip");
  if (!_recovery.zip){
    RLOG("recovery_init: libaroma_zip resource failed");
    libaroma_canvas_free(_recovery.status_canvas);
    libaroma_end();
    return 0;
  }
  
  /* init stream callback */
  libaroma_stream_set_uri_callback(recovery_stream_uri_cb);
  
  /* load font id=0 */
  libaroma_font(0,
    libaroma_stream(
      "res:///fonts/Roboto-Regular.ttf"
    )
  );
  
  if (!recovery_init_ui()){
    recovery_release();
    return 0;
  }
  
  /* cleanup display */
  libaroma_sync();
  
  return 1;
}
예제 #8
0
/* Init UI */
byte recovery_init_ui(){
  /* create window */
  _recovery.win = libaroma_window(
      NULL, 0, 0, LIBAROMA_SIZE_FULL, LIBAROMA_SIZE_FULL
    );
  
  if (!_recovery.win){
    RLOG("Cannot init main window");
    return 0;
  }
  
  /* appbar */
  _recovery.appbar = libaroma_ctl_bar(
    _recovery.win, ID_APPBAR, 0, 0, LIBAROMA_SIZE_FULL, 56,
    "AROMA Recovery",
    libaroma_colorget(NULL,_recovery.win)->primary,
    libaroma_colorget(NULL,_recovery.win)->primary_text
  );
  
  if (!_recovery.appbar){
    return 0;
  }
  libaroma_ctl_bar_set_icon_mask(_recovery.appbar,1,0);
  libaroma_ctl_bar_set_textgap(_recovery.appbar,1,0);
  
  /* fragment */
  _recovery.fragment = libaroma_ctl_fragment(
    _recovery.win, ID_FRAGMENT,
    0, 56, LIBAROMA_SIZE_FULL, LIBAROMA_SIZE_FULL
  );
  if (!_recovery.fragment){
    return 0;
  }
  
  /* init sidebar */
  _recovery.sidebar = libaroma_window_sidebar(_recovery.win,0);
  if (_recovery.sidebar){
    /* sidebar onslide callback */
    libaroma_window_sidebar_onslide(
      _recovery.sidebar,
      &recovery_sidebar_onslide
    );
    
    word menuflags =
      LIBAROMA_LISTITEM_MENU_INDENT_NOICON|
      LIBAROMA_LISTITEM_MENU_SMALL_ICON|
      LIBAROMA_LISTITEM_MENU_FREE_ICON|
      LIBAROMA_LISTITEM_MENU_SMALL;
    
    /* menu item macro */
    #define _ITEM(id,text,ico,extra) \
      libaroma_listitem_menu(\
        _recovery.sidemenu, id, text, extra, \
        (ico!=NULL)?recovery_load_icon(ico,_recovery.win):NULL, \
        menuflags,-1)
    #define _TITLE(id,text) \
      libaroma_listitem_caption_color(_recovery.sidemenu, id, text, \
        libaroma_colorget(NULL,_recovery.win)->accent, -1)
    #define _DIV(id) \
      libaroma_listitem_divider(_recovery.sidemenu, id, \
        LIBAROMA_LISTITEM_SEPARATOR_TEXTALIGN,-1)
    
    /* create menu list */
    _recovery.sidemenu = libaroma_ctl_list(
      _recovery.sidebar, ID_SIDEMENU,
      0, 0, LIBAROMA_SIZE_FULL, LIBAROMA_SIZE_FULL,
      0, 0,
      libaroma_colorget(NULL,_recovery.win)->control_bg,
      0 /*LIBAROMA_CTL_SCROLL_WITH_SHADOW*/
    );
    
    libaroma_ctl_scroll_set_min_scroll(
       _recovery.sidemenu,
       recovery_statusbar_sidebar_list_cb, 
       libaroma_dp(24)
    );
    
    /* sidebar image */
    libaroma_listitem_image(
      _recovery.sidemenu, ID_SIDEMENU_IMAGE,
      libaroma_image_uri("res:///bg/sidebar.jpg"), 150,
      LIBAROMA_LISTITEM_IMAGE_FREE|LIBAROMA_LISTITEM_IMAGE_FILL|
      LIBAROMA_LISTITEM_IMAGE_PROPORTIONAL|LIBAROMA_CTL_LIST_ITEM_RECEIVE_TOUCH,
    -1);
    
    /* ITEMS */
    _TITLE(210,"POWER MENU");
      _ITEM(ID_SIDEMENU_SHUTDOWN,"Shutdown","power",NULL);
      _ITEM(ID_SIDEMENU_REBOOT_SYS,"Reboot System","android",NULL);
      _ITEM(ID_SIDEMENU_REBOOT_REC,"Reboot Recovery","direction",NULL);
      _ITEM(ID_SIDEMENU_REBOOT_BLD,"Reboot Bootloader","apps",NULL);
    _DIV(310);
    _TITLE(211,"SETTINGS");
      _ITEM(ID_SIDEMENU_SETTINGS,"Settings","settings",NULL);
      _ITEM(ID_SIDEMENU_ABOUT,"About","info",NULL);
      _ITEM(ID_SIDEMENU_HELP,"Help","help",NULL);
    
    /*
    _DIV(311);
    
    int u;
    for (u=0;u<20;u++){
      char extraText[100];
      snprintf(extraText,100,"Dummy Sidebar %i",u);
      _ITEM(501+u,"Dummy Sidebar",NULL,extraText);
    }
  */
  
    /* undef menu item macro */
    #undef _DIV
    #undef _TITLE
    #undef _ITEM
  }
  else{
    return 0;
  }
  return 1;
}
예제 #9
0
파일: window.c 프로젝트: sub77-bkp/libaroma
/*
 * Function    : libaroma_window_measure_point
 * Return Value: int
 * Descriptions: mesure point
 */
int libaroma_window_measure_point(int x){
  if (_libaroma_window_measurement_dp){
    return libaroma_dp(x);
  }
  return x;
} /* End of libaroma_window_measure_point */
예제 #10
0
/*
 * Function    : _libaroma_ctl_list_draw_item
 * Return Value: void
 * Descriptions: draw item
 */
void _libaroma_ctl_list_draw_item(
    LIBAROMA_CONTROLP ctl,
    LIBAROMA_CTL_LIST_ITEMP item,
    LIBAROMA_CANVASP canvas,
    word bgcolor
){
  if ((!item)||(!canvas)){
    return;
  }
  LIBAROMA_CTL_SCROLL_CLIENTP client = libaroma_ctl_scroll_get_client(ctl);
  if (!client){
    return;
  }
  if (client->handler!=&_libaroma_ctl_list_handler){
    return;
  }
  LIBAROMA_CTL_SCROLLP mi = (LIBAROMA_CTL_SCROLLP) client->internal;
  
  /* normal animation handler */
  if (item->state){
    if (item->state->normal_handler){
      libaroma_draw(canvas, item->state->cache_rest, 0, 0, 0);
      int ripple_i = 0;
      int ripple_p = 0;
      while(libaroma_ripple_loop(&item->state->ripple,&ripple_i,&ripple_p)){
        int x=0;
        int y=(item->y+libaroma_dp(1));
        int size=0;
        byte push_opacity=0;
        byte ripple_opacity=0;
        if (libaroma_ripple_calculation(
          &item->state->ripple, canvas->w, canvas->h,
          &push_opacity, &ripple_opacity,
          &x, &y, &size, ripple_p
        )){
          libaroma_draw_opacity(canvas, 
            item->state->cache_push, 0, 0, 2, 
            (byte) push_opacity
          );
          libaroma_draw_mask_circle(
              canvas, 
              item->state->cache_push, 
              x, y,
              x, y,
              size,
              ripple_opacity
            );
        }
      }
      if (item->state->normal_handler==2){
        _libaroma_ctl_list_draw_item_fresh(
          ctl, item,canvas,bgcolor,mi->hpad,
          LIBAROMA_CTL_LIST_ITEM_DRAW_ADDONS
        );
      }
      return;
    }
  }
  
  /* draw fresh */
  _libaroma_ctl_list_draw_item_fresh(
    ctl, item,canvas,bgcolor,mi->hpad, LIBAROMA_CTL_LIST_ITEM_DRAW_NORMAL
  );
} /* End of _libaroma_ctl_list_draw_item */
예제 #11
0
/*
 * Function    : libaroma_art_busy_progress
 * Return Value: LIBAROMA_CANVASP
 * Descriptions: create busy progress sprite canvas
 */
LIBAROMA_CANVASP libaroma_art_busy_progress(
    word basecolor) {
  int i, j;
  
  /* calculate size */
  int dp1   = libaroma_dp(1);
  int dp36  = libaroma_dp(36);
  int dp72  = libaroma_dp(72);
  int dp144 = dp72 * 2;
  int dp288 = dp144 * 2;
  int dp28  = libaroma_dp(28);
  int dp56  = dp28 * 2;
  int dp116 = dp144 - dp28;
  
  /* main + temp canvas */
  LIBAROMA_CANVASP load  = libaroma_canvas_ex(dp72 * 13, dp72, 1);
  if (!load){
    return NULL;
  }
  LIBAROMA_CANVASP load1 = libaroma_canvas_ex(dp288, dp288, 1);
  if (!load1){
    libaroma_canvas_free(load);
    return NULL;
  }
  LIBAROMA_CANVASP load2 = libaroma_canvas_ex(dp56, dp56, 1);
  if (!load2){
    libaroma_canvas_free(load1);
    libaroma_canvas_free(load);
    return NULL;
  }
  
  /* cleanup */
  libaroma_canvas_setcolor(load, 0x0000, 0);
  
  /* frame loop */
  for (j = 0; j < 13; j++) {
    /* angle per frame */
    double added = ((27.69230769230769 * j) / 360);
    
    /* cleanup load1 */
    libaroma_canvas_setcolor(load1, 0x0000, 0);
    
    /* circle draw */
    for (i = 0; i < 12; i++) {
      /* position */
      double angle = 2 * __PI * ((((double) i) / 12.0) + added);
      int xpos     = round(dp116 * cos(angle));
      int ypos     = round(dp116 * sin(angle));
      
      /* cleanup load2 */
      libaroma_canvas_setcolor(load2, 0x0000, 0);
      int b = 2;
      
      /* draw */
      libaroma_gradient_ex(
        load2,
        b * dp1,
        b * dp1,
        dp56 - (b * dp1 * 2),
        dp56 - (b * dp1 * 2),
        basecolor,
        basecolor,
        dp28,
        0x1111,
        MIN(0xff, ((i + 1) * 18) + 39),
        MIN(0xff, ((i + 1) * 18))
      );
      
      /* Stretch Copy to load1 */
      libaroma_draw_scale_smooth(
        load1,
        load2,
        dp144 + xpos - dp28,
        dp144 + ypos - dp28,
        dp56,
        dp56,
        0,
        0,
        dp56,
        dp56
      );
    }
    
    /* Stretch Copy to load canvas */
    libaroma_draw_scale_smooth(
      load,
      load1,
      j * dp72,
      0,
      dp72,
      dp72,
      0,
      0,
      dp288,
      dp288
    );
  }
  
  /* free temp canvases */
  libaroma_canvas_free(load1);
  libaroma_canvas_free(load2);
  
  /* return canvas */
  LIBAROMA_CANVASP load_out =
    libaroma_canvas_ex(dp36 * 13, dp36, 1);
  if (!load_out){
    libaroma_canvas_free(load);
    return NULL;
  }
  libaroma_canvas_setcolor(load_out, 0x0000, 0);
  
  /* draw */
  libaroma_draw_scale_smooth(
    load_out, load,
    0, 0, dp36 * 13, dp36,
    0, 0, dp72 * 13, dp72
  );
  libaroma_canvas_free(load);
  return load_out;
} /* End of libaroma_art_busy_progress */