libGDX button layout with no spacing - libgdx

I'm using a table to layout my menu buttons, but the spacing between buttons is big enough to drive a car through. What can I do to gain more control over the apparent cell padding? I've searched StackOverflow posts, read through the API, typed '.' after table and actor to browse the autocompletes, manually adjusted values in the skin file, and looked at other people's projects on Github. Some of the methods I've tried include sizeBy(), scaleBy(), pad(), setFillParent(), space(), fillY(), and grow()
A helpful answer would describe how to get buttons to stack on top of each other, touching.
Gdx.input.setInputProcessor(stage);
// Create a table that fills the screen. Everything else will go inside this table.
Table table = new Table();
table.setFillParent(true);
table.setDebug(true);
stage.addActor(table);
table.setBackground(new TiledDrawable(background));
//create buttons
TextButton newGame = new TextButton("New Game", skin);
TextButton preferences = new TextButton("Preferences", skin);
TextButton exit = new TextButton("Exit", skin);
TextButtonStyle tbs = new TextButtonStyle(newGame.getStyle());
NinePatch np = new NinePatch(skin.getPatch("button"));
np.setColor(np.getColor().sub(0f, 0f, 0f, .4f));
tbs.up = new NinePatchDrawable(np);
newGame.setStyle(tbs);
preferences.setStyle(tbs);
exit.setStyle(tbs);
table.bottom().right().padBottom(40f).padRight(40f);
//add buttons to table
table.add(newGame).bottom().right().fillX().uniformX();
table.row();//.pad(1, 0, 1, 0);
table.add(preferences).bottom().right().fillX().uniformX();
table.row();
table.add(exit).bottom().right().fillX().uniformX();

It was my skin. I used the sample "Rusty Robot UI", but it doesn't crop it's button images tightly. Tried another one and saw the stacking I was looking for.

Related

Re-sizing ImageButton - Scene2d

I am using libgdx + scene2d + box2d. Everything looked ok until I decided to replaced my TextButtons to ImageButton.
I can't get my ImageButton rezided, it always follows the image dimensions.
Here is my Stage:
stage = new Stage(new StretchViewport(camera.viewportWidth,camera.viewportHeight));
This how a create my Button:
ImageButtonStyle style = new ImageButtonStyle();
style.imageUp = new TextureRegionDrawable(textureButtonPlay);
ImageButton buttonPlay = new ImageButton(style);
buttonPlay.setSize(50, 20); //this does not work
This how a create my Window and add my Button to it:
WindowStyle windowStyle = new WindowStyle(new BitmapFont(), Color.WHITE, null);
windowTryAgain = new Window("", windowStyle);
windowTryAgain.setMovable(false);
//windowTryAgain.padTop(20);
windowTryAgain.setSize(150,150);
windowTryAgain.setPosition(camera.viewportWidth/2 - windowTryAgain.getWidth()/2,
camera.viewportHeight/2 - windowTryAgain.getHeight()/2);
windowTryAgain.row().fill().expandX();
windowTryAgain.add(buttonPlay).padTop(25).expandX().fillX();
windowTryAgain.center();
Is it possible to resize the Texture or TextureRegion? What would be the best approach?
My has issue has been resolved with following piece of code:
windowTryAgain.add(buttonMenu).width(100).height(100);
Then the image will resized accordiantly to the cell width and height.
Credits:
scene2d button scaling with libgdx

libGDX stage draw me mirrored text

I use Stage in libGDX for drawing GUI and adding listeners to controls in my game.
But when I draw text on ImageTextButton I get mirrored text as displayed on image below.
Can some help me and tell me how to draw normal text, not mirrored ?
stage = new Stage(Constants.VIEWPORT_GUI_WIDTH, Constants.VIEWPORT_GUI_HEIGHT);
stage.clear();
....
ImageTextButtonStyle imageTextButtonStyle = new ImageTextButtonStyle();
imageTextButtonStyle.font = Assets.instance.fonts.defaultSmall;
ImageTextButton imageTextButton = new ImageTextButton("ddsds", imageTextButtonStyle);
imageTextButton.setBackground( gameUISkin.getDrawable("fil_coins"));
imageTextButton.setPosition(50, 600);
imageTextButton.setHeight(85);
imageTextButton.setWidth(183);
stage.addActor(imageTextButton);
....
public void render (float deltaTime) {
stage.act(deltaTime);
stage.draw();
}
Thanks
Edit:
Button images are shown correct, only text has mirrored view
As #Springrbua suggest me in comment below, my bitmap font was flipped when creating.
defaultSmall = new BitmapFont(Gdx.files.internal("images/font.fnt"), true);
should be
defaultSmall = new BitmapFont(Gdx.files.internal("images/font.fnt"), false);
Even it's not case here it may be useful for someone - if font size parameter is set to negative value, text will be rendered upside-down (Y-scale).

Printing in Actionscript 3

How would I go about making a print screen run in flash. So when a user has arranged some artwork via a drag and drop flash/app - they click a button to 'Print' and there current design activates a printer?
Is this straight forward?
Thanks
I had a similar project and managed with something like the following example:
//creating a container as main canvas
var artworkContainers:Sprite = new Sprite();
addChild(artworkContainers);
//example adding content
var anyContentIWantToPrint:Sprite = new Sprite();
anyContentIWantToPrint.graphics.beginFill(0xf67821, 1);
anyContentIWantToPrint.graphics.drawRect(0, 0, 100, 100);
anyContentIWantToPrint.graphics.endFill();
artworkContainers.addChild(anyContentIWantToPrint);
var button:Sprite = new Sprite();
button.graphics.beginFill(0xf67821, 1);
button.graphics.drawRect(0, 0, 120, 60);
button.graphics.endFill();
addChild(button);
button.addEventListener(MouseEvent.CLICK, startPrintJobHandler, false, 0, true);
function startPrintJobHandler(event:MouseEvent):void
{
var printJob:PrintJob = new PrintJob();
printJob.start()
var printJobOptions:PrintJobOptions = new PrintJobOptions();
printJobOptions.printAsBitmap = true;
//When 'artworkContainer' will be your artwork canvas, where the user will drag and drop. Replace for the instance name you are using.
printJob.addPage(artworkContainer, null, printJobOptions);
printJob.send();
}
You can check out the PrintJob class.
You use the FlexPrintJob class to print one or more Flex objects, such as a Form or VBox container. For each object that you specify, Flex prints the object and all objects that it contains. The objects can be all or part of the displayed interface, or they can be components that format data specifically for printing. The FlexPrintJob class lets you scale the output to fit the page, and automatically uses multiple pages to print an object that does not fit on a single page.
You use the FlexPrintJob class to print a dynamically rendered
document that you format specifically for printing. This capability is
especially useful for rendering and printing such information as
receipts, itineraries, and other displays that contain external
dynamic content, such as database content and dynamic text.
You often use the FlexPrintJob class within an event listener. For
example, you can use a Button control with an event listener that
prints some or all of the application.
Note: The FlexPrintJob class causes the operating system to display a
Print dialog box. You cannot print without some user action.
Here is an example from Adobe's Live Docs.
private function doPrint():void {
// Create an instance of the FlexPrintJob class.
var printJob:FlexPrintJob = new FlexPrintJob();
// Start the print job.
if (printJob.start() != true) return;
// Add the object to print. Do not scale it.
printJob.addObject(myDataGrid, FlexPrintJobScaleType.NONE);
// Send the job to the printer.
printJob.send();
}
You probably want to look at the PrintJob functionality. You can add and arrange pages, etc. Examples on the Adobe help page.

ShapeRenderer doesn't render when using Skins

My shapes drawn by shape renderer does not show when I use skins. The shape is drawn inside the actor using an instance of ShapeRenderer. I think this is caused by the skin because I tried adding an empty table and the shapes show, but if I add an instance of a skin the shapes does not show.
This code is from the libgdx tests in github:
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Label nameLabel = new Label("Name:", skin);
Table t1 = new Table();
t1.setFillParent(true);
t1.add(nameLabel);
stage.addActor(t1);
you need to .end() the SpriteBatch befor using the ShapeRender.begin() after the ShapeRender.end() you need to call SpriteBatch.begin() in your actor. Else you do have 2 concurenting batches.
actor.draw(SpriteBatch batch, float delta){
batch.end();
ShapeRender.begin(Some Typee);//start it with your shapetype
//drawing stuff with the shaperender
ShapeRender.end();//dont forget to end it
batch.begin(); //need to be started again for the next actors to be dawn
}
An empty table shouldnt be a problem.

How to add editable JComboBox and Button on same Frame..?

I have created a JTable with 5 columns in it .I want the sixth column to have all cells as JComboBox from where an user can select his choice and the change will get appended in databasefor which i need a button on whose action i can fire the query to my database. So please please let me know how to add JComboBox and ButTon on JFrame...?? I am very new to Swings so do let me know how to get this donea detailed explanation about the same will be very thankful...!!! Thanks in advance..!!!
How to add JComboBox and JButton on a JFrame is rather trivial. Linking this question to the first part of your question with the table is something I did not manage. But for the part I did understand, you can have something like
JFrame frame = new JFrame( "TestFrame" );
JPanel contents = new JPanel( new BorderLayout() );
JComboBox comboBox = createComboBox();
contents.add( comboBox, BorderLayout.CENTER );
JButton button = createButton();
contents.add( button, BorderLayout.EASTH );
frame.add( contents );
frame.pack();
frame.setVisible( true );
The code illustrates how to add a combobox and a button. Note that I opted for the very simple BorderLayout. Other layouts are certainly possible, but it all depends on the requirements of your layout.