Added GetImageDimensions() so clients can tell the size of the image. Will fail gracefully if that info is not present.

This commit is contained in:
pinkerton%netscape.com 1998-10-06 03:56:56 +00:00
Родитель feb9491e09
Коммит 351524239e
2 изменённых файлов: 0 добавлений и 272 удалений

Просмотреть файл

@ -1,166 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
//
// CImageIconMixin
// Mike Pinkerton, Netscape Communications
//
// When you have an object that wants to draw itself using an image (gif, jpeg, etc),
// just mix this class in and call the appropriate routines when you want to draw.
// Most importantly, this handles cleaning up when the object goes away if it has
// made a request for an image that has yet to arrive.
//
#include "CImageIconMixin.h"
CImageIconMixin :: CImageIconMixin ( const string & inURL )
: mURL(inURL)
{
}
//
// destructor
//
// If we made a request to load an image and we have yet to display it, we get a
// message when the image is ready to draw. However, if we're going away, it would
// be bad for us to get that message at some point in the future. Make sure we
// are off the listener list for the image cache.
//
CImageIconMixin :: ~CImageIconMixin ( )
{
gImageCache().ListenerGoingAway ( mURL, this );
}
//
// ListenToMessage
//
// Listen for the update of image and then
//
void
CImageIconMixin :: ListenToMessage ( const MessageT inMessage, void* ioData )
{
if ( inMessage == CIconContext::msg_ImageReadyToDraw )
ImageIsReady();
} // ListenToMessage
//
// DrawIcon
//
// Draw the image. Will begin loading it if the data has not yet arrived and will
// draw the standby in its place
//
void
CImageIconMixin :: DrawImage ( const Point & inTopLeft, IconTransformType inTransform,
Uint32 inWidth, Uint32 inHeight ) const
{
try {
if ( gImageCache().RequestIcon(mURL, this) == CImageCache::kDataPresent ) {
StColorState::Normalize();
DrawingState state;
state.copyMode = srcCopy;
gImageCache().FetchImageData ( mURL, &state.pixmap, &state.mask );
LockFEPixmapBuffer ( state.pixmap ) ;
LockFEPixmapBuffer ( state.mask );
//¥¥ do appropriate things for transform
DoDrawing ( state, inTopLeft, inTransform, inWidth, inHeight ) ;
UnlockFEPixmapBuffer ( state.mask );
UnlockFEPixmapBuffer ( state.pixmap ) ;
}
else {
// icon not ready yet, just draw this thing....
DrawStandby ( inTopLeft, inTransform ) ;
}
}
catch ( invalid_argument & ia ) {
DebugStr("\pData requested for something not in cache");
DrawStandby ( inTopLeft, inTransform ) ;
}
catch ( bad_alloc & ba ) {
DebugStr("\pCould not allocate memory drawing icon");
DrawStandby ( inTopLeft, inTransform ) ;
}
} // DrawIcon
void
CImageIconMixin :: DoDrawing ( DrawingState & inState, const Point & inTopLeft,
IconTransformType inTransform, Uint32 inWidth, Uint32 inHeight ) const
{
if ( inWidth == 0 && inHeight == 0 ) {
inWidth = inState.pixmap->pixmap.bounds.right;
inHeight = inState.pixmap->pixmap.bounds.bottom;
}
DrawScaledImage ( &inState, inTopLeft, 0, 0, inWidth, inHeight );
} // DoDrawing
//
// SetImageURL
//
// Change the url of the image to draw. We might be in the middle of loading another
// image when we get this call, so unregister ourselves. This does NOT re-request
// the new icon.
//
void
CImageIconMixin :: SetImageURL ( const string & inNewURL )
{
gImageCache().ListenerGoingAway ( mURL, this );
mURL = inNewURL;
} // SetImageURL
#pragma mark -
CTiledImageMixin :: CTiledImageMixin ( const string & inURL )
: CImageIconMixin ( inURL )
{
}
CTiledImageMixin :: ~CTiledImageMixin ( )
{
}
//
// DoDrawing
//
// Overloaded to draw a image as a tiled image for drawing backgrounds
//
void
CTiledImageMixin :: DoDrawing ( DrawingState & inState, const Point & inTopLeft,
IconTransformType inTransform, Uint32 inWidth, Uint32 inHeight ) const
{
DrawTiledImage ( &inState, inTopLeft, 0, 0, inWidth, inHeight );
} // DoDrawing

Просмотреть файл

@ -1,106 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
//
// CImageIconMixin
// Mike Pinkerton, Netscape Communications
//
// When you have an object that wants to draw itself using an image (gif, jpeg, etc),
// just mix this class in and call the appropriate routines when you want to draw.
// Most importantly, this handles cleaning up when the object goes away if it has
// made a request for an image that has yet to arrive.
//
#pragma once
#include <string>
#include "CIconCache.h"
#include "mimages.h"
//
// class CImageIconMixin
//
// Draw an image, most likely as an icon.
//
class CImageIconMixin : public LListener
{
public:
CImageIconMixin ( ) { } ;
CImageIconMixin ( const string & inURL ) ;
virtual ~CImageIconMixin ( ) ;
// Change the url telling us which image to load. Safe to call even when an image
// load is pending, but will NOT re-request the new image.
virtual void SetImageURL ( const string & inNewURL ) ;
// Draw the image. Will begin loading it if the data has not yet arrived and will
// draw the standby in its place. Pass zero's for width and height to use image defaults
// or the image will be scaled to what you put in.
void DrawImage ( const Point & inTopLeft, IconTransformType inTransform,
Uint32 inWidth, Uint32 inHeight ) const;
protected:
// catch the message that the image is ready to draw
virtual void ListenToMessage ( MessageT inMessage, void* ioPtr ) ;
// called when the image is ready to draw. This should do something like
// refresh the view.
virtual void ImageIsReady ( ) = 0;
// Draw a scaled image as an icon. Override to draw differently
virtual void DoDrawing ( DrawingState & inState, const Point & inTopLeft,
IconTransformType inTransform, Uint32 inWidth,
Uint32 inHeight ) const ;
// Draw something when the real image is not yet here.
virtual void DrawStandby ( const Point & inTopLeft, IconTransformType inTransform ) const = 0;
private:
string mURL;
}; // class CImageIconMixin
//
// class CTiledImageMixin
//
// Tile an image, for use as backgrounds in chrome or tables
//
class CTiledImageMixin : public CImageIconMixin
{
public:
CTiledImageMixin ( ) { };
CTiledImageMixin ( const string & inURL ) ;
virtual ~CTiledImageMixin ( ) ;
protected:
// Draw a image as a tiled image for drawing backgrounds. Width and Height are
// reinterpreted to mean the width and height of the area the image is being tiled
// in.
virtual void DoDrawing ( DrawingState & inState, const Point & inTopLeft,
IconTransformType inTransform, Uint32 inWidth,
Uint32 inHeight ) const ;
}; // class CTiledImageMixin