mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 23:24:38 +00:00
expo: Use switch statements more for object types
In a lot of cases menus are the only objects which are have their own behaviour in the cedit, e.g. to move between menus. With expo expanding to support text, this is no-longer true. Use a switch() statement so that we can simply insert a new 'case' for the new object types. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
909c486d7c
commit
fd6073ac9f
2 changed files with 82 additions and 42 deletions
86
boot/cedit.c
86
boot/cedit.c
|
@ -71,10 +71,16 @@ int cedit_arange(struct expo *exp, struct video_priv *vpriv, uint scene_id)
|
|||
|
||||
y = 100;
|
||||
list_for_each_entry(obj, &scn->obj_head, sibling) {
|
||||
if (obj->type == SCENEOBJT_MENU) {
|
||||
switch (obj->type) {
|
||||
case SCENEOBJT_NONE:
|
||||
case SCENEOBJT_IMAGE:
|
||||
case SCENEOBJT_TEXT:
|
||||
break;
|
||||
case SCENEOBJT_MENU:
|
||||
scene_obj_set_pos(scn, obj->id, 50, y);
|
||||
scene_menu_arrange(scn, (struct scene_obj_menu *)obj);
|
||||
y += 50;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,31 +428,37 @@ static int h_write_settings_env(struct scene_obj *obj, void *vpriv)
|
|||
const char *str;
|
||||
int val, ret;
|
||||
|
||||
if (obj->type != SCENEOBJT_MENU)
|
||||
return 0;
|
||||
|
||||
menu = (struct scene_obj_menu *)obj;
|
||||
val = menu->cur_item_id;
|
||||
snprintf(var, sizeof(var), "c.%s", obj->name);
|
||||
|
||||
if (priv->verbose)
|
||||
printf("%s=%d\n", var, val);
|
||||
switch (obj->type) {
|
||||
case SCENEOBJT_NONE:
|
||||
case SCENEOBJT_IMAGE:
|
||||
case SCENEOBJT_TEXT:
|
||||
break;
|
||||
case SCENEOBJT_MENU:
|
||||
menu = (struct scene_obj_menu *)obj;
|
||||
val = menu->cur_item_id;
|
||||
|
||||
ret = env_set_ulong(var, val);
|
||||
if (ret)
|
||||
return log_msg_ret("set", ret);
|
||||
if (priv->verbose)
|
||||
printf("%s=%d\n", var, val);
|
||||
|
||||
ret = get_cur_menuitem_text(menu, &str);
|
||||
if (ret)
|
||||
return log_msg_ret("mis", ret);
|
||||
ret = env_set_ulong(var, val);
|
||||
if (ret)
|
||||
return log_msg_ret("set", ret);
|
||||
|
||||
snprintf(name, sizeof(name), "c.%s-str", obj->name);
|
||||
if (priv->verbose)
|
||||
printf("%s=%s\n", name, str);
|
||||
ret = get_cur_menuitem_text(menu, &str);
|
||||
if (ret)
|
||||
return log_msg_ret("mis", ret);
|
||||
|
||||
ret = env_set(name, str);
|
||||
if (ret)
|
||||
return log_msg_ret("st2", ret);
|
||||
snprintf(name, sizeof(name), "c.%s-str", obj->name);
|
||||
if (priv->verbose)
|
||||
printf("%s=%s\n", name, str);
|
||||
|
||||
ret = env_set(name, str);
|
||||
if (ret)
|
||||
return log_msg_ret("st2", ret);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -474,24 +486,28 @@ static int h_read_settings_env(struct scene_obj *obj, void *vpriv)
|
|||
char var[60];
|
||||
int val;
|
||||
|
||||
if (obj->type != SCENEOBJT_MENU)
|
||||
return 0;
|
||||
|
||||
menu = (struct scene_obj_menu *)obj;
|
||||
val = menu->cur_item_id;
|
||||
snprintf(var, sizeof(var), "c.%s", obj->name);
|
||||
|
||||
val = env_get_ulong(var, 10, 0);
|
||||
if (priv->verbose)
|
||||
printf("%s=%d\n", var, val);
|
||||
if (!val)
|
||||
return log_msg_ret("get", -ENOENT);
|
||||
switch (obj->type) {
|
||||
case SCENEOBJT_NONE:
|
||||
case SCENEOBJT_IMAGE:
|
||||
case SCENEOBJT_TEXT:
|
||||
break;
|
||||
case SCENEOBJT_MENU:
|
||||
menu = (struct scene_obj_menu *)obj;
|
||||
val = env_get_ulong(var, 10, 0);
|
||||
if (priv->verbose)
|
||||
printf("%s=%d\n", var, val);
|
||||
if (!val)
|
||||
return log_msg_ret("get", -ENOENT);
|
||||
|
||||
/*
|
||||
* note that no validation is done here, to make sure the ID is valid
|
||||
* and actually points to a menu item
|
||||
*/
|
||||
menu->cur_item_id = val;
|
||||
/*
|
||||
* note that no validation is done here, to make sure the ID is
|
||||
* valid * and actually points to a menu item
|
||||
*/
|
||||
menu->cur_item_id = val;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
38
boot/scene.c
38
boot/scene.c
|
@ -423,13 +423,20 @@ int scene_arrange(struct scene *scn)
|
|||
int ret;
|
||||
|
||||
list_for_each_entry(obj, &scn->obj_head, sibling) {
|
||||
if (obj->type == SCENEOBJT_MENU) {
|
||||
switch (obj->type) {
|
||||
case SCENEOBJT_NONE:
|
||||
case SCENEOBJT_IMAGE:
|
||||
case SCENEOBJT_TEXT:
|
||||
break;
|
||||
case SCENEOBJT_MENU: {
|
||||
struct scene_obj_menu *menu;
|
||||
|
||||
menu = (struct scene_obj_menu *)obj,
|
||||
ret = scene_menu_arrange(scn, menu);
|
||||
if (ret)
|
||||
return log_msg_ret("arr", ret);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -452,9 +459,16 @@ int scene_render_deps(struct scene *scn, uint id)
|
|||
if (ret && ret != -ENOTSUPP)
|
||||
return log_msg_ret("ren", ret);
|
||||
|
||||
if (obj->type == SCENEOBJT_MENU)
|
||||
switch (obj->type) {
|
||||
case SCENEOBJT_NONE:
|
||||
case SCENEOBJT_IMAGE:
|
||||
case SCENEOBJT_TEXT:
|
||||
break;
|
||||
case SCENEOBJT_MENU:
|
||||
scene_menu_render_deps(scn,
|
||||
(struct scene_obj_menu *)obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -537,7 +551,6 @@ static void send_key_obj(struct scene *scn, struct scene_obj *obj, int key,
|
|||
|
||||
int scene_send_key(struct scene *scn, int key, struct expo_action *event)
|
||||
{
|
||||
struct scene_obj_menu *menu;
|
||||
struct scene_obj *obj;
|
||||
int ret;
|
||||
|
||||
|
@ -561,10 +574,21 @@ int scene_send_key(struct scene *scn, int key, struct expo_action *event)
|
|||
return 0;
|
||||
}
|
||||
|
||||
menu = (struct scene_obj_menu *)obj,
|
||||
ret = scene_menu_send_key(scn, menu, key, event);
|
||||
if (ret)
|
||||
return log_msg_ret("key", ret);
|
||||
switch (obj->type) {
|
||||
case SCENEOBJT_NONE:
|
||||
case SCENEOBJT_IMAGE:
|
||||
case SCENEOBJT_TEXT:
|
||||
break;
|
||||
case SCENEOBJT_MENU: {
|
||||
struct scene_obj_menu *menu;
|
||||
|
||||
menu = (struct scene_obj_menu *)obj,
|
||||
ret = scene_menu_send_key(scn, menu, key, event);
|
||||
if (ret)
|
||||
return log_msg_ret("key", ret);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue