MenuItemLabel callback not working, never calls the callback, but the MenuItemImage works - cocos2d-x-3.0

Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Vector<MenuItem*> menuItems;
auto label = Label::createWithTTF("Space Combat", "fonts/Marker Felt.ttf", 24);
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
this->addChild(label, 1);
auto closeItem = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(MainMenu::menuCloseCallback, this));
closeItem->setPosition(origin.x + visibleSize.width - closeItem->getContentSize().width/2,
origin.y + closeItem->getContentSize().height/2);
menuItems.pushBack(closeItem);
auto playLabel = Label::createWithTTF("Play", "fonts/Marker Felt.ttf", 24);
playLabel->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height *2));
auto playItem = MenuItemLabel::create(playLabel, CC_CALLBACK_1(MainMenu::menuPlayCallback, this));
menuItems.pushBack(playItem);
auto menu = Menu::create();
menu->addChild(closeItem);
menu->addChild(playItem);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
auto sprite = Sprite::create("HelloWorld.png");
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(sprite, 0);
return true;
}
The above code will call my menuCloseCallback when the MenuItemImage is clicked on, but won't do the same for the MenuItemLabel.

Figured it out. I was positioning the label, but the menu item was being placed in the default location of 0,0 anchor 0,0. Once i added the label and positioned the menu item, all was well.

Related

Present Sheet in a center of parent window

I use function
NSViewController.PresentViewControllerAsSheet(NSViewController)
and everything works great, but I would like to have a chance change the position of this sheet (for ex. in the center of parent).
How to do that ?
Ok, I have found solution:
C# code, Xamarin.Mac
controller.PresentViewControllerAsModalWindow(_settingsController);
if (_settingsController.View.Window != null)
{
var x = (_window.Frame.Left) + (_window.Frame.Width / 2) - 400;
var y = (_window.Frame.Top) + (_window.Frame.Height / 2) - 300;
_settingsController.View.Window.SetFrame(new CoreGraphics.CGRect(x, y, 800, 600), true);
_settingsController.View.Window.TitleVisibility = NSWindowTitleVisibility.Hidden;
_settingsController.View.Window.TitlebarAppearsTransparent = true;
_settingsController.View.Window.StyleMask = NSWindowStyle.FullSizeContentView | NSWindowStyle.Borderless;
_settingsController.View.Window.IsMovable = false;
}

Underlining with pdfnet results in different line thickness

The code that i use for underlining a selection of text. I begin calling the addUnderline() method, the other methods are helper methods.
private pdftron.SDF.Obj CreateUnderlineAppearance(pdftron.PDF.Rect bbox)
{
ElementBuilder builder = new ElementBuilder();
ElementWriter writer = new ElementWriter();
builder.PathBegin();
builder.MoveTo(bbox.x1, bbox.y1);
builder.LineTo(bbox.x2, bbox.y1);
Element line = builder.PathEnd();
//Set color attributes for the line...
line.SetPathFill(false);
line.SetPathStroke(true);
GState gs = line.GetGState();
gs.SetStrokeColorSpace(ColorSpace.CreateDeviceRGB());
gs.SetStrokeColor(new ColorPt(0, 0, 0)); // black
gs.SetLineWidth(2);
writer.Begin(m_document);
writer.WriteElement(line);
pdftron.SDF.Obj stm = writer.End();
builder.Dispose();
writer.Dispose();
// Set the bounding box
stm.PutRect("BBox", bbox.x1, bbox.y1, bbox.x2, bbox.y2);
stm.PutName("Subtype", "Form");
return stm;
}
public Annot CreateUnderlineAnnot(pdftron.PDF.Rect rect)
{
Annot underlineAnnot = Annot.Create(m_document, Annot.Type.e_Underline, rect);
underlineAnnot.SetAppearance(CreateUnderlineAppearance(rect));
return underlineAnnot;
}
public void AddUnderline()
{
if (m_document != null)
{
PDFViewCtrl.Selection selection = m_pdfViewer.GetSelection();
int pageNumber = selection.GetPageNum();
double[] quads = selection.GetQuads();
int numQuads = quads.Length / 8;
if (quads.Length % 8 == 0) //must have at least 8 points to be valid
{
Console.WriteLine("GetRectsFromQuads - numQuads: " + numQuads.ToString());
for (int i = 0; i < numQuads; i++)
{
Rect selectionRect = GetSelectionRect(ref quads, i);
//Console.WriteLine("GetRectsFromQuads - aRect: " + rectX1.ToString() + " | " + rectY1.ToString() + " | " + rectX2.ToString() + " | " + rectY2.ToString());
Annot underlineAnnot = CreateUnderlineAnnot(selectionRect);
m_pdfViewer.AddUnderlineAnnotationToPage(underlineAnnot, pageNumber);
//m_pdfViewer.Refresh(); --> to see how this algorithm works when debugging
}
m_pdfViewer.RefreshAnnotations();
}
}
}
You can see in the image if you look closely that some lines are thicker or thinner than others. Is this fixable? by the way, when i zoom in/out the problem is gone...
You need to set the following on your pdf view control:
PDFViewCtrl.SetThinLineAdjustment(true, true);
That will remove the aliasing on the lines, and mean all lines that are 1.5px are 1px, and so on. See here: https://www.pdftron.com/pdfnet/mobile/docs/WinRT/html/M_pdftron_PDF_PDFViewCtrl_SetThinLineAdjustment.htm

cocos2dx: Sprite3D rotating, culling error

Hi I'm trying to have 2 sprites with different z in 3d world and a camera that rotates around the center of the screen and points at the center of the screen.
Even if the sprites has different z (and zorder, I don't know if this is necessary) the sprites are always visualized while I'm expecting to have the second sprite hided from the other...
This is helloworld layer init
auto sp3d = Sprite3D::create();
sp3d->setPosition(visibleSize.width/2, visibleSize.height/2);
addChild(sp3d);
auto sprite = Sprite::create("JP9_table.png");
auto spritePos = Vec3(0,0,0);
sprite->setScale(0.3);
sprite->setPosition3D(spritePos);
sp3d->addChild(sprite,0);
auto sprite2 = Sprite::create("JP9_logo_yc.png");
auto spritePos2 = Vec3(0,0,10);
sprite2->setPosition3D(spritePos2);
sp3d->addChild(sprite2,10);
sp3d->setCullFace(GL_BACK);
sp3d->setCullFaceEnabled(true);
this->setCameraMask((unsigned short)CameraFlag::USER2, true);
camera = Camera::createPerspective(60, (float)visibleSize.width/visibleSize.height, 1.0, 1000);
camera->setCameraFlag(CameraFlag::USER2);
camera->setPosition3D(spritePos + Vec3(-200,0,800));
camera->lookAt(spritePos, Vec3(0.0,1.0,0.0));
this->addChild(camera);
this->scheduleUpdate();
angle=0;
and this is update:
void TestScene::update(float dt)
{
angle+=0.1;
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Vec3 spritePos=Vec3(visibleSize.width/2,visibleSize.height/2,0);
camera->setPosition3D(Vec3(visibleSize.width/2,visibleSize.height/2,0) + Vec3(800*cos(angle),0,800*sin(angle)));
camera->lookAt(spritePos, Vec3(0.0,1.0,0.0));
}
I have tryed something simplier:
auto sp3d = Sprite3D::create();
sp3d->setPosition(visibleSize.width/2, visibleSize.height/2);
addChild(sp3d);
auto sprite = Sprite::create("JP9_table.png");
auto spritePos = Vec3(0,0,0);
sprite->setScale(0.3);
sprite->setPosition3D(spritePos);
sp3d->addChild(sprite,0);
auto sprite2 = Sprite::create("JP9_logo_yc.png");
auto spritePos2 = Vec3(0,0,10);
sprite2->setPosition3D(spritePos2);
sp3d->addChild(sprite2,10);
sp3d->setCullFace(GL_BACK);
sp3d->setCullFaceEnabled(true);
even with sp3d->runAction(RotateTo::create(20,vec3(0,3000,0))) same error.
Is it a cocos2dx bug?
the sprite with z=10 disappear before it is covered by the other sprite...
remain hidden for a while, and when it should be hidden completely reappear!!!
Do I have forgot something?
thanks
Maybe you should check this.
_camControlNode = Node::create();
_camControlNode->setNormalizedPosition(Vec2(.5,.5));
addChild(_camControlNode);
_camNode = Node::create();
_camNode->setPositionZ(Camera::getDefaultCamera()->getPosition3D().z);
_camControlNode->addChild(_camNode);
auto sp3d = Sprite3D::create();
sp3d->setPosition(s.width/2, s.height/2);
addChild(sp3d);
auto lship = Label::create();
lship->setString("Ship");
lship->setPosition(0, 20);
sp3d->addChild(lship);
and
_lis->onTouchMoved = [this](Touch* t, Event* e) {
float dx = t->getDelta().x;
Vec3 rot = _camControlNode->getRotation3D();
rot.y += dx;
_camControlNode->setRotation3D(rot);
Vec3 worldPos;
_camNode->getNodeToWorldTransform().getTranslation(&worldPos);
Camera::getDefaultCamera()->setPosition3D(worldPos);
Camera::getDefaultCamera()->lookAt(_camControlNode->getPosition3D());
};

css style transform

I wanted to be able to put into effect the css transform property depending on the size of a container with respect to the size of the enclosing window.
With the following code, scaleCameraShutter() is called. Zooming does occur with the re-written code for scaleCameraShutter()and the scaling is accurate.
Here's the only remaining problem = window resizes and so does the container. THEN, I do a reload of the window and the correct zooming totally disappears. In short, the zooming is only temporary, not permanent??
Since this Board thrives on code, the .css specs are at the bottom ...
$(window).bind('resize', function() {
scaleCameraShutter(); // below, container is GLOBAL
});
I call:
function scaleCameraShutter() {
// .width() returns "###px"
// value before scaling
var containerWidth = parseInt( container.width() );
var windowWidth = parseInt( $(window).width() );
var theScale = windowWidth/containerWidth;
var maxContainerWidth = 480;
if (windowWidth > maxContainerWidth)
{
theScale = maxContainerWidth/containerWidth;
}
// Let the Browser pick the parm it accepts:
// IE 10 and Firefox
container.css("-transform" , "scale(" + theScale + ", " + theScale + ")");
// IE 9
container.css("-ms-transform" , "scale(" + theScale + ", " + theScale + ")");
// Firefox
container.css("-moz-transform" , "scale(" + theScale + ", " + theScale + ")");
// Chrome and Safari
container.css("-webkit-transform", "scale(" + theScale + ", " + theScale + ")");
// Opera
container.css("-o-transform" , "scale(" + theScale + ", " + theScale + ")");
}
Last, here's the css:
#container {
position: relative;
margin: 0 auto;
width: 30.00em;
height: 22.50em;
}
As Far as I know, you are passing only one value to SCALE. Try doing one of the following:
scale(x,y) Defines a 2D scale transformation
scale3d(x,y,z) Defines a 3D scale transformation
scaleX(x) Defines a scale transformation by giving a value for the X-axis
scaleY(y) Defines a scale transformation by giving a value for the Y-axis
scaleZ(z) Defines a 3D scale transformation by giving a value for the Z-axis
http://www.w3schools.com/cssref/css3_pr_transform.asp
good luck.

How to create a combo box(drop down list) with button controls for window form tool strip???

Like a layer control drop down in AutoCAD.
Thanks.
I solved it myself...
I create a user control which inherit the combo box class,this control works fine for me like a normal combo box.
Here is a code, that may help you to understand more about this control.
public partial class dropdown : ComboBox
{
public dropdown()
{
this.DrawMode = DrawMode.OwnerDrawVariable;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
// Make sure we're not trying to draw something that isn't there.
if (e.Index >= this.Items.Count || e.Index <= -1)
return;
// Get the item object.
object item = this.Items[e.Index];
if (item == null)
return;
// Draw the background color depending on
// if the item is selected or not.
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
// The item is selected.
// We want a blue background color.
e.Graphics.FillRectangle(new SolidBrush(Color.Moccasin), e.Bounds);
}
else
{
// The item is NOT selected.
// We want a white background color.
e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
}
if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit)
{
e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
}
// Draw the items...
LayerEdit le = (LayerEdit)item;
string text = le.LayerName.ToString();
SizeF stringSize = e.Graphics.MeasureString(text, this.Font);
// Draw layer visible(on/off)...
e.Graphics.DrawImage(byteArrayToImage(le.Visible), 2, 1 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 14, 14);
// Draw layer Lock...
e.Graphics.DrawImage(byteArrayToImage(le.Lock), 18, 1 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 15, 14);
// Draw layer plot...
e.Graphics.DrawImage(byteArrayToImage(le.Plot), 37, 1 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 14, 14);
// Draw layer color...
Brush brush = new SolidBrush(ColorTranslator.FromHtml(le.ColourValue));
e.Graphics.FillRectangle(brush, 55, 4 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 10, 10);
e.Graphics.DrawRectangle(Pens.Black, 55, 4 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 10, 10);
// Draw layer name...
e.Graphics.DrawString(text, this.Font, new SolidBrush(Color.Black), new PointF(68, e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2));
}
//convert bytes into image...
public Image byteArrayToImage(byte[] byteArrayIn)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
}