/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static int mat_livedb_show_one_level_exec(bContext *C, wmOperator *op)
{
    SpaceLDB    *slivedb    = CTX_wm_space_mat_livedb(C);
    ARegion     *ar         = CTX_wm_region(C);
    int         level       = mat_livedb_has_one_flag(slivedb, &slivedb->tree, TE_CLOSED, 1);

    if (level) mat_livedb_openclose_level(slivedb, &slivedb->tree, 1, level, 1);
    
    ED_region_tag_redraw(ar);
    
    return OPERATOR_FINISHED;
} /* mat_livedb_show_one_level_exec() */
Exemple #2
0
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static void mat_livedb_namebutton_cb(bContext *C, void *itemp, char *oldname)
{
    Main        *mainvar    = CTX_data_main(C);
    SpaceLDB    *slivedb    = CTX_wm_space_mat_livedb(C);
    LiveDbItem  *item       = itemp;

    if (item) {
        if (TE_GET_TYPE(item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) {
            /* TODO: implement for categories */
        }
        else {
            LiveDbItem  *cur_item;
            size_t      store_len = MEM_allocN_len(slivedb->treestore);
            int         size_diff = strlen(new_name) - strlen(oldname);

            LiveDbItem *new_items = MEM_mallocN(store_len + size_diff, "ldb tree");
            LiveDbItem *new_item  = new_items;

            for(cur_item = (LiveDbItem*)slivedb->treestore; (((char*)cur_item + cur_item->size) - slivedb->treestore) <= store_len; cur_item = (LiveDbItem*)((char*)cur_item + cur_item->size)) {
                if(TE_GET_TYPE(cur_item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) {
                    memcpy(new_item, cur_item, cur_item->size);
                }
                else {
                    if(cur_item == item) {
                        char *cur_name, *cur_new_name;

                        new_item->size          = cur_item->size + size_diff;
                        new_item->type          = cur_item->type;
                        new_item->mat_item.id   = cur_item->mat_item.id;

                        strcpy(new_item->mat_item.name, new_name);
                        cur_name        = cur_item->mat_item.name + strlen(cur_item->mat_item.name) + 1;
                        cur_new_name    = new_item->mat_item.name + strlen(new_name) + 1;
                        strcpy(cur_new_name, cur_name);
                        cur_new_name    = cur_new_name + strlen(cur_name) + 1;
                        cur_name        = cur_name + strlen(cur_name) + 1;
                        strcpy(cur_new_name, cur_name);
                    }
                    else memcpy(new_item, cur_item, cur_item->size);
                }
                new_item = (LiveDbItem*)((char*)new_item + new_item->size);
            }
            new_name[0] = 0;
            MEM_freeN(slivedb->treestore);
            slivedb->treestore = (char*)new_items;

            mat_livedb_build_tree(mainvar, slivedb, 0);
        }
    }
} /* mat_livedb_namebutton_cb() */
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static int mat_livedb_toggle_expanded_exec(bContext *C, wmOperator *UNUSED(op))
{
    SpaceLDB    *slivedb    = CTX_wm_space_mat_livedb(C);
    ARegion     *ar         = CTX_wm_region(C);
    
    if (mat_livedb_has_one_flag(slivedb, &slivedb->tree, TE_CLOSED, 1))
        mat_livedb_set_flag(slivedb, &slivedb->tree, TE_CLOSED, 0);
    else 
        mat_livedb_set_flag(slivedb, &slivedb->tree, TE_CLOSED, 1);
    
    ED_region_tag_redraw(ar);
    
    return OPERATOR_FINISHED;
} /* mat_livedb_toggle_expanded_exec() */
Exemple #4
0
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
void draw_mat_livedb(const bContext *C)
{
    uiBlock     *block;
    Main        *mainvar    = CTX_data_main(C);
    Scene       *scene      = CTX_data_scene(C);
    ARegion     *ar         = CTX_wm_region(C);
    View2D      *v2d        = &ar->v2d;
    SpaceLDB    *slivedb    = CTX_wm_space_mat_livedb(C);
    int sizey = 0, sizex = 0, sizex_rna = 0;

    if(!slivedb) return;

    if(!strlen(slivedb->server_address)) strcpy(slivedb->server_address, "127.0.0.1");

    mat_livedb_build_tree(mainvar, slivedb, 0); /* always */

    /* get extents of data */
    mat_livedb_height(slivedb, &slivedb->tree, &sizey);
    mat_livedb_width(slivedb, &slivedb->tree, &sizex, 0);

    /* adds vertical offset */
    sizey += LDB_Y_OFFSET;

    /* update size of tot-rect (extents of data/viewable area) */
    UI_view2d_totRect_set(v2d, sizex, sizey);

    /* force display to pixel coords */
    v2d->flag |= (V2D_PIXELOFS_X | V2D_PIXELOFS_Y);
    /* set matrix for 2d-view controls */
    UI_view2d_view_ortho(v2d);

    /* draw LiveDB stuff */
    block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
    mat_livedb_draw_tree((bContext *)C, block, ar, slivedb);
    mat_livedb_draw_mat_preview(block, scene, ar, slivedb, &slivedb->tree);

    /* draw edit buttons if nessecery */
    mat_draw_rename_buttons(C, block, ar, slivedb, &slivedb->tree);

    UI_block_end(C, block);
    UI_block_draw(C, block);

    /* clear flag that allows quick redraws */
    slivedb->storeflag &= ~LDB_TREESTORE_REDRAW;
} /* draw_mat_livedb() */
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static int mat_livedb_item_openclose(bContext *C, wmOperator *op, const wmEvent *event)
{
    ARegion             *ar         = CTX_wm_region(C);
    SpaceLDB            *slivedb    = CTX_wm_space_mat_livedb(C);
    int                 all         = RNA_boolean_get(op->ptr, "all");
    LiveDbTreeElement   *te;
    float               fmval[2];
    
    UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval + 1);
    
    for (te = slivedb->tree.first; te; te = te->next) {
        if (do_mat_livedb_item_openclose(C, slivedb, te, all, fmval)) 
            break;
    }
    ED_region_tag_redraw(ar);
    
    return OPERATOR_FINISHED;
} /* mat_livedb_item_openclose() */
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static int mat_livedb_toggle_selected_exec(bContext *C, wmOperator *UNUSED(op))
{
    SpaceLDB    *slivedb    = CTX_wm_space_mat_livedb(C);
    ARegion     *ar         = CTX_wm_region(C);
    Scene       *scene      = CTX_data_scene(C);
    
    if (mat_livedb_has_one_flag(slivedb, &slivedb->tree, TE_SELECTED, 1))
        mat_livedb_set_flag(slivedb, &slivedb->tree, TE_SELECTED, 0);
    else 
        mat_livedb_set_flag(slivedb, &slivedb->tree, TE_SELECTED, 1);
    
    slivedb->storeflag |= LDB_TREESTORE_REDRAW;
    
    WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
    ED_region_tag_redraw(ar);
    
    return OPERATOR_FINISHED;
} /* mat_livedb_toggle_selected_exec() */
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static int mat_livedb_item_rename(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
    ARegion             *ar         = CTX_wm_region(C);
    SpaceLDB            *slivedb    = CTX_wm_space_mat_livedb(C);
    bool                change      = false;
    LiveDbTreeElement   *te;
    float               fmval[2];
    
    UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval + 1);
    
    for (te = slivedb->tree.first; te; te = te->next) {
        if (do_mat_livedb_item_rename(C, ar, slivedb, te, fmval)) {
            change = true;
            break;
        }
    }
    return change ? OPERATOR_FINISHED : OPERATOR_PASS_THROUGH;
} /* mat_livedb_item_rename() */