Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Problem with GeUserArea

    Scheduled Pinned Locked Moved SDK Help
    5 Posts 0 Posters 445 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

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

      On 08/02/2011 at 10:09, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   11.5 
      Platform:   Windows  ;   
      Language(s) :   C.O.F.F.E.E  ;

      ---------
      Hi Guys,

      I added a dialog to my OffsetRandomizer coffee-plugin and wanted to add a UserArea, so i can show an Image in the dialog.
      But i ran into some trouble, i can't actually figure out where the problem is.

      There is a banner.jpg in the 'res'-folder.

        
      const var PLUGIN_BANNER = "res/banner.jpg";  
        
      LoadBitmap(path,resx,resy) {  
        var fn = GeGetRootFilename();   
        fn->RemoveLast();               
        fn->AddLast(path);    
        var bm = new(BaseBitmap, resx, resy);  
        bm->Load(fn);   
        return bm;  
      }  
        
      class UserArea : GeUserArea {  
      private:  
        var bm;  
      public:  
        UserArea(id,dialog);  
        Init();  
        GetUserWidth();  
        GetUserHeight();  
        Draw(x1,y1,x2,y2);  
      }  
      UserArea::UserArea(id,dialog) {  
        super(id,dialog);  
      }  
      UserArea::Init() {  
        bm = LoadBitmap(PLUGIN_BANNER,1,1);  
        Redraw();  
      }  
      UserArea::GetUserWidth() {  
        return 288;  
      }  
      UserArea::GetUserHeight() {  
        return 52;  
      }  
      UserArea::Draw(x1,y1,x2,y2) {  
        OffScreenOn();  
        SetClippingRegion(x1,y1,x2,y2);  
        DrawBitmap(bm, 0, 0, 288, 52, 0, 0, 288, 52, BMP_NORMAL);  
      }  
        
      class OffsetRandomizerDialog : GeDialog {  
      private:  
        var banner;  
      public:  
        OffsetRandomizerDialog();  
        CreateLayout();  
        Init();  
        Command(id,msg);  
        CoreMessage(id,msg);  
        RestoreLayout(secret);  
      }  
      OffsetRandomizerDialog::OffsetRandomizerDialog() {   
        banner = null;  
        super(PLUGIN_ID);  
      }  
      OffsetRandomizerDialog::CreateLayout() {  
        LoadDialogResource(OR_DIALOG,LoadResource(),1);  
        banner = new(UserArea, OR_UA, this);  
        return true;  
      }  
      OffsetRandomizerDialog::Init() {  
        Enable(OR_UA,true);  
        return true;  
      }
      

      The rest of the code should not be interesting for you, because it doesn't have to do anything with the Userarea.
      What I recive, is a black field that obtains previous used elements. Hard to explain, better show you.

      Watch Video here

      Any Idea why this is happening ?

      I also have a 2nd question. In ResEdit one can set an elements dimension. But it's obviously not in pixels. I sized my UserArea in ResEdit to 480x40, but on my screen it's just 288x52 pixels.

      Thanks in advance, nux

      //edit:
      Ah, and when i call the Draw(); funktion within the CreateLayout of the Dialog, the console tells me that bm is null.. ?!

      banner = new(UserArea,OR_UA,this);  
      banner->Draw(0,0,480,50);  
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        On 10/02/2011 at 00:02, xxxxxxxx wrote:

        Ok, now I found the problem. I thought a new Bitmap with resolution 1x1  is loaded in original Size, but it isn't.

        new(BaseBitmap,1,1);
        

        My image has got a size of 288x52 pixels. Also, the size must be substrated with 1, because the Bitmap is an array of pixels, starting with 0. 😉

        new(BaseBitmap,287,51);
        

        Same in the UserArea in the overloaded functions 'GetUserWidth' and 'GetUserHeight'

        UserArea::GetUserWidth() {  
            
            
                return 287;  
            }  
            UserArea::GetUserHeight() {  
              return 51;  
            }
        

        greets, nux

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          On 10/02/2011 at 06:15, xxxxxxxx wrote:

          Originally posted by xxxxxxxx

          Ok, now I found the problem. I thought a new Bitmap with resolution 1x1  is loaded in original Size, but it isn't.

          new(BaseBitmap,1,1);
          

          It actually is.

          My image has got a size of 288x52 pixels. Also, the size must be substrated with 1, because the Bitmap is an array of pixels, starting with 0. 😉

          new(BaseBitmap,287,51);
          

          No, if the bitmap is 512x512 it will be initialized with 512x512. In any case it's not necessary. You can simply use:

          new(BaseBitmap,1,1);
          

          Same in the UserArea in the overloaded functions 'GetUserWidth' and 'GetUserHeight'

          UserArea::GetUserWidth() {  
           
            return 287;  
          }  
          UserArea::GetUserHeight() {  
            return 51;  
          }
          

          No, the real bitmap width and height must be returned.

          Please have a look at the following simple example of a dialog with a user area which draws a bitmap.

            
          // be sure to use a unique ID obtained from www.plugincafe.com  
          var PLUGIN_ID = 910000;  
          // be sure to use a unique ID obtained from www.plugincafe.com  
            
            
            
          // definition of my user area  
          class MyUserArea : GeUserArea  
          {  
            private:  
                var bmp;  
            
            public:  
                MyUserArea(id,dialog);  
                Init();  
                GetUserWidth();  
                GetUserHeight();  
            
                Draw(x1,y1,x2,y2);  
          }  
            
          MyUserArea::MyUserArea(id,dialog)  
          {  
            super(id,dialog);  
            
            bmp = new(BaseBitmap, 1, 1);  
              
            var fn = GeGetRootFilename();  
            fn->RemoveLast();  
            fn->AddLast("res");  
            fn->AddLast("icon.tif");  
            bmp->Load(fn);  
              
            println(bmp->GetWidth());  
            println(bmp->GetHeight());  
          }  
            
          MyUserArea::Init()  
          {  
          }  
            
          MyUserArea::GetUserWidth()  
          {  
            return bmp->GetWidth();  
          }  
            
          MyUserArea::GetUserHeight()  
          {  
            return bmp->GetHeight();  
          }  
            
          MyUserArea::Draw(x1,y1,x2,y2)  
          {  
            OffScreenOn();  
            SetClippingRegion(x1,y1,x2,y2);  
              
            DrawBitmap(bmp,x1,y1,x2,y2,x1,y1,x2,y2,BMP_NORMAL);  
              
            ClearClippingRegion();  
          }  
            
            
          // definition of my Dialog class  
          class MyDialog : GeDialog  
          {  
            private:  
                var ua;  
            
            public:  
                MyDialog();  
            
                CreateLayout();  
                Init();  
                Command(id,msg);  
          }  
            
          MyDialog::MyDialog()  
          {  
            super(PLUGIN_ID);  
            ua=NULL;  
          }  
            
          MyDialog::CreateLayout()  
          {  
            SetTitle("Draw Bitmap");  
            
            AddUserArea(5000,BFH_FIT|BFV_FIT,0,0);  
            
            ua = new(MyUserArea,5000,this);  
            
            return TRUE;  
          }  
            
          MyDialog::Init()  
          {  
          }  
            
          MyDialog::Command(id,msg)  
          {  
          //    switch (id)  
            {  
            }  
          }  
            
            
          class MyMenuPlugin : MenuPlugin  
          {  
            public:  
                MyMenuPlugin();  
            
                GetID();  
                GetName();  
                GetHelp();  
                Execute(doc);  
            
                RestoreLayout(secret,subid);  
          }  
            
          MyMenuPlugin::MyMenuPlugin()  
          {  
            super();  
          }  
            
          MyMenuPlugin::GetID()  
          {  
            return PLUGIN_ID;  
          }  
            
          MyMenuPlugin::GetName()  
          {  
            return "Draw Bitmap";  
          }  
            
          MyMenuPlugin::GetHelp()  
          {  
            return "Shows drawing of user areas";  
          }  
            
          var d;  
            
          MyMenuPlugin::Execute(doc)  
          {  
            d->Open(TRUE,-1,-1);  
          }  
            
          MyMenuPlugin::RestoreLayout(secret,subid)  
          {  
            if (!d) d = new(MyDialog);  
            d->RestoreLayout(secret);  
          }  
            
            
          main()  
          {  
            d = new(MyDialog);  
            
            Register(MyMenuPlugin);  
          }  
          

          cheers,
          Matthias

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

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

            On 11/02/2011 at 00:07, xxxxxxxx wrote:

            DrawBitmap(bmp,x1,y1,x2,y2,x1,y1,x2,y2,BMP_NORMAL);
            
            So i don't have to insert the Bitmaps size here ?  
              
            >  
            

            No, if the bitmap is 512x512 it will be initialized with 512x512. In any case it's not necessary. You can simply use:

            So i was right. A friend told me this. I actually didnt try it again, since it works, with 'new(BaseBitmap,1,1);'  
              
            Thanks for your correction!  
            I could only think of theese reasons but I was not really sure. There was no example in the SDK, or am I blind ?  
            It would be great if Maxon would add this one, I think that would have answered my questions and problems earlier.  
              
            Cheers, nux  
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

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

              On 11/02/2011 at 02:44, xxxxxxxx wrote:

              Originally posted by xxxxxxxx

              DrawBitmap(bmp,x1,y1,x2,y2,x1,y1,x2,y2,BMP_NORMAL);
              

              So i don't have to insert the Bitmaps size here ?

              Only as long as the user area and the bitmap have the same dimensions. The advantage of passing the Draw() area parameters to DrawBitmap is that only this partial area is redrawn. If you are not sure about it pass 0,0 to GetWidth()-1,GetHeigth()-1 to DrawBitmap.

              cheers,
              Matthias

              1 Reply Last reply Reply Quote 0
              • First post
                Last post