wxWidgets issue using wxClientDc - wxwidgets

i'm be beginning to use wxWidgets in a project and i'm using wxClientDc to draw on a image. I created a class that inherits wxStaticBitmap adding my properties and drawing over it. To clear the image i'm setting the background as the same wxBitmap that i used in MY image:
//that is my class
class myImage : public wxStaticBitmap {
public:
wxBitmap frame; //imagem
myImage(wxWindow* parent, wxWindowID id, wxPoint pos, wxSize size, wxBitmap frame);
private:
void redesenha();
void mouseUp(wxMouseEvent& event);
void mouseDown(wxMouseEvent& event);
void mouseMove(wxMouseEvent& event);
wxDECLARE_EVENT_TABLE();
};
myImage::myImage(wxWindow* parent, wxWindowID id, wxPoint pos, wxSize size, wxBitmap frame): wxStaticBitmap(parent, id, frame, pos, size){
this->frame = frame;
}
//that is my function to clear my image
void myFrame::onClickClear(wxCommandEvent& event)
{
wxClientDC dc(myImg);
dc.SetBackground(wxBrush(myImg->frame)); //frame is a wxBitmap type
dc.Clear();
}
The issue is that works in my laptop but when my friend download and compile it's doesn't work in his laptop.

If you need to "clear" a wxStaticBitmap, just assign a solid bitmap with the given colour.
More generally speaking, you shouldn't try to draw over the native controls (such as wxStaticBitmap) and you shouldn't use wxClientDC at all as drawing is only supported from wxEVT_PAINT handlers on many modern systems (e.g. macOS).

Related

Minecraft Forge - Place block onItemUse

I'm trying to make my custom item place water when used:
public class Beaker extends Item implements IHasModel {
public Beaker(String name, CreativeTabs tab, int maxStackSize) {
setUnlocalizedName(name);
setRegistryName(name);
setCreativeTab(tab);
setMaxStackSize(maxStackSize);
ItemInit.ITEMS.add(this);
}
#Override
public void registerModels() {
Main.proxy.registerItemRenderer(this, 0, "inventory");
}
#Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
BlockPos clickedBlock = new BlockPos(hitX, hitY, hitZ);
worldIn.setBlockState(clickedBlock, Blocks.WATER.getDefaultState());
return EnumActionResult.SUCCESS;
}
}
However, when I right click, the item gets used (animation plays) but the water is not placed, I'm using Minecraft 1.12.2 and Forge 14.23.2.2613.
hitX hitY and hitZ have no relation to the world location where the action was performed. They are partial values within the clicked block for performing actions based on where the block was clicked (e.g. which button on a number pad).
If we look at ItemBlockSpecial (which handles items like Cake, Repeaters, Brewing Stands, and Cauldrons) we find this code:
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
// snow layer stuff we don't care about
if (!block.isReplaceable(worldIn, pos))
{
pos = pos.offset(facing);
}
// placement code
}
The important thing to note here is that the pos parameter is used directly, while being modified by the facing parameter in the event that the block clicked is not replaceable (e.g. Tall Grass is replaceable, Stone is not).
If ItemBlockSpecial isn't sufficient for you (i.e. you can't make your item an instance of ItemBlockSpecial), then the code it uses to do things probably still will be.

How to solve Out of memory error in android after using volley lib and image loader?

I am getting out of memory error, App crash frequently even though I used picasso,Volley lib, Universal image loader to view images.
I am using volley lib to make API call.
public class Holder
{
TextView title,Category,Amount;
NetworkImageView img;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent)
{
Holder holder=new Holder();
View rowView;
File cacheDir;
rowView = inflater.inflate(R.layout.solvent_list_forproduct, null);
holder.img=(NetworkImageView)
rowView.findViewById(R.id.productImage);
ImageLoader imageloader =
ImageGetter.getInstance(context).getImageLoader();
holder.img.setImageUrl
(VarproductImageList.get(position)
.replace(" ", "%20").toString(), imageloader);
}
Some time it through Negative Array size exception.

wxListView in MOTIF doesn't refresh after scrolling

I'm working with wxWidgets 2.8 on a MOTIF (sic) linux box.
I noticed that wxListView and wxListCtrl don't refresh correctly their content after a scroll. When I act on the scrollbar, the new items are invisible until I click on them.
The misbehaviour is present also in the sample "listctrl" that comes with the wxWidgets library.
How can I solve this problem?
It seems it's a wxWidgets bug.
My first try was to work-around it by refreshing the wxListView after a scroll. Unfortunately, it seems wxWidgets doesn't provide scroll events for wxListView/wxListCtrl.
Finally, I solved my problem using the following ListView instead of wxListView in my code:
// listview.h
#ifndef LISTVIEW_H_
#define LISTVIEW_H_
#include <wx/listctrl.h>
class RefreshingListView : public wxListView, private wxTimer
{
public:
RefreshingListView( wxWindow *parent, wxWindowID id,
const wxPoint &pos=wxDefaultPosition,
const wxSize &size=wxDefaultSize,
long style=wxLC_ICON,
const wxValidator &validator=wxDefaultValidator,
const wxString &name=wxListCtrlNameStr ) :
wxListView( parent, id, pos, size, style, validator, name ),
lastTopItem( GetTopItem() )
{
Start( 300 ); // ms
}
// override
virtual void Notify() { CheckTopItem(); }
private:
void CheckTopItem()
{
long it = GetTopItem();
if ( it != lastTopItem )
{
Refresh();
lastTopItem = it;
}
}
long lastTopItem;
};
#ifdef __WXMOTIF__
typedef RefreshingListView ListView;
#else
typedef wxListView ListView;
#endif
#endif // LISTVIEW_H_
Maybe it can be useful to someone :-)

Detect when mouse is not in QGraphicsScene

I am having a class inherited from QGraphicsScene. I have a mouseMoveEvent in this class. Based on the mouse move I am sending the co ordinates via signal to the main window. I have multiple GraphicViews in main window. Based on the scene from which the signal is received I am display the scene co ordinates using QGraphicsTextItem.
The problem is when I move out of the scene area I am unable to hide the QGraphicsTextItem.
Can someone give me a work around for this?
Class Scene::QGraphicsScene
{
void MouseMoveEvent(QGraphicsSceneMouseEvent *Event)
{
int XPos = event.x();
int YPos = event.y();
emit SignalPos(XPos,YPos);
}
}
//In Main Window
connect(scene1,SignalPos(int,int),this,SlotPos1(int,int);
//Similarly for scene2,scene3,scene4
void MainWindow::SlotPos(int X, int Y)
{
m_qgtxtItemX.setText(QString::x);
//I want to hide this once I am out of scene.It is a member variable. I tried
//taking local variable but it didn't work.
//Similarly for y and other slots
}
Install an event filter on the scene.
scene1->installEventFilter(this);
then implement the method in the class that is referenced by "this":
bool eventFilter(QObject *watched, QEvent *event) {
if (event->type() == QEvent::Leave)
{
qDebug() << "Mouse left the scene";
}
return false;
}
Just tried it and it worked! If you are installing the event filter on more than one object, please use "watched" to differentiate between them.
Best,

How do I draw to the window's title bar in C++.NET?

I'm trying to draw a custom title bar, and I've read that in order to paint outside a window's client area, I need to override WndProc and handle the WM_NCPAINT message. Currently, I'm doing that like this:
//WndProc override
virtual void WndProc(Message% m) override
{
switch(m.Msg)
{
case 0x85: //WM_NCPAINT
case 0x0A: //WM_PAINT
//Call original
System::Windows::Forms::Form::WndProc(m);
//Now we'll do our painting
DrawTitleBar(m.HWnd);
break;
default:
System::Windows::Forms::Form::WndProc(m);
break;
}
}
Which works, because I can put a breakpoint in and it gets hit. If I remove the call to the original, the window's frame isn't drawn. DrawTitleBar looks like this:
void DrawTitleBar(IntPtr hWnd)
{
IntPtr hDC;
Graphics^ g;
//Get the device context (DC)
hDC = GetWindowDC(hWnd);
//Get the graphics
g = Graphics::FromHdc(hDC);
//Draw
g->FillRectangle(Brushes::Blue, 0, 0, 100, 10);
//Cleanup
g->Flush();
ReleaseDC(hWnd, hDC);
}
I first get the DC from the window handle. Then I get the Graphics object by using Graphics::FromHdc. I release the DC with ReleaseDC. Incase there's an issue here, this is how I import the native Win32 functions:
[DllImport("user32.dll")]
extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")]
extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
Also: I've tried a bunch of different methods, all with the same results. I can find a bunch of C# and VB examples on the web, but no C++ examples. I've also read about Windows Vista compatibility being an issue with this sort of thing. Currently, I don't care about that, as I will add it later.
Two simple facts. 1. under DWM GetWindowDC is essentially broken.
2. Two work arounds partially exist A. set compatiblity mode to xp or 98 or 95.
B. program example in msdn social exists. search for
"GetWindowDC broken" then follow a lengthy url to a code
sample [fix the broken url by adding a trailing ) ].
Unhappily, the window shows up with rounded corners on
my box build 9200, win 8.0 , no updates.