- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# render.c

Go to the documentation of this file.

    00001
    00005 //    /**
    00006 //      *@defgroup render render.c
    00007 //      *Routines to queue objects in a list and draw them on screen in the order they arrived in the queue
    00008 //      *@{
    00009 //      */
    00010
    00011 /*----------------------------------------------------------------------------------------------------------*/
    00012
    00013 #ifndef _ALLEGRO5_
    00014 #define _ALLEGRO5_
    00015 #include <allegro5/allegro5.h>
    00016 #endif // _ALLEGRO5_
    00017
    00018 #ifndef _ALLEGRO5FONT_
    00019 #define _ALLEGRO5FONT_
    00020 #include <allegro5/allegro_font.h>
    00021 #endif // _ALLEGRO5FONT_
    00022
    00023 #ifndef _ALLEGRO5IMAGE_
    00024 #define _ALLEGRO5IMAGE_
    00025 #include <allegro5/allegro_image.h>
    00026 #endif // _ALLEGRO5IMAGE_
    00027
    00028 #ifndef _COMMONS_
    00029 #define _COMMONS_
    00030 #include "../include/commons.h"
    00031 #endif // _COMMONS_
    00032
    00033 #ifndef _BUTTONS_
    00034 #define _BUTTONS_
    00035 #include "../include/buttons.h"
    00036 #endif // _BUTTONS_
    00037
    00038 #ifndef _PROGRESSBAR_
    00039 #define _PROGRESSBAR_
    00040 #include "../include/progressbar.h"
    00041 #endif // _PROGRESSBAR_
    00042
    00043 #ifndef _RENDER_
    00044 #define _RENDER_
    00045 #include "../include/render.h"
    00046 #endif // _RENDER_
    00047
    00048 /*----------------------------------------------------------------------------------------------------------*/
    00049
    00050 // A pointer to the first object in the render queue
    00051 static RENDERQUEUEPTR firstptr = NULL;
    00052
    00053 /*----------------------------------------------------------------------------------------------------------*/
    00054
    00055 // Returns the first object in the RENDERQUEUE
    00056 RENDERQUEUEPTR get_first_element_from_render_queue(void)
    00057 {
    00058     return firstptr;
    00059 }
    00060
    00061 /*----------------------------------------------------------------------------------------------------------*/
    00062
    00063 // Sets the first item in the RENDERQUEUE to the specified item
    00064 // This function should never be used in other modules, it should only be used internally in this module
    00065 RENDERQUEUEPTR set_first_element_in_render_queue(RENDERQUEUEPTR *newfirst)
    00066 {
    00067     firstptr = *newfirst;
    00068     return firstptr;
    00069 }
    00070
    00071 /*----------------------------------------------------------------------------------------------------------*/
    00072
    00073 // Takes the first item in the RENDERQUEUE, processes it, draws it, removes it from the queue and moves on to
    00074 // the next item in the queue
    00075 void render(void)
    00076 {
    00077     RENDERQUEUEPTR currentptr;
    00078     currentptr = firstptr;
    00079     while(currentptr != NULL)
    00080     {
    00081         al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, currentptr->blend_color);
    00082         if(currentptr->rcallb != NULL)
    00083             currentptr->rcallb(currentptr->image, currentptr->x, currentptr->y, currentptr->nflags,
    00084                                currentptr->blend_color);
    00085         else
    00086             al_draw_bitmap(currentptr->image, currentptr->x, currentptr->y, currentptr->nflags);
    00087         al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, RDEFAULT);
    00088         currentptr = remove_element_from_render_queue(&currentptr);
    00089     }
    00090     render_buttons();
    00091     render_progress_bars();
    00092     render_mouse_cursor(get_game_data()->cursor);
    00093 }
    00094
    00095 /*----------------------------------------------------------------------------------------------------------*/
    00096
    00097 // Adds an element to the queue, this function is used mainly by other modules when something needs to be
    00098 // drawn
    00099
    00100 RENDERQUEUEPTR add_element_to_render_queue(ALLEGRO_BITMAP *image, float x, float y, int nflags,
    00101                                            ALLEGRO_COLOR blendcol, RENDER_CALLBACK rcallback)
    00102 {
    00103     RENDERQUEUEPTR newptr, currentptr;
    00104
    00105     newptr = (RENDERQUEUEPTR)malloc(sizeof(RENDERQUEUE));
    00106     if(newptr != NULL)
    00107     {
    00108         newptr->image = image;
    00109         newptr->x = x;
    00110         newptr->y = y;
    00111         newptr->nflags = nflags;
    00112         newptr->blend_color = blendcol;
    00113         newptr->rcallb = rcallback;
    00114         newptr->next = NULL;
    00115         newptr->prev = NULL;
    00116
    00117         currentptr = firstptr;
    00118
    00119         while(currentptr != NULL && currentptr->next != NULL)
    00120             currentptr = currentptr->next;
    00121
    00122         if(currentptr == NULL)
    00123         {
    00124             currentptr = newptr;
    00125             firstptr = currentptr;
    00126         }
    00127         else
    00128         {
    00129             currentptr->next = newptr;
    00130             newptr->prev = currentptr;
    00131         }
    00132         return newptr;
    00133     }
    00134     else
    00135     {
    00136          return NULL;
    00137     }
    00138 }
    00139
    00140 /*----------------------------------------------------------------------------------------------------------*/
    00141
    00142 // Removes an item from the queue, mainly used after the item has been drawn
    00143 RENDERQUEUEPTR remove_element_from_render_queue(RENDERQUEUEPTR *currentptr)
    00144 {
    00145     if(*currentptr == NULL || firstptr == NULL) return NULL;
    00146     if((*currentptr)->next != NULL)
    00147     {
    00148         (*currentptr)->next->prev = NULL;
    00149         firstptr = (*currentptr)->next;
    00150         free(*currentptr);
    00151     }
    00152     else
    00153     {
    00154         firstptr = NULL;
    00155         free(*currentptr);
    00156     }
    00157     return firstptr;
    00158 }
    00159
    00160 /*----------------------------------------------------------------------------------------------------------*/
    00161
    00162 // Empties render queue of all pending items
    00163 _Bool empty_render_queue(RENDERQUEUEPTR rfirstptr)
    00164 {
    00165     RENDERQUEUEPTR currentptr = rfirstptr;
    00166     if(rfirstptr == NULL) return false;
    00167
    00168     while(currentptr != NULL)
    00169     {
    00170         currentptr = currentptr->next;
    00171         free(rfirstptr);
    00172         rfirstptr = currentptr;
    00173     }
    00174
    00175     firstptr = NULL;
    00176     return true;
    00177 }
    00178
    00179 /*----------------------------------------------------------------------------------------------------------*/
    00180
    00181 void render_mouse_cursor(ALLEGRO_BITMAP *cursor)
    00182 {
    00183     ALLEGRO_MOUSE_STATE mouse;
    00184     al_get_mouse_state(&mouse);
    00185     al_draw_bitmap(cursor, mouse.x, mouse.y, 0);
    00186 }
    00187
    00188 /*----------------------------------------------------------------------------------------------------------*/
    00189
    00190 //    /**
    00191 //      *@}
    00192 //      */