📄 cocoa_image.mm
字号:
// This file is part of Ambulant Player, www.ambulantplayer.org.//// Copyright (C) 2003-2007 Stichting CWI, // Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.//// Ambulant Player is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published by// the Free Software Foundation; either version 2.1 of the License, or// (at your option) any later version.//// Ambulant Player is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public License// along with Ambulant Player; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA/* * @$Id: cocoa_image.mm,v 1.32 2007/02/12 14:14:49 jackjansen Exp $ */#include "ambulant/gui/cocoa/cocoa_gui.h"#include "ambulant/gui/cocoa/cocoa_image.h"//#include "ambulant/gui/cocoa/cocoa_transition.h"//#include "ambulant/common/region_info.h"//#include "ambulant/common/smil_alignment.h"//#define AM_DBG#ifndef AM_DBG#define AM_DBG if(0)#endifnamespace ambulant {using namespace lib;namespace gui {namespace cocoa {cocoa_image_renderer::~cocoa_image_renderer(){ m_lock.enter(); AM_DBG logger::get_logger()->debug("~cocoa_image_renderer(0x%x)", (void *)this); if (m_image) [m_image release]; m_image = NULL; m_lock.leave();} voidcocoa_image_renderer::redraw_body(const rect &dirty, gui_window *window){ m_lock.enter(); const rect &r = m_dest->get_rect(); AM_DBG logger::get_logger()->debug("cocoa_image_renderer.redraw(0x%x, local_ltrb=(%d,%d,%d,%d)", (void *)this, r.left(), r.top(), r.right(), r.bottom()); if (m_data && !m_image) { AM_DBG logger::get_logger()->debug("cocoa_image_renderer.redraw: creating image"); m_nsdata = [NSData dataWithBytesNoCopy: m_data length: m_data_size freeWhenDone: NO]; m_image = [[NSImage alloc] initWithData: m_nsdata]; if (!m_image) logger::get_logger()->error("%s: could not create NSImage", m_node->get_url("src").get_url().c_str()); [m_image setFlipped: true]; // XXXX Could free data and m_data again here... } cocoa_window *cwindow = (cocoa_window *)window; AmbulantView *view = (AmbulantView *)cwindow->view(); if (!m_image) { m_lock.leave(); return; } // Now find both source and destination area for the bitblit. NSSize cocoa_srcsize = [m_image size]; size srcsize = size((int)cocoa_srcsize.width, (int)cocoa_srcsize.height); rect srcrect; NSRect cocoa_srcrect; rect dstrect; NSRect cocoa_dstrect; // While rendering background images only, check for tiling. This code is // convoluted, it knows that the node and the region we're painting to are // really the same node. if (m_node->get_attribute("backgroundImage") && m_dest->is_tiled()) { AM_DBG lib::logger::get_logger()->debug("cocoa_image_renderer.redraw: drawing tiled image"); dstrect = m_dest->get_rect(); dstrect.translate(m_dest->get_global_topleft()); common::tile_positions tiles = m_dest->get_tiles(srcsize, dstrect); common::tile_positions::iterator it; for(it=tiles.begin(); it!=tiles.end(); it++) { srcrect = (*it).first; dstrect = (*it).second; cocoa_srcrect = NSMakeRect(srcrect.left(), srcrect.top(), srcrect.width(), srcrect.height()); cocoa_dstrect = [view NSRectForAmbulantRect: &dstrect]; AM_DBG logger::get_logger()->debug("cocoa_image_renderer.redraw: draw image %f %f -> (%f, %f, %f, %f)", cocoa_srcsize.width, cocoa_srcsize.height, NSMinX(cocoa_dstrect), NSMinY(cocoa_dstrect), NSMaxX(cocoa_dstrect), NSMaxY(cocoa_dstrect)); [m_image drawInRect: cocoa_dstrect fromRect: cocoa_srcrect operation: NSCompositeSourceAtop fraction: 1.0]; } m_lock.leave(); return; } dstrect = m_dest->get_fit_rect(srcsize, &srcrect, m_alignment); cocoa_srcrect = NSMakeRect(0, 0, srcrect.width(), srcrect.height()); dstrect.translate(m_dest->get_global_topleft()); cocoa_dstrect = [view NSRectForAmbulantRect: &dstrect]; AM_DBG logger::get_logger()->debug("cocoa_image_renderer.redraw: draw image %f %f -> (%f, %f, %f, %f)", cocoa_srcsize.width, cocoa_srcsize.height, NSMinX(cocoa_dstrect), NSMinY(cocoa_dstrect), NSMaxX(cocoa_dstrect), NSMaxY(cocoa_dstrect)); [m_image drawInRect: cocoa_dstrect fromRect: cocoa_srcrect operation: NSCompositeSourceAtop fraction: 1.0]; m_lock.leave();}} // namespace cocoa} // namespace gui} //namespace ambulant
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -