Here goes my first question. I've embedded a youtube video (HTML5) in a panel created using the Panel API from Firefox SDK. The problem is that the video won't go fullscreen. It tries to, but goes back to normal size within the panel. I've also tried to use the method described here with a random div but the same thing happens. So, is this a limitation from the api or is there any way I could get it to work? Thanks.
I've just started experimenting with a floating YouTube player plugin using the Firefox sdk and ran in to the same issue. I did find a some what sloppy work around, that you might find suitable to use.
This method causes the panel to resize to the full screen. However, when resizing it, even with the border property set to 0, the panel will still show a bit of a border.
in the main document, "index.js"
var self = require('sdk/self');
var data = require("sdk/self").data;
let { getActiveView }=require("sdk/view/core");
let myPanel = require("sdk/panel").Panel({
contentURL: "./index.htm",
contentScriptFile: ["./youtube.js", "./index.js"]
});
var player = getActiveView(myPanel);
player.setAttribute("noautohide", true);
player.setAttribute("border", 0);
player.setAttribute('style', 'background-color:rgba(0,0,0,0);');
myPanel.show();
init();
myPanel.port.on('fullscreen', fullScreen);
function init(){
var size = 30,
width = size * 16,
height = size * 9;
myPanel.resize(width,height);
}
function fullScreen(width, height){
player.moveTo(3840, 0); // Need to moove the video to the top left
//of the monitor or else the resize only takes a potion of the screen.
//My left position is 3840 because i'm doing this on my right
//screen and the left is 4k so i need the offset.
myPanel.resize(width,height);
}
And in my content script file
var container = document.getElementById('container'),
overlay = document.getElementById('overlay');
overlay.addEventListener('click', fullscreen);
function fullscreen() {
var x = window.screen.availWidth,
y = window.screen.availHeight;
self.port.emit('fullscreen', x, y);
}
Some things I've noticed while experimenting is that when playing YouTube videos in the panel, the video has a tendency to lag, but the audio plays fine. The lag gets more apparent when moving the mouse over elements on other pages, and over the panel itself. The faster the movement the more apparent it becomes. I've found a workaround for mousing over the panel by placing an div that stretches over the video. The problem with this is that the default YouTube controls don't react to the mouse over, which would be possible to get around by using the YouTube api and creating custom controls. Also multiple monitor support would be hard to work with when positioning the video.
Edit:
Here's another way that does the same thing, but this one appears to deal with multi monitor support. It will position to the top left of whatever window firefox is currently on.
in the index.js file
function fullScreen(width, height){
myPanel.hide();
myPanel.show({position:{left:0,top:0}});
myPanel.resize(width,height);
}
Related
I'm working on a basic design app where the user can upload images to a canvas, drag them around and resize them. The problem I have is resizing the image with a mouse drag. I'd like the user to position the mouse pointer on either corner of the bitmap image and drag either towards or away from the bitmap to resize it proportionally. I'd be grateful for any code or suggestions.
Lanny mentioned that you had this question here. ZIM, which is based on CreateJS has this functionality built in - it is called transform(). We also have an uploader built in called Loader().
Here is the code that you would use inside the ZIM template available on the code page at ZIM https://zimjs.com
const loader = new Loader().center();
loader.on("loaded", e=>{
e.bitmap.center().transform();
// or if you want multiple files
// loop(e.bitmaps, bitmap=>{
// bitmap.center().transform();
// });
loader.removeFrom();
stage.update();
});
Below is an image that has been loaded. You can try it here https://zimjs.com/explore/uploadresize.html. The transform interface will go away when the user clicks off the image and then comes back when they click on the image. There are various options for all of this that you can read about in the Docs available on the ZIM site.
All your regular CreateJS will work and you will find that ZIM is helpful in many other ways too! Aside from transform() there is drag() for normal dragging, and gesture() for pinch zoom and rotate - you would use one or the other of these not combined.
When developing using cocos2d-x 3.x for a device, it automatically sets the GL view to fit the device. In VS2012 on windows, it creates a seemingly-arbitrarily sized window. How do I set the size of that window?
My solution was as follows.
In AppDelegate.cpp:
bool AppDelegate::applicationDidFinishLaunching() {
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("My Game");
glview->setFrameSize(800, 600); // or whatever
director->setOpenGLView(glview);
}
...
}
In my particular use case, I'm setting the window sizes to various resolutions and aspect ratios to test my layouts. I'm sharing Q&A format because I couldn't find a straight answer to this anywhere.
+1 to Tom. Also, I would just like to share my answer and experience to everyone.
Remember, do not set the screen size "AFTER" the director set the GL view. This causes some problem with bounds detection on some nodes most notably cocos2d::ui::Button and other ways on how create buttons. I am using cocos2d-x v3.6
Check my answer here:
cocos2d::Menu click detection is a bit off to bottom left whenever using a custom window size
Doing this way will cause some problem:
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLViewImpl::create("My Game");
director->setOpenGLView(glview);
}
director->getOpenGLView()->setFrameSize(width , height);
Clicking the button, doesn't kick in the callback. Which is frustrating. Probably out of your frustration as well you click all through out the screen and notice there are some part of the screen (most likely bottom left part) which triggers the callback as if the bounding box of the node lies there. It doesn't even match the position and the size of the node in question. I can reproduce the problem whenever I change the screen size like the one I describe above. So never ever do it like that.
Tom's answer is the correct way of changing screen size.
I hope this will deter anyone doing it this way. I swear to God, this post could have save me heck of time solving this.
Cheers!
I'm writing an app whose sole purpose is to periodically download some images and display them in a live tile. I want to be able to update the tile with 4-8 images every thirty minutes or so, so I need to use a CycleTile. Downloading the images and getting them into a live tile is pretty straight forward. The real kicker is adding text on each image.
If it was just two images, I would use a flip tile, displaying one on the front and one on the back. Then I would add the text by assigning a different tile title to the front and back. However, since I need to display more than 2 images, I need to use the CycleTile. And this approach won't work with the CycleTile. (but please, correct me if I'm wrong!)
So my next thought was to overlay a TextBlock on a WriteableBitmap. This could work, but i think it would get complicated quickly taking into account factors like: different image resolutions, medium/large tile layouts, and varying screen PPIs. I'm sure I could figure it out, but it seems... messy.
Is there a better way to do this? Are there some Tile features I'm overlooking?
To sum it up my requirements are:
Display 4-8 images using a live tile.
Each image needs to have some text associated with it.
Update the images every thirty minutes or so.
Needs to scale to wide tiles.
Needs to scale to phones with higher PPI screens.
For item one, you should be able to merge as many images together using the Blit method from the WriteableBitmapEx project. Since you can merge your images together in any way you want, you can ensure they cover wide tile widths and any ppi you need.
To cover the second item, the following will overlay text on an image:
private static ImageSource createBitmapImageWithImage(string text, int x, int y, Color textColor, BitmapSource bitmapSource)
{
using(var mem = new MemoryStream())
{
//Create Formatted Text
var textBlock = new TextBlock
{
Text = text,
Foreground = new SolidColorBrush(textColor),
FontFamily = new FontFamily("Courier New"),
FontSize = 40
};
//Moves an object two dimensionally
var tf = new TranslateTransform
{
X = x,
Y = y
};
//Overlay text on existing image
var bmpImage = new WriteableBitmap(bitmapSource);
bmpImage.Render(textBlock, tf);
bmpImage.Invalidate();
//Convert back into bitmap
bmpImage.SaveJpeg(mem, bmpImage.PixelWidth, bmpImage.PixelHeight, 0, 100);
mem.Seek(0, SeekOrigin.Begin);
var image = new BitmapImage();
image.SetSource(mem);
return image;
}
}
Of course you can pass in the text block too, or the options to configure the text block. But I wanted to show how you can format the text however you want.
Your third request is covered by background tasks. In your phone solution, add a new project and you can select background task. It is fairly straightforward to have this call your code to update the images. Nokia even created a walk through on how to add one with code examples.
I need to know, which is the best way to blur the background of the Windows Phone 7 app to concentrate the user's attention on a "always on top" popup window.
My idea is:
Make an in-memory screenshot of the background grid (by turning it into a freezable or something).
Add an image that overlaps the background grid, but is below (with the z-index) the popup.
Still I doubt I will be able to overlap the application bar.
At this point, if you have a solution, please advise.
A few pointers for you ...
Unfortunately the Silverlight BlurEffect and other Bitmap effects didn't make it into Window Phone 7, so you will have to implement the blur yourself. This is actually pretty simple, just use a Gaussian Convolution Filter.
To achieve this effect you can capture the visuals of your application into a WriteableBitmap, manipulate the image to create your blur, then overlay this image over your application using a PopUp. I did something similar in a blog post I wrote about fly-out text animations here:
http://www.scottlogic.co.uk/blog/colin/2011/04/metro-in-motion-3-flying-titles/
Find your root visual as follows:
var rootElement = Application.Current.RootVisual as FrameworkElement;
Add a copy of this UI into a popup as follows:
_backgroundMask = new Rectangle()
{
Fill = new SolidColorBrush(Colors.Black),
Opacity = 0.0,
Width = rootElement.ActualWidth,
Height = rootElement.ActualHeight
};
_popupCanvas.Children.Add(_backgroundMask);
_targetElementClone = new Image()
{
Source = new WriteableBitmap(element, null)
};
_popupCanvas.Children.Add(_targetElementClone);
And show it:
_popup.IsOpen = true;
I'll leave you to work out how to blur the background!
As an aside, your will not be able to overlay or capture the application bar visuals. Hide it before performing this transformation.
Finally, blurring the background isn't really very 'Metro'. Are you sure you want to do this?
Instead of blurring just use a semi transparent layer over the top of the page.
You should hide the application bar before trying to create such an effect as you won't be able to place anything on top of it.
I am amazed at how well the native Symbian components are implemented. One of them is CAknSlider. CAknSlider is a control that has a slider that users can use to slide it along a bar whose orientation can be vertical or horizontal.
Now when you slide the slider the sliding is very smooth and does not flicker. But if for some reason I were to implement a custom slider control I would not get it as neat as CAknSlider.
So my question is how can I figure out how CAknSlider is implemented under the hood. I want to implement a custom slider for my radio application to control the volume of audio stream.
Any idea how should I go about it.
[EDIT: In response to the comment from laalto]
The CAknSlider control is often implemented as a setting item in the settings screen.
I have never seen it implemented as a component control within a compound control container ( like CCoeControl or CAknView ). This is what I have tried so far:
First I created a resource file describing the slider control like below:
RESOURCE SLIDER r_volume_slider
{
layout=EAknCtSlider;
minvalue=0;
maxvalue=10;
step=1;
valuetype=EAknSliderValuePercentage;
minlabel="mute";
maxlabel="full";
}
Then I am using the resource file in my source to create the slider like below:
void CVolumePopupAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
InitComponentArrayL( );
iSlider = new ( ELeave ) CAknSlider( );
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC( reader, R_VOLUME_SLIDER );
iSlider->ConstructFromResourceL( reader );
CleanupStack::PopAndDestroy ( );
iSlider->SetContainerWindowL( *this );
iSlider->SetParent( this );
Components().AppendLC( iSlider );
CleanupStack::Pop ( iSlider );
// Set the windows size
SetRect(aRect);
// Activate the window, which makes it ready to be drawn
ActivateL();
}
Now here is the comparison between the CAknSlider as a setting item ( Screenshot1 ) and the CAknSlider that gets created by the above described technique ( Screenshot2 ). Notice that the one I create does not have a percentage value indicator and the minimum and maximum text labels even though I specified them in the resource. The look and feel is also pathetic.
There are lots of techniques to avoid flicker, from double-buffering the whole screen down to more simple optimizations, like only re-drawing the parts of the control that have actually changed. Having appropriate rectangles pre-drawn to blit over where the slider was and its next step is probably the easiest way to do it efficiently.
To find out exactly how CAknSlider does it, you can either:
1) Wait for the relevant package in the Symbian Foundation platform to go open source (EPL) - should sometime in the next 12 months, or
2) Join the Symbian Foundation and get access to the source now
EDIT: (In response to request for more details on graphics optimisation)
Most commonly flicker is caused by redrawing the whole control. I have implemented (via a porting project) some custom controls that don't flicker here:http://developer.symbian.com/main/documentation/porting/#linux2
There's even something a bit like a slider. This example is far from ideal, it doesn't have pre-drawn rectangles for blitting but the graphics are very simple lines and filled rectangles. The concept of overwriting just the changed part is identical though. To blit pre-drawn sections. Draw the backgroud of the slider to an off-screen bitmap and do the same with the movable part of the slider. When the slider is moved, erase the movable part by doing a BitBlt() from the off-screen background (of only the part that needs to be erased) and then BitBlt() the movable part into the new position.
Does that make sense?
You need CAknSlider? steal it! :) CAknSliderSettingPage do everything for us. We, just use that.
iSettingPage = new(ELeave) CAknSliderSettingPage(R_SLIDER_PAGE, iValue);
iSettingPage->ConstructL();
iSettingPage->SetSize(iSettingPage->MinimumSize());
TInt CCustomColorPalette::CountComponentControls() const
{
return 1;
}
CCoeControl* CCustomColorPalette::ComponentControl( TInt aIndex ) const
{
return iSettingPage->SliderControl();
}