Just starting out hope this isn’t too noob a question
For the game I’m working on I want to have different tabs, the effect of which would be similar to an iOS bottom tab controller as pictured:
Where I’m at a loss is how to create this? Should this all be on one Scene with different layers being turned on and off? Should I be using multiple Scenes?
Seems like keeping this in one scene wouldn’t really scale. How is this normally done, does cocos2d-x have some sort of concept of containers or something?
I would suggest that you have 2 layers:
The first layers will deal with the images. I guess you can use
ImageView. and position them with the size that you want.
The second part is a tab menu that can be implemented with a second
layer in which you will add the buttons and the background. for the
buttons use the Button class.
I hope that helps.
bool ScreenController::init(){
if(Layer::init())
{
footer = Footer::create();
footer->setDelegate(this);
this->addChild(footer,3);
auto homeLayer= HomeView::create(psize,this);
homeLayer->setPosition(Point(0,footer->getBoundingBox().getMaxY()));
// homeLayer->setAllApiFireTo(this);
auto rakeLayer = RakeView::create(psize);
rakeLayer->setPosition(Point(0,footer->getBoundingBox().getMaxY()));
rakeLayer->setDelegate(this);
Tablayers = LayerMultiplex::create();
Tablayers->addLayer(homeLayer);
Tablayers->addLayer(rakeLayer);
this->addChild(Tablayers);
}
}
void ScreenController::TabControllerAction(ViewDisplayType type) {
Tablayers -> switchTo(index);
}
bool Footer::init(){
if(Layer::init())
{
this->setContentSize(Size(constantDeviceSize.width,108*gamescaleY));
// auto btlayer = LayerColor::create(Color4B::RED,this->getContentSize().width,this->getContentSize().height);
//
// this->addChild(btlayer);
SubButton*sb1 = SubButton::create(Size(this->getContentSize().width/5,this->getContentSize().height),"Home.png","Home.png",CC_CALLBACK_2(Footer::callMenuItem, this) );
sb1->setAnchorPoint(Point(0,0));
sb1->setPosition(Point(0,0));
sb1->addTitleText("Home", SFUI_Regular.c_str());
sb1->colorEfact(true);
sb1->setColorbtn(Color3B::WHITE,colorSkyBlue3B);
this->addChild(sb1);
SubButton*sb2 = SubButton::create(Size(this->getContentSize().width/5,this->getContentSize().height),"Balance.png","Balance.png",CC_CALLBACK_2(Footer::callMenuItem, this));
sb2->setAnchorPoint(Point(0,0));
sb2->setPosition(Point(sb2->getBoundingBox().size.width,0));
sb2->addTitleText("Rake", "arial.ttf");
sb2->colorEfact(true);
sb2->setColorbtn(Color3B::WHITE,colorSkyBlue3B);
this->addChild(sb2);
sb1->setDisplayType(myHomeView);
sb2->setDisplayType(myRakeView);
}
void Footer::selectionByController(int tab)
{
auto tmpbar = dynamic_cast<SubButton *>(this -> getChildren().at(tab-1));
callMenuItem(tmpbar, TouchBegan);
}
void Footer::callMenuItem(Ref *sender, TouchEvent event)
{
if(event==TouchBegan)
{
auto sbitem = (SubButton*)sender;
if(event==TouchBegan)
{
sbitem->selected();
if(this->getDelegate())
{
this->getDelegate()->TabControllerAction(sbitem->getDisplayType());/*call to parant*/
}
CCLOG("CLICKED!->%d",sbitem->getTag());
}
for (int i = 0; i < this->getChildren().size(); i++)
{
auto tmpbar = dynamic_cast<SubButton *>(this -> getChildren().at(i));
if (tmpbar != NULL && tmpbar -> getTag() != sbitem -> getTag())
{
tmpbar ->unSelected();
}
}
}
}
Related
I am using the ITextSharp for creating a PDF document. As part of creating a document, I have to render a HTML block in a window of a particular page. I am using the below code to render the HTML. Surprisingly it is not rendering the HTML.
I have attached the HTML Here
public override Rectangle Draw(Rectangle curRectangle)
{
try
{
var column = new ColumnText(this.DocRenderer.PdfDocContentByte);
string css = "p {font-family:HELVETICA; font-style:normal; color:black; font-size:10px}"
+ " li {font-family:HELVETICA; font-style:normal; color:black;font-size:10px}";
foreach (var element in XMLWorkerHelper.ParseToElementList(FileContents of guide.html, css))
{
column.AddElement(element);
}
curRectangle = this.SimulateHeight(curRectangle, column);
column.SetSimpleColumn(curRectangle);
column.Go(false);
}
catch (Exception ex)
{
Logger.LogError(ex.Message, ex);
}
return curRectangle;
}
private Rectangle SimulateHeight(Rectangle curRectangle,ColumnText column)
{
float top = 15;
column.SetSimpleColumn(curRectangle.Left, curRectangle.Bottom, curRectangle.Right, top);
int status = column.Go(true);
top = column.YLine-1;
return new Rectangle(curRectangle.Left, curRectangle.Bottom, curRectangle.Right, top);
}
Even if it only is simulating, your line
int status = column.Go(true);
swallows all composite content added to column if all that content fits into the rectangle. (This allows to easily simulate drawing yet more composite content to the same ColumnText.)
Thus, if the status value is ColumnText.NO_MORE_TEXT, you'll have to add it again, e.g. like this:
private iTextSharp.text.Rectangle SimulateHeight(iTextSharp.text.Rectangle curRectangle, ColumnText column)
{
var compositeContent = new List<IElement>(column.CompositeElements);
float top = 15;
column.SetSimpleColumn(curRectangle.Left, curRectangle.Bottom, curRectangle.Right, top);
int status = column.Go(true);
if (ColumnText.NO_MORE_TEXT == status)
{
foreach (var element in compositeContent)
{
column.AddElement(element);
}
}
top = column.YLine - 1;
return new iTextSharp.text.Rectangle(curRectangle.Left, curRectangle.Bottom, curRectangle.Right, top);
}
Actually even for other status values that list may be partially emptied of the top level elements that did fit. In your case, though, there is but one top level element, the div, so if that does not fit completely, it remains.
As an aside, you use a top value located near to the actual bottom of the page, so it actually is the bottom y coordinate. Such a naming is quite misleading.
I'm new to cocos2d and I'm trying to make a menu. I created a MenuItemImage here:
mSetting = MenuItemImage::create("setting.png", "setting_selected.png");
Now I'm looking for a way to add glowing effect to the border of it in stead of a boring static setting_selected.png image.
(for example: the light-blue glowing border of the menu image here , check at 1:00 https://youtu.be/PJSlvhDbB4I?t=1m).
Your attention and help is very much appreciated :D
Update: I have an idea that using a sprite with square shape, which exactly fits the menu item to make it looks like the border of it. Then make it animate (changing color) to show glowing effects likes how they do in the video. Is that possible, easy and effective to do the job?
You can use MenuItemSprite instead of MenuItemImage and run actions when menu item is clicked. Look at this link:
Cocos2d-x: simple button effect
You should find more actions here: Cocos2d-x actions
I update and write the example to be similar to what you need (It's not exactly what you want but may help you).
I have a scene named EditorScene.
In EditorScene.h:
....
virtual void onMenuItemSelected(Ref *item );
MenuItemSprite* createMenuButton( const char* img );
MenuItemSprite* btEnter;
void actionEnter();
....
And in EditorScene.cpp:
bool EditorScene::init()
{
...
btEnter = createMenuButton("button_normal.png");
auto menu = Menu::create(btEnter, nullptr);
menu->setPosition( 400,400);
addChild(menu);
}
MenuItemSprite* EditorScene::createMenuButton( const char* img )
{
Sprite* spr = Sprite::create( img );
auto light = Sprite::create( "a2.png" );
light->setTag( 1 );
light->setPosition( 0,
spr->getBoundingBox().size.height );
light->setOpacity( 0 );
if( ! spr )
{
return NULL;
}
MenuItemSprite* item = MenuItemSprite::create( spr,
NULL, NULL,
CC_CALLBACK_1( EditorScene::onMenuItemSelected, this ) );
item->addChild(light);
return item;
}
void EditorScene::onMenuItemSelected( Ref* item ) {
Sprite* btm = (Sprite*) item;
Sprite* light = (Sprite*)btm->getChildByTag( 1 );
if( item == btEnter ){
float w = btm->getBoundingBox().size.width;
float h = btm->getBoundingBox().size.height;
std::function<void(void)> f1 = std::bind(&EditorScene::actionEnter, this);
light->runAction(
Sequence::create(
FadeIn::create(0),
MoveBy::create( 0.09f, Vec2(w, 0) ),
MoveBy::create( 0.045f, Vec2(0, -h) ),
MoveBy::create( 0.09f, Vec2(-w, 0) ),
MoveBy::create( 0.045f, Vec2(0, h) ),
FadeOut::create(0),
CallFunc::create( f1 ),
NULL ) );
}
}
void EditorScene::actionEnter()
{
log("Do something!");
}
This code creates a menu item that by clicking shows a small dot orbiting on border of button:
You can use Animation::createWithSpriteFrames if you want to animate your menu item's background.
I have a QTableview (multiple columns, sorting) and would like to add a button that shows additional data below the current row. For the rendering of this additional data I would like to use another widget, that fills up a variable height and spans all the rows.
While I know that I can create delegates for cells, I was wondering if this is possible for rows or whether that would mean that I would have to inherit from a tableview and modify its paint method, which seems to be lot of work for a novice like me.
QVariant YourTableModel::data(const QModelIndex & index, int32_t role) const
{
if (!index.isValid()) {
return QVariant();
}
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
switch (index.column())
{
case YOUR_COL:
double theDouble = getDoubleFromModelSomewhere();
return QString::number(theDouble, 'f', 3); // Format shows 3 decimals
}
}
return QVariant();
}
If I have understood your question properly then I think this is the answer.
QTableView *view = new QTableView;
view->setItemDelegateForRow(int row, QAbstractItemDelegate *delegate);
I'm trying to make a custom GTK widget in Vala, but I'm already failing at the very first basic attempt, so I'd like some help in knowing where I'm going wrong. I feel like I must be missing something painstakingly obvious, but I just can't see it.
I have three files with the following contents:
start.vala:
using Gtk;
namespace WTF
{
MainWindow main_window;
int main(string[] args)
{
Gtk.init(ref args);
main_window = new MainWindow();
Gtk.main();
return 0;
}
}
main_window.vala:
using Gtk;
namespace WTF
{
public class MainWindow : Window
{
public MainWindow()
{
/* */
Entry entry = new Entry();
entry.set_text("Yo!");
this.add(entry);
/* */
/*
CustomWidget cw = new CustomWidget();
this.add(cw);
/* */
this.window_position = WindowPosition.CENTER;
this.set_default_size(400, 200);
this.destroy.connect(Gtk.main_quit);
this.show_all();
}
}
}
custom_widget.vala:
using Gtk;
namespace WTF
{
public class CustomWidget : Bin
{
public CustomWidget()
{
Entry entry = new Entry();
entry.set_text("Yo");
this.add(entry);
this.show_all();
}
}
}
As you can see, in main_window.vala, I have two sets of code. One that adds the Entry widget directly, and one that adds my custom widget. If you run the one that adds the Entry widget directly, you get this result:
If you run the one with the custom widget, however, you get this result:
Just for the record, this is the complication command I use:
valac --pkg gtk+-2.0 start.vala main_window.vala custom_widget.vala -o wtf
EDIT:
Following user4815162342's suggestion, I implemented the size_allocate method on my custom Bin widget, like so:
public override void size_allocate(Gdk.Rectangle r)
{
stdout.printf("Size_allocate: %d,%d ; %d,%d\n", r.x, r.y, r.width, r.height);
Allocation a = Allocation() { x = r.x, y = r.y, width = r.width, height = r.height };
this.set_allocation(a);
stdout.printf("\tHas child: %s\n", this.child != null ? "true" : "false");
if (this.child != null)
{
int border_width = (int)this.border_width;
Gdk.Rectangle cr = Gdk.Rectangle()
{
x = r.x + border_width,
y = r.y + border_width,
width = r.width - 2 * border_width,
height = r.height - 2 * border_width
};
stdout.printf("\tChild size allocate: %d,%d ; %d, %d\n", cr.x, cr.y, cr.width, cr.height);
this.child.size_allocate(cr);
}
}
It writes the following in the console:
Size_allocate: 0,0 ; 400,200
Has child: true
Child size allocate: 0,0 ; 400, 200
And the window renders thusly:
GtkBin is an abstract single-child container, typically intended to decorate the child widget in some way, or change its visibility or size. Without some added value, a single-child container would be indistinguishable from the widget it contains and therefore not very useful.
Since GtkBin doesn't know what kind of decorations you will draw around the child, it expects you to implement your own size_allocate. A simple implementation is available in gtk_event_area_size_allocate, a more complex one in gtk_button_size_allocate.
This answer shows a minimal size_allocate implementation in PyGTK which should be straightforward to port to Vala. If you do anything more complex than that, you will need to also implement expose, and possibly other methods, but this will get you started.
I've got a flash vertical menu which has auto-scroll but it scrolls too fast and the only way to slow it down is to increase the height of the button.
I would like to replace the code with a scrollpane so I can control the menu:
Code chunk I need to remove then add the additional scrollpane code
menu_mc_Europe.onEnterFrame = function() {
if (_ymouse>10 && _ymouse<boundry_mc._height && _xmouse>0 && _xmouse<boundry_mc._width) {
ratio = (menu_mc_Europe._height-boundry_mc._height)/(boundry_mc._height);
if (_ymouse>boundry_mc._height/2) {
destScroll = -(_ymouse)*ratio-menu_mc_Europe.bttn_mc._height*ratio;
} else {
destScroll = -(_ymouse)*ratio
}
menu_mc_Europe._y += Math.round((destScroll-menu_mc_Europe._y)/5);
if (menu_mc_Europe._y<-(totalBttns*menu_mc_Europe.bttn_mc._height-boundry_mc._height)) {
menu_mc_Europe._y = -(totalBttns*menu_mc_Europe.bttn_mc._height-boundry_mc._height);
}
} else {
destScroll = 1;
menu_mc_Europe._y += Math.round((destScroll-menu_mc_Europe._y)/5);
}
};
hard to read that code w/out line breaks - what does 'ratio' represent above? is it a variable you can set? if not, just a wild guess, but try changing the divisor (the 5) in the '_y)/5' sections above?