~ubuntu-branches/ubuntu/utopic/blender/utopic-proposed

« back to all changes in this revision

Viewing changes to source/blender/editors/interface/interface.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
559
559
/* ************** BLOCK ENDING FUNCTION ************* */
560
560
 
561
561
/* NOTE: if but->poin is allocated memory for every defbut, things fail... */
562
 
static bool ui_but_equals_old(uiBut *but, uiBut *oldbut)
 
562
static bool ui_but_equals_old(const uiBut *but, const uiBut *oldbut)
563
563
{
564
564
        /* various properties are being compared here, hopefully sufficient
565
565
         * to catch all cases, but it is simple to add more checks later */
566
566
        if (but->retval != oldbut->retval) return false;
567
567
        if (but->rnapoin.data != oldbut->rnapoin.data) return false;
568
 
        if (but->rnaprop != oldbut->rnaprop)
569
 
                if (but->rnaindex != oldbut->rnaindex) return false;
 
568
        if (but->rnaprop != oldbut->rnaprop && but->rnaindex != oldbut->rnaindex) return false;
570
569
        if (but->func != oldbut->func) return false;
571
570
        if (but->funcN != oldbut->funcN) return false;
572
571
        if (oldbut->func_arg1 != oldbut && but->func_arg1 != oldbut->func_arg1) return false;
573
572
        if (oldbut->func_arg2 != oldbut && but->func_arg2 != oldbut->func_arg2) return false;
574
 
        if (!but->funcN && ((but->poin != oldbut->poin && (uiBut *)oldbut->poin != oldbut) || but->pointype != oldbut->pointype)) return false;
 
573
        if (!but->funcN && ((but->poin != oldbut->poin && (uiBut *)oldbut->poin != oldbut) ||
 
574
                            (but->pointype != oldbut->pointype))) return false;
575
575
        if (but->optype != oldbut->optype) return false;
576
576
 
577
577
        return true;
611
611
 
612
612
static int ui_but_update_from_old_block(const bContext *C, uiBlock *block, uiBut **butpp)
613
613
{
 
614
        /* flags from the buttons we want to refresh, may want to add more here... */
 
615
        const int flag_copy = UI_BUT_REDALERT;
 
616
 
614
617
        uiBlock *oldblock;
615
618
        uiBut *oldbut, *but = *butpp;
616
619
        int found = 0;
620
623
                return found;
621
624
 
622
625
        for (oldbut = oldblock->buttons.first; oldbut; oldbut = oldbut->next) {
623
 
                if (ui_but_equals_old(oldbut, but)) {
 
626
                if (ui_but_equals_old(but, oldbut)) {
624
627
                        if (oldbut->active) {
625
628
#if 0
626
629
//                              but->flag = oldbut->flag;
659
662
                                /* drawing */
660
663
                                oldbut->icon = but->icon;
661
664
                                oldbut->iconadd = but->iconadd;
 
665
                                oldbut->alignnr = but->alignnr;
662
666
                                
663
667
                                /* typically the same pointers, but not on undo/redo */
664
668
                                /* XXX some menu buttons store button itself in but->poin. Ugly */
667
671
                                        SWAP(void *, oldbut->func_argN, but->func_argN);
668
672
                                }
669
673
                                
 
674
                                oldbut->flag = (oldbut->flag & ~flag_copy) | (but->flag & flag_copy);
 
675
 
670
676
                                /* copy hardmin for list rows to prevent 'sticking' highlight to mouse position
671
677
                                 * when scrolling without moving mouse (see [#28432]) */
672
678
                                if (ELEM(oldbut->type, ROW, LISTROW))
837
843
{
838
844
 
839
845
        if (do_strip) {
840
 
                char *cpoin = strchr(but->str, '|');
 
846
                char *cpoin = strchr(but->str, UI_SEP_CHAR);
841
847
                if (cpoin) {
842
848
                        *cpoin = '\0';
843
849
                }
855
861
                }
856
862
                BLI_snprintf(but->strdata,
857
863
                             sizeof(but->strdata),
858
 
                             "%s|%s",
 
864
                             "%s" UI_SEP_CHAR_S "%s",
859
865
                             butstr_orig, shortcut_str);
860
866
                MEM_freeN(butstr_orig);
861
867
                but->str = but->strdata;
962
968
                                                data_path = BLI_sprintfN("scene.%s", path);
963
969
                                                MEM_freeN(path);
964
970
                                        }
965
 
                                        /*else {
966
 
                                                printf("ERROR in %s(): Couldn't get path for scene property - %s\n", 
 
971
#if 0
 
972
                                        else {
 
973
                                                printf("ERROR in %s(): Couldn't get path for scene property - %s\n",
967
974
                                                       __func__, RNA_property_identifier(but->rnaprop));
968
 
                                        }*/
 
975
                                        }
 
976
#endif
969
977
                                }
970
978
                        }
971
979
                        else {
985
993
                        
986
994
                        IDPropertyTemplate val = {0};
987
995
                        prop_path = IDP_New(IDP_GROUP, &val, __func__);
988
 
                        prop_path_value = IDP_NewString(data_path, "data_path", strlen(data_path) + 1); /* len + 1, or else will be truncated */
 
996
                        prop_path_value = IDP_NewString(data_path, "data_path", strlen(data_path) + 1);
989
997
                        IDP_AddToGroup(prop_path, prop_path_value);
990
998
                        
991
999
                        /* check each until one works... */
1644
1652
                if (RNA_property_editable(&but->rnapoin, prop)) {
1645
1653
                        switch (RNA_property_type(prop)) {
1646
1654
                                case PROP_BOOLEAN:
1647
 
                                        if (RNA_property_array_length(&but->rnapoin, prop))
 
1655
                                        if (RNA_property_array_check(prop))
1648
1656
                                                RNA_property_boolean_set_index(&but->rnapoin, prop, but->rnaindex, value);
1649
1657
                                        else
1650
1658
                                                RNA_property_boolean_set(&but->rnapoin, prop, value);
1651
1659
                                        break;
1652
1660
                                case PROP_INT:
1653
 
                                        if (RNA_property_array_length(&but->rnapoin, prop))
 
1661
                                        if (RNA_property_array_check(prop))
1654
1662
                                                RNA_property_int_set_index(&but->rnapoin, prop, but->rnaindex, (int)value);
1655
1663
                                        else
1656
1664
                                                RNA_property_int_set(&but->rnapoin, prop, (int)value);
1657
1665
                                        break;
1658
1666
                                case PROP_FLOAT:
1659
 
                                        if (RNA_property_array_length(&but->rnapoin, prop))
 
1667
                                        if (RNA_property_array_check(prop))
1660
1668
                                                RNA_property_float_set_index(&but->rnapoin, prop, but->rnaindex, value);
1661
1669
                                        else
1662
1670
                                                RNA_property_float_set(&but->rnapoin, prop, value);
1807
1815
static float ui_get_but_step_unit(uiBut *but, float step_default)
1808
1816
{
1809
1817
        int unit_type = RNA_SUBTYPE_UNIT_VALUE(uiButGetUnitType(but));
1810
 
        float step;
 
1818
        double step;
1811
1819
 
1812
1820
        step = bUnit_ClosestScalar(ui_get_but_scale_unit(but, step_default), but->block->unit->system, unit_type);
1813
1821
 
1814
 
        if (step > 0.0f) { /* -1 is an error value */
1815
 
                return (float)((double)step / ui_get_but_scale_unit(but, 1.0)) * 100.0f;
 
1822
        /* -1 is an error value */
 
1823
        if (step != -1.0) {
 
1824
                BLI_assert(step > 0.0);
 
1825
                return (float)(step / ui_get_but_scale_unit(but, 1.0)) * 100.0f;
1816
1826
        }
1817
1827
        else {
1818
1828
                return step_default;
2047
2057
        return false;
2048
2058
}
2049
2059
 
2050
 
void ui_set_but_default(bContext *C, short all)
 
2060
void ui_set_but_default(bContext *C, const bool all)
2051
2061
{
 
2062
        const char *opstring = "UI_OT_reset_default_button";
2052
2063
        PointerRNA ptr;
2053
2064
 
2054
 
        WM_operator_properties_create(&ptr, "UI_OT_reset_default_button");
 
2065
        WM_operator_properties_create(&ptr, opstring);
2055
2066
        RNA_boolean_set(&ptr, "all", all);
2056
 
        WM_operator_name_call(C, "UI_OT_reset_default_button", WM_OP_EXEC_DEFAULT, &ptr);
 
2067
        WM_operator_name_call(C, opstring, WM_OP_EXEC_DEFAULT, &ptr);
2057
2068
        WM_operator_properties_free(&ptr);
2058
2069
}
2059
2070
 
2230
2241
{
2231
2242
        uiBut *but;
2232
2243
 
2233
 
        while ( (but = block->buttons.first) ) {
2234
 
                BLI_remlink(&block->buttons, but);
 
2244
        while ((but = BLI_pophead(&block->buttons))) {
2235
2245
                ui_free_but(C, but);
2236
2246
        }
2237
2247
 
2255
2265
{
2256
2266
        uiBlock *block;
2257
2267
        
2258
 
        while ( (block = lb->first) ) {
2259
 
                BLI_remlink(lb, block);
 
2268
        while ((block = BLI_pophead(lb))) {
2260
2269
                uiFreeBlock(C, block);
2261
2270
        }
2262
2271
}
2426
2435
                case NUM:
2427
2436
                case NUMSLI:
2428
2437
 
2429
 
                        UI_GET_BUT_VALUE_INIT(but, value);
 
2438
                        if (!but->editstr) {
 
2439
                                UI_GET_BUT_VALUE_INIT(but, value);
2430
2440
 
2431
 
                        if (ui_is_but_float(but)) {
2432
 
                                if (value == (double) FLT_MAX) {
2433
 
                                        BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%sinf", but->str);
2434
 
                                }
2435
 
                                else if (value == (double) -FLT_MAX) {
2436
 
                                        BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s-inf", but->str);
2437
 
                                }
2438
 
                                /* support length type buttons */
2439
 
                                else if (ui_is_but_unit(but)) {
2440
 
                                        char new_str[sizeof(but->drawstr)];
2441
 
                                        ui_get_but_string_unit(but, new_str, sizeof(new_str), value, TRUE, -1);
2442
 
                                        BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%s", but->str, new_str);
 
2441
                                if (ui_is_but_float(but)) {
 
2442
                                        if (value == (double) FLT_MAX) {
 
2443
                                                BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%sinf", but->str);
 
2444
                                        }
 
2445
                                        else if (value == (double) -FLT_MAX) {
 
2446
                                                BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s-inf", but->str);
 
2447
                                        }
 
2448
                                        /* support length type buttons */
 
2449
                                        else if (ui_is_but_unit(but)) {
 
2450
                                                char new_str[sizeof(but->drawstr)];
 
2451
                                                ui_get_but_string_unit(but, new_str, sizeof(new_str), value, TRUE, -1);
 
2452
                                                BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%s", but->str, new_str);
 
2453
                                        }
 
2454
                                        else {
 
2455
                                                const int prec = ui_but_float_precision(but, value);
 
2456
                                                BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%.*f", but->str, prec, value);
 
2457
                                        }
2443
2458
                                }
2444
2459
                                else {
2445
 
                                        const int prec = ui_but_float_precision(but, value);
2446
 
                                        BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%.*f", but->str, prec, value);
2447
 
                                }
2448
 
                        }
2449
 
                        else {
2450
 
                                BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%d", but->str, (int)value);
2451
 
                        }
2452
 
                        
2453
 
                        if (but->rnaprop) {
2454
 
                                PropertySubType pstype = RNA_property_subtype(but->rnaprop);
2455
 
                        
2456
 
                                if (pstype == PROP_PERCENTAGE)
2457
 
                                        strcat(but->drawstr, "%");
 
2460
                                        BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%d", but->str, (int)value);
 
2461
                                }
 
2462
 
 
2463
                                if (but->rnaprop) {
 
2464
                                        PropertySubType pstype = RNA_property_subtype(but->rnaprop);
 
2465
 
 
2466
                                        if (pstype == PROP_PERCENTAGE)
 
2467
                                                strcat(but->drawstr, "%");
 
2468
                                }
2458
2469
                        }
2459
2470
                        break;
2460
2471
 
2477
2488
                        if (!but->editstr) {
2478
2489
                                char str[UI_MAX_DRAW_STR];
2479
2490
 
2480
 
                                ui_get_but_string(but, str, UI_MAX_DRAW_STR - strlen(but->str));
2481
 
 
 
2491
                                ui_get_but_string(but, str, UI_MAX_DRAW_STR);
2482
2492
                                BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%s", but->str, str);
2483
2493
                        }
2484
2494
                        break;
2485
2495
        
2486
2496
                case KEYEVT:
2487
 
                        BLI_strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
 
2497
                {
 
2498
                        const char *str;
2488
2499
                        if (but->flag & UI_SELECT) {
2489
 
                                strcat(but->drawstr, "Press a key");
 
2500
                                str = "Press a key";
2490
2501
                        }
2491
2502
                        else {
2492
2503
                                UI_GET_BUT_VALUE_INIT(but, value);
2493
 
                                strcat(but->drawstr, WM_key_event_string((short)value));
 
2504
                                str = WM_key_event_string((short)value);
2494
2505
                        }
 
2506
                        BLI_snprintf(but->drawstr, UI_MAX_DRAW_STR, "%s%s", but->str, str);
2495
2507
                        break;
2496
 
                
 
2508
                }
2497
2509
                case HOTKEYEVT:
2498
2510
                        if (but->flag & UI_SELECT) {
2499
 
                                but->drawstr[0] = '\0';
2500
2511
 
2501
2512
                                if (but->modifier_key) {
2502
2513
                                        char *str = but->drawstr;
 
2514
                                        but->drawstr[0] = '\0';
2503
2515
 
2504
2516
                                        if (but->modifier_key & KM_SHIFT)
2505
2517
                                                str += BLI_strcpy_rlen(str, "Shift ");
2512
2524
 
2513
2525
                                        (void)str; /* UNUSED */
2514
2526
                                }
2515
 
                                else
2516
 
                                        strcat(but->drawstr, "Press a key  ");
 
2527
                                else {
 
2528
                                        BLI_strncpy(but->drawstr, "Press a key", UI_MAX_DRAW_STR);
 
2529
                                }
2517
2530
                        }
2518
2531
                        else
2519
2532
                                BLI_strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
2525
2538
                        break;
2526
2539
                default:
2527
2540
                        BLI_strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
 
2541
                        break;
2528
2542
                
2529
2543
        }
2530
2544
 
2861
2875
        }
2862
2876
 
2863
2877
        /* keep track of UI_interface.h */
2864
 
        if      (ELEM8(but->type, BLOCK, BUT, LABEL, PULLDOWN, ROUNDBOX, BUTM, SCROLL, SEPR)) {}
 
2878
        if      (ELEM9(but->type, BLOCK, BUT, LABEL, PULLDOWN, ROUNDBOX, LISTBOX, BUTM, SCROLL, SEPR)) {}
2865
2879
        else if (but->type >= SEARCH_MENU) {}
2866
2880
        else but->flag |= UI_BUT_UNDO;
2867
2881
 
3019
3033
        but->rnapoin = *ptr;
3020
3034
        but->rnaprop = prop;
3021
3035
 
3022
 
        if (RNA_property_array_length(&but->rnapoin, but->rnaprop))
 
3036
        if (RNA_property_array_check(but->rnaprop))
3023
3037
                but->rnaindex = index;
3024
3038
        else
3025
3039
                but->rnaindex = 0;
3959
3973
{
3960
3974
        wmEvent event;
3961
3975
        
3962
 
        event = *(win->eventstate);
 
3976
        wm_event_init_from_window(win, &event);
 
3977
 
3963
3978
        event.type = EVT_BUT_OPEN;
3964
3979
        event.val = KM_PRESS;
3965
3980
        event.customdata = but;