Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

pointer.h

00001 /*
00002   libwftk - Worldforge Toolkit - a widget library
00003   Copyright (C) 2003 Ron Steinke <malcolm@worldforge.org>
00004   Based on code copyright  (C) 1999-2002  Karsten Laux
00005 
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Lesser General Public
00008   License as published by the Free Software Foundation; either
00009   version 2.1 of the License, or (at your option) any later version.
00010   
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Lesser General Public License for more details.
00015   
00016   You should have received a copy of the GNU Lesser General Public
00017   License along with this library; if not, write to the
00018   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019   Boston, MA  02111-1307, SA.
00020 */
00021 
00022 #ifndef _POINTER_H
00023 #define _POINTER_H
00024 
00025 #include <wftk/mouse.h>
00026 #include <wftk/surface.h>
00027 #include <wftk/timer.h>
00028 
00029 #include <vector>
00030 
00031 namespace wftk {
00032 
00034 class HardPointer : public Pointer
00035 {
00036  public:
00038   HardPointer(const Surface&, const Point& hotspot);
00040   ~HardPointer() {SDL_FreeCursor(ptr_);}
00041 
00042 
00044   static void insert(const std::string&, const Surface&, const Point& hotspot);
00045 
00046  protected:
00047   virtual void show() {SDL_SetCursor(ptr_); SDL_ShowCursor(1);}
00048   virtual void hide() {SDL_ShowCursor(0);}
00049 
00050  private:
00051   // Pointer::ResInval used the default constructor
00052   friend struct ResInval;
00053   HardPointer();
00054 
00055   SDL_Cursor* ptr_;
00056 };
00057 
00059 class SoftPointer : public Pointer
00060 {
00061  public:
00063   SoftPointer(Surface::Resource* image, const Point& hotspot)
00064     : image_(image), hotspot_(hotspot) {image_->bind();}
00066   ~SoftPointer() {image_->free();}
00067 
00069   static void insert(const std::string&, Surface::Resource*, const Point& hotspot);
00070 
00072   const Surface& image() const {return *image_->res();}
00074   const Point& hotspot() const {return hotspot_;}
00075 
00076  protected:
00077   // RootWindow takes care of the drawing, so these don't do much
00078   virtual void show() {SDL_ShowCursor(0);}
00079   virtual void hide() {}
00080 
00082   Surface::Resource* image_;
00084   Point hotspot_;
00085 };
00086 
00088 class AnimatedPointer : public SoftPointer
00089 {
00090  public:
00092   typedef std::pair<Surface::Resource*,Point> Data;
00094   AnimatedPointer(const std::vector<Data>&, unsigned update);
00096   ~AnimatedPointer();
00097 
00099   static void insert(const std::string&, const std::vector<Data>&, unsigned update);
00100 
00101  protected:
00102   virtual void show() {SoftPointer::show(); update_.run();}
00103   virtual void hide() {SoftPointer::hide(); update_.halt();}
00104 
00105  private:
00106   Timer update_;
00107 
00108   void switchImage();
00109 
00110   std::vector<Data> data_;
00111   unsigned image_num_;
00112 };
00113 
00114 } // namespace
00115 
00116 #endif
00117 

Generated Thu Mar 18 20:06:04 2004.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.