Scaling inside the clip - actionscript-3

How to scale inside a clip?
I dynamically create a clip that simulates a window and calculate its width as
stage.stageWidth * my_window_width / my_scene_width;
inside the window, i need to create a square that must have a width, coordinate x, and so on, proportionally scaling according to the size of the window screen. Because if the size of the square is set pixel by pixel, then the sizes differ on different screens.

You could setting square w/h according to window size...
mc_window.square.width = (mc_window.width / 8); //square is eight times smaller
mc_window.square.height = mc_window.square.width; //set to "square" geometry

I create a clip that simulates a window:
window_bonus = new windowBonus;
window_bonus.x = stage.stageWidth * indent_to_x_to_photoshop / width_all_file_photoshop;
window_bonus.y = stage.stageHeight * indent_to_y_to_photoshop / height_all_file_photoshop;
window_bonus.width = stage.stageWidth * width_of_photoshop / width_of_all_file_photoshop;
window_bonus.height = stage.stageHeight * height_of_photoshop / height_all_file_photoshop;
I get a window like in figure 1.
Then I create another clip on the window - figure 2.
And on the device it looks like in figure 3.
I decided to create clips of containers that are not initially visible but they are installed on the window and therefore are scaled with the window,
Inside them already, I load the card image.
But my question is how to scale without containers,
using width, height, x and y
for a nested clip?

Related

MovieClips scale down when StageScaleMode.NO_BORDER

I have my stage aligned to TOP_LEFT and scaled to StageScaleMode.NO_BORDER, the width and height of my SWF are : width = 1920 and height = 1080.
The thing is when my i change the SWF size to bigger (height/width) the movieClips on the stage scale up and that's a good thing for me, but when i reduce the size of my SWF to smaller values (smaller than the default size), the movieClips get reduced as well, aren't they supposed to stay the same, if not is there a way to make that happen ?
In fact the NO_BORDER scaleMode makes sure to not show the borders of the SWF and scale the center depending on the :
The ratios :
widthRatio = currentStageWidth/stageWidth
and
heightRatio = currentStageHeight/stageHeight.
The stageWidth and stageHeight are provided by AS3.
The currentStageWidth and currentStageHeight are supposed to be changing while resizing the browser window, the can be retrieved from the Flash Object (ie: $("#flashObjectId").width()).
Then we should compare the two ratios (widthRatio and heightRatio), the bigger one has the scale value for the stage and the other elements on the stage.

AS3 - Scale image to full width or height without cut off

I need to scale an image with maintaining the aspect ratio in AS3. It should be scaled to the full stage size but nothing should be cut off.
How to do it?
Thank you,
Uli
Something like this should work:
// set the scale to fit the width of the image to the width of the stage
var scale:Number = stage.stageWidth / myImage.width;
// if the height of the image will be taller than the stage,
// set the scale to fit the height of the image to the height of the stage
if(myImage.height * scale > stage.stageHeight){
scale = stage.stageHeight / myImage.height;
}
// apply the scale to the image
myImage.scaleX = myImage.scaleY = scale;

scaling in sprite that preserves central point of it's visible part

I'm having a sprite (canvas) which is being scaled. The canvas has a mask. The problem is that simple scaling (scaleX=newScale; scaleY=newScale;) takes the part of canvas under mask beyound the mask. So I need to move canvas after scaling in such a way that point of canvas under mask remain in the same place. I'm trying to do something like the following:
var deltaScale = newScale / scale;
//w and h are width and height of mask
canvas.scaleX = newScale;
canvas.scaleY = newScale;
canvas.x += (canvas.x + w/2) - (canvas.x + w/2) / deltaScale;
canvas.y += (canvas.y + h/2) - (canvas.y + h/2) / deltaScale;
still after that central point do not remain on the same place. Can somebody prompt me how should I move canvas after scaling?
PS: width and height of canvas is extremely big (some of 25000) if that helps.
UPD: Canvas with it's mask are added on Sprite, mask is having the same sizes as that parent sprite, canvas.x and canvas.y are negative.
The way I did something similar before was to put the canvas sprite inside another sprite eg. zoom which has its reg point in the centre of the screen (or where ever needed). You can then move canvas around inside the zoom sprite (in my case it was draggable) and scale the outer sprite so the centre is zoomed into.
Scaling and positioning different sprites I found much easier than doing an offset.

Set HTML5 Canvas Height And Width And Having Content Inside Scale

Is it possible to set the width and height of a canvas element and have the existing content scale to fit these new dimensions?
Right now the user uploads an image and my page creates a canvas element containing this image and whose dimensions are the same size as the image. I want to limit the size that I'm working with, however, so here is an example of what I want to have happen:
The user uploads an image that is 1600 x 1200 pixels (Not saved to server)
The data goes right to an html5 canvas object
The canvas height and width are set to 800 x 600 and the image content scales appropriately and then is displayed.
Right now if I set the canvas width and height it just crops the image at those dimension, not resizing as I would like. Thanks!
There are many ways to call drawImage
One is:
ctx.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh)
Where dx,dy,dw,dh are the destination x, y, width, and height.
If you make dw and dh always 800x600, the image will drawn will always automatically be scaled to 800x600.
Here's a tiny example that will always draw any size image to 800x600 http://jsfiddle.net/jAT8Y/
Another alternative is to use context.scale function. Your image quality will remain better if you use scale.

How can I have a jfreechart ChartPanel automatically enlarge itself?

I have a Swing JFrame with a ChartPanel as its only component. When I resize the frame, the chart panel gets stretched out as if it were an image. For example, if I shrink it vertically, all of the character get compressed.
Is it possible to have the ChartPanel redraw itself on resize events so that it shows more detail on the graph, instead of getting stretched as a static image?
You have to change a few options when constructing your ChartPanel :
* #param minimumDrawWidth the minimum drawing width.
* #param minimumDrawHeight the minimum drawing height.
* #param maximumDrawWidth the maximum drawing width.
* #param maximumDrawHeight the maximum drawing height.
I had the same issue. I now realize that ADR gave the solution: you have to set the minimum and maximum drawing width and height, for example:
chartPanel.setMinimumDrawWidth( 0 );
chartPanel.setMinimumDrawHeight( 0 );
chartPanel.setMaximumDrawWidth( 1920 );
chartPanel.setMaximumDrawHeight( 1200 );
ChartPanel has methods to control zoom, as shown in this example. I don't see characters getting compressed.