diff options
author | Yohann Ferreira <bertram@cegetel.net> | 2005-01-17 17:32:38 +0000 |
---|---|---|
committer | Yohann Ferreira <bertram@cegetel.net> | 2005-01-17 17:32:38 +0000 |
commit | de3f91b623ab9c5ed3f2107bc768cbe9ce058a1b (patch) | |
tree | 8e3de206f7046ea213599533e9080b2455e95ec0 | |
parent | a7ab4b11e5bdbddad509f9b4ad62220145899ebc (diff) | |
download | mana-de3f91b623ab9c5ed3f2107bc768cbe9ce058a1b.tar.gz mana-de3f91b623ab9c5ed3f2107bc768cbe9ce058a1b.tar.bz2 mana-de3f91b623ab9c5ed3f2107bc768cbe9ce058a1b.tar.xz mana-de3f91b623ab9c5ed3f2107bc768cbe9ce058a1b.zip |
*** empty log message ***
-rw-r--r-- | src/gui/progressbar.cpp | 189 |
1 files changed, 141 insertions, 48 deletions
diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index fdaefa73..6ada672b 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -24,6 +24,10 @@ #include "progressbar.h" #include "gui.h" +// To draw primitives without dependencies +void DrawPixel(SDL_Surface * screen, int x, int y, Uint8 R, Uint8 G, Uint8 B); +void DrawLine(SDL_Surface * screen, int x1, int y1, int x2, int y2, unsigned char Red, unsigned char Green, unsigned char Blue); + ProgressBar::ProgressBar(float progress, int x, int y, int width, unsigned char red, unsigned green, unsigned char blue) { @@ -40,71 +44,34 @@ void ProgressBar::draw(gcn::Graphics *graphics) { int absx, absy; getAbsolutePosition(absx, absy); - /* + // outer bar - int MyColor = makecol(abs(Red-70), abs(Green-70), abs(Blue-70)); - hline(buffer, absx+X+7, absy+Y, absx+X+Width, MyColor); - hline(buffer, absx+X, absy+Y+7, absx+X+Width-7, MyColor); - line(buffer, absx+X+7, absy+Y, absx+X, absy+Y+7, MyColor); - line(buffer, absx+X+Width, absy+Y, absx+X+Width-7, absy+Y+7, MyColor); + DrawLine(screen, absx+X+7, absy+Y, absx+X+Width, absy+Y, abs(Red-70), abs(Green-70), abs(Blue-70)); + DrawLine(screen, absx+X, absy+Y+7, absx+X+Width-7, absy+Y+7, abs(Red-70), abs(Green-70), abs(Blue-70)); + DrawLine(screen, absx+X+7, absy+Y, absx+X, absy+Y+7, abs(Red-70), abs(Green-70), abs(Blue-70)); + DrawLine(screen, absx+X+Width, absy+Y, absx+X+Width-7, absy+Y+7, abs(Red-70), abs(Green-70), abs(Blue-70)); // Shadow of outer bar - MyColor = makeacol(0, 0, 0, 80); - hline(buffer, absx+X+1, absy+Y+7+1, absx+X+Width-7, MyColor); - line(buffer, absx+X+Width+1, absy+Y, absx+X+Width-7+1, absy+Y+7, MyColor); + DrawLine(screen, absx+X+1, absy+Y+7+1, absx+X+Width-7, absy+Y+7+1, 20, 20, 20); + DrawLine(screen, absx+X+Width+1, absy+Y, absx+X+Width-7+1, absy+Y+7, 20, 20, 20); // Inner bar - MyColor = makecol(Red, Green, Blue); - int Temp = 0; - for(int i = 1; i < 7; i++) { Temp = absx+X+int(float(Width)*progress)-i-1; if (Temp < (absx + X + 8 - i)) Temp = (absx + X + 8 - i); - hline(buffer, absx+X+8-i, absy+Y+i, Temp, MyColor); + DrawLine(screen, absx+X+8-i, absy+Y+i, Temp, absy+Y+i, Red, Green, Blue); } // Shadow of inner bar Temp = absx+X+int(float(Width)*progress)-2; if ( Temp < (absx+X+7+1) ) Temp = absx+X+7; - MyColor = makeacol(abs(Red-40), abs(Green-40), abs(Blue-40), 80); - hline(buffer, absx+X+7+1, absy+Y+1, Temp, MyColor); - line(buffer, absx+X+7, absy+Y+1, absx+X+2, absy+Y+7-1, MyColor); - - //rectfill(buffer, absx+7, absy+7, absx+39, absy+9, MyColor); - */ -/* - if (progress != 0) { - masked_blit(gui_skin.bar.bg.grid[3], buffer, - 0, 0, x, y, buffer->w, buffer->h); - } - else { - masked_blit(gui_skin.bar.bg.grid[0], buffer, - 0, 0, x, y, buffer->w, buffer->h); - } - - for (int i = 3; i < (w - 3); i++) { - if (i < progress * w - 3) { - masked_blit(gui_skin.bar.bg.grid[4], buffer, - 0, 0, x + 1 * i, y, buffer->w, buffer->h); - } - else { - masked_blit(gui_skin.bar.bg.grid[1], buffer, - 0, 0, x + 1 * i, y, buffer->w, buffer->h); - } - } - - if (progress == 1) { - masked_blit(gui_skin.bar.bg.grid[5], buffer, - 0, 0, x + w - 3, y, buffer->w, buffer->h); - } - else { - masked_blit(gui_skin.bar.bg.grid[2], buffer, - 0, 0, x + w - 3, y, buffer->w, buffer->h); - }*/ + DrawLine(screen, absx+X+7+1, absy+Y+1, Temp, absy+Y+1, abs(Red-40), abs(Green-40), abs(Blue-40)); + DrawLine(screen, absx+X+7, absy+Y+1, absx+X+2, absy+Y+7-1, abs(Red-40), abs(Green-40), abs(Blue-40)); + } void ProgressBar::setProgress(float progress) @@ -116,3 +83,129 @@ float ProgressBar::getProgress() { return progress; } + +// Cette fonction permet de dessiner facilement une pixel sur l'écran, en gérant automatiquement le nombre de couleurs + // de ce dernier... + // Il suffit de lui passer la surface à peindre, les coordonnées (x,y), et la couleur (R,G,B) [0 ... 255] + void DrawPixel(SDL_Surface * screen, int x, int y, Uint8 R, Uint8 G, Uint8 B) +{ + Uint32 color = SDL_MapRGB(screen->format, R, G, B); + if ( (x >= screen->w) || (x < 0) ) + return; + if ( (y >= screen->h) || (y < 0) ) + return; + + switch (screen->format->BytesPerPixel) + { + case 1: // Pour 8 BPP + { + Uint8 *bufp; + bufp = (Uint8 *) screen->pixels + y * screen ->pitch + x; + *bufp = color; + } + break; + + case 2: // 15 ou 16 BPP + { + Uint16 * bufp; + bufp = (Uint16 *)screen->pixels + y * screen->pitch/2 + x; + *bufp = color; + } + break; + + case 3: // 24 BPP, peu utilisé, mais bon ... + { + Uint8 *bufp; + bufp = (Uint8 *)screen->pixels + y * screen->pitch + x * 3; + + if (SDL_BYTEORDER == SDL_LIL_ENDIAN) + { + bufp[0] = color; + bufp[1] = color >> 8; + bufp[2] = color >> 16; + } else { + bufp[2] = color; + bufp[1] = color >> 8; + bufp[0] = color >> 16; + } + } + break; + + case 4: // 32 BPP, le plus utilisé ! + { + Uint32 *bufp; + bufp = (Uint32 *)screen->pixels + y * screen->pitch/4 + x; + *bufp = color; + } + break; + } +} // Fin DrawLine + +// Dessine une ligne à l'écran avec une couleur et des coordonnées fournies. +void DrawLine(SDL_Surface * screen, int x1, int y1, int x2, int y2, unsigned char Red, unsigned char Green, unsigned char Blue) +{ + float a, b, Temp_x1, Temp_x2, Temp_y1, Temp_y2; + + Temp_x1 = x1; + Temp_x2 = x2; + Temp_y1 = y1; + Temp_y2 = y2; + + if ( (x1-x2) != 0) + { + a=(Temp_y1-Temp_y2)/(Temp_x1-Temp_x2); // La pente // -350/-410=0.00 + } + else // la ligne est verticale ! + { + if ( y1 < y2) + { + for (int Y=y1; Y<=y2; Y++) + { + DrawPixel(screen, x1, Y, Red, Green, Blue); + } + } + else + { + for (int Y=y2; Y<=y1; Y++) + { + DrawPixel(screen, x1, Y, Red, Green, Blue); + } + } + + return; + } + + b=y1-a*x1; + + if ( x1 < x2) + { + for (int X = x1; X <= x2; X++) + { + DrawPixel(screen, X, int(a*X+b), Red, Green, Blue); + } + } + else + { + for (int X = x2; X <= x1; X++) + { + DrawPixel(screen, X, int(a*X+b), Red, Green, Blue); + } + } + + if ( y1 < y2) + { + for (int Y = y1; Y <= y2; Y++) + { + if (a != 0) DrawPixel(screen, int((Y-b)/a), Y, Red, Green, Blue); + } + } + else + { + for (int Y = y2; Y <= y1; Y++) + { + if (a != 0) DrawPixel(screen, int((Y-b)/a), Y, Red, Green, Blue); + } + } + +} // Fin DrawLine + |