]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins/controls/text.cpp
* x11/x11_timer.* : classes to implement platform-independant timers
[vlc] / modules / gui / skins / controls / text.cpp
index 07dc3ac8012c1863f072f71fa4856636b983118c..676975e72c1fc52debaeb4b2d80e4ebb192abc28 100644 (file)
@@ -2,10 +2,11 @@
  * text.cpp: Text control
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: text.cpp,v 1.1 2003/03/18 02:21:47 ipkiss Exp $
+ * $Id: text.cpp,v 1.10 2003/06/05 22:16:15 asmax Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
+ *          Cyril Deguet     <asmax@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <vlc/intf.h>
 
 //--- SKIN ------------------------------------------------------------------
-#include "os_api.h"
-#include "bitmap.h"
-#include "banks.h"
-#include "graphics.h"
-#include "os_graphics.h"
-#include "font.h"
+#include "../os_api.h"
+#include "../src/bitmap.h"
+#include "../src/banks.h"
+#include "../src/graphics.h"
+#include "../os_graphics.h"
+#include "../src/font.h"
+#include "../os_font.h"
 #include "generic.h"
 #include "text.h"
-#include "event.h"
-#include "theme.h"
-#include "window.h"
-#include "os_window.h"
-#include "skin_common.h"
+#include "../src/event.h"
+#include "../src/theme.h"
+#include "../src/window.h"
+#include "../os_window.h"
+#include "../src/skin_common.h"
+
+#ifdef X11_SKINS
+#include "../x11/x11_timer.h"
+extern intf_thread_t *g_pIntf;
+#endif
 
 
 
 // Scrolling : one for each OS
 //---------------------------------------------------------------------------
 
+    #if defined( WIN32 )
     //-----------------------------------------------------------------------
     // Win32 methods
     //-----------------------------------------------------------------------
-    #if defined( WIN32 )
     void CALLBACK ScrollingTextTimer( HWND hwnd, UINT uMsg, UINT_PTR idEvent,
         DWORD dwTime )
     {
     }
     //-----------------------------------------------------------------------
 
+    #elif defined GTK2_SKINS
+
+    //-----------------------------------------------------------------------
+    // Gtk2 methods
+    //-----------------------------------------------------------------------
+    gboolean ScrollingTextTimer( gpointer data )
+    {
+        if( (ControlText *)data != NULL )
+        {
+            if( !( (ControlText *)data )->IsScrolling() )
+                return false;
+
+            if( !( (ControlText *)data )->GetSelected() )
+               ( (ControlText *)data )->DoScroll();
+
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+    //-----------------------------------------------------------------------
+    void ControlText::StartScrolling()
+    {
+        g_timeout_add( 100, (GSourceFunc)ScrollingTextTimer, (gpointer)this );
+    }
+    //-----------------------------------------------------------------------
+    void ControlText::StopScrolling()
+    {
+    }
+    //-----------------------------------------------------------------------
+
+    #elif defined X11_SKINS
+
+    //-----------------------------------------------------------------------
+    // X11 methods
+    //----------------------------------------------------------------------- 
+    void ScrollingTextTimer( void *data )
+    { 
+        if( (ControlText *)data != NULL
+            && !( (ControlText *)data )->GetSelected() )
+        {
+            ( (ControlText *)data )->DoScroll();
+        }
+    }
+
+    //-----------------------------------------------------------------------
+    void ControlText::StartScrolling()
+    {
+        X11Timer *timer = new X11Timer( g_pIntf, 100000, ScrollingTextTimer, 
+                                        (void*)this );
+        X11TimerManager *timerManager = X11TimerManager::Instance( g_pIntf );
+        timerManager->addTimer( timer );
+    }
+    //-----------------------------------------------------------------------
+    void ControlText::StopScrolling()
+    {
+    }
+    //-----------------------------------------------------------------------
 
     #endif
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 ControlText::ControlText( string id, bool visible, int x, int y, string text,
     string font, int align, int width, string display, bool scroll,
-    int scrollspace, string help, Window *Parent )
+    int scrollspace, string help, SkinWindow *Parent )
     : GenericControl( id, visible, help, Parent )
 {
     InitLeft         = x;
@@ -155,8 +222,8 @@ void ControlText::SetScrolling()
     }
     else if( Scroll && TextWidth <= Width )
     {
-        StopScrolling();
         Scroll = false;
+        StopScrolling();
     }
 }
 //---------------------------------------------------------------------------
@@ -177,12 +244,12 @@ void ControlText::SetSize()
     Height = h;
 
     // Set position wether alignment
-    if( Align == DT_CENTER )
+    if( Align == VLC_FONT_ALIGN_CENTER )
     {
         Left     = InitLeft - Width / 2;
         TextLeft = InitLeft - TextWidth / 2;
     }
-    else if( Align == DT_RIGHT )
+    else if( Align == VLC_FONT_ALIGN_RIGHT )
     {
         Left     = InitLeft - Width;
         TextLeft = InitLeft - TextWidth;
@@ -197,7 +264,7 @@ void ControlText::SetSize()
     if( TextClipRgn != NULL )
         delete TextClipRgn;
 
-    TextClipRgn = (Region *)new OSRegion( Left, Top, Width, Height );
+    TextClipRgn = (SkinRegion *)new OSRegion( Left, Top, Width, Height );
 
 }
 //---------------------------------------------------------------------------
@@ -266,7 +333,7 @@ void ControlText::Draw( int x, int y, int w, int h, Graphics *dest )
     }
 
     // Reset clipping region to old region
-    Region *destClipRgn = (Region *)new OSRegion( 0, 0, w, h );
+    SkinRegion *destClipRgn = (SkinRegion *)new OSRegion( 0, 0, w, h );
     dest->SetClipRegion( destClipRgn );
     delete destClipRgn;
     TextClipRgn->Move( x, y );