Dialog Group change width



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 10/04/2007 at 17:57, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R8.2-R10 
    Platform:   Windows  ; Mac  ;  Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    This is my code for updating a dynamic 'thumbnail' scroll group. In CreateThumbnailGroup(), you'll see that I prepass the folder items to get the maximum width for the ScrollGroup GROUP_THUMBNAIL_SCROLL. Of course, this endeavor doubles the time it takes to load all of the bitmaps (as they are loaded twice - once for calculation, once to set the BitmapButton). Is there any way that the group's width could be set after the fact to avoid the prepass? Or would you suggest just getting the count of elements that 'might' have a bitmap and preallocating an array of BaseBitmap which is then disposed of upon exiting CreateThumbnailGroup()?

    // Relayout Thumbnail Group  
    //*---------------------------------------------------------------------------*  
    Bool IPPDialog::LayoutThumbnailGroup()  
    //*---------------------------------------------------------------------------*  
    {  
         if (functableExplorer.inDragMode())     return TRUE;  
      
         SetMousePointer(MOUSE_BUSY);  
         LayoutFlushGroup(GROUP_THUMBNAIL);  
         CreateThumbnailGroup(FALSE);  
         LayoutChanged(GROUP_THUMBNAIL);  
         SetMousePointer(MOUSE_NORMAL);  
      
         // Reset ScrollArea to top/center  
         LONG     x;  
         GetVisibleArea(GROUP_THUMBNAIL_SCROLL, &x;, &thumb;_y1, &thumb;_x2, &thumb;_y2);  
         SetVisibleArea(GROUP_THUMBNAIL_SCROLL, 0, 0, thumb_x2-x, thumb_y2-thumb_y1);  
      
         return TRUE;  
    }  
    // Create Thumbnail Group of BitmapButtons  
    //*---------------------------------------------------------------------------*  
    Bool IPPDialog::CreateThumbnailGroup(BOOL inittg)  
    //*---------------------------------------------------------------------------*  
    {  
         // Fully Collapse Thumbnail Group  
         if (thumbColumns == 0)  
         {  
              // ScrollGroup to handle long file names  
              ScrollGroupBegin(GROUP_THUMBNAIL_SCROLL,BFH_CENTER|BFV_SCALEFIT,SCROLLGROUP_NOSCROLLER,1,0);  
              GroupEnd();  
              return TRUE;  
         }  
      
         // Get Widest Thumbnail Image  
         LONG     w;  
         folder =               root.GetSelectedFolder();  
         if (folder && settings->GetAutoThumbWidth() && !inittg)  
         {  
              LONG     thumbWidth =     91;  
              w =                             91;  
              for (RuntimeItem* item = folder->GetChild(); item; item = item->GetNext())  
              {  
                   if (item->IsTypeOf(ITEMTYPE_FOLDER))     continue;  
                   iconType =                                        item->GetIconType();  
                   if (iconType < RTICON_RSR)                    continue;  
                   if (iconType > RTICON_FORK)  
                   {  
                        bitmap->Init(item->GetIcon());  
                        w =     bitmap->GetBw();  
                        bitmap->FlushAll();  
                        if (w > thumbWidth)     thumbWidth =     w;  
                   }  
                   else if (ReadRSR(item))  
                   {  
                        bitmap->Init(tmpthumbFN);  
                        w =     bitmap->GetBw();  
                        bitmap->FlushAll();  
                        if (w > thumbWidth)     thumbWidth =     w;  
                   }  
                   clipmap->BeginDraw();  
                   w =     clipmap->TextWidth(item->GetDisplayName());  
                   clipmap->EndDraw();  
                   if (w > thumbWidth)     thumbWidth =     w;  
              }  
              clipmap->BeginDraw();  
              w =     clipmap->TextWidth(GeLoadString(IPPS_THUMBNAILS)+" [Cols: "+LongToString(thumbColumns)+"]");  
              clipmap->EndDraw();  
              if (w > thumbWidth)     w = SizePix(w+12);  
              else                    w =     SizePix(thumbWidth+12);  
         }  
         else  
         {  
              clipmap->BeginDraw();  
              w =     clipmap->TextWidth(GeLoadString(IPPS_THUMBNAILS)+" [Cols: "+LongToString(thumbColumns)+"]");  
              clipmap->EndDraw();  
              if (w <= 91)     w = SizePix(103);  
              else               w =     SizePix(w+12);  
         }  
      
         // ScrollGroup to handle long file names  
         ScrollGroupBegin(GROUP_THUMBNAIL_SCROLL,BFH_CENTER|BFV_SCALEFIT,SCROLLGROUP_HORIZ|SCROLLGROUP_VERT|SCROLLGROUP_BORDERIN,w*thumbColumns,0);  
         if (inittg || !folder)  
         {  
              GroupEnd();  
              return TRUE;  
         }  
         // Interior Group to handle gridding of multiple columns  
         GroupBegin(GROUP_THUMBNAIL_INTERIOR,BFH_CENTER|BFV_SCALEFIT,thumbColumns,0,blankStr,BFV_GRIDGROUP_EQUALCOLS|BFV_GRIDGROUP_EQUALROWS);  
      
         StopAllThreads();  
      
         UINT     poserType =     folder->GetPoserType();  
         // v1.4.3: For Materials library, skip Frame check  
         if (poserType == POSERTYPE_MATERIAL)  
         {  
              LONG     id;  
              // Folder's Thumbnails  
              for (RuntimeItem* item = folder->GetChild(); item; item = item->GetNext())  
              {  
                   if (item->IsTypeOf(ITEMTYPE_FOLDER))     continue;  
                   iconType =                                        item->GetIconType();  
                   if (iconType == RTICON_NONE)               continue;  
                   id =                                             item->GetID();  
                   // BitMap Button  
                   bmbutton =          (BitmapButtonCustomGui* )AddCustomGui(id,CUSTOMGUI_BITMAPBUTTON,blankStr,BFH_CENTER|BFV_CENTER,thumb_x1,thumb_x1,thumb_bc);  
                   if (!bmbutton)     return ErrorException::Throw(EE_DIALOG, GeLoadString(IPPERR_MEMORY_TEXT), "IPPDialog.CreateThumbnailGroup.bmbutton");  
                   // Group for thumbnail and text  
                   GroupBegin(0,BFH_CENTER|BFV_TOP,0,2,blankStr,0);  
                   GroupBorderSpace(4,4,4,4);  
                   if (iconType > RTICON_FORK)  
                   {  
    #ifdef     XCODE  
                        // v1.2.2:     Fix for masked PNG images in UB plugin  
                        if (iconType == RTICON_PNG)  
                        {  
                             bitmap->Init(item->GetIcon());  
                             bitmap->RemoveChannel(bitmap->GetChannelNum(0));  
                             bmbutton->SetImage(bitmap, TRUE, FALSE);  
                             bitmap->FlushAll();  
                        }  
                        else bmbutton->SetImage(item->GetIcon());  
    #else  
                        bmbutton->SetImage(item->GetIcon());  
    #endif  
                   }  
                   else if (ReadRSR(item))  
                   {  
                        bitmap->Init(tmpthumbFN);  
                        bitmap->RemoveChannel(bitmap->GetChannelNum(0));  
                        bmbutton->SetImage(bitmap, TRUE, FALSE);  
                        bitmap->FlushAll();  
                   }  
                   else  
                   {  
                        item->SetIconType(RTICON_BLANK);  
                        bmbutton->SetImage(nothumbBitmap, FALSE, FALSE);  
                   }  
                   // Item Name  
                   //AddStaticText(0,flags,0,0,item->GetDisplayName(),BORDER_NONE);  
                   AddButton(-id, BFH_CENTER|BFV_CENTER, 0, 0, item->GetDisplayName());  
                   GroupEnd();  
              }  
         }  
         else  
         {  
              String     ttitle;  
              LONG     id;  
              ippLoader.InitKeyCount(poserType);  
              // Folder's Thumbnails  
              for (RuntimeItem* item = folder->GetChild(); item; item = item->GetNext())  
              {  
                   if (item->IsTypeOf(ITEMTYPE_FOLDER))     continue;  
                   iconType =                                        item->GetIconType();  
                   if (iconType == RTICON_NONE)               continue;  
                   id =                                             item->GetID();  
                   // BitMap Button  
                   bmbutton =          (BitmapButtonCustomGui* )AddCustomGui(id,CUSTOMGUI_BITMAPBUTTON,blankStr,BFH_CENTER|BFV_CENTER,thumb_x1,thumb_x1,thumb_bc);  
                   if (!bmbutton)     return ErrorException::Throw(EE_DIALOG, GeLoadString(IPPERR_MEMORY_TEXT), "IPPDialog.CreateThumbnailGroup.bmbutton");  
                   // Group for thumbnail and text  
                   GroupBegin(0,BFH_CENTER|BFV_TOP,0,2,blankStr,0);  
                   GroupBorderSpace(4,4,4,4);  
                   if (iconType > RTICON_FORK)  
                   {  
    #ifdef     XCODE  
                        // v1.2.2:     Fix for masked PNG images in UB plugin  
                        if (iconType == RTICON_PNG)  
                        {  
                             bitmap->Init(item->GetIcon());  
                             bitmap->RemoveChannel(bitmap->GetChannelNum(0));  
                             bmbutton->SetImage(bitmap, TRUE, FALSE);  
                             bitmap->FlushAll();  
                        }  
                        else bmbutton->SetImage(item->GetIcon());  
    #else  
                        bmbutton->SetImage(item->GetIcon());  
    #endif  
                   }  
                   else if (ReadRSR(item))  
                   {  
                        bitmap->Init(tmpthumbFN);  
                        bitmap->RemoveChannel(bitmap->GetChannelNum(0));  
                        bmbutton->SetImage(bitmap, TRUE, FALSE);  
                        bitmap->FlushAll();  
                   }  
                   else  
                   {  
                        item->SetIconType(RTICON_BLANK);  
                        bmbutton->SetImage(nothumbBitmap, FALSE, FALSE);  
                   }  
                   // Item Name - Get Frames for animated poses  
                   ttitle =     item->GetDisplayName()+ippLoader.ParseKeyCount(item->GetFilename());  
                   //AddStaticText(0,flags,0,0,ttitle,BORDER_NONE);  
                   AddButton(-id, BFH_CENTER|BFV_CENTER, 0, 0, ttitle);  
                   GroupEnd();  
                   ippLoader.FlushSimple();  
              }  
              ippLoader.FlushTemp();  
         }  
      
         GroupEnd();     // Interior Group  
         GroupEnd();     // Scroll Group  
      
         // Add "Save Pose" button to bottom of Thumbnails group  
         switch (poserType)  
         {  
              case POSERTYPE_POSE:  
              case POSERTYPE_FACE:  
              case POSERTYPE_HAND:  
              case POSERTYPE_CAMERA:  
              case POSERTYPE_LIGHT:  
              case POSERTYPE_MATERIAL:  
                   GroupBegin(0L,BFH_CENTER|BFV_BOTTOM,2,2,blankStr,BFV_GRIDGROUP_EQUALCOLS|BFV_GRIDGROUP_EQUALROWS);  
                        AddButton(IP_RUNTIME_ADDPOSE,     BFH_LEFT|BFV_CENTER, 0, 0, String("+"));  
                        AddStaticText(0, BFH_LEFT|BFV_CENTER, 0, 0, GeLoadString(IPPS_RUNTIME_ADDPOSE), BORDER_NONE);  
                        AddButton(IP_RUNTIME_REMPOSE,     BFH_LEFT|BFV_CENTER, 0, 0, String("-"));  
                        AddStaticText(0, BFH_LEFT|BFV_CENTER, 0, 0, GeLoadString(IPPS_RUNTIME_REMPOSE), BORDER_NONE);  
                   GroupEnd();  
                   break;  
              case POSERTYPE_FIGURE:  
              case POSERTYPE_HAIR:  
              case POSERTYPE_PROP:  
                   GroupBegin(0L,BFH_CENTER|BFV_BOTTOM,2,0,blankStr,BFV_GRIDGROUP_EQUALCOLS|BFV_GRIDGROUP_EQUALROWS);  
                        AddButton(IP_RUNTIME_REMPOSE,     BFH_LEFT|BFV_CENTER, 0, 0, String("-"));  
                        AddStaticText(0, BFH_LEFT|BFV_CENTER, 0, 0, GeLoadString(IPPS_RUNTIME_REMPOSE), BORDER_NONE);  
                   GroupEnd();  
              default:  
                   break;  
         };  
      
         StatusClear();  
         return TRUE;  
    }
    

    Thanks,



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/04/2007 at 23:56, xxxxxxxx wrote:

    To respond to this myself, I could not find a way to 'reset' the ScrollGroup width after the fact. There might be a way, but the docs are inprecise about how this could be done.

    Instead, the BaseBitmap array was used to store all of the bitmaps during the width calculation phase and then these set to the BitmapButtons instead of reconstructing the image path and reloading the image into a generic bitmap. This means that the width calculation variation is about as fast as the non-calculation instead of taking twice the time.

    That's about as good as it gets. Now if the developers would make image loading into bitmaps a little faster (as that is my main bottleneck here from testing) users of my plugin would be elated. :)

    Thanks,


Log in to reply