How to change an Windows Image^ attribute with C++ - xaml

I'm trying to change an Image that I've defined in XAML in C++.
Currently there is no reason for me not to simply define it as it is in XAML, but later on it will need to change, so I want to get that sorted now.
Anyways, here's the XAML:
<Image x:Name="playerBot"
Width="25"
Height="25"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Source="ms-appx:///Assets/Square Button.png"
Stretch="Fill"
RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<CompositeTransform TranslateX="0"
TranslateY="0"
Rotation="0"/>
</Image.RenderTransform>
</Image>
What I have is a class which stores position data and an Image^ for the Image^ defined in XAML.
Sprite.cpp - note that the variables have been defined fine in Sprite.h
image = Windows::ApplicationModel::Package::Current->InstalledLocation->Path + image;
auto img = ref new BitmapImage;
img->UriSource = ref new Uri(image);
m_image = ref new Image;
m_image->Source = img;
m_image->Width = m_width;
m_image->MaxWidth = m_width;
m_image->MinWidth = m_width;
m_image->Height = m_height;
m_image->MaxHeight = m_height;
m_image->MinHeight = m_height;
And finally my 2 attempts to change the Image^ defined in XAML in InGamePage.cpp:
Attempt 1:
String^ img = "Assets//Main Screen Background.png";
player = new Robot(img, 25, 25, 0, 0, 10, 0.5);
playerBot = player->getImage();
Attempt 2:
String^ img = "Assets//Main Screen Background.png";
player = new Robot(img, 25, 25, 0, 0, 10, 0.5);
playerBot->MaxWidth = player->getWidth();
playerBot->MaxHeight = player->getHeight();
playerBot->Source = ref new BitmapImage(ref new Uri(Windows::ApplicationModel::Package::Current->InstalledLocation->Path + img));
What these two methods do is either absolutely nothing (method one) or simply seem to delete the image/make it invisible (method two).
img is definitely the right file location, as I've used it in XAML earlier and it worked fine.

Related

TweenJS rect command "grow from center"

new to createjs here:
Created this fiddle: example. I would like the rect to grow from the center and not from the top left corner. I couldn't find any help, I don't know what to search for.
Code:
const PAGE_WIDTH = 150,
PAGE_HEIGHT = 75;
var stage = new createjs.Stage("canvas");
createjs.Ticker.setFPS(60);
createjs.Ticker.on("tick", tick);
var page = new createjs.Shape();
page.regX = PAGE_WIDTH/2;
page.regY = PAGE_HEIGHT/2;
page.x = 50;
page.y = 50;
stage.addChild(page);
var pageCommand = page.graphics
.beginFill('red')
.drawRect(0, 0, 1, 1).command;
createjs.Tween.get(pageCommand)
.to({w:PAGE_WIDTH, h: PAGE_HEIGHT}, 700, createjs.Ease.elasticOut)
function tick() {
stage.update();
}
Thanks.
The best way is to change the registration point of your graphics so it grows from the center.
Your code:
.drawRect(0, 0, 1, 1).command;
.to({w:PAGE_WIDTH, h: PAGE_HEIGHT})
Instead:
.drawRect(-1.-1, 2, 2);
.to({x:-PAGE_WIDTH/2, y:-PAGE_WIDTH/2, w:PAGE_WIDTH, h: PAGE_HEIGHT})
Fiddle: http://jsfiddle.net/1kjkqo2v/
[edit: I said 2 options initially, but the second (using regX and regY) wouldn't work well, since you have to tween that value as well as your size changes.]

Subscript in Windows Store Apps

How to create a subscripted text in Windows Store App?
The followed codes not work.
var s = new Span();
s.Inlines.Add(new Run() { Text = "subscript" });
ITextCharacterFormat x = (ITextCharacterFormat)s;
x.Subscript = FormatEffect.On;
Paragraph p = new Paragraph();
p.Inlines.Add(s);
rtb.Blocks.Add(p);//rtb is a RichTextBlock
or
<RichTextBlock Name="rtb" Grid.Row="2" >
<Paragraph FontSize="50" >
Some<Span Typography.Variants="Subscript" >subscript</Span>
</Paragraph>
</RichTextBlock>
Does anyone know a way?

fit a image on a background image with wideimage

is it possible to fit image onto a white background image using wideimage and in that way to show the image without deformations?.
Now I have this, this source merges a background image with an uploaded image, but a part of image loses
public function createThumb($pathimg, $img, $id) {
$paththumb = 'img/upload/thumbs/' . $img;
$imagen = WideImage::load($pathimg);
$width = $imagen->getWidth();
$height = $imagen->getHeight();
$newWidth = 427;
$newHeight = ($newWidth / $width) * $height;
$imagen->resize($newWidth, $newHeight, 'fill')->saveToFile($paththumb);
$img1 = WideImage::load(realpath($paththumb));
$watermark = WideImage::load(realpath('img/bg.jpg'));
$new = $img1->merge($watermark, 0, 0, 20);
$new->saveToFile($paththumb);
}

How to set axis margin in WinRT XAML Toolkit line chart?

Answer
Finally I solved my answer with this.
((LineSeries)MyChart.Series[0]).IndependentAxis = new LinearAxis
{
Minimum = 1,
Maximum = 5,
Orientation = AxisOrientation.X,
Interval = 1,
Margin = new Thickness(10, 0, 10, 0)
};
((LineSeries)MyChart.Series[0]).Clip = null;
((LineSeries)MyChart.Series[0]).Margin = new Thickness(10, 0, 10, 0);
I am drawing line chart with help of WinRT XAML Toolkit. I am setting X axis manually, but when I set I am getting wierd start & end point. I tried to set margin and padding but it's not working. Will you please suggest me how can I do that ?
((LineSeries)MyChart.Series[0]).IndependentAxis = new LinearAxis
{
Minimum = 1,
Maximum = 5,
Orientation = AxisOrientation.X,
Interval = 1,
//Margin = .... Not working
//Padding = .... Not working
};
I'd use a visual tree debugger to walk up the visual tree from these data points to see where the Clip property is set. In fact I just did that on the samples project and it is set on the LineSeries. See if it's set as part of its XAML template or if it is done in C# and remove it there. Also you could change the Minimum/Maximum values on your X axis to make more space. I'll add cleaning this all up to my TODO list.

How to position a Rectangle in Embedded Silverlight?

I'm trying to position a Rectangle on a Canvas but can't figure out what the correct syntax is to do this. In C# I would write
rect = new Rectangle();
rect.Width = 100D;
rect.Height = 50D;
rect.Fill = new SolidColorBrush(Colors.Red);
rect.StrokeThickness = 2;
rect.Stroke = new SolidColorBrush(Colors.Black);
Canvas.SetLeft(rect,5);
Canvas.SetTop(rect,5);
DrawCanvas.Children.Add(rect);
I try to do the same thing with the embedded code but have trouble with positioning the Rectangle. What is the correct way to create and position a shape on a Canvas programatically in embedded Silverlight? This is what I have so far but when running it nothing shows on the Canvas.
HRESULT MainPage::BtnOk_Click (IXRDependencyObject* pSender, XRMouseButtonEventArgs* ? pArgs)
{
HRESULT hr = E_NOTIMPL;
if ((NULL == pSender) || (NULL == pArgs))
{
hr = E_INVALIDARG;
}
IXRApplicationPtr pApplication;
if (FAILED(hr = App::GetApplication(&pApplication)))
return hr;
IXRVisualHostPtr pVisualHost;
if (FAILED(hr = App::GetVisualHost(&pVisualHost)))
return hr;
//Create Brush
IXRSolidColorBrushPtr pPaintBrushRed;
IXRSolidColorBrushPtr pPaintBrushBlack;
COLORREF brushColorRed = RGB(255,0,0);
COLORREF brushColorBlack = RGB(0,0,0);
pApplication->CreateObject(&pPaintBrushRed);
pPaintBrushRed->SetColor(brushColorRed);
pApplication->CreateObject(&pPaintBrushBlack);
pPaintBrushBlack->SetColor(brushColorBlack);
IXRRectanglePtr pRectangle;
IXRFrameworkElementPtr pRootElement;
IXRCanvasPtr pCanvasPanel;
IXRUIElementCollectionPtr pChildrenCollection;
pApplication->CreateObject(IID_IXRRectangle, &pRectangle);
pRectangle->SetWidth(100);
pRectangle->SetHeight(50);
pRectangle->SetFill(pPaintBrushRed);
pRectangle->SetStroke(pPaintBrushBlack);
pRectangle->SetStrokeThickness(2);
pRectangle->SetName(TEXT("MyRect"));
pVisualHost->GetRootElement(&pRootElement);
pRootElement->FindName(TEXT("DrawCanvas"), &pCanvasPanel);
pCanvasPanel->GetChildren(&pChildrenCollection);
pChildrenCollection->Add(pRectangle, NULL);
pCanvasPanel->SetAttachedProperty(L"MyRect.Left",NULL,5);
pCanvasPanel->SetAttachedProperty(L"MyRect.Top",NULL,5);
/*rect = new Rectangle();
rect.Width = 100D;
rect.Height = 50D;
rect.Fill = new SolidColorBrush(Colors.Red);
rect.StrokeThickness = 2;
rect.Stroke = new SolidColorBrush(Colors.Black);
Canvas.SetLeft(rect,5);
Canvas.SetTop(rect,5);
DrawCanvas.Children.Add(rect);*/
return hr;
}
The XAML Code:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ChartApplication"
x:Class="ChartApplication.MainPage"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" Background="White">
<local:ChartControl Margin="97,58,82,89"/>
<Rectangle Fill="#FFE25E5E" Stroke="Black" Height="133" Margin="97,98,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="217"/>
<Ellipse Fill="#FFB7E25E" Stroke="Black" Height="105" HorizontalAlignment="Right" Margin="0,0,41,78" VerticalAlignment="Bottom" Width="235"/>
<Button x:Name="BtnOk" Height="85" HorizontalAlignment="Left" Margin="113,0,0,89" VerticalAlignment="Bottom" Width="155" Content="Ok" Click="BtnOk_Click"/>
<Canvas x:Name="DrawCanvas" HorizontalAlignment="Right" Margin="0,98,41,198" Width="240" Background="#FFE4E4F2"/>
</Grid>
canvas may not support in embedded silverlight.
You can add directly to Grid
IXRUIElementCollectionPtr pElementCollection;
m_pLayoutRoot->GetChildren(&pElementCollection);
int nIndex=0;
pChildrenCollection->Add(pRectangle, &nIndex);
nIndex++;