From 559a902cbeb52e6811beaf0cd25b747331a5ea6b Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Sat, 23 Nov 2013 14:45:01 +0100 Subject: Added gemtk_obj_create_popup_tree util. --- atari/gemtk/objc.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) (limited to 'atari/gemtk/objc.c') diff --git a/atari/gemtk/objc.c b/atari/gemtk/objc.c index 5d47bd64c..3c13f553c 100644 --- a/atari/gemtk/objc.c +++ b/atari/gemtk/objc.c @@ -368,3 +368,136 @@ OBJECT *gemtk_obj_tree_copy(OBJECT *tree) return(new_tree); } + + +OBJECT * gemtk_obj_create_popup_tree(const char **items, int nitems, + char * selected, bool horizontal, + int max_width) +{ + OBJECT * popup = NULL; + int box_width = 0; + int box_height = 0; + int char_width = 10; + int char_height = 16; + int item_height; // height of each item + + assert(items != NULL); + + item_height = char_height; + + /* Allocate room for n items and the root G_BOX: */ + popup = calloc(nitems+1, sizeof(OBJECT)); + assert(popup != null); + + for (int i=0; i box_width){ + box_width = (len+2) * char_width; + } + box_height += item_height; + } + } + + if (max_width>0){ + box_width = max_width; + } + + if (horizontal) { + box_height = item_height; + } + +/* + printf("popup height: %d, popup width: %d\n", box_height, box_width); +*/ + + popup[0].ob_next = -1; /**< object's next sibling */ + popup[0].ob_head = 1; /**< head of object's children */ + popup[0].ob_tail = nitems; /**< tail of object's children */ + popup[0].ob_type = G_BOX; /**< type of object */ + popup[0].ob_flags = OF_FL3DBAK; /**< flags */ + popup[0].ob_state = OS_NORMAL; /**< state */ + popup[0].ob_spec.index = (long) 16650496L; /**< object-specific data */ + popup[0].ob_x = 0; /**< upper left corner of object */ + popup[0].ob_y = 0; /**< upper left corner of object */ + popup[0].ob_width = box_width; /**< width of obj */ + popup[0].ob_height = box_height; + + + + /* Add items to popup: */ + int xpos = 0, ypos = 0; + + for (int i=0; i