I'm trying to use overFont and overColor on TextButton so the button appearance can changes when the mouse move over.
Here's the style I defined.
var buttonStyle = new TextButtonStyle();
buttonStyle.fontColor = new Color(1f, 1f, 1f, 1f);
buttonStyle.disabledFontColor = new Color(0, 0, 0, 0.4f);
buttonStyle.down = skin.getDrawable( "button_down");
buttonStyle.up= skin.getDrawable( "button_up");
buttonStyle.over= skin.getDrawable( "button_over");
buttonStyle.overFontColor = new Color(0, 0.3f, 0.3f, 1f);
buttonStyle.font = font
skin.add("default", buttonStyle);
The button is created as follows:
var startGameButton = new TextButton("Start game", skin);
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
stage.addActor(startGameButton);
/*startGameButton.addListener ([ Event e |
Gdx.app.log ("App", "Start game") ;
return true ;
])*/
startGameButton.addListener (new ChangeListener () {
override changed(ChangeEvent event, Actor actor) {
Gdx.app.log ("App", "Start game") ;
}
})
While the down and up state are properly taken into account, the over properties are not used: the button doesn't change when the mouse enters the button area.
buttonStyle.fontOverColor = Color.BLUE; works fine for me,
try to pass to your TextButton constructor not skin, but buttonStyle,
in TextButton there is such constructor
public TextButton (String text, TextButtonStyle style)
It's difficult to say something else, because code not looks like real working code, I mean var keyword or this code is not correct (there is no public variables x, y, width, height):
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
If changing constructor will not help you, please post your real code.
Related
I am adding a down arrow to the xamarin picker. I created a custom iOS renderer for this. I can get the arrow to show up fine, but it is touching the right hand side of the picker. How can I add some padding to the right of the arrow? I have tried the following in my ios renderer.
protected void UpdateBackground(UITextField control)
{
if (control == null) return;
control.Layer.CornerRadius = ElementV2.CornerRadius;
control.Layer.BorderWidth = ElementV2.BorderThickness;
control.Layer.BorderColor = ElementV2.BorderColor.ToCGColor();
var downArrowLabel = new UILabel(new CoreGraphics.CGRect(new CoreGraphics.CGPoint(control.Frame.Size.Width - 20 - 16, 0), new CoreGraphics.CGSize(20, control.Frame.Size.Height)));
downArrowLabel.Font = UIFont.FromName("FontAwesome", 30);
downArrowLabel.Text = "\uf0d7";
downArrowLabel.TextColor = UIColor.Black;
downArrowLabel.TextAlignment = UITextAlignment.Center;
downArrowLabel.ContentMode = UIViewContentMode.ScaleAspectFit;
control.RightView = downArrowLabel;
control.RightViewMode = UITextFieldViewMode.Always;
control.RightView.Bounds = new CoreGraphics.CGRect(0, 0, 20 + 16, control.Frame.Size.Height);
}
I wrote a Picker renderer based on your code and tested it. I found that adding a few spaces after the Text can effectively solve this problem. It looks strange, but it works, like this
downArrowLabel.Text = "\uf0d7 ";
First I made a picture of my problem:
http://imgur.com/a/D8oOj
You have 3 sliders and they all need a background color. Maybe the 3 labels below need a background color too.
GUI.color = Color.white;
Does not seem to help much. I need this black background for the simulation so i need to make the slider background white...
But GUILayout and GUISkin do not have properties for this, no? I can not find something useful there...
The components i use:
GUI.HorizontalSlider + GUI.Label
Within a GUI Skin, there is a Horizontal Slider property. That property has GUI Style properties of Normal, Hover, Active, and Focused. You should set a background to all 4 of those elements.
Here's an example using programmatically-created GUIStyle (tested with Unity 5.4.2p4). Note that when creating a fresh GUIStyle, you need to assign dimensions, or it might not be visible.
public class MySliderIMGUI : MonoBehaviour
{
private GUIStyle _sliderBackgroundStyle;
private GUIStyle _sliderThumbStyle;
private float _sliderValue = 0f;
private Texture2D _whitePixel;
private Texture2D _blackPixel;
void Start()
{
this._whitePixel = new Texture2D(1, 1, TextureFormat.ARGB32, false);
this._whitePixel.SetPixel(0, 0, Color.white);
this._whitePixel.Apply();
this._blackPixel = new Texture2D(1, 1, TextureFormat.ARGB32, false);
this._blackPixel.SetPixel(0, 0, Color.black);
this._blackPixel.Apply();
this._sliderBackgroundStyle = new GUIStyle();
this._sliderBackgroundStyle.padding = new RectOffset(2, 2, 2, 2);
this._sliderBackgroundStyle.normal.background = this._whitePixel;
this._sliderBackgroundStyle.hover.background = this._whitePixel;
this._sliderBackgroundStyle.active.background = this._whitePixel;
this._sliderBackgroundStyle.focused.background = this._whitePixel;
this._sliderThumbStyle = new GUIStyle();
this._sliderThumbStyle.stretchHeight = true;
this._sliderThumbStyle.fixedWidth = 20f;
this._sliderThumbStyle.normal.background = this._blackPixel;
this._sliderThumbStyle.hover.background = this._blackPixel;
this._sliderThumbStyle.active.background = this._blackPixel;
this._sliderThumbStyle.focused.background = this._blackPixel;
}
void OnGUI()
{
this._sliderValue = GUI.HorizontalSlider(new Rect(100, 100, 200f, 20f), this._sliderValue, 0, 1, this._sliderBackgroundStyle, this._sliderThumbStyle);
}
}
am using urhosharp game engine from xamarim to develop a cross-platform game .... it was really good choice and compatible with WPF but I did not know how to draw shapes , I went through the guide and documentation and did not find a way maybe to draw circles,Rounded Shapes,annulus or any geometric type anyone knows or could help me . I would be very grateful .
Thanks in advance
I tried this piece of code but no circle appeared in the screen:
DebugRenderer debug = new DebugRenderer();
debug.AddCircle(new Vector3(50,50,0),new Vector3(100,25,0),50,Color.Magenta,2 ,true );
for (int i = 0; i < 512; ++i)
{
var start = new Vector3(i, 0, 0);
var end = new Vector3(i, 100, 0);
debug.AddLine(start, end, Color.White, false);
debug.AddCircle(start, end, 50f, Color.Red, i, false);
}
scene.AddComponent(debug);
Just want to note that DebugRenderRender is intended for debugging purposes. If you want to make DebugRenderer work you will need to subscribe to PostRenderUpdate like this:
Engine.SubscribeToPostRenderUpdate(args => YourMethodHandler);
Usually you will do that in your setup. And then YourMethodHandler is like:
protected void YourMethodHandler()
{
// this requires that you have already added a DebugRenderer
// component in your scene object
var debugRenderer = scene.GetComponent<DebugRenderer>();
if (debugRenderer != null)
{
// do your drawing code here
// to draw a rectangle for example:
var upperBound = new Vector3(-4.0f, 2.0f, 0.0f);
var lowerBound = new Vector3(4.0f, -2.0f, 0.0f);
debugRenderer.AddBoundingBox(
new BoundingBox(upperBound, lowerBound),
Color.White,
false);
}
}
To be more precise, it works only when implemented like this:
var dr = app.Scene.GetOrCreateComponent<DebugRenderer>();
app.Engine.PostRenderUpdate += (arg4) => {
app.Renderer.DrawDebugGeometry(false);
};
app.Renderer.BeginViewRender += (arg5) => {
dr.AddBoundingBox(new BoundingBox(-1000, 1000), Color.Blue);
dr.LineAntiAlias = true;
dr.AddTriangle(new Vector3(2,0,0), new Vector3(2,1,0), new Vector3(2,0,1), Color.Magenta, false);
dr.AddCircle(new Vector3(2,0,0), new Vector3(1,1,1), 5.0f, Color.Red);
};
I've been doing a essay about map on windows phone. I added pushpins default into map and its content is a image. I want to show information when I tap or click on pushpin, but I don't know what to do. I've just thought about use tooltip to show info, but I can't do it.
here is my createpushpin function.
can you help me? thank you for all kind of you!
private void CreateNewPushpin(object selectedItem)
{
var pushpinPrototype = selectedItem as Pushpinsmodel;
var pushpinicon = pushpinPrototype.Icon;
Pushpin pushpins = new Pushpin() { Tag = adress.Name };
pushpins.Background = new SolidColorBrush(Colors.Green);
pushpins.Location = new GeoCoordinate(lad, long);
ImageBrush image = new ImageBrush() {
ImageSource = new System.Windows.Media.Imaging.BitmapImage
(pushpinicon)};
Ellipse elip = new Ellipse()
{
Fill = image,
Name = adress.Name,
StrokeThickness = 10,
Height = 30,
Width = 30
};
pushpins.Content = elip;
var tooltipText = new ToolTip { Content = adress.Name};
ToolTipService.SetToolTip(pushpins, tooltipText);
map1.Children.Add(pushpins);
listpushpin.Add(pushpins);
this.map1.SetView(pushpins.Location, 18.0);
}
In my app I want to display a simple string within a popup when the user clicks on an image. For this I added a Tap gesture listener to the image and within the handler I have the following code:
private void GestureListener_Tap( object sender, GestureEventArgs e )
{
var img = sender as Image;
if( img == null ) {
return;
}
Point pos = e.GetPosition( img );
string text = "I'm a popup!";
var popup = new Popup() {
Child = new Border() {
BorderBrush = new SolidColorBrush( Colors.LightGray ),
Child = new TextBlock() {
Text = text,
TextWrapping = TextWrapping.Wrap,
},
},
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalOffset = pos.X,
VerticalOffset = pos.Y,
Visibility = Visibility.Visible,
};
popup.IsOpen = true;
Debug.WriteLine( "GestureListener_Tap: " + text );
}
The call to WriteLine prints in the debugger output window but the popup doesn't get displayed. What am I doing wrong here?
Thanks for your help!
I tried your code and the Popup is displayed. I think the problem for you is the Position for the Image relative to the Mouse. Try to set another Background for the Parent Container and I think you'll see the Popup. You can also try to play around with
Point pos = e.GetPosition(null);
until you get the Position you require