]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 735948 ] wxStaticPicture contrib
authorJulian Smart <julian@anthemion.co.uk>
Sun, 1 Jun 2003 16:26:58 +0000 (16:26 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sun, 1 Jun 2003 16:26:58 +0000 (16:26 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20826 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

contrib/include/wx/gizmos/statpict.h [new file with mode: 0644]
contrib/src/gizmos/GizmosVC.dsp
contrib/src/gizmos/Makefile.in
contrib/src/gizmos/makefile.b32
contrib/src/gizmos/makefile.g95
contrib/src/gizmos/makefile.unx
contrib/src/gizmos/makefile.vc
contrib/src/gizmos/makefile.wat
contrib/src/gizmos/statpict.cpp [new file with mode: 0644]
contrib/src/gizmos/statpict.txt [new file with mode: 0644]

diff --git a/contrib/include/wx/gizmos/statpict.h b/contrib/include/wx/gizmos/statpict.h
new file mode 100644 (file)
index 0000000..942d6d2
--- /dev/null
@@ -0,0 +1,141 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        statpict.h
+// Purpose:     wxStaticPicture class
+// Author:      Wade Brainerd
+// Modified by:
+// Created:     2003-05-01
+// RCS-ID:
+// Copyright:   (c) Wade Brainerd
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_STATPICT_H_
+#define _WX_STATPICT_H_
+
+#if defined(__GNUG__) && !defined(__APPLE__)
+#pragma interface "statpict.h"
+#endif
+
+#include "wx/control.h"
+
+#include "wx/icon.h"
+#include "wx/bitmap.h"
+#include "wx/image.h"
+
+enum
+{
+    wxSCALE_HORIZONTAL = 0x1,
+    wxSCALE_VERTICAL   = 0x2,
+    wxSCALE_UNIFORM    = 0x4,
+    wxSCALE_CUSTOM     = 0x8
+};
+
+//WXDLLEXPORT_DATA(extern const wxChar*) wxStaticBitmapNameStr;
+extern const wxChar* wxStaticPictureNameStr;
+
+class /*WXDLLEXPORT*/ wxStaticPicture : public wxControl
+{
+    DECLARE_DYNAMIC_CLASS(wxStaticPicture)
+
+public:
+    wxStaticPicture() {}
+
+    wxStaticPicture( wxWindow* parent, wxWindowID id,
+        const wxBitmap& label,
+        const wxPoint& pos = wxDefaultPosition,
+        const wxSize& size = wxDefaultSize,
+        long style = 0,
+        const wxString& name = wxStaticPictureNameStr )
+    {
+        Create( parent, id, label, pos, size, style, name );
+    }
+
+    bool Create( wxWindow* parent, wxWindowID id,
+        const wxBitmap& label,
+        const wxPoint& pos = wxDefaultPosition,
+        const wxSize& size = wxDefaultSize,
+        long style = 0,
+        const wxString& name = wxStaticPictureNameStr );
+
+    virtual void Command(wxCommandEvent& WXUNUSED(event)) {};
+    virtual void ProcessCommand(wxCommandEvent& WXUNUSED(event)) {};
+    void OnPaint(wxPaintEvent& event);
+
+    void SetBitmap( const wxBitmap& bmp );
+
+    wxBitmap GetBitmap() const
+    {
+        return Bitmap;
+    }
+
+    // Icon interface for compatibility with wxStaticBitmap.
+    void SetIcon( const wxIcon& icon )
+    {
+        wxBitmap bmp;
+        bmp.CopyFromIcon( icon );
+        SetBitmap( bmp );
+    }
+
+    wxIcon GetIcon() const
+    {
+        wxIcon icon;
+        icon.CopyFromBitmap( Bitmap );
+        return icon;
+    }
+
+    void SetAlignment( int align )
+    {
+        Align = align;
+    }
+
+    int GetAlignment() const
+    {
+        return Align;
+    }
+
+    void SetScale( int scale )
+    {
+        Scale = scale;
+    }
+
+    int GetScale() const
+    {
+        return Scale;
+    }
+
+    void SetCustomScale( float sx, float sy )
+    {
+        ScaleX = sx;
+        ScaleY = sy;
+    }
+
+    int GetCustomScale( float* sx, float* sy ) const
+    {
+        *sx = ScaleX;
+        *sy = ScaleY;
+    }
+
+protected:
+    wxBitmap Bitmap;
+
+    int Align;
+
+    int Scale;
+    float ScaleX;
+    float ScaleY;
+
+#ifndef __WXMSW__
+    // When scaling is enabled, measures are taken to improve performance on non-Windows platforms.
+    // - The original bitmap is stored as a wxImage, because conversion from wxBitmap to wxImage is slow.
+    // - The latest scaled bitmap is cached, this improves performance when the control is repainted
+    //   but the size hasn't changed (overlapping windows, movement, etc).
+    wxImage OriginalImage;
+    float LastScaleX;
+    float LastScaleY;
+    wxBitmap ScaledBitmap;
+#endif
+
+    DECLARE_EVENT_TABLE()
+};
+
+#endif // #ifndef _WX_STATPICT_H_
index 3862a451d445c816363afe9d3ca9963c7d2ba900..61e449c4d6554980ca661899d18b2ca581cbe992 100644 (file)
@@ -122,5 +122,9 @@ SOURCE=.\splittree.cpp
 
 SOURCE=.\ledctrl.cpp
 # End Source File
+# Begin Source File
+
+SOURCE=.\statpict.cpp
+# End Source File
 # End Target
 # End Project
index 436da14ab3843bb175cc16f868d66c059e7cc116..6fb1b583310cf55d2698aa4dd6f26e6be0c2b5ea 100644 (file)
@@ -14,9 +14,9 @@ LIBVERSION_AGE=@WX_AGE@
 HEADER_PATH=$(top_srcdir)/contrib/include/wx
 HEADER_SUBDIR=gizmos
 
-HEADERS=multicell.h splittree.h editlbox.h dynamicsash.h ledctrl.h
+HEADERS=multicell.h splittree.h editlbox.h dynamicsash.h ledctrl.h statpict.h
 
-OBJECTS=multicell.o splittree.o editlbox.o dynamicsash.o ledctrl.o
+OBJECTS=multicell.o splittree.o editlbox.o dynamicsash.o ledctrl.o statpict.o
 DEPFILES=$(OBJECTS:.o=.d)
 
 APPEXTRADEFS=-I$(top_srcdir)/contrib/include
index 55ae2e4baa97c158ddd701c36d1648d12898d24a..d9aa9610d054d3bac3b5c3fc2273433b1aee5f07 100644 (file)
@@ -19,6 +19,7 @@ OBJECTS = \
        $(OBJ_PATH)\editlbox.obj \
        $(OBJ_PATH)\dynamicsash.obj \
        $(OBJ_PATH)\ledctrl.obj \
+       $(OBJ_PATH)\statpict.obj \
 
 !include $(WXDIR)\src\makelib.b32
 
@@ -27,4 +28,5 @@ $(OBJ_PATH)\splittree.obj : splittree.cpp
 $(OBJ_PATH)\editlbox.obj : editlbox.cpp
 $(OBJ_PATH)\dynamicsash.obj : dynamicsash.cpp
 $(OBJ_PATH)\ledctrl.obj : ledctrl.cpp
+$(OBJ_PATH)\statpict.obj : statpict.cpp
 
index 0601ece9e9c0ad495c288c1632e91ec8cb401339..e4e6453d0ffafdfa5fbf5bed07f83e30db8a5266 100644 (file)
@@ -10,7 +10,7 @@
 WXDIR = ../../..
 
 LIBTARGET=$(WXDIR)/lib/libgizmos.a
-OBJECTS = multicell.o splittree.o editlbox.o dynamicsash.o ledctrl.o
+OBJECTS = multicell.o splittree.o editlbox.o dynamicsash.o ledctrl.o statpict.o
 
 include $(WXDIR)/src/makelib.g95
 
index b070bc96afd382998bd7a10af7add2549f5b6b76..3ab72925b1708e441a41cdb139974df1f6fb6d32 100644 (file)
@@ -17,7 +17,9 @@ LIB_CPP_SRC=\
   multicell.o\
   editlbox.o\
   splittree.o\
-  dynamicsash.o
+  dynamicsash.o\
+  ledctrl.o\
+  statpict.o
 
 all:    $(GIZMOSLIB)
 
index 3dfd1cae6c8c4ee273f41cb9323d627d654e833a..0988345d069e86c7d5cacc07f49e94de2baddc1e 100644 (file)
@@ -23,7 +23,7 @@ LOCALDOCDIR=$(WXDIR)\contrib\docs\latex\gizmos
 
 !include $(WXDIR)\src\makevc.env
 
-OBJECTS = $(D)\multicell.obj $(D)\splittree.obj $(D)\editlbox.obj $(D)\dynamicsash.obj $(D)\ledctrl.obj
+OBJECTS = $(D)\multicell.obj $(D)\splittree.obj $(D)\editlbox.obj $(D)\dynamicsash.obj $(D)\ledctrl.obj $(D)\statpict.obj
 
 LIBTARGET=$(WXDIR)\lib\gizmos$(LIBEXT).lib
 
index ab3762115383addcf5755eea3b3c364442982746..806efd6055b2bb9e0a56676669ad37ad2efa5981 100644 (file)
@@ -10,7 +10,8 @@ OBJECTS =  &
     $(OUTPUTDIR)\splittree.obj &
     $(OUTPUTDIR)\editlbox.obj &
     $(OUTPUTDIR)\dynamicsash.obj &
-    $(OUTPUTDIR)\ledctrl.obj
+    $(OUTPUTDIR)\ledctrl.obj &
+    $(OUTPUTDIR)\statpict.obj
 
 !include $(WXDIR)\src\makelib.wat
 
diff --git a/contrib/src/gizmos/statpict.cpp b/contrib/src/gizmos/statpict.cpp
new file mode 100644 (file)
index 0000000..e3f39f4
--- /dev/null
@@ -0,0 +1,157 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        statpict.cpp
+// Purpose:     wxStaticPicture
+// Author:      Wade Brainerd (wadeb@wadeb.com)
+// Modified by:
+// Created:     2003-05-01
+// RCS-ID:
+// Copyright:   (c) Wade Brainerd
+// Licence:       wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+  #pragma implementation "statpict.h"
+#endif
+
+#include "wx/defs.h"
+
+#include "statpict.h"
+#include "wx/dcclient.h"
+
+#if !USE_SHARED_LIBRARY
+IMPLEMENT_DYNAMIC_CLASS(wxStaticPicture, wxControl)
+#endif
+
+/*
+ * wxStaticPicture
+ */
+
+BEGIN_EVENT_TABLE(wxStaticPicture, wxControl)
+    EVT_PAINT(wxStaticPicture::OnPaint)
+END_EVENT_TABLE()
+
+bool wxStaticPicture::Create(wxWindow *parent, wxWindowID id,
+           const wxBitmap& bitmap,
+           const wxPoint& pos,
+           const wxSize& s,
+           long style,
+           const wxString& name)
+{
+    SetName(name);
+
+    wxSize size = s ;
+    if ( bitmap.Ok() )
+    {
+        if ( size.x == -1 )
+            size.x = bitmap.GetWidth() ;
+        if ( size.y == -1 )
+            size.y = bitmap.GetHeight() ;
+    }
+
+    m_backgroundColour = parent->GetBackgroundColour() ;
+    m_foregroundColour = parent->GetForegroundColour() ;
+
+    Bitmap = bitmap;
+    Align = 0;
+    Scale = 0;
+    ScaleX = ScaleY = 1;
+
+#ifndef __WXMSW__
+    LastScaleX = LastScaleY = -1;
+    if ( Bitmap.Ok() )
+        OriginalImage = Bitmap.ConvertToImage();
+#endif
+
+    if ( id == -1 )
+        m_windowId = (int)NewControlId();
+    else
+        m_windowId = id;
+
+    m_windowStyle = style;
+
+    bool ret = wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name );
+
+    SetBestSize( size ) ;
+
+    return ret;
+}
+
+void wxStaticPicture::SetBitmap( const wxBitmap& bmp )
+{
+    Bitmap = bmp;
+#ifndef __WXMSW__
+    if ( Bitmap.Ok() )
+        OriginalImage = Bitmap.ConvertToImage();
+    LastScaleX = LastScaleY = -1;
+#endif
+}
+
+void wxStaticPicture::OnPaint(wxPaintEvent& WXUNUSED(event))
+{
+    if ( !Bitmap.Ok() )
+        return;
+
+    wxPaintDC dc( this );
+    PrepareDC( dc );
+    dc.BeginDrawing();
+
+    wxSize sz = GetSize();
+    wxSize bmpsz( Bitmap.GetWidth(), Bitmap.GetHeight() );
+    float sx = 1.0f, sy = 1.0f;
+
+    if ( Scale & wxSCALE_UNIFORM )
+    {
+        float _sx = (float)sz.GetWidth() / (float)bmpsz.GetWidth();
+        float _sy = (float)sz.GetHeight() / (float)bmpsz.GetHeight();
+        sx = sy = _sx < _sy ? _sx : _sy;
+    }
+    else
+    if ( Scale & wxSCALE_CUSTOM )
+    {
+        sx = ScaleX;
+        sy = ScaleY;
+    }
+    else
+    {
+        if ( Scale & wxSCALE_HORIZONTAL )
+            sx = (float)sz.x/(float)bmpsz.x;
+        if ( Scale & wxSCALE_VERTICAL )
+            sy = (float)sz.y/(float)bmpsz.y;
+    }
+
+    bmpsz = wxSize( (int)(bmpsz.x*sx), (int)(bmpsz.y*sy) );
+
+    wxPoint pos( 0, 0 );
+
+    if ( Align & wxALIGN_CENTER_HORIZONTAL ) pos.x = (sz.x-bmpsz.x)/2;
+    else if ( Align & wxALIGN_RIGHT ) pos.x = sz.x-bmpsz.x;
+
+    if ( Align & wxALIGN_CENTER_VERTICAL ) pos.y = (sz.y-bmpsz.y)/2;
+    else if ( Align & wxALIGN_BOTTOM ) pos.y = sz.y-bmpsz.y;
+
+    if ( Scale )
+    {
+#ifdef __WXMSW__
+        double ux, uy;
+        dc.GetUserScale( &ux, &uy );
+        dc.SetUserScale( ux*sx, uy*sy );
+        dc.DrawBitmap( Bitmap, (int)((float)pos.x/sx), (int)((float)pos.y/sy) );
+        dc.SetUserScale( ux, uy );
+#else
+        if ( LastScaleX != sx || LastScaleY != sy )
+        {
+            LastScaleX = sx;
+            LastScaleY = sy;
+            ScaledBitmap = wxBitmap( OriginalImage.Scale( bmpsz.x, bmpsz.y ) );
+        }
+        dc.DrawBitmap( ScaledBitmap, pos.x, pos.y );
+#endif
+    }
+    else
+        dc.DrawBitmap( Bitmap, pos.x, pos.y );
+
+    dc.EndDrawing();
+}
+
+//WXDLLEXPORT_DATA(const wxChar *) wxStaticPictureNameStr = wxT("message");
+const wxChar * wxStaticPictureNameStr = wxT("message");
diff --git a/contrib/src/gizmos/statpict.txt b/contrib/src/gizmos/statpict.txt
new file mode 100644 (file)
index 0000000..9a26328
--- /dev/null
@@ -0,0 +1,34 @@
+wxStaticPicture class
+by Wade Brainerd (wadeb@wadeb.com)
+
+Description:
+
+This class is an improved version of wxStaticBitmap.  
+
+Rather than using a native bitmap control, it uses DC operations to draw the
+control.  This makes its appearance more consistent across platforms, and
+allows for additional features.
+
+Features include:
+
+  wxStaticBitmap compatible API - drop-in replacement.  Image alignment - top,
+  left, bottom, right, center vertical and/or horizontal.
+  Image scaling - scale horizontally and/or vertically, justified scaling
+  (maintains image aspect ratio).
+
+Platforms tested:  
+
+  wxMSW
+  wxGTK
+  wxMac
+  
+Implementation notes:
+
+Under MSW wxWindows uses the operating system to do an optimized (potentially
+hardware accelerated) blit in wxDC::DrawBitmap.  This is usually fast enough to
+do image scaling without affecting the program's interactivity.  
+
+On wxMac and wxGTK however, wxDC::DrawBitmap implicitly calls wxImage::Scale 
+which is a much slower operation.  Therefore, on these platforms wxStaticPicture 
+caches the scaled image to make updates that don't change the image (overlapping 
+windows, etc.) faster.