Commit e99877d4 authored by daFischer's avatar daFischer

Changed the timeline to be more efficient. Also pushed the Controls down and fixated their position

parent 5a9cd62c
......@@ -26,11 +26,7 @@ Controls::Controls(Video* video, AudioInterface* audio) {
width=prefs.framebufferWidth;
screenHeight=prefs.framebufferHeight;
y=screenHeight-height;
visible=true;
//In the beginning, the whole screen should be redrawn
redefineRect(&videoUpdate,0,0,width,screenHeight);
y=screenHeight;
timeLineClicked=false;
volumeClicked=false;
......@@ -102,7 +98,6 @@ void Controls::registerClick(Uint16 mx, Uint16 my){
void Controls::registerMouseUp(){
if(timeLineClicked)
{
redefineRect(&videoUpdate,0,0,width,screenHeight-height);
skipTo(duration/width*mouseX);
}
timeLineClicked=false;
......@@ -114,7 +109,7 @@ void Controls::registerMouseUp(){
* Will be called whenever the mouse has moved
*/
void Controls::registerMovement(Uint16 mx, Uint16 my) {
visible=(my>=screenHeight-height)||timeLineClicked||volumeClicked||speedClicked;
//visible=(my>=screenHeight-height)||timeLineClicked||volumeClicked||speedClicked;
mouseX=mx;
mouseY=my;
if(volumeClicked)
......@@ -142,7 +137,7 @@ extern "C" bool getOnPlayButton(){
* When the mouse is not hovering over Controls' position, Controls moves out of the screen
*/
void Controls::update(){
if(visible)
/*if(visible)
{
if(y>screenHeight-height)
y-=4;
......@@ -157,7 +152,7 @@ void Controls::update(){
redefineRect(&videoUpdate,0,y,width,4);
y+=4;
}
}
}*/
}
void Controls::togglePlay(){
......@@ -172,20 +167,15 @@ void Controls::toggleFullscreen(){
}
void Controls::draw(SDL_Surface *screen, bool hasDrawn){
if(y>=screenHeight)
{
return;
}
void Controls::draw(SDL_Surface *screen){
SDL_Rect srcRect={0,0,48,32};
//main body
SDL_Rect rect = {0, y+timeLineHeight, width, height-timeLineHeight};
if(SDL_FillRect(screen, &rect, emColor(0x000000))==-1)
printf("fill rect error\n");
SDL_FillRect(screen, &rect, emColor(0x000000));
//play/pause
SDL_Rect srcRect={0,0,48,32};
redefineRect(&rect, 0, y+timeLineHeight, 48, height-timeLineHeight);
if(surfPlay!=NULL)
{
......@@ -228,6 +218,9 @@ void Controls::draw(SDL_Surface *screen, bool hasDrawn){
SDL_BlitSurface(surfFullscreen,&srcRect,screen,&rect);
}
if(duration==0)
duration=audio->getDuration();
//timeLine background
redefineRect(&rect, 0, y, width, timeLineHeight);
SDL_FillRect(screen, &rect, emColor(0x333333));
......
......@@ -34,9 +34,8 @@ public:
void registerClick(Uint16 mx, Uint16 my);
void registerMouseUp();
void registerMovement(Uint16 mx, Uint16 my);
void draw(SDL_Surface *screen, bool hasDrawn);
void draw(SDL_Surface *screen);
SDL_Rect videoUpdate;
int progress; //timestamp of next to be filled IndexEntry, -1 if all have been filled
private:
......@@ -53,7 +52,6 @@ private:
Video* video;
AudioInterface* audio;
bool visible;
int y;
int width, height, screenHeight;
int timeLineHeight;
......
......@@ -9,13 +9,15 @@
#include "Inflater.h"
Index::Index(Inflater* in, int numBytes) {
waypoint = NULL;
this->numBytes=numBytes;
in->readShort(&entryNumber);
this->numBytes -= 2;
}
Index::Index(Message** messages, int numMessages) {
waypoint = NULL;
if (VERBOSE)
printf("\ncompute index table:\n");
......@@ -114,6 +116,7 @@ Index::Index(Message** messages, int numMessages) {
if (VERBOSE)
printf("\n\nGenerated index with %d entries.\n\n", index.size());
it = index.begin();
currentMessage=0;
}
SDL_Surface* Index::readThumbnail(Inflater* in, int* numBytes) {
......@@ -164,6 +167,7 @@ bool Index::readIndexEntry(Inflater* in) {
in->skipBytes(numBytes);
}
it = index.begin();
currentMessage=0;
//TODO: what if too many bytes have been read?
return false;
......@@ -174,13 +178,43 @@ bool Index::readIndexEntry(Inflater* in) {
void Index::loadUntil(IndexEntry* entry, SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs) {
if(VERBOSE)
printf("Loading IndexEntries from %d s until %d s\n",(*it)->timestamp/1000,entry->timestamp/1000);
for(; it!=index.end() && (*it)->timestamp<=entry->timestamp;)//it is incremented in fill'Surface
fillSurface(screen,messages,numMessages,prefs);
for(; it!=index.end() && (*it)->timestamp<=entry->timestamp;)//'it' is incremented in fillSurface
fillSurface(screen,messages,numMessages,1000000,prefs);
}
bool Index::fillSurface(SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs) {
if (it == index.end())
bool Index::fillSurface(SDL_Surface* screen, Message** messages, int numMessages, int areaLeft, ProtocolPreferences* prefs) {
if (it == index.end() || currentMessage >= numMessages)
{
progress=-1;
return false;
}
while(areaLeft > 0 && currentMessage < numMessages && it != index.end())
{
if (messages[currentMessage]->timestamp > (*it)->timestamp)
{
progress=(*it)->timestamp;
(*it)->setWaypoint(waypoint);
it++;
if (it == index.end())
{
progress=-1;
return false;
}
waypoint=NULL;
}
if(waypoint==NULL)
waypoint = SDL_CreateRGBSurface(SDL_ANYFORMAT, screen->w, screen->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
if (messages[currentMessage]->type == FRAMEBUFFER)
{
messages[currentMessage]->paint(waypoint, prefs);
areaLeft-=messages[currentMessage]->getArea();
}
currentMessage++;
}
return true;
/*if (it == index.end())
return false;
SDL_Surface* waypoint = SDL_CreateRGBSurface(SDL_ANYFORMAT, screen->w, screen->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
......@@ -207,7 +241,7 @@ bool Index::fillSurface(SDL_Surface* screen, Message** messages, int numMessages
progress=-1;
else
progress=(*it)->timestamp;
return true;
return true;*/
}
IndexEntry* Index::lastBefore(int timestamp) {
......
......@@ -26,7 +26,7 @@ public:
Index(Message** messages, int numMessages);
virtual ~Index();
IndexEntry* lastBefore(int timestamp);
bool fillSurface(SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs);
bool fillSurface(SDL_Surface* screen, Message** messages, int numMessages, int areaLeft, ProtocolPreferences* prefs);
bool readIndexEntry(Inflater* in);
void loadUntil(IndexEntry* entry, SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs);
......@@ -38,6 +38,7 @@ private:
list<IndexEntry*> index;
std::list<IndexEntry*>::iterator it;
int currentMessage;
SDL_Surface* waypoint;
short entryNumber;
int numBytes;
......
......@@ -61,7 +61,7 @@ void CursorMessage::paint(SDL_Surface* screen, ProtocolPreferences* prefs) {
SDL_LockSurface(cursor);
memset(cursor->pixels,0x0,cursor->w*cursor->h*cursor->format->BytesPerPixel);
SDL_UnlockSurface(cursor);
cursor
handleCursorShapeUpdate();
//printf("CursorMessage last\n");
}
......
......@@ -120,13 +120,13 @@ bool Video::loadAsync() {
if(VERBOSE)
printf("%d x %d, color depth: %d\n",prefs.framebufferWidth, prefs.framebufferHeight, prefs.bytesPerPixel);
screen = SDL_SetVideoMode(prefs.framebufferWidth, prefs.framebufferHeight, prefs.bitsPerPixel, SDL_ANYFORMAT|SDL_DOUBLEBUF);
screen = SDL_SetVideoMode(prefs.framebufferWidth, prefs.framebufferHeight+48, prefs.bitsPerPixel, SDL_ANYFORMAT|SDL_DOUBLEBUF);
//prefs.format->Amask=0xffffffff-screen->format->Rmask-screen->format->Gmask-screen->format->Bmask;
rawScreen=SDL_CreateRGBSurface(screen->flags,screen->w,screen->h,screen->format->BitsPerPixel,screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,0xffffffff-screen->format->Rmask-screen->format->Gmask-screen->format->Bmask);
rawScreen=SDL_CreateRGBSurface(screen->flags,screen->w,prefs.framebufferHeight,screen->format->BitsPerPixel,screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,0xffffffff-screen->format->Rmask-screen->format->Gmask-screen->format->Bmask);
prefs.format=rawScreen->format;
if(containsAnnotations)
{
annScreen=SDL_CreateRGBSurface(screen->flags,screen->w,screen->h,screen->format->BitsPerPixel,screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,0xffffffff-screen->format->Rmask-screen->format->Gmask-screen->format->Bmask);
annScreen=SDL_CreateRGBSurface(screen->flags,screen->w,prefs.framebufferHeight,screen->format->BitsPerPixel,screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,0xffffffff-screen->format->Rmask-screen->format->Gmask-screen->format->Bmask);
}
if (screen == NULL)
......@@ -173,14 +173,7 @@ void Video::update(int time, Controls* controls)
if(time<=2000 && (currentMessage>0 && messages[currentMessage-1]->timestamp>time+5000))
currentMessage=0;
if(lastTime<0)
lastTime=SDL_GetTicks();
if(SDL_GetTicks()-lastTime>=500) //only fill IndexEntries every second to avoid slowness
{
index->fillSurface(screen,messages,numMessages,&prefs);
controls->progress=index->progress;
lastTime=SDL_GetTicks();
}
int updatedArea=0;
while(currentMessage<numMessages)
{
......@@ -194,11 +187,12 @@ void Video::update(int time, Controls* controls)
case FRAMEBUFFER:
blitRaw=true;
messages[currentMessage]->paint(rawScreen, &prefs);
updatedArea+=messages[currentMessage]->getArea();
break;
case CURSOR:
SDL_Rect cm=CursorMessage::getMask();
cm.x=max(min((int)cm.x,(int)screen->w-cm.w),0);
cm.y=max(min((int)cm.y,(int)screen->h-cm.h),0);
cm.y=max(min((int)cm.y,(int)prefs.framebufferHeight-cm.h),0);
if(CursorMessage::showCursor){
// repair place on screen, where the cursor was
SDL_BlitSurface(rawScreen,&cm,screen,&cm);
......@@ -218,14 +212,17 @@ void Video::update(int time, Controls* controls)
if(Annotation::mustRedraw)
Annotation::redraw(annScreen,&prefs);
}
redrawScreen(controls, blitAnn||blitRaw);
redrawScreen(controls, blitAnn || blitRaw);
index->fillSurface(rawScreen,messages,numMessages,screen->w*prefs.framebufferHeight-updatedArea,&prefs);
controls->progress=index->progress;
}
void Video::redrawScreen(Controls* controls, bool fully) {
if(fully)
{
//redraw screen completely
SDL_Rect rect = {0,0,screen->w,controls->videoUpdate.y+controls->videoUpdate.h};
SDL_Rect rect = {0,0,screen->w,prefs.framebufferHeight};
if(WhiteboardMessage::number>0)
SDL_FillRect(screen,&rect,SDL_MapRGBA(ProtocolPreferences::format,0xff,0xff,0xff,0xff));
else
......@@ -254,7 +251,7 @@ void Video::redrawScreen(Controls* controls, bool fully) {
}
lastThumbnail.w=0;
}
if(controls->videoUpdate.h!=0)
/*if(controls->videoUpdate.h!=0)
{
//only redraw the part that controls releases when moving downwards
if(WhiteboardMessage::number>0)
......@@ -267,10 +264,10 @@ void Video::redrawScreen(Controls* controls, bool fully) {
SDL_Rect cm=CursorMessage::getMask();
SDL_BlitSurface(CursorMessage::cursor,NULL,screen,&cm);
}
}
}*/
}
//always redraw controls
controls->draw(screen, fully);
controls->draw(screen);
SDL_Flip(screen);
}
......
This diff is collapsed.
......@@ -7,8 +7,13 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Constants.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/IndexEntry.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Index.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Controls.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Video.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/IndexEntry.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/CursorMessage.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Index.cpp</file>
</group>
</open-files>
</project-private>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment