You can download the full source HERE
parallax-theme.c posted for reference
- Code: Select all
/* usplash
*
* parallax-theme.c
* Copyright © 2008 red_team316
* Original Code found throughout Copyright © 2006 Dennis Kaarsemaker
*
* Notes: Includes pallete index bugfix see URL below.
* https://bugs.launchpad.net/ubuntu/+source/usplash/+bug/66760
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <usplash-theme.h>
/* Needed for the custom drawing functions */
#include <usplash_backend.h>
extern struct usplash_pixmap pixmap_usplash_640x480;
extern struct usplash_pixmap pixmap_usplash_800x600;
extern struct usplash_pixmap pixmap_usplash_1024x768;
extern struct usplash_pixmap pixmap_usplash_1280x1024;
/* Parallax Pixmaps */
extern struct usplash_pixmap pixmap_logo;
extern struct usplash_pixmap pixmap_strip1_640x480;
extern struct usplash_pixmap pixmap_strip2_640x480;
extern struct usplash_pixmap pixmap_strip1_800x600;
extern struct usplash_pixmap pixmap_strip2_800x600;
extern struct usplash_pixmap pixmap_strip1_1024x768;
extern struct usplash_pixmap pixmap_strip2_1024x768;
extern struct usplash_pixmap pixmap_strip1_1280x1024;
extern struct usplash_pixmap pixmap_strip2_1280x1024;
extern struct usplash_pixmap pixmap_throbber_back;
extern struct usplash_pixmap pixmap_throbber_fore;
extern struct usplash_font font_helvB10;
void t_init(struct usplash_theme* theme);
void t_clear_progressbar(struct usplash_theme* theme);
void t_draw_progressbar(struct usplash_theme* theme, int percentage);
void t_animate_step(struct usplash_theme* theme, int pulsating);
struct usplash_theme usplash_theme_640x480;
struct usplash_theme usplash_theme_800x600;
struct usplash_theme usplash_theme_1024x768;
struct usplash_theme usplash_theme_1280x1024;
/* Theme definition */
struct usplash_theme usplash_theme = {
.version = THEME_VERSION,
.next = &usplash_theme_800x600,
.ratio = USPLASH_4_3,
/* Background and font */
.pixmap = &pixmap_usplash_640x480,
.font = &font_helvB10,
/* Palette indexes */
.background = 0,
.progressbar_background = 0,
.progressbar_foreground = 30,
.text_background = 0,
.text_foreground = 125,
.text_success = 125,
.text_failure = 215,
/* Progress bar position and size in pixels */
.progressbar_x = 212, /* 640/2-216/2 */
.progressbar_y = 290, /* (strip2 height)+(logo height)+3 */
.progressbar_width = 216,
.progressbar_height = 8,
/* Text box position and size in pixels */ /* */
.text_x = 100, /* 100+440+100=640 */ /* x,y----------------- */
.text_y = 310, /* Fit between progressbar and strip1 */ /* | | */
.text_width = 440, /* -----------------w,h */
.text_height = 105, /* 7 lines */ /* */
/* Text details */
.line_height = 15, /* Height of line in pixels */
.line_length = 32, /* Length of line in characters */
.status_width = 64, /* Number of RHS pixels for status */
/* Functions */
.init = t_init,
.clear_progressbar = t_clear_progressbar,
.draw_progressbar = t_draw_progressbar,
.animate_step = t_animate_step,
};
struct usplash_theme usplash_theme_800x600 = {
.version = THEME_VERSION,
.next = &usplash_theme_1024x768,
.ratio = USPLASH_4_3,
/* Background and font */
.pixmap = &pixmap_usplash_800x600,
.font = &font_helvB10,
/* Palette indexes */
.background = 0,
.progressbar_background = 0,
.progressbar_foreground = 30,
.text_background = 0,
.text_foreground = 125,
.text_success = 125,
.text_failure = 215,
/* Progress bar position and size in pixels */
.progressbar_x = 292, /* 800/2 - 216/2 */
.progressbar_y = 335, /* (strip2 height)+(logo height)+5 */
.progressbar_width = 216,
.progressbar_height = 8,
/* Text box position and size in pixels */
.text_x = 100, /* 100+600+100=800 */
.text_y = 345, /* Fit between progressbar and strip1 */
.text_width = 600,
.text_height = 165, /* 11 lines */
/* Text details */
.line_height = 15,
.line_length = 32,
.status_width = 64,
/* Functions */
.init = t_init,
.clear_progressbar = t_clear_progressbar,
.draw_progressbar = t_draw_progressbar,
.animate_step = t_animate_step,
};
struct usplash_theme usplash_theme_1024x768 = {
.version = THEME_VERSION,
.next = &usplash_theme_1280x1024,
.ratio = USPLASH_4_3,
/* Background and font */
.pixmap = &pixmap_usplash_1024x768,
.font = &font_helvB10,
/* Palette indexes */
.background = 0,
.progressbar_background = 0,
.progressbar_foreground = 30,
.text_background = 0,
.text_foreground = 125,
.text_success = 125,
.text_failure = 215,
/* Progress bar position and size in pixels */
.progressbar_x = 404, /* 1024/2 - 216/2 */
.progressbar_y = 390, /* (strip2 height)+(logo height)+3 */
.progressbar_width = 216,
.progressbar_height = 8,
/* Text box position and size in pixels */
.text_x = 200, /* 200+624+200=1024 */
.text_y = 400, /* Fit between progressbar and strip1 */
.text_width = 624,
.text_height = 270, /* 18 lines */
/* Text details */
.line_height = 15,
.line_length = 32,
.status_width = 64,
/* Functions */
.init = t_init,
.clear_progressbar = t_clear_progressbar,
.draw_progressbar = t_draw_progressbar,
.animate_step = t_animate_step,
};
struct usplash_theme usplash_theme_1280x1024 = {
.version = THEME_VERSION,
.next = NULL,
.ratio = USPLASH_4_3,
/* Background and font */
.pixmap = &pixmap_usplash_1280x1024,
.font = &font_helvB10,
/* Palette indexes */
.background = 0,
.progressbar_background = 0,
.progressbar_foreground = 30,
.text_background = 0,
.text_foreground = 125,
.text_success = 125,
.text_failure = 215,
/* Progress bar position and size in pixels */
.progressbar_x = 532, /* 1280/2 - 216/2 */
.progressbar_y = 460, /* (strip2 height)+(logo height)+6 */
.progressbar_width = 216,
.progressbar_height = 8,
/* Text box position and size in pixels */
.text_x = 200, /* 200+880+200=1280 */
.text_y = 475, /* Fit between progressbar and strip1 */
.text_width = 880,
.text_height = 420, /* 28 lines */
/* Text details */
.line_height = 15,
.line_length = 32,
.status_width = 64,
/* Functions */
.init = t_init,
.clear_progressbar = t_clear_progressbar,
.draw_progressbar = t_draw_progressbar,
.animate_step = t_animate_step,
};
void t_init(struct usplash_theme *theme) {
int x, y;
usplash_getdimensions(&x, &y);
theme->progressbar_x = (x - theme->pixmap->width)/2 + theme->progressbar_x;
theme->progressbar_y = (y - theme->pixmap->height)/2 + theme->progressbar_y;
}
void t_clear_progressbar(struct usplash_theme *theme) {
t_draw_progressbar(theme, 0);
}
void t_draw_progressbar(struct usplash_theme *theme, int percentage) {
int w = (pixmap_throbber_back.width * percentage / 100);
usplash_put(theme->progressbar_x, theme->progressbar_y, &pixmap_throbber_back);
if(percentage == 0)
return;
if(percentage < 0)
usplash_put_part(theme->progressbar_x - w, theme->progressbar_y, pixmap_throbber_back.width + w,
pixmap_throbber_back.height, &pixmap_throbber_fore, -w, 0);
else
usplash_put_part(theme->progressbar_x, theme->progressbar_y, w, pixmap_throbber_back.height,
&pixmap_throbber_fore, 0, 0);
}
void t_animate_step(struct usplash_theme* theme, int pulsating) {
static int pulsate_step = 0;
static int pulse_width = 28;
static int step_width = 2;
static int num_steps = (216 - 28)/2;
int x1;
if (pulsating) {
t_draw_progressbar(theme, 0);
if(pulsate_step < num_steps/2+1)
x1 = 2 * step_width * pulsate_step;
else
x1 = 216 - pulse_width - 2 * step_width * (pulsate_step - num_steps/2+1);
usplash_put_part(theme->progressbar_x + x1, theme->progressbar_y, pulse_width,
pixmap_throbber_fore.height, &pixmap_throbber_fore, x1, 0);
pulsate_step = (pulsate_step + 1) % num_steps;
}
/* Parallax Code */ /* Variable Descriptions*/
static short firstrun = 1; /* firstrun = ensure this block of code is only run once */
static short ani1 = 0; /* ani1 = pixel offset for scrolling strip1 */
static short ani2 = 0; /* ani2 = pixel offset for scrolling strip2 */
static short resX = 640; /* resX = holds the x value of the resolution */
static short resY = 480; /* resY = holds the y value of the resolution */
static short px1 = 0; /* px1 = upper left coord of strip1 */
static short px2 = 0; /* px2 = upper left coord of strip2 */
static short py1 = 420; /* py1 = upper left coord of strip1 */
static short py2 = 0; /* py2 = upper left coord of strip2 */
static short pw1 = 640; /* pw1 = half the width of strip image, for tessellation effect */
static short pw2 = 640; /* pw2 = half the width of strip image, for tessellation effect */
static short ph1 = 60; /* ph1 = we want to draw the full height of strip */
static short ph2 = 168; /* ph2 = we want to draw the full height of strip */
static short logoX = 92; /* logoX = centered (ResWidth/2 - logoWidth/2) */
static short logoY = 170; /* logoY = strip2 height + 1 */
if(firstrun)
{
firstrun = 0;
int x, y;
usplash_getdimensions(&x, &y);
if(x == 800 && y == 600)
{
resX = 800; resY = 600; logoX = 172; logoY = 210;
px1 = 0; py1 = 525; pw1 = 800; ph1 = 75;
px2 = 0; py2 = 0; pw2 = 800; ph2 = 209;
}
else if(x == 1024 && y == 768)
{
resX = 1024; resY = 768; logoX = 284; logoY = 269;
px1 = 0; py1 = 672; pw1 = 1024; ph1 = 96;
px2 = 0; py2 = 0; pw2 = 1024; ph2 = 268;
}
else if(x == 1280 && y == 1024)
{
resX = 1280; resY = 1024; logoX = 412; logoY = 336;
px1 = 0; py1 = 904; pw1 = 1280; ph1 = 120;
px2 = 0; py2 = 0; pw2 = 1280; ph2 = 335;
}
}
/* Move this strip fast */
if(ani1 < pw1) ani1 += 5;
else ani1 = 0;
/* Move this strip slow */
if(ani2 < pw2) ani2 += 1;
else ani2 = 0;
/* Draw the scrolling strips */
if(resX == 640 && resY == 480)
{
usplash_put_part(px1, py1, pw1, ph1, &pixmap_strip1_640x480, ani1, 0); /* GRASS */
usplash_put_part(px2, py2, pw2, ph2, &pixmap_strip2_640x480, ani2, 0); /* SKY */
}
else if(resX == 800 && resY == 600)
{
usplash_put_part(px1, py1, pw1, ph1, &pixmap_strip1_800x600, ani1, 0);
usplash_put_part(px2, py2, pw2, ph2, &pixmap_strip2_800x600, ani2, 0);
}
else if(resX == 1024 && resY == 768)
{
usplash_put_part(px1, py1, pw1, ph1, &pixmap_strip1_1024x768, ani1, 0);
usplash_put_part(px2, py2, pw2, ph2, &pixmap_strip2_1024x768, ani2, 0);
}
else if(resX == 1280 && resY == 1024)
{
usplash_put_part(px1, py1, pw1, ph1, &pixmap_strip1_1280x1024, ani1, 0);
usplash_put_part(px2, py2, pw2, ph2, &pixmap_strip2_1280x1024, ani2, 0);
}
/* Draw the logo */
usplash_put(logoX, logoY, &pixmap_logo);
}
parallax-theme-function.c posted for reference
- Code: Select all
/* usplash
*
* parallax-theme.c
* Copyright © 2008 red_team316
* Original Code found throughout Copyright © 2006 Dennis Kaarsemaker
*
* Notes: Includes pallete index bugfix see URL below.
* https://bugs.launchpad.net/ubuntu/+source/usplash/+bug/66760
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <usplash-theme.h>
/* Needed for the custom drawing functions */
#include <usplash_backend.h>
extern struct usplash_pixmap pixmap_usplash_640x480;
extern struct usplash_pixmap pixmap_usplash_800x600;
extern struct usplash_pixmap pixmap_usplash_1024x768;
extern struct usplash_pixmap pixmap_usplash_1280x1024;
/* Parallax Pixmaps */
extern struct usplash_pixmap pixmap_logo;
extern struct usplash_pixmap pixmap_strip1_640x480;
extern struct usplash_pixmap pixmap_strip2_640x480;
extern struct usplash_pixmap pixmap_strip1_800x600;
extern struct usplash_pixmap pixmap_strip2_800x600;
extern struct usplash_pixmap pixmap_strip1_1024x768;
extern struct usplash_pixmap pixmap_strip2_1024x768;
extern struct usplash_pixmap pixmap_strip1_1280x1024;
extern struct usplash_pixmap pixmap_strip2_1280x1024;
extern struct usplash_pixmap pixmap_throbber_back;
extern struct usplash_pixmap pixmap_throbber_fore;
extern struct usplash_font font_helvB10;
void t_init(struct usplash_theme* theme);
void t_clear_progressbar(struct usplash_theme* theme);
void t_draw_progressbar(struct usplash_theme* theme, int percentage);
void t_animate_step(struct usplash_theme* theme, int pulsating);
void t_parallax(short px1, short px2, short py1, short py2, short pw1, short pw2, short ph1, short ph2, short logoX, short logoY, short Res);
struct usplash_theme usplash_theme_640x480;
struct usplash_theme usplash_theme_800x600;
struct usplash_theme usplash_theme_1024x768;
struct usplash_theme usplash_theme_1280x1024;
/* Theme definition */
struct usplash_theme usplash_theme = {
.version = THEME_VERSION,
.next = &usplash_theme_800x600,
.ratio = USPLASH_4_3,
/* Background and font */
.pixmap = &pixmap_usplash_640x480,
.font = &font_helvB10,
/* Palette indexes */
.background = 0,
.progressbar_background = 0,
.progressbar_foreground = 30,
.text_background = 0,
.text_foreground = 125,
.text_success = 125,
.text_failure = 215,
/* Progress bar position and size in pixels */
.progressbar_x = 212, /* 640/2-216/2 */
.progressbar_y = 290, /* (strip2 height)+(logo height)+3 */
.progressbar_width = 216,
.progressbar_height = 8,
/* Text box position and size in pixels */ /* */
.text_x = 100, /* 100+440+100=640 */ /* x,y----------------- */
.text_y = 310, /* Fit between progressbar and strip1 */ /* | | */
.text_width = 440, /* -----------------w,h */
.text_height = 105, /* 7 lines */ /* */
/* Text details */
.line_height = 15, /* Height of line in pixels */
.line_length = 32, /* Length of line in characters */
.status_width = 64, /* Number of RHS pixels for status */
/* Functions */
.init = t_init,
.clear_progressbar = t_clear_progressbar,
.draw_progressbar = t_draw_progressbar,
.animate_step = t_animate_step,
};
struct usplash_theme usplash_theme_800x600 = {
.version = THEME_VERSION,
.next = &usplash_theme_1024x768,
.ratio = USPLASH_4_3,
/* Background and font */
.pixmap = &pixmap_usplash_800x600,
.font = &font_helvB10,
/* Palette indexes */
.background = 0,
.progressbar_background = 0,
.progressbar_foreground = 30,
.text_background = 0,
.text_foreground = 125,
.text_success = 125,
.text_failure = 215,
/* Progress bar position and size in pixels */
.progressbar_x = 292, /* 800/2 - 216/2 */
.progressbar_y = 335, /* (strip2 height)+(logo height)+5 */
.progressbar_width = 216,
.progressbar_height = 8,
/* Text box position and size in pixels */
.text_x = 100, /* 100+600+100=800 */
.text_y = 345, /* Fit between progressbar and strip1 */
.text_width = 600,
.text_height = 165, /* 11 lines */
/* Text details */
.line_height = 15,
.line_length = 32,
.status_width = 64,
/* Functions */
.init = t_init,
.clear_progressbar = t_clear_progressbar,
.draw_progressbar = t_draw_progressbar,
.animate_step = t_animate_step,
};
struct usplash_theme usplash_theme_1024x768 = {
.version = THEME_VERSION,
.next = &usplash_theme_1280x1024,
.ratio = USPLASH_4_3,
/* Background and font */
.pixmap = &pixmap_usplash_1024x768,
.font = &font_helvB10,
/* Palette indexes */
.background = 0,
.progressbar_background = 0,
.progressbar_foreground = 30,
.text_background = 0,
.text_foreground = 125,
.text_success = 125,
.text_failure = 215,
/* Progress bar position and size in pixels */
.progressbar_x = 404, /* 1024/2 - 216/2 */
.progressbar_y = 390, /* (strip2 height)+(logo height)+3 */
.progressbar_width = 216,
.progressbar_height = 8,
/* Text box position and size in pixels */
.text_x = 200, /* 200+624+200=1024 */
.text_y = 400, /* Fit between progressbar and strip1 */
.text_width = 624,
.text_height = 270, /* 18 lines */
/* Text details */
.line_height = 15,
.line_length = 32,
.status_width = 64,
/* Functions */
.init = t_init,
.clear_progressbar = t_clear_progressbar,
.draw_progressbar = t_draw_progressbar,
.animate_step = t_animate_step,
};
struct usplash_theme usplash_theme_1280x1024 = {
.version = THEME_VERSION,
.next = NULL,
.ratio = USPLASH_4_3,
/* Background and font */
.pixmap = &pixmap_usplash_1280x1024,
.font = &font_helvB10,
/* Palette indexes */
.background = 0,
.progressbar_background = 0,
.progressbar_foreground = 30,
.text_background = 0,
.text_foreground = 125,
.text_success = 125,
.text_failure = 215,
/* Progress bar position and size in pixels */
.progressbar_x = 532, /* 1280/2 - 216/2 */
.progressbar_y = 460, /* (strip2 height)+(logo height)+6 */
.progressbar_width = 216,
.progressbar_height = 8,
/* Text box position and size in pixels */
.text_x = 200, /* 200+880+200=1280 */
.text_y = 475, /* Fit between progressbar and strip1 */
.text_width = 880,
.text_height = 420, /* 28 lines */
/* Text details */
.line_height = 15,
.line_length = 32,
.status_width = 64,
/* Functions */
.init = t_init,
.clear_progressbar = t_clear_progressbar,
.draw_progressbar = t_draw_progressbar,
.animate_step = t_animate_step,
};
void t_init(struct usplash_theme *theme) {
int x, y;
usplash_getdimensions(&x, &y);
theme->progressbar_x = (x - theme->pixmap->width)/2 + theme->progressbar_x;
theme->progressbar_y = (y - theme->pixmap->height)/2 + theme->progressbar_y;
}
void t_clear_progressbar(struct usplash_theme *theme) {
t_draw_progressbar(theme, 0);
}
void t_draw_progressbar(struct usplash_theme *theme, int percentage) {
int w = (pixmap_throbber_back.width * percentage / 100);
usplash_put(theme->progressbar_x, theme->progressbar_y, &pixmap_throbber_back);
if(percentage == 0)
return;
if(percentage < 0)
usplash_put_part(theme->progressbar_x - w, theme->progressbar_y, pixmap_throbber_back.width + w,
pixmap_throbber_back.height, &pixmap_throbber_fore, -w, 0);
else
usplash_put_part(theme->progressbar_x, theme->progressbar_y, w, pixmap_throbber_back.height,
&pixmap_throbber_fore, 0, 0);
}
void t_animate_step(struct usplash_theme* theme, int pulsating) {
static int pulsate_step = 0;
static int pulse_width = 28;
static int step_width = 2;
static int num_steps = (216 - 28)/2;
int x1;
if (pulsating) {
t_draw_progressbar(theme, 0);
if(pulsate_step < num_steps/2+1)
x1 = 2 * step_width * pulsate_step;
else
x1 = 216 - pulse_width - 2 * step_width * (pulsate_step - num_steps/2+1);
usplash_put_part(theme->progressbar_x + x1, theme->progressbar_y, pulse_width,
pixmap_throbber_fore.height, &pixmap_throbber_fore, x1, 0);
pulsate_step = (pulsate_step + 1) % num_steps;
}
/* Parallax Code */
static short firstrun = 1;
static int x = 640;
static int y = 480;
if(firstrun)
{
firstrun = 0;
usplash_getdimensions(&x, &y);
}
/* Call the parallax function */
if(x == 640 && y == 480) t_parallax(0, 0, 420, 0, 640, 640, 60, 168, 92, 170, 1);
else if(x == 800 && y == 600) t_parallax(0, 0, 525, 0, 800, 800, 75, 209, 172, 210, 2);
else if(x == 1024 && y == 768) t_parallax(0, 0, 672, 0, 1024, 1024, 96, 268, 284, 269, 3);
else if(x == 1280 && y == 1024) t_parallax(0, 0, 904, 0, 1280, 1280, 120, 335, 412, 336, 4);
}
/* Variable Descriptions*/
/* px = upper left coord of strip */
/* py = upper left coord of strip */
/* pw = half the width of strip image, for tessellation effect */
/* ph = we want to draw the full height of strip */
/* logoX = centered (ResWidth/2 - logoWidth/2) */
/* logoY = strip2 + 1 */
void t_parallax(short px1, short px2, short py1, short py2, short pw1, short pw2, short ph1, short ph2, short logoX, short logoY, short Res)
{
static short ani1 = 0;
static short ani2 = 0;
/* Move this strip fast */
if(ani1 < pw1) ani1 += 5;
else ani1 = 0;
/* Move this strip slow */
if(ani2 < pw2) ani2 += 1;
else ani2 = 0;
/* Draw the scrolling strips */
if(Res == 1)
{
usplash_put_part(px1, py1, pw1, ph1, &pixmap_strip1_640x480, ani1, 0); /* GRASS */
usplash_put_part(px2, py2, pw2, ph2, &pixmap_strip2_640x480, ani2, 0); /* SKY */
}
else if(Res == 2)
{
usplash_put_part(px1, py1, pw1, ph1, &pixmap_strip1_800x600, ani1, 0);
usplash_put_part(px2, py2, pw2, ph2, &pixmap_strip2_800x600, ani2, 0);
}
else if(Res == 3)
{
usplash_put_part(px1, py1, pw1, ph1, &pixmap_strip1_1024x768, ani1, 0);
usplash_put_part(px2, py2, pw2, ph2, &pixmap_strip2_1024x768, ani2, 0);
}
else if(Res == 4)
{
usplash_put_part(px1, py1, pw1, ph1, &pixmap_strip1_1280x1024, ani1, 0);
usplash_put_part(px2, py2, pw2, ph2, &pixmap_strip2_1280x1024, ani2, 0);
}
/* Draw the logo */
usplash_put(logoX, logoY, &pixmap_logo);
}