BitmapData with Scale9Grid - apache-flex

I have a Skin for SkinnableContainer.
Skin contains only the original contentGroup and s:BitmapImage as background.
Background image stretchers out according to width and height content.
The used image is .png with transparent regions.
To create hitarea, I used this algorithm:
http://www.webverwirklichung.com/en/blog/programming/flex/creating-hitarea-png-image-transparent-alpha-regions-flex
Everything's working fine until I start to stretch the SkinnableContainer (along with the image in the skin).
I have a scale9Grid for the image.
The problem is, that when stretching the image, the bitmapData of the image is still the same (same width and height). Therefore I need to somehow obtain the bitmapData of the image for the scale9Grid application.
The background of the component is an image, which has some transparent areas. It is only possible to click on the visible part of the image. The image will stretch according to the content in contentGroup.
Need an advice, please.

How about using the BitmapData.draw() method?
After the container is resized and the 9 slice scaling has been applied (or whatever the appropriate trigger is) do:
var b:BitmapData = new BitmapData(container.width, container.height);
b.draw(container);
Then use this new bitmap with the algorithm that creates the hit area.

Related

Responsive CheckBox JAVAFX

This is my first javaFX project. The project I'm working on includes a feature where the application window can be resized. Upon resizing the window, I expect all objects in my window to increase proportionally according to the window resize. I am not getting this to work with the "CheckBox" Objects.
As you can see below highlighted in red, a CheckBox object is shown before and after a window resize. Before the resize the red checkbox nicely fits in the green box, but after the resize, the red checkbox is the correct (scaled) width, but did not increase in height as I'd expect. Where should I begin my effort to make my CheckBox objects more vertically responsive?
Minimized
Maximized
As you can see (IN RED), the CheckBox scales horizontally as I expect, but it doesn't scale vertically to occupy the remaining space!
After a lot more research and helpful responses, I gathered a solution that works.
A "DoubleProperty" object is made, and binded to the width of the container holding my checkboxes. Call this container, "dryLeafGridPane" for example.
DoubleProperty checkboxFontSize = new SimpleDoubleProperty(10);
checkboxFontSize.bind((dryLeafGridPane.widthProperty().divide(36)));
The .divide(36) scales the CheckBox's font size to 1/36 the gridpane's width.
Finally, I just add the new font size using CSS.
dryLeafGridPane.styleProperty().bind(Bindings.concat("-fx-font-size: ", checkboxFontSize.asString()));
Here is a gif of the (slightly more) responsive app!
You can choose to increase the font size on the root pane when you go full screen. For example:
rootPane.setStyle("-fx-font-size: 150%;");
That isn't perfect though... it seems the size of the box that is checked doesn't scale with the font.

MURA: getImageURL small size cuts off the image

The small size creates an image too large to fit in the box. Is there a way by which the image can be wrapped completely?
I am doing
<div class="catimgback">
<img src="#arguments.item.getImageURL(size='arguments.size',width=arguments.width,height=arguments.height)#" alt="#htmlEditFormat(arguments.item.getValue('title'))#" class="catimg" />
</div>
Where arguments.width = 163px; arguments.height=163px; and arguments.size = small
If i make catimgback's style=height:100% then all goes well. Also, I played with keeping the size to be custom and giving custom width and height but could not get the images to work. all the small size images gets cut off.
I think you may be confused as to how getImageURL() works. The only time you need to pass in the height or width arguments, is if you pass in size='custom' or omit the size attribute altogether.
Also, when you use size='custom', the image gets cropped automatically based on the dimensions of the image that's been uploaded. So, in your case, you want a square image ... but what if the image that's been uploaded is not exactly square, maybe it's a rectangle. So, in that case, Mura starts at the very center of the image, then scales out from there to the outer most boundaries. If the image were a vertical rectangle, you can imagine then that the top and bottom parts of the rectangle won't make the cut. Conversely, if the image were a horizontal rectangle, then the left and right edges of the image won't make it into the cut.
What you really want in this case is a pre-defined image size called catimg with a height and width attribute of 163px. To create this:
Go to Site Config > Edit Site from the Admin area
Click the Images tab
Towards the bottom, click Add Custom Image Size
Enter a Name (for example, catimg)
Enter the Height
Enter the Width
Click Save (You now have a custom image size that can be used for any content items)
Go to the Site Manager, and add/edit a content item
If editing an existing content item that already has an image, click the crop marks to get to the Image Details screen. Otherwise, select an image to upload, and Publish.
From the Image Details screen, scroll down to the custom image size you've created, and you can now Re-Crop your image to select your desired image region.
Now, anytime you call getImageURL(size='catimg'), Mura will use this specific image to display.
Cheers!

How do I set the background position and size of a background image I set with setBackgroundBrush?

I used Qt's setBackgroundBrush function to set a background image. How do I resize the image or set it's position?
For example, I'd like it to be centered and for it to fill the entire region.
I don't think it's possible with setBackgroundBrush, but you can also set background image with style sheets if you want more control. Sample code from Qt docs:
QLabel {
background-image: url(dense6pattern.png);
background-repeat: repeat-xy;
}
More info available here.

2 vertical css sprite images but different result

I created new sprite image using Instant Sprite, sprite_main.png and replaced old sprite image created by SpritMe, spriteme1.png.
I just changed image path and used given background positions only but the result is disappointing with sprite_main.png. I don't understand what happen but is that because I added another 20+ icons to the sprite image?
http://fiddle.jshell.net/6TaQt/40/
Background positions result is disappointing with sprite_main.png because sprite_main.png's height are different with (higher than) spriteme1.png's height and have defferent position for each icons between both images. So, you must re-calculate top background position.
Here my revision background position for sprite_main.png : http://fiddle.jshell.net/Vrf7g/

how can move the child only inside the parent?

Recently I worked in a project using Flex. Its a Photo editing project. I have took a Canvas and take a image in that canvas using the code canvas.addChild(image) . Now i can move the image freely by using moving code. The image move inside the canvas and outside the canvas. I want to move the image/child only inside the canvas not outside. How can i do this?
There are two ways to do this:
Bounding Rectangle
Scroll Rectangle (or Mask)
Assuming your "moving code" is something like an Event.ENTER_FRAME handler initialized onClick, you want to make it so the image can't leave the bounds of the parent Canvas.
The first case (bounding rectangle) will allow you to drag the image within the retangle but you will always be able to see the whole image. This is how Image croppers work.
To create a bounding rectangle, you'll have to write a fairly detailed method, but the idea behind it is simple. Just get the bounding rectangle from the canvas, and don't let the image.x go below 0 and don't let image.x + image.width go beyond canvas.width. Same with height. Here's a sample Image Cropper in Flex (and the source). Check out how they did it for details.
The second case (scroll rectangle) would allow you to create more of a pan/zoom like container like you see on this Flex Pan/Zoom Map (here's the source). Also, the large image in the Flex Image Cropper on the right is an example of this second case, but they don't have the dragging. That requires that you manipulate the position of the scrollRect property on the canvas. The scrollRect property is a flash.geom.Rectangle defining the Canvas' "viewport". You then change/update the verticalScrollPosition and horizontalScrollPosition properties, so it's backwards (compared to the Bounding Rectangle).
I think if you set clipAndEnableScrolling to true on the canvas, and you drag a child image around inside of it (and image.includeInLayout = true), it should clip the image to only show up inside the canvas. But I'm guessing you want case 1. Just search those properties and you'll find some good examples on google.
Good luck, should be a fun project.
Lance

Resources