Beispiel #1
0
void Buffer::resize(int w, int h) {
   if (!shouldDelete)
      throw RubyException(rb_eRuntimeError, "Not allowed to resize this Buffer");

   OSL_IMAGE *old_image = img;
   OSL_IMAGE *old_buffer = oslGetDrawBuffer();
   
   img = oslCreateImage(w, h, OSL_IN_VRAM, img->pixelFormat);
   if (!img) {
      img = oslCreateImage(w, h, OSL_IN_RAM, img->pixelFormat);
      if (!img)
	 throw RubyException(rb_eRuntimeError, "Could not recreate the buffer.");
   }
   else {
      Buffer::registerInVram(img);
   }

   setActual();
   oslDrawImageXY(old_image, 0, 0);
   oslSetDrawBuffer(old_buffer);

   if (old_image->location == OSL_IN_RAM)
      oslDeleteImage(old_image);
   else
      Buffer::removeFromVram(old_image);
}
Beispiel #2
0
void Buffer::createFromDrawable(Drawable &obj) {
   shouldDelete = true;

   if (obj.getW() > 512 || obj.getH() > 512)
      throw RubyException(rb_eRuntimeError, "Drawable too big for a buffer.");

   int width = obj.getW();
   int height = obj.getH();
   img = oslCreateImage(width, height, OSL_IN_VRAM, OSL_PF_8888);
   if (!img) {
      img = oslCreateImage(width, height, OSL_IN_RAM, OSL_PF_8888);
      if (!img)
	 throw RubyException(rb_eRuntimeError, "Buffer could not be created");
   }
   else {
      Buffer::registerInVram(img);
   }

   OSL_IMAGE *old = oslGetDrawBuffer();
   setActual();

   obj.clearMove();
   obj.setPos(0, 0);
   obj.draw();
   obj.cancelMove();

   oslSetDrawBuffer(old);
}
Beispiel #3
0
void Buffer::createFromGeom(int w, int h, int format) {
   shouldDelete = true;

   if (w > 512 || h > 512)
      throw RubyException(rb_eRuntimeError,
			  "Either width or height is greter than 512.");

   img = oslCreateImage(w, h, OSL_IN_VRAM, format);
   if (!img) {
      img = oslCreateImage(w, h, OSL_IN_RAM, format);
      if (!img)
	 throw RubyException(rb_eRuntimeError, "Buffer could not be created.");
   }
   else {
      Buffer::registerInVram(img);
   }
}
Beispiel #4
0
Buffer::Buffer(int w, int h, int format): shouldDelete(true) {
   setClass("Buffer");

   if (w > 512 || h > 512)
      throw RubyException(rb_eRuntimeError, 
			  "Either width or height is greter than 512.");

   img = oslCreateImage(w, h, OSL_IN_VRAM, format);
   if (!img)
      throw RubyException(rb_eRuntimeError, "Buffer could not be created.");
}
Beispiel #5
0
void Buffer::resize(int w, int h) {
   OSL_IMAGE *old_image = img;
   OSL_IMAGE *old_buffer = oslGetDrawBuffer();
   
   img = oslCreateImage(w, h, OSL_IN_VRAM, img->pixelFormat);
   if (!img)
      throw RubyException(rb_eRuntimeError, "Could not recreate the buffer.");
   
   setActual();
   oslDrawImageXY(old_image, 0, 0);
   oslSetDrawBuffer(old_buffer);

   oslDeleteImage(old_image);
}
Beispiel #6
0
Buffer::Buffer(Drawable &obj): shouldDelete(true) {
   setClass("Buffer");

   if (obj.getW() > 512 || obj.getH() > 512)
      throw RubyException(rb_eRuntimeError, "Drawable too big for a buffer.");
   
   img = oslCreateImage(obj.getW(), obj.getH(), OSL_IN_VRAM, OSL_PF_8888);
   if (!img)
      throw RubyException(rb_eRuntimeError, "Buffer could not be created");
   
   OSL_IMAGE *old = oslGetDrawBuffer();
   setActual();

   obj.clearMove();
   obj.setPos(0, 0);
   obj.draw();
   obj.cancelMove();

   oslSetDrawBuffer(old);
}
Beispiel #7
0
//<-- STAS: -->
int oslDialogDrawAndWait(int dialogType) {
    int        status = OSL_DIALOG_STATUS_INIT;
    OSL_IMAGE* img    = oslCreateImage(480, 272, OSL_IN_RAM, OSL_PF_8888);

    oslSyncDrawing();
    oslCopyImageTo(img, OSL_DEFAULT_BUFFER);			// Save the currently drawn image

    while((status >= 0)  &&  (status != OSL_DIALOG_STATUS_NONE)  &&  !osl_quit) {
       if (!oslSyncFrameEx(0,0,1)) {
          oslStartDrawing();
          oslCopyImageTo(OSL_DEFAULT_BUFFER, img);		// Restore the image drawn by the user app

          switch (dialogType) {
             case OSL_DIALOG_MESSAGE:
             case OSL_DIALOG_ERROR:
             case OSL_DIALOG_NETCONF:
                oslDrawDialog();
                status = oslGetDialogStatus();
                break;
             case OSL_DIALOG_OSK:
                oslDrawOsk();
                status = oslGetOskStatus();
                break;
             case OSL_DIALOG_SAVELOAD:
                oslDrawSaveLoad();
                status = oslGetLoadSaveStatus();
                break;
             case OSL_DIALOG_BROWSER:
                oslDrawBrowser();
                status = oslGetBrowserStatus();
                break;
          }

          oslEndDrawing();
       }
       oslEndFrame();
    }

    oslDeleteImage(img);
    return (status < 0)? status : 0;
}
static OSL_IMAGE *logoCreeImageFond()			{
	OSL_IMAGE *fond;
	unsigned char *data;
	int i, j;
	fond = oslCreateImage(480, 272, OSL_IN_RAM, OSL_PF_8BIT);
	if (!fond)
		return 0;
	fond->palette = oslCreatePalette(256, OSL_PF_8888);
	if (!fond->palette)		{
		oslDeleteImage(fond);
		return 0;
	}
	for (j=0;j<HEIGHT;j++)			{
		data = (unsigned char*)oslGetImageLine(fond, j);
		for (i=0;i<WIDTH/2;i++)			{
			*data++ = i;
			*data++ = i;
		}
	}
	oslUncacheImage(fond);
	return fond;
}
Beispiel #9
0
OSL_FONT *oslLoadFont(OSL_FONTINFO *fi)
{
	OSL_FONT *f;
	int i, x, y;
	int imageFormat;
	const int pixelplanewidth[4]={3, 2, 2, 1};

	f = (OSL_FONT*)malloc(sizeof(OSL_FONT));
	if (!f)
		return NULL;
	memset(f, 0, sizeof(OSL_FONT));					//<-- STAS: Initialize the OSL_FONT structure

    f->fontType = OSL_FONT_OFT;

	//Liste des tailles
	f->charWidths = (u8*)malloc(256*sizeof(char));
	if (!f->charWidths)		{
		free(f);
		return NULL;
	}
	if (fi->charWidths)		{
		//Réutilise les tailles fournies
		for (i=0;i<256;i++)
			f->charWidths[i] = fi->charWidths[i];
//		f->charWidths = fi->charWidths;
		f->isCharWidthConstant = 0;
	}
	else		{
		//Remplit la table avec les mêmes tailles
		for (i=0;i<256;i++)
			f->charWidths[i] = fi->charWidth;
		f->isCharWidthConstant = 1;
		f->charWidth = fi->charWidth;				//<-- STAS: Initialize f->charWidth somehow...
	}
	//Position des caractères (pour les fontes non proportionnelles)
	f->charPositions = (u16*)malloc(256*sizeof(short));
	if (!f->charPositions)		{
		free(f->charWidths);
		free(f);
		return NULL;
	}
	f->addedSpace = fi->addedSpace;
	x = y = 0;
	for (i=0;i<256;i++)
	{
		if (x + f->charWidths[i] + f->addedSpace >= OSL_TEXT_TEXWIDTH)			{
			//Prochaine ligne
			x = 0;
			y ++;
		}
		f->charPositions[i] = x + (y<<OSL_TEXT_TEXDECAL);
		x += f->charWidths[i] + f->addedSpace;
	}

	//16x16 caractères
	f->img = oslCreateImage(512, (y+1)*fi->charHeight, OSL_IN_RAM, OSL_PF_4BIT);
	//4 bit texture format
	imageFormat = 4;
	if (!f->img)		{
		free(f->charPositions);
		free(f->charWidths);
		free(f);
		return NULL;
	}
	//La palette
	f->img->palette = oslCreatePalette(16, OSL_PF_8888);
	if (!f->img->palette)		{
		oslDeleteImage(f->img);					//<-- STAS: It would beter to do it before free(f) :-)
		free(f->charPositions);
		free(f->charWidths);
		free(f);
		return NULL;
	}

	if (fi->paletteCount)		{
		for (i=0;i<oslMin(fi->paletteCount,f->img->palette->nElements);i++)		//<-- STAS: check i against oslMin(...) !
			((unsigned long*)f->img->palette->data)[i] = fi->paletteData[i];
	}
	else	{
		((unsigned long*)f->img->palette->data)[0] = RGBA(255,255,255, 0);
		((unsigned long*)f->img->palette->data)[1] = RGBA(255,255,255, 255);
	}

	//Vide directement le cache
	sceKernelDcacheWritebackInvalidateRange(f->img->palette->data, 16*4);

	f->charHeight = fi->charHeight;
	memset(f->img->data, 0, f->img->totalSize);
	//Dessine les caractères sur le buffer
	for (i=0;i<256;i++)		{
		oslDrawChar1BitToImage(f->img, OSL_TEXT_CHARPOSXY(f, i),
			f->charWidths[i] + f->addedSpace, f->charHeight, fi->lineWidth << pixelplanewidth[fi->pixelFormat - 1],
			fi->pixelFormat, imageFormat, (u8*)fi->fontdata+i*fi->lineWidth*fi->charHeight);
	}
	//Pareil, vide direct le cache
	sceKernelDcacheWritebackInvalidateRange(f->img->data, f->img->totalSize);
	return f;
}
Beispiel #10
0
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Main:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main(){
    SetupCallbacks();
    oslSrand(1);
    //Init network (for net conf dialog):
    oslNetInit();
    int skip = 0;
    LedAnimFreq.f=2;
    const int calx1=-20,calx2=20,caly1=-20,caly2=20;
    //float fx,fy;
    float_or_int_t _movW,_movX,_movY,_movZ;

    DroneSck = oslNetSocketCreate();
    DroneUdp = make_udpsocket(AT_PORT);
    initOSLib();
    oslIntraFontInit(INTRAFONT_CACHE_MED);

    //Loads image:
    //OSL_IMAGE *bkg = oslLoadImageFileJPG("back1.jpg", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_8888);
    OSL_IMAGE *bkg = oslLoadImageFileJPG("back1.jpg", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_5650);
   	OSL_IMAGE *img1 = oslCreateImage (130,130,OSL_IN_RAM,OSL_PF_8BIT);
   	FirePalette (img1,255);
    oslClearImage (img1,0);

    //Load font:
    OSL_FONT *font = oslLoadFontFile("flash0:/font/ltn0.pgf");
    oslSetFont(font);

    while(runningFlag && !osl_quit){
        if (!skip){
            oslStartDrawing();
            oslDrawImageXY(bkg, 0, 0);

            oslReadKeys();
            _movX.f = ((float)osl_pad.analogX/128)*mscale;
            _movY.f = ((float)osl_pad.analogY/128)*mscale;
            _movZ.f = 0;
            _movW.f = 0;
            if ((osl_pad.analogX > calx1) && (osl_pad.analogX < calx2)) _movX.f = 0; //Deadzone X
            if ((osl_pad.analogY > caly1) && (osl_pad.analogY < caly2)) _movY.f = 0; //Deadzone Y
			if (osl_pad.held.triangle) _movZ.f = delta; //Up
			if (osl_pad.held.cross) _movZ.f = -delta; //Down
			if (osl_pad.held.L) _movW.f = -delta; //CW
			if (osl_pad.held.R) _movW.f = delta; //CCW
            if (_movX.f==0 && _movY.f==0 && _movZ.f==0 && _movW.f==0) Hover=0; else Hover=1;

            oslDrawStringf(320, 10, "Tic#= %d",AT_SEQ);
            oslDrawStringf(10, 220, "x= %d  y= %d  z= %d  w= %d  !Hvr= %d",osl_pad.analogX,osl_pad.analogY,_movZ.i,_movW.i,Hover);
            oslDrawStringf(10, 240, "xf= %1.2f  yf= %1.2f  Scl= %1.2f",_movX.f,_movY.f,mscale);

            if (Connected==1) GameTic++;

            if (drawMenu==1) {
            	Menu();}
            else {
    			if (osl_pad.pressed.up) {
    				//Drone.AddCmd "AT*ANIM=", CStr(Seq) & "," & Anim_Time(Seq) vb anim code
    				snprintf(netbuf,1024,"AT*ANIM=%d,%d,%d%c",AT_SEQ++,ARDRONE_ANIM_FLIP_AHEAD,MAYDAY_TIMEOUT[ARDRONE_ANIM_FLIP_AHEAD],CR);
    				sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));}
    			if (osl_pad.pressed.down) {
    				snprintf(netbuf,1024,"AT*ANIM=%d,%d,%d%c",AT_SEQ++,ARDRONE_ANIM_FLIP_BEHIND,MAYDAY_TIMEOUT[ARDRONE_ANIM_FLIP_BEHIND],CR);
    				sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));}
    			if (osl_pad.pressed.right) {
    				snprintf(netbuf,1024,"AT*ANIM=%d,%d,%d%c",AT_SEQ++,ARDRONE_ANIM_FLIP_RIGHT,MAYDAY_TIMEOUT[ARDRONE_ANIM_FLIP_RIGHT],CR);
    				sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));}
    			if (osl_pad.pressed.left) {
    				snprintf(netbuf,1024,"AT*ANIM=%d,%d,%d%c",AT_SEQ++,ARDRONE_ANIM_FLIP_LEFT,MAYDAY_TIMEOUT[ARDRONE_ANIM_FLIP_LEFT],CR);
    				sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));}
                if (osl_pad.pressed.start) {
                	drawMenu=1;}
				if (osl_pad.pressed.circle){//Take off
					snprintf(netbuf,1024,"AT*REF=%d,%d%c",AT_SEQ++,AT_REF|512,CR);//TAKE OFF
					sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));}
				if (osl_pad.pressed.square){//Land
					snprintf(netbuf,1024,"AT*REF=%d,%d%c",AT_SEQ++,AT_REF,CR);
					sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));}
            }
            if (showjoypad) JoyPadGfx(img1);
            if (showfire) FireFx(img1);
        	if (showjoypad||showfire) oslDrawImageXY(img1, 345, 85);

        	oslEndDrawing();

		}

		if (GameTic >= TicRoof){
        	GameTic=0;
            //snprintf(netbuf,1024,"AT*COMWDG=%d%cAT*PCMD=%d,%d,%d,%d,%d,%d%c",AT_SEQ++,CR,AT_SEQ++,Hover,_movX.i,_movY.i,_movZ.i,_movW.i,CR);//XY
            snprintf(netbuf,1024,"AT*PCMD=%d,%d,%d,%d,%d,%d%c",AT_SEQ++,Hover,_movX.i,_movY.i,_movZ.i,_movW.i,CR);//XY
			sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));}


        oslEndFrame();
        skip = oslSyncFrame();
    }
    //Quit OSL:
    oslNetTerm();
    oslEndGfx();
    oslQuit();

    sceKernelExitGame();
    return 0;

}
Beispiel #11
0
static int image_init(PyImage *self,
                      PyObject *args,
                      PyObject *kwargs)
{
    PyObject *initial;
    int location = OSL_IN_VRAM;
    int pf = OSL_PF_8888;

    if (!PyArg_ParseTuple(args, "O|ii:__init__", &initial, &location, &pf))
       return -1;

    self->location = location;

    if (PyString_Check(initial))
    {
       // Load from file

       char *filename = PyString_AsString(initial);

       self->pImg = oslLoadImageFile(filename, location, pf);

       if (!self->pImg)
       {
          PyErr_SetString(osl_Error, "Could not load image.");
          return -1;
       }
    }
    else if (PyTuple_Check(initial))
    {
       int w, h;

       if (PyTuple_Size(initial) != 2)
       {
          PyErr_SetString(PyExc_TypeError, "Image dimension must be a 2-tuple");
          return -1;
       }

       if (!PyInt_Check(PyTuple_GetItem(initial, 0)))
       {
          PyErr_SetString(PyExc_TypeError, "Image width must be an integer");
          return -1;
       }

       if (!PyInt_Check(PyTuple_GetItem(initial, 1)))
       {
          PyErr_SetString(PyExc_TypeError, "Image height must be an integer");
          return -1;
       }

       w = PyInt_AsLong(PyTuple_GetItem(initial, 0));
       h = PyInt_AsLong(PyTuple_GetItem(initial, 1));

       self->pImg = oslCreateImage(w, h, location, pf);

       if (!self->pImg)
       {
          PyErr_SetString(osl_Error, "Could not create image");
          return -1;
       }
    }
    else
    {
       PyErr_SetString(PyExc_TypeError, "First argument must be a filename or a 2-tuple");
       return -1;
    }

    if (location == OSL_IN_VRAM)
    {
       FREEIMG *pFree = (FREEIMG*)malloc(sizeof(FREEIMG));

       pFree->bDelete = 0;
       pFree->pImg = self->pImg;
       pFree->next = (void*)pCurrent;
       pCurrent = pFree;
    }

    return 0;
}