/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "tilebuffer.hxx" #if !GLIB_CHECK_VERSION(2,40,0) #define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__) #endif /* ------------------ Utility functions ------------------ */ float pixelToTwip(float fInput, float zoom) { return (fInput / DPI / zoom) * 1440.0f; } float twipToPixel(float fInput, float zoom) { return fInput / 1440.0f * DPI * zoom; } /* ---------------------------- Tile class member functions ---------------------------- */ GdkPixbuf* Tile::getBuffer() { return m_pBuffer; } void Tile::setPixbuf(GdkPixbuf *buffer) { m_pBuffer = buffer; } /* ---------------------------------- TileBuffer class member functions ---------------------------------- */ void TileBuffer::resetAllTiles() { std::map::iterator it = m_mTiles.begin(); for (; it != m_mTiles.end(); ++it) { it->second.valid = false; } } void TileBuffer::setInvalid(int x, int y, float fZoom, GTask* task, GThreadPool* lokThreadPool) { int index = x * m_nWidth + y; g_info("Setting tile invalid (%d, %d)", x, y); if (m_mTiles.find(index) != m_mTiles.end()) { m_mTiles[index].valid = false; LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE); pLOEvent->m_nPaintTileX = x; pLOEvent->m_nPaintTileY = y; pLOEvent->m_fPaintTileZoom = fZoom; g_task_set_task_data(task, pLOEvent, g_free); g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL); } } Tile& TileBuffer::getTile(int x, int y, float fZoom, GTask* task, GThreadPool* lokThreadPool) { int index = x * m_nWidth + y; if (m_mTiles.find(index) != m_mTiles.end() && !m_mTiles[index].valid) { LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE); pLOEvent->m_nPaintTileX = x; pLOEvent->m_nPaintTileY = y; pLOEvent->m_fPaintTileZoom = fZoom; g_task_set_task_data(task, pLOEvent, g_free); g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL); return m_mTiles[index]; } else if(m_mTiles.find(index) == m_mTiles.end()) { LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE); pLOEvent->m_nPaintTileX = x; pLOEvent->m_nPaintTileY = y; pLOEvent->m_fPaintTileZoom = fZoom; g_task_set_task_data(task, pLOEvent, g_free); g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL); return m_DummyTile; } return m_mTiles[index]; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */