Removing a body with box2D - cocos2d-iphone

I need to remove a certain vector from my world bounds, for example only the left one.
(box2d+cocos2d iphone)
This is how I set the bounds:
screenBorderShape.Set(lowerLeftCorner, lowerRightCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(lowerRightCorner, upperRightCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(upperRightCorner, upperLeftCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(upperLeftCorner, lowerLeftCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
How can I remove the left one ONLY?
I know this :
screenBorderBody->DestroyFixture(b2Fixture *fixture)
But I need to do that later on, so can I reach that fixture (having the body pointer) without saving this specific one as a global?
Thanks.

screenBorderShape.Set(lowerRightCorner, upperRightCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
Name this fixture as left fixture or left wall....
After this you can use screenBorderBody->DestroyFixture(<#b2Fixture *fixture#>)
...
The way is
groundBox.Set(b2Vec2(X1/PTM_RATIO,Y1/PTM_RATIO), b2Vec2(X2/PTM_RATIO, Y1/PTM_RATIO));
bottomFixture = groundBody->CreateFixture(&groundBoxDef);
and then remove bottom fixture (left in your case)
In caseyou just want to cancel the collisions do it by setting category or mask bits that way

Related

UXTheme: Draw Combobox Chevron Without Border

I'm trying to draw a custom control that should use the "combobox" theme class.
Using
m_hTheme = OpenThemeData(m_hWnd, _T("COMBOBOX"));
auto stateBG = ...; // depends on window state
DrawThemeBackground(m_hTheme, ps.hdc, CP_READONLY, stateBG, &clientRect, nullptr);
gives the correct background (read-only-look) without the chevron. But how do I add the chevron?
auto stateCV = ...; // depends on window state
DrawThemeBackground(m_hTheme, ps.hdc, CP_DROPDOWNBUTTON, stateCV, &rect, nullptr);
draws the chevron correctly, but with its own border and the chevron centered within the rect. So if I use the full client rect, I get this:
If I use a smaller rect so that the chevron is positioned correctly, I get a separated dropdown:
How do I get the "normal" look? - i.e like this:
Bonus Questions:
Is there any documentation that does a better job than MSDN? It's as sparse as most newer documentation, e.g. just listing "Parts and States", without describing their purpose (which is not always obvious), and whether it's DrawThemeBackground or ~Edgefor a particular item.
Do I still use the good old DrawFocusRectfor the focus rect?
GetThemeBackgroundContentRect calculates the expected rectable for iPartId=CP_READONLY, but for iPartId=CP_CUEBANNER, it returns the full client rectangle, so the cue text is badly aligned. Is this... normal?
Have you tried replacing CP_DROPDOWNBUTTON by CP_DROPDOWNBUTTONRIGHT ?
As a workaround you could use the ClipRect of DrawThemeBackground to cut off the left edge of the drop down button.
CRect clip_rect = rect;
clip_rect.DeflateRect(1, 0, 0, 0);
auto stateCV = ...; // depends on window state
DrawThemeBackground(m_hTheme, ps.hdc, CP_DROPDOWNBUTTON, stateCV, &rect, &clip_rect);

qt chart remove space for title/legend/

I want to display a QPolarChart in a QChartView.
I won't add a title or a legend anything else than the QPolarChart.
Unfortunately, when I add my chart I have bit empty white space around the QPolarChart.I guess this is the space for the title and or the legend...
Is there a way to reduce this space?
I already used
chart->layout()->setContentsMargins(0, 0, 0, 0);
chart->setBackgroundRoundness(0);
which helped a bit.
I want to reduce the red margins:
Seems like you already followed the guidelines from the answers to the related question: How to remove margin from QChartView or QChart
If you are still not satisfied with the result, you can go one step further and use negative values by calling setContentsMargins directly on the chart object:
chart->setContentsMargins(-10, -10, -10, -10);
while keeping your layout object margins at 0 as you were doing already:
chart->layout()->setContentsMargins(0, 0, 0, 0);
I've done this in the past and it always worked fine, although it's a bit of a hack.
Also, the legend takes up some space so don't forget to hide it if you don't need it.
chart->legend()->hide();
This is the result you will get after making these changes:
You might try experimenting with negative values other than -10 to get the desired result.

Scrolling a very large GtkDrawingArea

I have a GtkDrawingArea that is used to visualize data.
Depending on the database and user input the drawing can grow really large (larger than the maximum allowed GtkDrawingArea size). Therefore I would like to use a drawing area that is just as big as the current window and update it manually upon scrolling.
If I use the ScrolledWindow + Viewport method to add scroll-bars to the drawing area it does obviously not work because the drawing area is not big enough to need scroll-bars.
Is there any way that that I can trick the viewport into thinking that the underlying widget is larger than it actually is?
If not what would be the best way to solve this problem?
Note: I am using Gtk2 and switching to Gtk3 is not a possibility.
You need to subclass GtkDrawingArea and override the set_scroll_adjustments signal. GtkWidget docs
In this signal you will get the adjustments for the scrolled window. I wrote some code a few years back that you can look at to see how to implement it.
MarlinSampleView code
This code was able to pretend that the widget was millions of pixels wide when in reality it wasn't any bigger than the window.
It turned out to be quite simple:
The GtkScrolledWindow has another constructor which can be used to set the GtkAdjustments that the scrolled window should use.
//These adjustments will be attached to the scrollbars.
prvt->hAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 0, 0, 0));
prvt->vAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 0, 0, 0));
GtkWidget* scrolledTree = gtk_scrolled_window_new(prvt->hAdjustment, prvt->vAdjustment);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledTree), drawing_area);
Now, whenever the size of the drawing changes you just need to modify the GTKAdjustments to simulate the change. There is no need to actually resize the drawing area.
gtk_adjustment_set_lower(prvt->hAdjustment, 0);
gtk_adjustment_set_step_increment(prvt->hAdjustment, 1);
gtk_adjustment_set_page_increment(prvt->hAdjustment, 10);
gtk_adjustment_set_upper(prvt->hAdjustment, picture_width);
gtk_adjustment_set_page_size(prvt->hAdjustment, scrollArea_width);
gtk_adjustment_changed(prvt->hAdjustment);
Notice that I call gtk_adjustment_changed in the end. This is important, otherwise the ScrolledWindow will not update the scrollbars.
Finaly the value_changed callback of the GtkAdjustmens can be used to catch the scroll events and adjust the drawing.
Edit: This does not work properly because the GtkScrolledWindow receives the scroll event
as well and moves the image :(

display lists wont run

I am trying to create a tool that will draw a shape in openGL and then modify the values of the properties of that shape in a windows form. So if my shape is a rectangle, I will create a form that will allow the user to control the size, color etc of the rectangle. I have written the openGL code in managed c++ and the form in c#, and as some of these shapes got more complicated I decided to make display lists for them (for both performance and predictability purposes).
I define the display list in the constructor for the shape and I call the display lists in the render method.
My issue is that my display lists won't run at all. The parts that I render outside of a display list will be rendered, but the parts inside the display list will not be rendered.
Here's some sample code of my process:
//c# side
GLRectangle rect
public CSharpRectangle() {
rect = new GLRectangle();
}
//managed c++ side
public GLRectangle() {
width = 50;
height = 50;
//initialize more values
rectDL = glGenLists(1);
glNewList(rectDL, GL_COMPILE);
renderRect();
glEndList();
}
public render() {
//Draw border
glBegin(GL_LINE_LOOP);
glVertex2f(0, 0);
glVertex2f(width, 0);
glVertex2f(width, height);
glVertex2f(0, height);
glEnd();
//Draw interior
glCallList(rectDL);
}
private renderRect() {
glRectf(0,0,width,height);
}
In this example, the border of the rectangle would be rendered, but the rectangle itself won't be rendered... if I replace the display list with simply a method call, the rectangle is rendered fine. Does anyone know why this might be happening?
I want to give my 2 cents.
The code in your question seems correct to me, so probably there something else in your application that make your display list not runnable.
The only thing I can think is there's no current context when compiling the display list (indeed when executing GlRectangle constructor). So, is that routine executed in the same thread which have called glMakeCurrent? Is that routine called after glMakeCurrent?
Further, check with glGetError after each OpenGL routine in order to validate the operation. In the case it returns an error, you can know what's wrong in your code..
The reason you may not get what you want is simply because it isn't there anymore. In time I was reading openGL Red book, I've noticed that display lists were deprecated in openGL 3.1 and higher (means simply removed) and googling for that confirmed it. I don't remember reason anymore, but I believe because it was messing with VAOs and VBOs. So if you are using higher than opengl 3.1 you won't get display lists anymore.

Point-in-poly for QPainterPath with holes

I'm trying to use a QGraphicsPathItem to represent a polygon with a hole in it (think doughnut). I can get it to draw correctly, and the center is transparent. However, with item selection or movement turned on, I am able to interact with my object when clicking in the hole. I'd rather treat the hole as not part of the polygon.
I've done some testing, and it appears that QPainterPath::contains() will return true when I check a point within the hole. Will I need to subclass QGraphicsPathItem to implement a more specific contains() function, or is there something else I'm missing?
If you change the filling rule from default value Qt::OddEvenFill to Qt::WindingFill, can you still see the hole? I guess you'll not be able to see the hole. So the hole is actually not a "physical" hole in your path. If you are going to represent a polygon with a hole, you may need to subclass the QGraphicsPathItem, explicitly define outer most path and holes, and maintain the relationship among paths in different role.
You'll need to subclass QGraphicsPathItem and reimplement the shape method. Here's what I did to solve the similar problem with an unfilled versus filled rectangle. This particular case is subclassed from QGraphicsRectItem. This also has some adjustment to the path width to make it easier for the user to click on, essentially a buffer zone around the path.
In the case of a filled rectangle, the returned shape is simply a rectangle, but for an unfilled rectangle, it's a stroked path with an empty interior. Then the object only moves when the user drags the edge, but not the middle. Figuring out the QPainterPathStroker wasn't intuitive from the documentation, but it was actually pretty simple to use.
QPainterPath MyRectItem::shape (void) const
{
if (this->brush().style() != Qt::NoBrush)
{
return QGraphicsRectItem::shape();
}
// The rectangle is unfilled. Create a path outlining the rectangle.
QPainterPath path;
QRectF rect = this->rect();
path.moveTo (rect.topLeft());
path.lineTo (rect.topRight());
path.lineTo (rect.bottomRight());
path.lineTo (rect.bottomLeft());
path.lineTo (rect.topLeft());
QPainterPathStroker stroker;
if (this->pen().style() != Qt::NoPen)
{
// For easier selection, increase the pen width to provide a buffer zone
// around the line where the user can click and still select.
stroker.setWidth (this->pen().width() + 20);
stroker.setCapStyle (this->pen().capStyle());
stroker.setJoinStyle (this->pen().joinStyle());
}
return stroker.createStroke (path);
}