1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
#include <fenix/fxdll.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <memory.h>
/* PluginVersion is used to identify the plugin structures against which
* we're linking to prevent potential mismatches and segmentation faults
*/
unsigned int PluginVersion = FXDLL_VERSION;
static int altura = 40;
static char *agua = NULL;
static int altura_agua = 0;
static float ondulacion = 32.0;
static int refresh_ticks = 0;
static int last_ticks = 0;
static int current_desp = 0;
static int current_despx = 0;
static int current_dec = 0;
static int old_object = -1;
static void x_agua (void * ptr)
{
static int desp = 15000;
static int dec = -1;
static int despx = 0;
int pixelsize = 1;
int x, y, inc;
GRAPH * gr = scrbitmap;
int current_ticks = SDL_GetTicks() ;
if (gr == NULL)
return;
if (gr->depth == 8)
pixelsize = 1;
else
pixelsize = 2;
if (altura > gr->height/5)
altura = gr->height/5;
if (agua==NULL || altura > altura_agua)
{
if (agua) free(agua);
altura_agua = (altura & ~31) + 32;
if ( ( agua = (char *) malloc(gr->pitch * altura_agua) ) == NULL )
return ;
}
if ( last_ticks + refresh_ticks > current_ticks ) {
desp = current_desp;
despx = current_despx;
dec = current_dec;
} else {
last_ticks = current_ticks;
}
inc = (gr->height - altura - 1)*100;
for(y = 0 ; y < altura ; y++)
{
int shift = (int) ((y*(ondulacion/2.0)/altura) * cos(despx/200.0 + ondulacion * (y*2+altura)/(altura*3)));
if (inc < 0) {
inc = 0;
altura--;
}
memcpy( agua + y *gr->pitch + shift * pixelsize,
(char *)gr->data + (inc/100)*gr->pitch,
(gr->width - shift) * pixelsize);
if (shift > 0){
memcpy( agua + y *gr->pitch,
(char *)gr->data + (inc/100)*gr->pitch + (gr->width - shift) * pixelsize,
shift * pixelsize);
}
inc -= desp/50;
desp += dec;
despx++;
if (desp < 12500) dec=1;
if (desp > 17500) dec=-1;
}
if ( last_ticks == current_ticks ) {
current_desp = desp;
current_despx = despx;
current_dec = dec;
}
memset(agua, 0, gr->pitch);
for (y = 1 ; y < altura ; y++)
{
Uint8 * dest = (char *)gr->data + (gr->height-altura-1+y)*gr->pitch;
Uint8 * orig = agua + gr->pitch * y;
if (pixelsize == 1)
{
gr_make_trans_table();
for (x = 0 ; x < gr->widthb ; x++, dest++, orig++)
*dest = trans_table[(*dest << 8) + *orig] ;
}
else
{
for (x = 0 ; x < gr->width ; x++, dest+=2, orig+=2)
*(Uint16 *)dest = colorghost[*(Uint16*)dest] + colorghost[*(Uint16*)orig];
}
}
}
int info_desktop (void * user, REGION * bbox)
{
bbox->x = 0;
bbox->y = 0;
bbox->x2 = scr_width-1;
bbox->y2 = scr_height-1;
return 1;
}
void draw_desktop (void * user, REGION * clip)
{
static int lastmx = -1;
static int lastmy = -1;
static int lastmleft = -1;
static int lastmright = -1;
static int lastmcenter = -1;
static int lastmwup = -1;
static int lastmwdown = -1;
static int lastkey = -1;
x_agua(clip);
return;
}
static int fxi_agua (INSTANCE * my, int * params)
{
if (old_object != -1) {
gr_destroy_object (old_object);
old_object = -1;
}
refresh_ticks = params[3];
ondulacion = params[2]/10;
if (ondulacion < 0.0 ) {
ondulacion = 0.0;
}
altura = params[1];
if (altura > 0)
{
// z Z value of the object to be drawn
// info Pointer to the object information function
// (fills bounding box, returns 1 if changed since last frame)
// draw Pointer to the object drawing function
// what User-defined parameter that will be passed to "draw"
old_object = gr_new_object (params[0],info_desktop ,draw_desktop,NULL);
return 1;
}
return 1;
}
static int fxi_agua_stop (INSTANCE * my, int * params)
{
if (old_object != -1)
{
gr_destroy_object (old_object);
old_object = -1;
if ( agua ) {
free (agua);
agua = NULL;
}
}
return 1;
}
FENIX_MainDLL RegisterFunctions (COMMON_PARAMS)
{
FENIX_DLLImport
FENIX_export ("FXAGUA_START", "IIII", TYPE_DWORD, fxi_agua ) ;
FENIX_export ("FXAGUA_STOP", "", TYPE_DWORD, fxi_agua_stop ) ;
}
|