r97 - trunk/src

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Thu Feb 24 06:55:38 EST 2005


Author: jonas
Date: 2005-02-24 06:55:38 -0500 (Thu, 24 Feb 2005)
New Revision: 97

Modified:
   trunk/src/font.cpp
   trunk/src/font.h
   trunk/src/gfxeng.cpp
   trunk/src/gfxeng.h
   trunk/src/menu.cpp
Log:
support for large menus, introduced a private vflag for gfxeng which represents the currently used video flags

Modified: trunk/src/font.cpp
===================================================================
--- trunk/src/font.cpp	2005-02-23 15:16:13 UTC (rev 96)
+++ trunk/src/font.cpp	2005-02-24 11:55:38 UTC (rev 97)
@@ -103,6 +103,10 @@
     write(surface, text, surface->w/2 - getTextWidth(text)/2, y);
 }
 
+void Font::writeCenter(SDL_Surface *surface, string text, int x, int y) const {
+    write(surface, text, x - getTextWidth(text)/2, y);
+}
+
 Uint32 Font::getPixel(SDL_Surface *surface, Sint32 X, Sint32 Y) {
     Uint8  *bits;
     Uint32 Bpp;

Modified: trunk/src/font.h
===================================================================
--- trunk/src/font.h	2005-02-23 15:16:13 UTC (rev 96)
+++ trunk/src/font.h	2005-02-24 11:55:38 UTC (rev 97)
@@ -40,6 +40,7 @@
         int getTextWidth(std::string text) const;
         void write(SDL_Surface* surface, std::string text, int x, int y) const;
         void writeCenter(SDL_Surface* surface, std::string text, int y) const;
+        void writeCenter(SDL_Surface* surface, std::string text, int x, int y) const;
     private:
         SFont_Font* initFont(SDL_Surface* Font);
         static Uint32 getPixel(SDL_Surface* surface, Sint32 X, Sint32 Y);

Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp	2005-02-23 15:16:13 UTC (rev 96)
+++ trunk/src/gfxeng.cpp	2005-02-24 11:55:38 UTC (rev 97)
@@ -17,7 +17,8 @@
   menubg(NULL),
   show_bar(true),
   show_fps(true),
-  fullscreen(config.full) {
+  fullscreen(config.full),
+  vflags(SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF) {
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
     rmask = 0xff000000;
     gmask = 0x00ff0000;
@@ -88,8 +89,10 @@
 
 void GraphicsEngine::resize(Uint16 width, Uint16 height) {
     if (screen) SDL_FreeSurface(screen);
-    
-    if ((screen=SDL_SetVideoMode(width,height,config.bpp,SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF|(fullscreen ? SDL_FULLSCREEN : 0))) != NULL) {
+    if (fullscreen) vflags|=SDL_FULLSCREEN;
+    else vflags&=~SDL_FULLSCREEN;
+
+    if ((screen=SDL_SetVideoMode(width,height,config.bpp,vflags)) != NULL) {
     } else {
         cout << "Couldn't set VideoMode: " << SDL_GetError() << endl;
         quitGame(-1);
@@ -291,22 +294,41 @@
 
     menu->font_title->writeCenter(screen,menu->title,0);
 
+    //size of the menu in pixels if it was just one row
+    Uint16 menu_pix_size   = (menu->getSize()-1)*DFONT+(menu->getSize()-1)*(menu->font->getHeight())+menu->font_high->getHeight();
+    //number of rows to use
+    Uint8  rows            = menu_pix_size/(screen->h-menu->font_title->getHeight()-DFONT)+1;
+    //number of entries per row
+    Uint8  row_size        = menu->getSize()/rows+1;
+    //size of one row in pixels, differs from menu_pix_size/rows and depends on the currententry
+    Uint16 row_pix_size    = (row_size-1)*DFONT+row_size*(menu->font->getHeight());
+    Uint16 currow_pix_size = (row_size-1)*DFONT+(row_size-1)*(menu->font->getHeight())+menu->font_high->getHeight();
+    //current height of the text
     Uint16 h;
+    //current row
+    Uint8  currow          = 0;
+    //true if the currententry is in the current row
+    bool   current_row     = false;
+
     for (Uint8 i=0; i< menu->getSize(); i++) {
-        if (i<=menu->currententry) {
-            h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-1)*DFONT-(menu->getSize()-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2
+        if (i>=row_size*(currow+1)) currow++;
+        if (menu->currententry>=row_size*currow && menu->currententry<row_size*(currow+1)) current_row=true;
+        else current_row=false;
+        
+        if (i<=menu->currententry || (!current_row)) {
+            h=(screen->h+menu->font_title->getHeight()-(current_row ? currow_pix_size : row_pix_size))/2
               -DFONT
-              +i*DFONT
-              +i*(menu->font->getHeight());
+              +(i-row_size*currow)*DFONT
+              +(i-row_size*currow)*(menu->font->getHeight());
         } else {
-            h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-1)*DFONT-(menu->getSize()-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2
+            h=(screen->h+menu->font_title->getHeight()-currow_pix_size)/2
               -DFONT
-              +i*DFONT
-              +(i-1)*(menu->font->getHeight())
+              +(i-row_size*currow)*DFONT
+              +(i-1-row_size*currow)*(menu->font->getHeight())
               +(menu->font_high->getHeight());
         }
-        if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],h);
-        else menu->font->writeCenter(screen,menu->entries[i],h);
+        if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],currow*(screen->w)/rows+(screen->w)/rows/2,h);
+        else menu->font->writeCenter(screen,menu->entries[i],currow*(screen->w)/rows+(screen->w)/rows/2,h);
     }
 }
 

Modified: trunk/src/gfxeng.h
===================================================================
--- trunk/src/gfxeng.h	2005-02-23 15:16:13 UTC (rev 96)
+++ trunk/src/gfxeng.h	2005-02-24 11:55:38 UTC (rev 97)
@@ -51,6 +51,8 @@
         bool fullscreen;
         //update state
         Uint8 updatetype;
+        //video flags
+        Uint32 vflags;
     protected:
         /// Draw the background and all objects in the pool. This is a very time
         /// consuming function...

Modified: trunk/src/menu.cpp
===================================================================
--- trunk/src/menu.cpp	2005-02-23 15:16:13 UTC (rev 96)
+++ trunk/src/menu.cpp	2005-02-24 11:55:38 UTC (rev 97)
@@ -187,22 +187,21 @@
 
 GraphicConfigMenu::GraphicConfigMenu(): Menu() {
     title="-== GRAPHIC SETTINGS ==-";
-    entries.resize(4);
     update();
 }
 void GraphicConfigMenu::act() {
     switch (currententry) {
-    case 1: {
+    case 0: {
         gfxeng->toggleFullScreen();
         gfxeng->update(UPDATE_ALL);
         break;
     }
-    case 2: {
+    case 1: {
         gfxeng->toggleFPS();
         gfxeng->update(UPDATE_MENU);
         break;
     }
-    case 3: {
+    case 2: {
         gfxeng->togglePlayerBar();
         gfxeng->update(UPDATE_ALL);
         break;
@@ -214,8 +213,22 @@
     update();
 }
 void GraphicConfigMenu::update() {
-    entries[0]="Resolution:  " + itos(gfxeng->screen->w) + " x " + itos(gfxeng->screen->h) + "  (" + itos(config.bpp) + " bpp)";
-    entries[1]="Fullscreen:  " + string((gfxeng->fullscreen) ? "ON" : "OFF");
-    entries[2]="Show FPS: "+string((gfxeng->show_fps) ? "ON" : "OFF");
-    entries[3]="Show Player Bar: "+string((gfxeng->show_bar) ? "ON" : "OFF");
+    entries.resize(4);
+    char driver_name[10];
+    SDL_VideoDriverName(driver_name, 10);
+
+    entries[0]="Fullscreen:  " + string((gfxeng->fullscreen) ? "ON" : "OFF");
+    entries[1]="Show FPS: "+string((gfxeng->show_fps) ? "ON" : "OFF");
+    entries[2]="Show Player Bar: "+string((gfxeng->show_bar) ? "ON" : "OFF");
+    entries[3]="Video settings:  [" + string(driver_name) + "]   " + itos(gfxeng->screen->w) + " x " + itos(gfxeng->screen->h) + "  (" + itos(config.bpp) + " bpp)";
+/*
+    entries.push_back("");
+
+    SDL_Rect** modes=SDL_ListModes(NULL, gfxeng->vflags);
+    if(modes == (SDL_Rect **)0)  entries.push_back("No modes available");
+    else if(modes == (SDL_Rect **)-1) entries.push_back("All resolutions available");
+    else {
+        for(Uint16 i=0;modes[i];++i) entries.push_back(itos(modes[i]->w) + " x " + itos(modes[i]->h));
+    }
+*/
 }




More information about the lostpenguins-commits mailing list