Bitmap of graphics.lineBitmapStyle treat as View with Mediator

iamable's Avatar

iamable

11 Mar, 2014 10:46 AM

Hey there,

I have a problem and I hope somewhere in this outer space is any help ;-)

I am drawing a line while runtime. This line has a lineBitmapStyle. This BitmapData is stored in a Sprite where I am adding different Shapes to one.
Now to my question: How can I mediate those Shapes or the Sprite where the BitmapData is stored in?
The problem is these are never added to stage and thatswhy Mediators onRegister() is never executed because they are just a style.

Thanks

  1. Support Staff 1 Posted by Ondina D.F. on 11 Mar, 2014 12:30 PM

    Ondina D.F.'s Avatar

    Hello,

    Create a class that extends Shape, say SomeShape and a mediator SomeShapeMediator.
    SomeShape would draw the lines and set the lineBitmapStyle. When you add SomeShape to the stage inside your Sprite, SomeShapeMediator is created. Each SomeShape added to the stage will have its own mediator.

    The problem is these are never added to stage

    The Sprite and Shape must be added to the stage, if you want to see your drawings. You mean lineBitmapStyle? You surely don't want to mediate the styles.

    Ondina

  2. 2 Posted by iamable on 12 Mar, 2014 07:47 AM

    iamable's Avatar

    Hey thank you for replying.
    I think you dont get what I mean.

    I will try again to explain.

    There is an object added to the stage which is drawing lets say a circle. this circle should have a bitmap filling. for that bitmap filling i would like to have a view called Filling. and i would like to mediate this filling with FillingMediator because that filling is changing while runtime based on model data. but mediating that filling isnt possible because the filling is only visible because of that bitmapStyle for the circle. it is never added to the stage.

  3. Support Staff 3 Posted by Ondina D.F. on 12 Mar, 2014 09:39 AM

    Ondina D.F.'s Avatar

    I don't think that what you want is a mediator for your 'filling'. Your Filling is rather a property of the Circle.

    and i would like to mediate this filling with FillingMediator because that filling is changing while runtime based on model data.

    I would probably solve this like so:
    A view, SomeShape, which is drawing the circle, would expose an API, that SomeShapeMediator would access, to pass a VO (value object) with the modified styles. When the model's data changes, it dispatches an event with the style vo as a payload, and SomeShapeMediator, listening for that event, passes the vo to SomeShape.

    Another option is using the viewProcessorMap, which allows you to inject properties into views. [https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...]
    Let's say you had a VO with different properties, color, position, etc, called ShapeStyle, that you want to inject into a view, called SomeShape. SomeShape, extending a Shape or a Sprite, is drawing a circle and it uses the ShapeStyle's properties to set the styles of the circle.

    The mappings would look like this:

    injector.map(ShapeStyle).asSingleton();
    
    viewProcessorMap.map(SomeShape).toInjection();//in order to be injected with ShapeStyle
    
    mediatorMap.map(SomeShape).toMediator(SomeShapeMediator);
    

    If you insist on having a mediator for the filling, you can, again, use the viewProcessorMap to map it like this:

    viewProcessorMap.map(ShapeStyle).toProcess(new MediatorCreator(ShapeStyleMediator));
    
    injector.map(ShapeStyle).asSingleton();
    
    viewProcessorMap.map(SomeShape).toInjection();
    
    mediatorMap.map(SomeShape).toMediator(SomeShapeMediator);
    

    But, since ShapeStyle won't be added to the stage, you'd have to manually process and unprocess it, probably inside of SomeShapeMediator, where you would also inject ShapeStyle:

    viewProcessorMap.process(shapeStyle);
    

    and unprocess it, when/if SomeShape leaves the stage.

    Is that what you wanted?

  4. 4 Posted by iamable on 12 Mar, 2014 10:52 AM

    iamable's Avatar
    I would probably solve this like so: A view, SomeShape, which is drawing the circle, would expose an API, that SomeShapeMediator would access, to pass a VO (value object) with the modified styles. When the model's data changes, it dispatches an event with the style vo as a payload, and SomeShapeMediator, listening for that event, passes the vo to SomeShape.

    Great thank you. Good idea. It's working fine

  5. Support Staff 5 Posted by Ondina D.F. on 12 Mar, 2014 11:43 AM

    Ondina D.F.'s Avatar

    You're welcome!

    N.B. I've just noticed that the mappings in my example were for robotlegs version 2, whilst you're using rl1.

    I'm going to close this discussion, but feel free to re-open it, if need be.

  6. Ondina D.F. closed this discussion on 12 Mar, 2014 11:43 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac