specifying width and height of actors - libgdx

I am using horizontal and vertical group to create a layout as seen in a photo. The problem is that I don't know how to specify how wide each group should be. In my case, the vertical group gets squeezed together and this results in really small UI component. The docs talk about preferred size to be the indicator of how width and tall Actors are, but there is no method like setPreferredWidth() method. So how do I specify the width and height of Actor entities. I tried using setWidth(), setBounds() but these doesn't work.
backbone of my setup now. I currently have only 1 actor in vertical group.
mySlider=new Slider(1,100,1,false,ss);
mySlider.setBounds(0,0,300,30);
mySlider.setWidth(300);
verticalGroup=new VerticalGroup();
verticalGroup.setWidth(300);
verticalGroup.addActor(mySlider);
horizontalGroup=new HorizontalGroup();
horizontalGroup.setBounds(stage.getWidth() - 120, stage.getHeight() - 125, 400, 100);
horizontalGroup.setPosition(stage.getWidth() - 120 - 350, stage.getHeight() - 125);
horizontalGroup.setWidth(400);
horizontalGroup.addActor(buttonLeftToTheVerticalGroup);
horizontalGroup.addActor(verticalGroup);
stage.addActor(horizontalGroup);

Related

How does the training data look like in Yolo model

I'm trying to figure out how to create YOLOv1 model from scratch but I can't figure out how the training data should look like. I suspect training labels (ground truth) looks like a matrix with (7, 7, 5*2 + 10) where
7x7 stands for the prediction grid
5 is object location and confidence (always equal to 1); x,y - known box center; h,v - box height and width
*2 is because there should be horizontal and vertical box for each cell
10 - is one-hot encoding for a class present in this position
what I don't understand is
whether to put confidence==1 to both horizontal and vertical bounding boxes?
whether x and y should be coordinates in the original (resized for the input) image?
...or maybe I'm completely off with my whole understanding. Does somebody have experience with YOLO?

Text scaling and positioning in libgdx

I am working with libgdx. I need to scale and position text. Let's say I want to draw X that is 30 pixels hight and I want it to be in the middle of the screen. I want to draw more of those in diffrent locations and with different scales.
Is there any way how could I achieve that? I can't find the solution anywhere. I dont want to create more BitmapFonts if possible.
If you want to handle all platforms (android, html, ios, desktop) you need to use several BitmapFonts in order to avoid ugly scaling. Otherwise, if you don't need to deploy to HTML, you can use the gdx-freetype extension (see here https://github.com/libgdx/libgdx/wiki/Gdx-freetype).
Assuming you go with BitmapFont, you can simply use code similar to this to center your text:
String text = "Your text here!";
TextBounds bounds = font.getBounds(text);
font.draw(batch, text, (width - bounds.width) / 2.0f, (height - bounds.height) / 2.0f);
For scaling, you can set the scale in font.draw, but you probably want several BitmapFont of various sizes to avoid ugly artifacts.

PyQt - QGridLayout without changing Qwidget Geometry?

I'm working with PyQt and I was wondering if there is any way to set a grid layout in a window so that, for example, one button's geometry wouldn't be affected by the configuration of the layout - because I'm trying to have my button in a square shape and, with the grid layout, it always becomes a long rectangle.
Also, I have multiple rows and columns, and to edit each minimum size would be horrifying. So, is there is any way to establish the geometry of a widget in a grid layout?
UPDATE: my grid
self.Grid = QtGui.QGridLayout()
self.Grid.addWidget(self.Button1,0,0)
self.Grid.addWidget(self.Box1,2,1)
self.Grid.addWidget(self.Box2,2,3)
self.Grid.addWidget(self.Button2,0,4,Qt.AlignRight)
self.Grid.setRowMinimumHeight(1,50)
self.Grid.setRowMinimumHeight(1,50)
self.Grid.setRowMinimumHeight(3,250)
self.Grid.setColumnMinimumWidth(0,100)
self.Grid.setColumnMinimumWidth(2,50)
self.Grid.setColumnMinimumWidth(4,100)
self.setLayout(self.Grid)
Given the example code in your question, just add something like the following:
self.Button1.setMinimumSize(50, 50)
self.Button1.setMaximumSize(50, 50)
or:
self.Button1.setFixedSize(50, 50)

libgdx Shaperenderer line .. How to draw line with a specific width

I am trying to draw a line of specific width using libgdx shape renderer. I followed this link
The problem is if i specify more line width i.e more than 9 it does not show increased width. More than 9 either i specify 20 or 100 pixels it will have the same result as 9
shapeRenderer.begin(ShapeType.Line);
shapeRenderer.line(50, 70, 0, 50, 200, 0, Color.BLUE, Color.RED);
int lineWidth = 20; // pixels
Gdx.gl10.glLineWidth(lineWidth / camera.zoom);
shapeRenderer.end();
Thanks
Shakeel
To query the range of supported widths and the size difference between
supported widths within the range, call glGet with arguments
GL_ALIASED_LINE_WIDTH_RANGE, GL_SMOOTH_LINE_WIDTH_RANGE, and
GL_SMOOTH_LINE_WIDTH_GRANULARITY.
Reference
To avoid device specific behavior, I use a quad instead. Draw a 1x1 square from a small texture and then position, scale (depending on the width and height of the line you wanted to draw), color, and rotate it.
You should use ShapaRenderer.rectLine. You can see a more detailed answer here
Use this
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
instead of shapeRenderer.begin(ShapeType.Line);
Replace 10 with line width you want
Gdx.gl.glLineWidth(10 / camera.zoom);

Flash AS3 Reduce stage height from top

I'm trying to reduce stage height from the top to get an item to spawn under a specific area. Where the HUD is.
I used to have my HUD on the bottom which caused no problem. Because my function has:
headY = Math.ceil((((stage.stageHeight - hudHeight)))/(headWidth))*Math.random())*headWidth;
This reduces stage.stageHeight with 80 so the head can spawn properly. However, this isn't the case when the HUD is at the top. What this line currently does is that it is making the head not able to spawn under stageheight - 80 pixels instead of the top.
My question is; how can I make the code reduce the stageheight from the top.
Thanks in advance,
Jordi
Extra info about my question:
All I'm trying to do actually, is 'selecting' the bottom of the stage, leaving the stage out of the picture. I was just using stageheight as an indicator to control the 800 pixels. So when I manipulate the stageheight, I wouldn't have to change the code. But since this might not be possible. There should be a different way. I hope you understand my question now. If not, what I want to do is select everything from 80 pixels down and under. The stage's height is 800 pixels so I need to select 720 pixels. However, I can't find a way to select the bottom 720 pixels.. only the top 720 pixels.
Although your question is hard to understand, the answer is most likely that you cant. The stageHeight is read-only. You can set it in HTML, and even set it to a percentage. But you can't alter it in Actionscript.
The way your question is worded, makes it extremely hard to understand what you want.
I am guessing that what you want is to spawn a given object and ensure that it is not spawned in the same space as your HUD.
So if your screen is 800 x 800 , and your HUD takes up the full width of the screen and the top 80 pixels of the screen you might try this to get a valid y spawn location :
var headY:Number = Math.random() * (800 - 80) + 80;
That would give you a resulting value from 80 - 800;
Given your variables I would suggest this :
var headY:Number = Math.random() * (stage.stageHeight - hudHeight) + hudHeight;
Now based on your code, it seems like you are also trying to ensure that whatever you are spawning is not partially off the top or bottom of the screen, so you need to factor in the height of the head. So consider this code :
var headY:Number = Math.random() * ((stage.stageHeight - headHeight) - (hudHeight + headHeight)) + (hudHeight + headHeight);
Not completely sure if this is what you are looking for, but it's the best I can do based on your question and trying to suppose what it is that you want.