Author: baby-guest
Date: 2007-07-04 20:43:09 +0000 (Wed, 04 Jul 2007)
New Revision: 3241

Modified:
   software/ui/src/common.h
   software/ui/src/games.cpp
   software/ui/src/pkgbrowser.cpp
   software/ui/src/pkgbrowser.h
Log:
support for multiple bar  graphics in the package browser



Modified: software/ui/src/common.h
===================================================================
--- software/ui/src/common.h    2007-07-04 19:31:54 UTC (rev 3240)
+++ software/ui/src/common.h    2007-07-04 20:43:09 UTC (rev 3241)
@@ -38,13 +38,21 @@
 #endif
 
 #ifndef FILE_STARS_ON
-#define FILE_STARS_ON DATADIR "/people_on.png"
+#define FILE_STARS_ON DATADIR "/stars_on.png"
 #endif
 
 #ifndef FILE_STARS_OFF
-#define FILE_STARS_OFF DATADIR "/people_off.png"
+#define FILE_STARS_OFF DATADIR "/stars_off.png"
 #endif
 
+#ifndef FILE_PEOPLE_ON
+#define FILE_PEOPLE_ON DATADIR "/people_on.png"
+#endif
+
+#ifndef FILE_PEOPLE_OFF
+#define FILE_PEOPLE_OFF DATADIR "/people_off.png"
+#endif
+
 #ifndef THUMBNAILSDIR
 #define THUMBNAILSDIR DATADIR "/screenshots"
 #endif

Modified: software/ui/src/games.cpp
===================================================================
--- software/ui/src/games.cpp   2007-07-04 19:31:54 UTC (rev 3240)
+++ software/ui/src/games.cpp   2007-07-04 20:43:09 UTC (rev 3241)
@@ -207,7 +207,7 @@
                {
                        desc += "\t";
                        char stars[16];
-                       snprintf(stars, sizeof(stars), "%%%d ",
+                       snprintf(stars, sizeof(stars), "%%%d/8/1;",
                                (int)rintf(log(i->popcon) * 100 / 
log(engine.popconLocalMax())));
                        desc += stars;
                        printf ("%s (%s): POPCON=%f\n", rec.package().c_str(), 
rec.shortDescription().c_str(), i->popcon);

Modified: software/ui/src/pkgbrowser.cpp
===================================================================
--- software/ui/src/pkgbrowser.cpp      2007-07-04 19:31:54 UTC (rev 3240)
+++ software/ui/src/pkgbrowser.cpp      2007-07-04 20:43:09 UTC (rev 3241)
@@ -54,23 +54,28 @@
 using namespace ept::textsearch;
 
 PackageBrowser::PackageBrowser(int x, int y, int w, int h, const char *l)
-       : VersatileBrowser(x, y, w, h, l), stars_on(NULL), stars_off(NULL)
+       : VersatileBrowser(x, y, w, h, l), num_bar_images(2)
 {
        showcolsep(1);
        //colsepcolor(FL_RED);
        column_char('\t'); // tabs as column delimiters
-       stars_on = new Fl_PNG_Image(FILE_STARS_ON);
-       if (stars_on && !stars_on->count())
-               printf(_("Cannot open file '%s'\n"), FILE_STARS_ON);
-       stars_off = new Fl_PNG_Image(FILE_STARS_OFF);
-       if (stars_off && !stars_off->count())
-               printf(_("Cannot open file '%s'\n"), FILE_STARS_OFF);
+       bar_images[0] = new Fl_PNG_Image(FILE_STARS_ON);
+       bar_images[1] = new Fl_PNG_Image(FILE_STARS_OFF);
+       bar_images[2] = new Fl_PNG_Image(FILE_PEOPLE_ON);
+       bar_images[3] = new Fl_PNG_Image(FILE_PEOPLE_OFF);
+       for (unsigned int i = 0; i < num_bar_images*2; i++)
+       {
+               if (bar_images[i] && !bar_images[i]->count())
+                       printf(_("Invalid bar image %u\n"), i);
+       }
 }
 
 PackageBrowser::~PackageBrowser()
 {
-       if (stars_on) delete stars_on;
-       if (stars_off) delete stars_off;
+       for (unsigned int i = 0; i < num_bar_images*2; i++)
+       {
+               if (bar_images[i]) delete bar_images[i];
+       }
 }
 
 void PackageBrowser::item_select(void *p, int s)
@@ -219,9 +224,19 @@
        int last_w = 0;
        if (*str=='%' && '0'<*str+1<'9')
        {
+               char *after;
+               /* int percent = */ strtol(str+1, &after, 10);
+               int steps = 8;
+               int bar = 0;
+               if (after && *after=='/')
+                       steps = strtol(after+1, &after, 10);
+               if (after && *after=='/')
+                       bar = strtol(after+1, &after, 10);
+               if (bar >= num_bar_images ) bar = num_bar_images - 1;
+               if (bar < 0 ) bar = 0;
 
-               if (stars_off && stars_off->w() > last_w) last_w = 
stars_off->w();
-               if (stars_on && stars_on->w() > last_w) last_w = stars_on->w();
+               if (bar_images[bar*2] && bar_images[bar*2]->w() > last_w) 
last_w = bar_images[bar*2]->w();
+               if (bar_images[bar*2+1] && bar_images[bar*2+1]->w() > last_w) 
last_w = bar_images[bar*2+1]->w();
        }
        else
        {
@@ -308,22 +323,33 @@
 
                if (*str=='%' && '0'<*str+1<'9')
                {
-                       int percent = atoi(str+1);
-                       int permil = percent * 10;
-                       permil = (permil) / 125 * 125;
-                       if (permil < 0) percent = 0;
-                       if (permil > 1000) permil = 1000;
-                       int active = stars_on->w()*permil/1000;
+                       char *after;
+                       int percent = strtol(str+1, &after, 10);
+                       int steps = 0;
+                       int bar = 0;
+                       if (after && *after=='/')
+                               steps = strtol(after+1, &after, 10);
+                       if (steps < 0 ) steps = 100;
+                       if (after && *after=='/')
+                               bar = strtol(after+1, &after, 10);
+                       if (bar >= num_bar_images ) bar = num_bar_images - 1;
+                       if (bar < 0 ) bar = 0;
+                       int n = (percent + (50/steps))* steps / 100; // convert 
to num of steps, round instead of just floor
+                       if (n < 0) n = 0;
+                       if (n > steps) n = steps;
+                       Fl_Image *bar_off = bar_images[bar*2+1];
+                       Fl_Image *bar_on = bar_images[bar*2];
+                       int active = bar_on->w()*n/steps;
 
-                       if (stars_off)
-                               stars_off->draw(x + active + 3, y, 
min(stars_off->w() - active, w1 - active - 6), h, active, 0);
-                       if (stars_on)
-                               stars_on->draw(x + 3, y, min(active, w1 - 6), 
h, 0, 0);
+                       if (bar_off)
+                               bar_off->draw(x + active + 3, y, 
min(bar_off->w() - active, w1 - active - 6), h, active, 0);
+                       if (bar_on)
+                               bar_on->draw(x + 3, y, min(active, w1 - 6), h, 
0, 0);
 
                        char tmp[32];
                        snprintf(tmp, sizeof(tmp), "%u%%", percent);
-                       //fl_draw(tmp, x + 3, y, min(stars_off->w(), w1) - 6, 
h, Fl_Align(FL_ALIGN_CENTER|FL_ALIGN_CLIP), 0, 0);
-                       //fl_draw(tmp, x + stars_on->w() + 3, y, w1 - 6, h, 
Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_CLIP), 0, 0);
+                       //fl_draw(tmp, x + 3, y, min(bar_off->w(), w1) - 6, h, 
Fl_Align(FL_ALIGN_CENTER|FL_ALIGN_CLIP), 0, 0);
+                       //fl_draw(tmp, x + bar_on->w() + 3, y, w1 - 6, h, 
Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_CLIP), 0, 0);
                }
                else
                {

Modified: software/ui/src/pkgbrowser.h
===================================================================
--- software/ui/src/pkgbrowser.h        2007-07-04 19:31:54 UTC (rev 3240)
+++ software/ui/src/pkgbrowser.h        2007-07-04 20:43:09 UTC (rev 3241)
@@ -209,8 +209,8 @@
        virtual int handle(int e);
 
 private:
-       Fl_Image *stars_on;
-       Fl_Image *stars_off;
+       const unsigned int num_bar_images;
+       Fl_Image *bar_images[2*2];
 };
 
 class PackageView : public Fl_Help_View


_______________________________________________
Pkg-games-commits mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/pkg-games-commits

Reply via email to