lang="en-US"> Useful Allegro Functions –  Design1online.com, LLC

Useful Allegro Functions

/***********
* Purpose: draw the buffer behind an image
* Precondition: image to use
* Postcondition: returns the image with the buffer behind it
***********/
BITMAP *blitBigger(BITMAP *image)
{
clear(buffer); //clear the buffer (or leave it if you want the old image there)
blit(image, buffer, 0, 0, x, y, image->w, image->h);

//now copy the buffer image back into image (to make the smaller image
centered in the screen for blitting later)
image = create_bitmap(SCREEN_W, SCREEN_H);
blit(buffer, image, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

clear(buffer);
return image;
}

/**************
* Purpose: open a browser window to the specified url (windows PCs only)
* Precondition: the url to open
* Postcondition: window has been opened
**************/
int openWindow(char *url)
{
char call[250];
sprintf(call, "url.dll, FileProtocolHandler %s", url);
ShellExecute(NULL, "open", "rundll32", call, "", SW_SHOWNOACTIVATE);
return 0;
}

/**************
* Purpose: connect to the appropriate database, requires
*             #include "mysql/mysql.h"
* Precondition: host, database, user name and password
* Postcondition: connected to that database
**************/
int openConnection(char *host, char *db, char *user, char *pass)
{
if (sock) //already connected to another database
disconnect(); //disconnect from that one (see function below)

//initilize the socket
sock = mysql_init(0);

//something went wrong with the socket
if (!sock)
return -1;

//try connecting to the database
if (!mysql_real_connect(sock, host, user, pass, db, 0, NULL, 0))
return 0;

//successfully connected to the database
return 1;
}

/**************
* Purpose: disconnect from the database
* Precondition: none
* Postcondition: socket closed
**************/
bool disconnect()
{
if (sock) //they have a socket open
mysql_close(sock);

//database disconnected
return true;
}

/**************
* Purpose: return the result set of the query
* Precondition: the query string
* Postcondition: the FIRST result is returned (or null)
*                will not return multiple rows, only the first
**************/
char *stringQuery(char *query)
{
MYSQL *sock;
MYSQL_RES *result;
MYSQL_ROW row;

//query the database
mysql_query(sock,query);

//store the results
result = mysql_store_result(sock);

if (!result)
return NULL; //no results

//fetch the row
row = mysql_fetch_row(result);

//store the result & convert it to a number
char *stringResult = row[0];

return stringResult;

}

You may also like...

Leave a Reply