PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Functions List

There doesn't seem to be much of a function list with descriptions on how to use them, so I've been looking through demo code and the PF code itself to try and figure out how it all works. I've listed below the stuff I've figured out. Please post any corrections and additions.

Delay:
Sleep(10); // Sleep 10 (microseconds?)

Reseed randomizer:
srand(PocketPC::GetTickCount());

Get Random Number:
x=rand()%5; // Random number 0-4

Before using display functions, set up display pointer:
Display* display=GetDisplay();

Get Display size:
dWidth=display->GetWidth();
dHeight=display->GetHeight();

Clear Display to color:
display->Clear(Color(0,0,0)); // Color black. Color function numbers are R,G,B = Red,Green,Blue

Draw Circle:
display->DrawCircle(120,160,80,Color(255,0,0)); //Red
ie.
display->DrawCircle(Point,radius,color) OR
display->DrawCircle(x,y,radius,color)

Draw Filled Rectangle:
display->FillRect(Rect(0,299,240,319),0xffff); // Cyan
OR
display->FillRect(x1,y1,x2,y2,color)

** Colors can be in hex (eg 0xffffff = white) or in RGB format (255,255,255 = white?)

Draw a pixel:
display->SetPixel(x,y,Color)
display->SetPixel(Point,color); // not sure how to set point yet
Possibly:
Point& spot;
spot.x=10; spot.y=20; // Don't quote me on this ;)

Draw a line:
display->DrawLine(x1,y1,x2,y2,color);
** These functions can use Point as well. I dont know how

Draw Horizontal Line (presumably faster than above function):
display->DrawHLine(x,y,length,color); // x,y is top. Draws right?

Draw Vertical Line (ditto):
display->DrawVLine(x,y,length,color); // Draws down?

Draw Polygons:
display->DrawPoly(points[],numberofpoints,color); // need example code for creating point array

display->FillPoly(points[],numberofpoints,color); // ditto

Get color of pixel:
display->GetPixel(x,y);

display->SetBlending(x); // x=0 transparent. x=255 opaque

display->SetClipping(Rect); // Rectangle defined for clipping drawing

display->SetDefaultShader(); // resets to the default shader
** Not sure about shader use yet.

display->BlitRotated(x,y,angle,surface); // Draw an image rotated 'angle' degrees on a surface

display->BlitStretched(Rect,surface,source,Rect); // Not sure about this one yet. Stretches an image to fit a surface.

display->BitRotatedStretch(x,y,angle,surface,destSurface,Rect); // Draw an image rotated 'angle' degrees from a surface onto another surface 'destSurface', stretched to fit the new surface.

There's much more, of course, but I don't want to post what Conan's done on his site. Not sure how to get sytlus x,y coordinates, but I think it's something to do with a point. eg. stylus.x,stylus.y if 'stylus' is defined as a Point. eg:
void BlitSample::StylusDown( Point stylus )
There used to be a doxygen listing of functions, but I don't know where it ended up... but you've got it mostly figured out.

some comments. Always use 1 GetDisplay at the start of a frame, and end with an Update.

The actual number returned from calling Color(r,g,b) is in 565 format - 5 bits red, 6 bits green, and 5 bits blue. So even though you set it with 0-255 numbers, internally it is 0-31 for red, etc. Very important if you use the GetPixel function for comparisons.

For a single point, you can use
display->SetPixel(Point(x,y) ,color);
or
Point p;
p.x=12; p.y=34;

display->DrawPoly(points[],numberofpoints,color); // need example code for creating point array



Code:

Point p[3];
p[0].x = 5;
p[0].y = 5;
p[1].x = 15;
p[1].y = 5;
p[2].x = 15;
p[2].y = 15;

display->DrawPoly(p,3,Color(0,255,0));


display->BlitStretched(Rect,surface,source,Rect); // Not sure about this one yet. Stretches an image to fit a surface.

I believe the source is strectched to completely fill the temp surface you give it. I'll see if I can find some example code if you need it.
Thanks! I think a lot of newbies (like myself) would find a list like this very handy :) There seems to be some posts in the forum requesting such a thing.

If I get a good list here, maybe I could add it to the Wiki (which seems to have been forgotten).
That doxygen reference used to be hosted on my site, but I took it down some time ago. All the ocntent from my site was passed along to Thierry some time ago, with the intention of it winding up on his site. I don't know what his plans are for it.
I did eventually find a dOxygen printout link somewhere on Thierry's site, but for someone like me it doesn't really help a lot and is still convoluted ;)
WauloK wrote:
Delay:
Sleep(10); // Sleep 10 (microseconds?)

Milliseconds (I think you meant that, but to be sure)

WauloK wrote:
Draw a line:
display->DrawLine(x1,y1,x2,y2,color);
display->DrawHLine(x,y,length,color);
display->DrawVLine(x,y,length,color);


Unfortunatelly these functions contain some bug (in my PF_0_8_1 version)
for example,
display->DrawLine(-x,-y,x,y,color);
wouldn't draw part of line correctly, to fix this bug change some code in rasterizer.cpp:
http://www.pocketmatrix.com/forums/viewtopic.php?t=18502

display->DrawHLine(x,y,length,color);
display->DrawVLine(x,y,length,color);

one of them draws one extra pixel, not much but keep it in mind, to find out, just try:
display->DrawHLine(120,160,1,0xffff);
display->DrawVLine(120,160,1,0xffff);

And as fast_rx mentioned be sure to use one GetDisplay() at the loop start and ONLY one Update() on the loop end;

rasterizer.h and other header files were very helpful to me when I just started using PocketFrog. It's a fast way to remember your favourite function :wink:
BIGBEN":1ctk76wq]

Ahum. Yes of course :oops:
I have looked in rasterize.h as you suggested. That's where I got most of the above from :)
I just think it's handy to have it somewhere people can look at what's available with a simple explanation.
WauloK wrote:I just think it's handy to have it somewhere people can look at what's available with a simple explanation.


Yes you are absolutely right, sometimes developers too lazy to make such a list, so thanks for that :) I remember when I started learning PocketFrog I was lacking of that kind of source
I was wrong about the BlitStretch. There's only 1 surface parameter (I was thinking of the RotateStretch).

Code:
BlitStretch( const Rect& dest, const Surface* source, const Rect* srcRect = 0 );


dest is a rect that will be completely filled with stretched image. source is the image, and srcRect - if provided - is a rect that defines a subsection of the source image instead of using the whole image.

The "extra" surface in the BlitRotatedStretch function is used as a temp surface - and defines the size of the stretch. So use something like:
Code:

float zoom = 2.4f;
Surface tempSurf =
display->CreateSurface(myimage->GetWidth()*zoom, myimage->GetHeight()*zoom);
display->BlitRotatedStretch(destx,desty,angle, myimage, tempSurf);
delete tempSurf;