Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 6, 2008, 9:46:11 PM (15 years ago)
Author:
dafrick
Message:
  • Completed the message clipping method for Notifications.
  • Some other minor changes…
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem3/src/orxonox/overlays/notifications/NotificationManager.cc

    r2346 r2349  
    104104                continue;
    105105           
    106             text = text + "\n\n\n------------\n\n" + container->notification->getTitle() + "\n\n" + container->notification->getMessage();
     106            text = text + "\n\n\n------------\n\n" + clipMessage(container->notification->getTitle()) + "\n\n" + clipMessage(container->notification->getMessage());
    107107        }
    108108       
     
    110110    }
    111111   
    112     const std::string & NotificationManager::clipMessage(const std::string & message)
     112    const std::string NotificationManager::clipMessage(const std::string & str)
    113113    {
    114         std::string* clippedMessageP = new std::string();
    115         std::string clippedMessage = *clippedMessageP;
    116         clippedMessage = "";
    117         std::string tempWord = "";
     114   
     115        std::string message = str;
     116        unsigned int i = 0;
     117       
     118        unsigned int found = message.find("\\n", i);
     119        while(found != std::string::npos)
     120        {
     121            message.replace(found, 2, "\n");
     122            i = found+2;
     123            found = message.find("\\n", i);
     124        }
     125   
     126        std::string clippedMessage = "";
    118127        int wordLength = 0;
    119         signed int i = 0;
     128        i = 0;
    120129        int widthLeft = NotificationQueue::queue_s->getWidth();
    121130        while(i < message.length())
     
    123132            while(i < message.length() && message[i] != ' ' && message[i] != '\n')
    124133            {
    125                 tempWord = tempWord + message[i];
    126134                i++;
    127135                wordLength++;
     
    130138            if(wordLength <= widthLeft)
    131139            {
    132                 clippedMessage = clippedMessage + tempWord + message[i];
     140                clippedMessage = clippedMessage + message.substr(i-wordLength, wordLength);
     141                if(i < message.length())
     142                {
     143                    clippedMessage = clippedMessage + message.substr(i,1);
     144                }
    133145                widthLeft -= (wordLength+1);
     146                if(message[i] == '\n')
     147                {
     148                    widthLeft = NotificationQueue::queue_s->getWidth() - (wordLength+1);
     149                }
    134150                wordLength = 0;
    135                 tempWord = "";
    136151                i++;
    137152            }
    138153            else
    139154            {
    140                 clippedMessage = clippedMessage + '\n' + tempWord + message[i];
     155                clippedMessage.push_back('\n');
     156                clippedMessage = clippedMessage + message.substr(i-wordLength, wordLength);
     157                if(i < message.length())
     158                {
     159                    clippedMessage = clippedMessage + message.substr(i,1);
     160                }
    141161                widthLeft = NotificationQueue::queue_s->getWidth() - (wordLength+1);
    142162                i++;
    143163                wordLength = 0;
    144                 tempWord = "";
    145164            }
    146165        }
Note: See TracChangeset for help on using the changeset viewer.