SurfaceGUI does not have CanvasSize property as can be seen in this image: https://postimg.cc/CZPgFX14
Searching for CanvasSize in the Explorer returns no results.
The CanvasSize property should be below the "AlwaysOnTop" property as seen in this image: https://images.contentstack.io/v3/assets/bltc2ad39afa86662c8/bltcdf38e0fefa655df/5c58c9f5194b42e50bc97905/forLoopBridge_setSurfaceGUISize.png?disposition=inline
I've tried to set the x,y values using a script with no luck.
Set "SizingMode" property to "FixedSize", Pixels per stud is a new feature
Related
I have a style sheet set up in which I set up tags that set font size such as <size=23px>. Is it possible to somehow modify the stylesheet on runtime to change these sizes (even if I have to do it one by one)? It's for implementing a font size slider in the UI settings of the game (ideally I'd like to multiply each fontsize by a modifier).
Thank you
Edit: To clarify, I set the sizes via opening tags in the style sheets and I am looking to update these settings on runtime, NOT update the text size on the TextMeshProUGUI components!
I'm able to reference my default styleSheet directly. According to https://docs.unity3d.com/Packages/com.unity.textmeshpro#1.3/api/TMPro.TMP_StyleSheet.html "GetStyle" retrieves "the Style matching the HashCode" (or name if I give it a string parameter). Once I get the style, however, I have very limited choice: https://docs.unity3d.com/Packages/com.unity.textmeshpro#1.3/api/TMPro.TMP_Style.html?q=TMP_Style based on this, my best bet would be to query "styleOpeningDefinition".
I am able to get the opening tags via styleOpeningDefinition, and then find and replace the relevant number that denotes the size in the "<size="50px">" tag but it's a readonly property so I cant set it afterwards.
Here's the code:
TMP_Text text = GetComponent<TMP_Text>();
TMP_Style style = styleSheet.GetStyle("H1");
openingTags = style.styleOpeningDefinition;
string[] size = openingTags.Split("px><cspace=");
string _splitString = size[0].Replace("<size=", "");
float _currentSize = float.Parse(_splitString);
_currentSize *= multiplier;
string _newTags = "<size=" + _currentSize + "px>" + size[1];
style.styleOpeningDefinition = _newTags; //Property or indexer 'TMP_Style.styleOpeningDefinition' cannot be assigned to -- it is read only
style.RefreshStyle();
In Unity, you can use the UnityEngine.UI.Text component to change the font size of text elements on runtime. You can use the fontSize property of the Text component to change the font size.
using UnityEngine;
using UnityEngine.UI;
public class FontSizeModifier : MonoBehaviour
{
public Text text;
public float fontSizeModifier = 1f;
void Update()
{
text.fontSize = (int)(text.fontSize * fontSizeModifier);
}
}
This script will update the font size of the text element on every frame, multiplying the current font size by the fontSizeModifier variable.
You can use this script and attach it to the text element you want to modify, or you can create a list of texts and modify them all via a loop.
I want to set exterior app's frame from my own project and I found a problem:
I can set its size and its position (but the thing is, I want it to be full screen, and even if I set the size to be full screen it does not set it's size to it (I have to press the button several times).
I think the problem is with its frame.
var frame = CGRectMake(0.0, 23.0, 1280.0, 770.0) //I post only this as size and position seem to work
let sizeCoo: AXValue = AXValueCreate(AXValueType(rawValue: kAXValueCGSizeType)!, &size)!.takeRetainedValue()
let positionCoo: AXValue = AXValueCreate(AXValueType(rawValue: kAXValueCGPointType)!, &position)!.takeRetainedValue()
let frameCoo: AXValue = AXValueCreate(AXValueType(rawValue: kAXValueCGRectType)!, &frame)!.takeRetainedValue()
let errorFrame = AXUIElementSetAttributeValue(myApp, "AXFrame", frameCoo)
Setting sizeCoo and positionCoo give me an error with raw value = 0 - everythng is ok, but setting frameCoo displays an error with rawValue = -25205 which means:
/*! The attribute is not supported by the AXUIElementRef. */
kAXErrorAttributeUnsupported = -25205
and I clearly see when I list attributes for this window there is the "AXFrame" attribute.
What am I doing wrong?
I am trying to use de Image Button on LIBGDX to create a button based on two images.
Using add to second image, works fine, but have one problem.
The images are of different sizes.
Note: I am testing with the same picture to see the result
Is there a way to correct this? Using some scale to the images?
levelsTexture = new Texture(Gdx.files.internal("level1.png"));
levels = new TextureRegion(levelsTexture).split(TILE_WIDTH, TILE_HEIGHT);
ImageButton levels_image = new ImageButton(new TextureRegionDrawable(new
TextureRegion(levels[0][0])));
levels_image.add(new Image (levels[0][0]));
stage.addActor(levels_image);
levels_image.setScale(2f);
The problem:
ImageButton is an extension of the Table class and typically the ImageButton images are set as the background. Using the "add" method for the second image like you did might work kind of, but it behaves differently than setting the background and it also might not be what you want if you want the the second image to also change when you click the button.
The easiest way to add two images to a single ImageButton would be to simply combine the two images in Photoshop (or equivalent) and use that single image on the ImageButton.
The more advanced (and more flexible) method would be to combine the two images programmatically and use this as the background for your ImageButton. This can be done by creating a custom class which extends BaseDrawable and have it take two Images in the constructor. If you want your images stacked on top of each other, set the minHeight of your custom drawable class to be the combined height of your two images. Then override the draw method and draw your two images on top of each other like this:
#Override
public void draw(Batch batch, float x, float y, float width, float height){
img1.getDrawable().draw(batch, x, y, img1.getWidth(), img1.getHeight());
img2.getDrawable().draw(batch, x, y+img1.getHeight(), img2.getWidth(), img2.getHeight());
}
}
The ImageButton takes a Drawable in its constructor, so you can pass this object right into the button when you create it and both of your Images should appear in the button and they will be treated as one.
I've done something similar to make a background for a table using multiple Images and this method works great.
I wrote my own SpriteButton class in which I implement this method for scaling my textures.
private Dimension getScaledDimension(Dimension imgSize, Dimension boundary) {
int original_width = imgSize.width;
int original_height = imgSize.height;
int bound_width = boundary.width;
int bound_height = boundary.height;
int new_width = original_width;
int new_height = original_height;
// first check if we need to scale width
if (original_width > bound_width) {
//scale width to fit
new_width = bound_width;
//scale height to maintain aspect ratio
new_height = (new_width * original_height) / original_width;
}
// then check if we need to scale even with the new height
if (new_height > bound_height) {
//scale height to fit instead
new_height = bound_height;
//scale width to maintain aspect ratio
new_width = (new_height * original_width) / original_height;
}
return new Dimension(new_width, new_height);
}
Then finally you draw the texture with the output dimension as as size to draw.
sb.begin();
sb.draw(this.texture2, this.x, this.y, dim_size_new.width, dim_size_new.height);
sb.end();
So you could technically draw the second image to the size of the the first image, if the first image size is correct.
Your implementation will look different from mine but you should be able to figure it out form here on out.
I have a very large image that I would like to show a 200x200px thumbnail of (showing a portion of the image, not a strethed version of the entire image). To achieve this I am looking into using CIImage.ImageByCroppingToRect or CICrop - but I am not able to get anything useful. Either the result is just black (I assume what I see is the black portion of the cropped image) or I get a SIGABRT ("Cannot handle a (6000 x 3000) sized texture with the given GLES context!")
There is a ObjC sample in this thread:
Cropping CIImage with CICrop isn't working properly
But I haven't managed to translate it in to C# and get it working properly.
Here's a MonoTouch port of the answer from the post you mentioned:
var croppedImaged = CIImage.FromCGImage (inputCGImage).ImageByCroppingToRect (new RectangleF (150, 150, 300, 300));
var transformFilter = new CIAffineTransform();
var affineTransform = CGAffineTransform.MakeTranslation (-150, 150);
transformFilter.Transform = affineTransform;
transformFilter.Image = croppedImaged;
CIImage transformedImage = transformFilter.OutputImage;
I'm wondering about the behavior of {Shape}.attr("fill","url({image.path})").
when applying a fill image to a shape:
public class AppMapCanvas extends Raphael {
public AppMapCanvas(int width, int height) {
super(width, height);
this.hCenter = width / 2;
this.vCenter = height / 2;
...
Rect rect = this.new Rect(hCenter, vCenter, 144, 40, 4);
rect.attr("fill", "url('../images/app-module-1-bg.png')"); // <--
...
}
}
The background image seem to teal accross the canvas behind the shape, thus gets weird positioning (an illustration snapshot is enclosed - i marked the original image borders in red).
This seem to resolve itself in the presence of an animation along a path (a mere path.M(0,0) is sufficiant).
How can i position the fill-image properly in the first place?
The proper way to do this from what I can understand would be to use an SVG pattern declaration to specify the portion and position of the image you would want to use. Then you would use that pattern to fill the rectangle element. Unfortunately, the Raphael javascript library doesn't have support for patterns... so there's no direct way to use an image to fill a rectangle.