Parts and Parameters question

SighmanSighman Posts: 56

I have a resource PMap with two properties that I want to keep in sync. Each has an associated UI widget (a slider bar and a textbox).

When I move the slider I want to update the textbox and visa versa.

I cannot use the combined slider/value feature because the ratio is not linear and the built in log scaling does not meet my needs. There are other reasons too like not enough digits.

I figure it has something to do with the IMCPart interface but I have no experience with it.

Has anyone tried updating a UI element like this?

Thanks

Comments

  • Eric WinemillerEric Winemiller Posts: 84
    edited December 1969

    Hey Sighman,

    I have in a few places just updated the data buffer in ExtensionDataChanged and seen it reflected on the UI. In Ground Control I take some stuff and generate a string that is displayed on the UI.

    I have a vague recollection that it doesn't work from all plug-ins (e.g. works in primitives, but didn't work in lights or something like that), but I don't remember the details and it's probably worth a try in yours.

    Extension data changed.

    MCCOMErr DEMPrim::ExtensionDataChanged()
    {
     lastPreviewMesh = NULL;
     if (fData.sResolution.Length() == 0)
     {
      TMCString255 widthstr, heightstr;
      widthstr.FromInt32(maxY);
      heightstr.FromInt32(maxX);
    
      fData.sResolution = widthstr + TMCString255(" x ") + heightstr;
     }
     uint32 lUSamples, lVSamples;
     TMCString255 facets;
    
     lUSamples = fData.fResolution * maxX;
     lVSamples = fData.fResolution * maxY;
    
     facets.FromInt32(lUSamples * lVSamples * 2);
    
     fData.facets = "";
     
     if (fData.adaptiveMesh)
      fData.facets = TMCString255("Up to ");
     
     fData.facets += facets + TMCString255(" facets");
     
     return MC_S_OK;
    }
    

    I also have just set values in my data buffer during HandleEvent. That seems to work just fine in Enhance:C when I reset to default values when changing the shader type in a combo. Same caveat applies; vague recollection of it not working in all plug-in types, but don't remember the details.

    You can keep track of previous values (so you know which one changed) as private members of your class. Just make sure to copy them around when your object is cloned. I've done similar things as "most recent settings" kinds of functions. Another option is listen for the specific kMsg_PartValueChanged message on the two UI elements in your HandleEvent, read it, then change the other.

    Listening to the event.

    
    MCCOMErr EnhanceCWood::HandleEvent(MessageID message, IMFResponder* source, void* data)
    {
     IDType sourceID;
     TMCCountedPtr sourcePart;
     
     source->QueryInterface(IID_IMFPart, (void**) &sourcePart;);
     ThrowIfNil(sourcePart);
     sourceID = sourcePart->GetIMFPartID();
     if (
      (sourceID == 'FUNC' &&message; == EMFPartMessage::kMsg_PartValueChanged )
       || message == kMsg_CUIP_ComponentAttached
      ) 
     {
      TMCCountedPtr parentPart;
      TMCCountedPtr tempPart;
      ActionNumber newValue;
      if (message == kMsg_CUIP_ComponentAttached)
      {
       parentPart = sourcePart;
       newValue = fData.Function;
      }
      else
      {
       sourcePart->GetPartParent(&parentPart;);
       ThrowIfNil(parentPart);
       sourcePart->GetValue(&newValue;, kActionValueType);
       setDefaultValues(newValue);
      }
    ...
    
    void EnhanceCWood::setDefaultValues(ActionNumber newValue)
    {
     switch (newValue)
     {
     case eoEasyWood:
      fData.Octaves = 4.0f;
      fData.Frequency = 4.0f;
      fData.Magnitude = 0.25f;
      fData.Detail = 2;
      break;
     case eoHardWood:
      fData.Grain = 0.25f;
      fData.Ringiness = 2.5f;
      break;
    ...
    


    Good luck,

  • SighmanSighman Posts: 56
    edited December 1969

    Once more you come to my rescue. Thanks again, Eric.

Sign In or Register to comment.