r3235 - software/ui/src

Miriam Ruiz baby-guest at alioth.debian.org
Wed Jul 4 14:50:28 UTC 2007


Author: baby-guest
Date: 2007-07-04 14:50:27 +0000 (Wed, 04 Jul 2007)
New Revision: 3235

Modified:
   software/ui/src/games.cpp
   software/ui/src/pkgbrowser.cpp
   software/ui/src/pkgbrowser.h
Log:
Updated visualization of popcon stars



Modified: software/ui/src/games.cpp
===================================================================
--- software/ui/src/games.cpp	2007-07-04 14:21:43 UTC (rev 3234)
+++ software/ui/src/games.cpp	2007-07-04 14:50:27 UTC (rev 3235)
@@ -207,7 +207,8 @@
 		{
 			desc += "\t";
 			char stars[16];
-			snprintf(stars, sizeof(stars), "%%%d ", (int)rintf(i->popcon * 100 / engine.popconLocalMax()));
+			snprintf(stars, sizeof(stars), "%%%d ",
+				12 * (int)rintf(log(i->popcon) * 8 / 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 14:21:43 UTC (rev 3234)
+++ software/ui/src/pkgbrowser.cpp	2007-07-04 14:50:27 UTC (rev 3235)
@@ -6,7 +6,8 @@
  * URL: http://seriss.com/people/erco/fltk/
  * GNU GPL License (version 2 or, at your option, any later version)
  *
- * PackageBrowser::item_draw uses code from FLTK 1.1 Fl_Browser.cxx
+ * PackageBrowser::item_draw and PackageBrowser::item_width
+ * use code from FLTK 1.1 Fl_Browser.cxx
  * Browser widget for the Fast Light Tool Kit (FLTK).
  * Copyright 1998-2005 by Bill Spitzak and others.
  * URL: http://www.fltk.org/
@@ -172,6 +173,67 @@
 	}
 }
 
+int PackageBrowser::item_width(void *p) const
+{
+	int n = VersatileBrowser::lineno(p);
+	char *text = strdup(VersatileBrowser::text(n));
+	char *str = text;
+	const int* i = column_widths();
+	int ww = 0;
+
+	while (*i)
+	{ // add up all tab-seperated fields
+		char* e;
+		e = strchr(str, column_char());
+		if (!e) break; // last one occupied by text
+		str = e+1;
+		ww += *i++;
+	}
+
+	// OK, we gotta parse the string and find the string width...
+	int tsize = textsize();
+	Fl_Font font = textfont();
+	int done = 0;
+
+	while (*str == format_char() && str[1] && str[1] != format_char())
+	{
+		str ++;
+		switch (*str++)
+		{
+			case 'l': case 'L': tsize = 24; break;
+			case 'm': case 'M': tsize = 18; break;
+			case 's': tsize = 11; break;
+			case 'b': font = (Fl_Font)(font|FL_BOLD); break;
+			case 'i': font = (Fl_Font)(font|FL_ITALIC); break;
+			case 'f': case 't': font = FL_COURIER; break;
+			case 'B':
+			case 'C': strtol(str, &str, 10); break;// skip a color number
+			case 'F': font = (Fl_Font)strtol(str, &str, 10); break;
+			case 'S': tsize = strtol(str, &str, 10); break;
+			case '.': done = 1; break;
+			case '@': str--; done = 1;
+		}
+		if (done) break;
+	}
+
+	int last_w = 0;
+	if (*str=='%' && '0'<*str+1<'9')
+	{
+
+		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();
+	}
+	else
+	{
+		if (*str == format_char() && str[1]) str ++;
+		fl_font(font, tsize);
+		last_w = int(fl_width(str));
+	}
+
+	free (text);
+	return ww + last_w + 6;
+}
+
 void PackageBrowser::item_draw(void *p, int x, int y, int w, int h) const
 {
 	//printf("PackageBrowser::item_draw(p=0x%lX, x=%d, y=%d, w=%d, h=%d)\n", (unsigned long)p, x, y, w, h);

Modified: software/ui/src/pkgbrowser.h
===================================================================
--- software/ui/src/pkgbrowser.h	2007-07-04 14:21:43 UTC (rev 3234)
+++ software/ui/src/pkgbrowser.h	2007-07-04 14:50:27 UTC (rev 3235)
@@ -204,6 +204,7 @@
 
 protected:
 	virtual void item_select(void *p, int s=1);
+	virtual int item_width(void *p) const;
 	virtual void item_draw(void *p, int x, int y, int w, int h)  const;
 	virtual int handle(int e);
 




More information about the Pkg-games-commits mailing list