Click here to Skip to main content
16,013,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have code in C + + that works and I would like to add it to my program on Android.

C++
extern bool rysuj;
extern bool kwadrat;
bool rys=false;
int x1, y1;
int x2, y2;
TChild *Child;

Graphics::TBitmap* bitmap = new Graphics::TBitmap;
TCanvas* dtCanvas = new TCanvas;
HWND hOkno;
RECT rcOkno;
unsigned uWidth;
unsigned uHeight;

FormMouseDown(int X, int Y)
{

   	bitmap->Width=uWidth;
   	bitmap->Height=uHeight;
	TRect src= Canvas->ClipRect;
  	bitmap->Canvas->CopyRect(src,Canvas,src);

   	if (kwadrat)
   	{
     		x1=X;
      		y1=Y;
   	}
   	rys=true;

}
FormMouseMove(int X, int Y)
{
   	if (rys && kwadrat)
   	{
        	Canvas->Draw(0,0, bitmap);
        	Canvas->Rectangle(x1, y1, X, Y);
   	}

}

FormMouseUp(int X, int Y)
{
        bitmap->Width=uWidth;
        bitmap->Height=uHeight;
        TRect src= Canvas->ClipRect;
        bitmap->Canvas->CopyRect(src,Canvas,src);

   	rys=false;


}
FormPaint(TObject *Sender)
{
        Canvas->Draw(0,0, bitmap);
}


Please to quickly response. I would be very grateful :D
Posted

You don't "convert C++ file to java style". You need to create a JNI wrapper around your existing C++ code. This JNI wrapper is actually C++ code that can be called by Java.

By wrapper I mean that you shouldn't have to modify your existing C++ code base. This wrapper, or better said this binding should generally be very thin. The wrapper code is only meant to expose existing functionalities, not to implement them. It is better to leave the implementation in the (portable) C++ code base.

If the code base isn't too large, then I recommend that you write this wrapper by hand, as explained in The JavaTM Native Interface Programmer's Guide and Specification

Now, if you are trying to bind a large library, it may be problematic. So, in regard to tools, I haven't used that, but have a look at SWIG, and the relevant SWIG Java documentation.

According to the homepage description, it's what you're asking for:

SWIG is typically used to parse C/C++ interfaces and generate the 'glue code' required for [Java, Python, PHP, ...] to call into the C/C++ code.

javah can be useful in certain cases, but it's not what you ask for. It extracts JNI boiler plate code out of native declarations found in Java classes. Regarding javac, it's the Java compiler, that's irrelevant.
 
Share this answer
 
Comments
Java
@Override
        public boolean onTouchEvent(MotionEvent event) 
        {
            float x = event.getX();
            float y = event.getY();
            switch (event.getAction()) 
            {
                case MotionEvent.ACTION_DOWN:
                    if (kwadrat) {
                    	rect = new Rect();
                        touch_start(x, y);
                		invalidate();
					}

                    tryb_rys = true;
                    break;
                case MotionEvent.ACTION_MOVE:

                    if (kwadrat && tryb_rys) {
                    	rect.set((int)mX, (int)mY, (int)event.getX(), (int)event.getY());
                    	mCanvas.drawRect(rect, mPaint);
                		invalidate();

                	break;
                case MotionEvent.ACTION_UP:

                    tryb_rys = false;
                	break;
            }
            return true;
        }


I have something like that but when i draw this rectangle it leave a trace. I only want a few lines of code to fix this.
 
Share this answer
 
Comments
Legor 18-Oct-12 4:17am    
Do not write additional informations as solutions. You can use the "Improve question" button (at the bottom right of your question) to edit your questions e.g. to add additional information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900