Interface margins and axes bounds properties.
[scilab.git] / scilab / modules / renderer / src / cpp / figureDrawing / DrawableFigureJoGL.cpp
1 /*------------------------------------------------------------------------*/
2 /* file: DrawableFigureJoGL.cpp                                           */
3 /* Copyright INRIA 2007                                                   */
4 /* Authors : Jean-Baptiste Silvy                                          */
5 /* desc : Class containing the driver dependant routines to draw a        */
6 /*        figure object with JoGL                                         */
7 /*------------------------------------------------------------------------*/
8
9 #include "DrawableFigure.h"
10 #include "DrawableFigureImp.h"
11 #include "DrawableFigureJoGL.h"
12 extern "C"
13 {
14 #include "Xcall1.h"
15 #include "GetProperty.h"
16 #include "periScreen.h" /* should be removed */
17 #include "DrawObjects.h"
18 #include "getScilabJavaVM.h"
19 #include "JniUtils.h"
20 #include "Scierror.h"
21 }
22
23 #include <stdio.h>
24
25 namespace sciGraphics
26 {
27
28 /*------------------------------------------------------------------------------------------*/
29 DrawableFigureJoGL::DrawableFigureJoGL( DrawableFigure * drawer )
30   : DrawableObjectImp(drawer), DrawableFigureImp(drawer), DrawableObjectJoGL(drawer, "org/scilab/modules/renderer/figureDrawing/DrawableFigureJoGL") {}
31 /*------------------------------------------------------------------------------------------*/
32 DrawableFigureJoGL::~DrawableFigureJoGL( void )
33 {
34   closeRenderingCanvas() ;
35   destroy() ;
36 }
37 /*------------------------------------------------------------------------------------------*/
38 void DrawableFigureJoGL::drawCanvas( void )
39 {
40   // We call the display function to be sure to be in the right context
41   jniUpdateCurrentEnv();
42   jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "display", "()V" ) ;
43   jniUpdateCurrentEnv();
44 }
45 /*------------------------------------------------------------------------------------------*/
46 void DrawableFigureJoGL::openRenderingCanvas( int figureIndex )
47 {
48   jniUpdateCurrentEnv();
49   jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "openRenderingCanvas", "(I)V", figureIndex ) ;
50   jniUpdateCurrentEnv();
51 }
52 /*------------------------------------------------------------------------------------------*/
53 void DrawableFigureJoGL::closeRenderingCanvas( void )
54 {
55   if ( m_oDrawableObject != NULL )
56   {
57     jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "closeRenderingCanvas", "()V" ) ;
58   }
59   DrawableObjectJoGL::destroy() ;
60 }
61 /*------------------------------------------------------------------------------------------*/
62 void DrawableFigureJoGL::setBackgroundColor( int backgroundColor )
63 {
64   jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "setBackgroundColor", "(I)V", backgroundColor ) ;
65 }
66 /*------------------------------------------------------------------------------------------*/
67 void DrawableFigureJoGL::setColorMap( const double rgbMat[], int nbColor )
68 {
69   jdoubleArray javaCmap = NULL;
70   jniUpdateCurrentEnv();
71   javaCmap = jniCreateDoubleArrayCopy(rgbMat, nbColor) ;
72   
73   jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "setColorMapData", "([D)V", javaCmap ) ;
74   jniDeleteLocalEntity(javaCmap) ;
75 }
76 /*------------------------------------------------------------------------------------------*/
77 void DrawableFigureJoGL::getColorMap( double rgbMat[] )
78 {
79   jdoubleArray javaCMap = NULL ;
80   jniUpdateCurrentEnv();
81   JNIEnv * curEnv = jniGetCurrentJavaEnv() ;
82
83   javaCMap = curEnv->NewDoubleArray( sciGetNumColors(getDrawer()->getDrawedObject()) * 3 ) ;
84   if ( !jniCheckLastCall(TRUE) )
85   {
86     Scierror( 999, "Unable to allocate colormap, memory full.\n" ) ;
87     return ;
88   }
89
90   jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "getColorMapData", "([D)V", javaCMap) ;
91
92
93   jniCopyJavaDoubleArray( javaCMap, rgbMat ) ;
94   
95   jniDeleteLocalEntity(javaCMap) ;
96 }
97 /*------------------------------------------------------------------------------------------*/
98 void DrawableFigureJoGL::getSize( int size[2] )
99 {
100
101   size[0] = jniGetIntValue(jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "getCanvasWidth", "()I")) ;
102   size[1] = jniGetIntValue(jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "getCanvasWidth", "()I")) ;
103
104 }
105 /*------------------------------------------------------------------------------------------*/
106 void DrawableFigureJoGL::setSize( const int size[2] )
107 {
108   jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "setCanvasSize", "(II)V", size[0], size[1] ) ;
109 }
110 /*------------------------------------------------------------------------------------------*/
111 void DrawableFigureJoGL::getWindowPosition( int pos[2] )
112 {
113   pos[0] = jniGetIntValue(jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "getWindowPosX", "()I")) ;
114   pos[1] = jniGetIntValue(jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "getWindowPosY", "()I")) ;
115 }
116 /*------------------------------------------------------------------------------------------*/
117 void DrawableFigureJoGL::setWindowPosition( const int pos[2] )
118 {
119   jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "setWindowPosition", "(II)V", pos[0], pos[1] ) ;
120 }
121 /*------------------------------------------------------------------------------------------*/
122 void DrawableFigureJoGL::getWindowSize( int size[2] )
123 {
124   size[0] = jniGetIntValue(jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "getWindowWidth", "()I")) ;
125   size[1] = jniGetIntValue(jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "getWindowHeight", "()I")) ;
126 }
127 /*------------------------------------------------------------------------------------------*/
128 void DrawableFigureJoGL::setWindowSize( const int size[2] )
129 {
130   jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "setWindowSize", "(II)V", size[0], size[1] ) ;
131 }
132 /*------------------------------------------------------------------------------------------*/
133 void DrawableFigureJoGL::setInfoMessage( const char * message )
134 {
135   jstring infoMessage = jniCreateStringCopy( message ) ;
136   jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "setInfoMessage", "(Ljava/lang/String;)V", infoMessage ) ;
137   jniDeleteLocalEntity( infoMessage ) ;
138 }
139 /*------------------------------------------------------------------------------------------*/
140 }