[Libreoffice-commits] core.git: Branch 'feature/gsoc-tiled-rendering' - libreofficekit/source

Pranav Kant pranavk at gnome.org
Wed Jun 3 15:03:16 PDT 2015


 libreofficekit/source/gtk/lokdocview.cxx |   50 ++++++++++++++++++++++++++++---
 libreofficekit/source/gtk/tilebuffer.cxx |   15 ++++++++-
 libreofficekit/source/gtk/tilebuffer.hxx |    1 
 3 files changed, 61 insertions(+), 5 deletions(-)

New commits:
commit 857440900b3169d19a560d24b08122405e2398db
Author: Pranav Kant <pranavk at gnome.org>
Date:   Thu Jun 4 03:32:18 2015 +0530

    gtktiledviewer: add support for editing
    
    Change-Id: I8637d99e6fa59129af207e667bcdf03dc212efeb

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index f476a23..2a3a395 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -821,7 +821,7 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
 
             if (bPaint)
             {
-                g_info("gettile: (%d %d)", nRow, nColumn);
+                //                g_info("gettile: (%d %d)", nRow, nColumn);
 
                 Tile& currentTile = m_pTileBuffer->tile_buffer_get_tile(nRow, nColumn);
                 GdkPixbuf* pPixBuf = currentTile.tile_get_buffer();
@@ -934,17 +934,50 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
         if (pCallback->m_aPayload != "EMPTY")
         {
             GdkRectangle aRectangle = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
-            renderDocument(&aRectangle);
+            GdkRectangle aRectanglePixels;
+            aRectanglePixels.x = twipToPixel(aRectangle.x);
+            aRectanglePixels.y = twipToPixel(aRectangle.y);
+            aRectanglePixels.width = twipToPixel(aRectangle.width);
+            aRectanglePixels.height = twipToPixel(aRectangle.height);
+            int rowStart = aRectanglePixels.x / nTileSizePixels;
+            int colStart = aRectanglePixels.y / nTileSizePixels;
+            int rowEnd = (aRectanglePixels.x + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
+            int colEnd = (aRectanglePixels.y + aRectanglePixels.width + nTileSizePixels) / nTileSizePixels;
+            int i,j;
+            for (i = rowStart; i < rowEnd; i++) {
+                for (j = colStart; j < colEnd; j++) {
+                    m_pTileBuffer->tile_buffer_set_invalid(i, j);
+                }
+            }
+            renderDocument(0);
         }
         else
+        {
+            m_pTileBuffer->tile_buffer_reset_all_tiles();
             renderDocument(0);
+        }
     }
     break;
     case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
     {
         m_aVisibleCursor = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
         m_bCursorOverlayVisible = true;
-        gtk_widget_queue_draw(GTK_WIDGET(m_pDrawingArea));
+        GdkRectangle aRectanglePixels;
+        aRectanglePixels.x = twipToPixel(m_aVisibleCursor.x);
+        aRectanglePixels.y = twipToPixel(m_aVisibleCursor.y);
+        aRectanglePixels.width = twipToPixel(m_aVisibleCursor.width);
+        aRectanglePixels.height = twipToPixel(m_aVisibleCursor.height);
+        int rowStart = aRectanglePixels.x / nTileSizePixels;
+        int colStart = aRectanglePixels.y / nTileSizePixels;
+        int rowEnd = (aRectanglePixels.x + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
+        int colEnd = (aRectanglePixels.y + aRectanglePixels.width + nTileSizePixels) / nTileSizePixels;
+        int i,j;
+        for (i = rowStart; i < rowEnd; i++) {
+            for (j = colStart; j < colEnd; j++) {
+                m_pTileBuffer->tile_buffer_set_invalid(i, j);
+            }
+        }
+        renderDocument(0);
     }
     break;
     case LOK_CALLBACK_TEXT_SELECTION:
@@ -961,7 +994,6 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
         }
         else
             memset(&m_aHandleMiddleRect, 0, sizeof(m_aHandleMiddleRect));
-        gtk_widget_queue_draw(GTK_WIDGET(m_pDrawingArea));
     }
     break;
     case LOK_CALLBACK_TEXT_SELECTION_START:
@@ -1144,6 +1176,16 @@ static void lok_docview_init( GTypeInstance* pInstance, gpointer )
     g_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
                      "expose-event",
                      GTK_SIGNAL_FUNC(LOKDocView_Impl::on_exposed), pDocView);
+    g_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
+                     "expose-event",
+                     GTK_SIGNAL_FUNC(LOKDocView_Impl::renderOverlay), pDocView);
+    gtk_widget_add_events(pDocView->m_pImpl->m_pDrawingArea,
+                          GDK_BUTTON_PRESS_MASK
+                          | GDK_BUTTON_RELEASE_MASK
+                          | GDK_BUTTON_MOTION_MASK);
+    g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea), "button-press-event", G_CALLBACK(LOKDocView_Impl::signalButton), pDocView);
+    g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea), "button-release-event", G_CALLBACK(LOKDocView_Impl::signalButton), pDocView);
+    g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea), "motion-notify-event", G_CALLBACK(LOKDocView_Impl::signalMotion), pDocView);
 
     gtk_signal_connect(GTK_OBJECT(pDocView), "destroy", GTK_SIGNAL_FUNC(LOKDocView_Impl::destroy), 0);
 }
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
index e1b5b32..f932e4f 100644
--- a/libreofficekit/source/gtk/tilebuffer.cxx
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -53,11 +53,24 @@ void TileBuffer::tile_buffer_reset_all_tiles()
   m_mTiles.clear();
 }
 
+void TileBuffer::tile_buffer_set_invalid(int x, int y)
+{
+  int index = x * m_nWidth + y;
+  g_info("setting invalid : %d %d",x, y);
+  if (m_mTiles.find(index) != m_mTiles.end())
+      {
+          m_mTiles[index].valid = 0;
+          m_mTiles[index].tile_release();
+          m_mTiles.erase(index);
+      }
+}
+
 Tile& TileBuffer::tile_buffer_get_tile(int x, int y)
 {
   int index = x * m_nWidth + y;
-  if(m_mTiles.find(index) == m_mTiles.end())
+  if(m_mTiles.find(index) == m_mTiles.end() || !m_mTiles[index].valid)
     {
+
       GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize);
       if (!pPixBuf){
         g_info ("error allocating memory to pixbuf");
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index 0bc2d38..a153247 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -63,6 +63,7 @@ public:
   Tile& tile_buffer_get_tile(int x, int y);
   void tile_buffer_update();
   void tile_buffer_reset_all_tiles();
+  void tile_buffer_set_invalid(int x, int y);
 private:
   LibreOfficeKitDocument *m_pLOKDocument;
   int m_nTileSize;


More information about the Libreoffice-commits mailing list