|
25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more... |
Home Projects Up Sitemap Search Blog Forum+Chat About Us Privacy Terms of Use Feedback FAQ Images Services Ads Donate Humor |
|
|
Windows bitmap (.bmp) animatorThis Borland C++ 4.0 ObjectWindows Library (OWL) 2.0 program displays .BMP bitmap files sequentially to animate them. Adapted from WLife2d.cpp, it has available all the features of my SDib and SDibWindow classes, though it uses few of them. Like my other programs that use SDibWindow, this demonstrates effective use of IdleAction(). It doesn't hog CPU time and runs well when other applications are also running. With the inclusion of SDibWindow, SDib, and other library classes you'll find on this site, the project winds up being large. Download:Click here to download wanimate.zip (about 33 KB). The zip contains these files that are unique to this project. Links to the other required files are provided in the listings below where they are referenced.
This screenshot of the project nodes in the Borland C++ 4.0 IDE might help you set up the project nodes.
|
|
/* wanimate.cpp 12-02-01
Copyright (C)1997-2001 Steven Whitney.
Initially published by http://25yearsofprogramming.com.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
Version 2 as published by the Free Software Foundation.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Displays .BMP bitmap files consecutively to animate them.
(Win32s target. Originally adapted from wlife2d.cpp)
------
TO DO:
Do whatever's possible to speed it up, then add a delay variable.
Preload the dibs just once: but they're big, so this would limit the number you can load.
Keep the preloads in a TIArray(dib); when user edits filenames in FileList,
you must compare the preloads against the list: add any not currently loaded,
delete any no longer in the list. Then empty FileList; you can set the window caption
from the string SDib::Title.
Allow single-stepping or stop-action, and backwards cycling.
------
Notes:
--Keep this program as a simple standalone utility (don't merge into another).
*/
#include <owl\owlpch.h>
#include <owl\chooseco.h> // forces MyCustomColors inclusion
#include <owl\opensave.h>
#include <math.h>
#pragma hdrstop
#include "c:\bcs\my.h"
#include "c:\bcs\library\sdibwin.h"
#include "wanimate.rh"
#include "c:\bcs\library\sdib.cpp"
#include "c:\bcs\library\filearay.cpp"
#include "c:\bcs\library\doubrect.cpp"
#include "c:\bcs\library\stopwatc.cpp"
#include "c:\bcs\mylib.cpp"
const char AppName[] = ".BMP Animator";
char INIFilename[] = "wanimate.ini";
char HelpFilename[] = "wanimate.hlp";
//////////////////////////////////////////////////////////////////////////////
// A window in which the .BMP files are displayed
//
class SAnimateWindow : public SDibWindow
{
public:
SAnimateWindow(TWindow* parent = 0);
~SAnimateWindow();
BOOL IdleAction(long idlecount);
protected:
// variables
BOOL autocycle; // whether to automatically cycle through the files
// TWindow overridden virtuals
void SetupWindow();
// normal functions
void setautocycle(BOOL);
// event handlers
void CmFileOpen();
void CmViewAutoCycle();
void CmHelpAbout();
DECLARE_RESPONSE_TABLE(SAnimateWindow);
};
DEFINE_RESPONSE_TABLE1(SAnimateWindow, SDibWindow)
EV_COMMAND(CM_FILEOPEN,CmFileOpen),
EV_COMMAND(CM_VIEWAUTOCYCLE,CmViewAutoCycle),
EV_COMMAND(CM_HELPABOUT,CmHelpAbout),
END_RESPONSE_TABLE;
//----------------------------------------------------------------------------
// constructor
SAnimateWindow::SAnimateWindow(TWindow* parent) : SDibWindow(parent)
{
autocycle = FALSE;
FileList.TEditControlOutput = TRUE; // maybe not necessary anymore
} //constructor
//----------------------------------------------------------------------------
// destructor
SAnimateWindow::~SAnimateWindow()
{
} //destructor
//----------------------------------------------------------------------------
void SAnimateWindow::SetupWindow()
{
SDibWindow::SetupWindow(); // do base first
// I think this must be here so the window and its menu are valid for CheckMenuItem.
setautocycle(FileList.GetItemsInContainer() > 0); // no cycling unless files in list
} //SetupWindow
//----------------------------------------------------------------------------
void SAnimateWindow::setautocycle(BOOL state)
{
autocycle = state;
CheckMenuItem(GetApplication()->GetMainWindow()->GetMenu(),CM_VIEWAUTOCYCLE,
MF_BYCOMMAND | (autocycle ? MF_CHECKED : MF_UNCHECKED));
}
//----------------------------------------------------------------------------
void SAnimateWindow::CmViewAutoCycle() { setautocycle(!autocycle); }
//----------------------------------------------------------------------------
void SAnimateWindow::CmFileOpen()
{
TOpenSaveDialog::TData filedata(OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT,
"Bitmap Files (*.BMP)|*.BMP|All Files (*.*)|*.*|",0,0,"BMP");
if((TFileOpenDialog(this,filedata)).Execute() == IDOK)
{
// FileList.Flush(); // possibility: no, undesirable
FileList.AddDialogList(filedata.FileName);
}
else
if(filedata.Error)
MessageBox("Dialog box returned error.","Warning",MB_OK);
setautocycle(FileList.GetItemsInContainer() > 0); // no cycling unless files in list
} //CmFileOpen
//----------------------------------------------------------------------------
void SAnimateWindow::CmHelpAbout()
{ MessageBox("Copyright (C)1997-2001 Steven Whitney. GNU GPL 2.",GetApplication()->GetName(),MB_OK); }
//----------------------------------------------------------------------------
BOOL SAnimateWindow::IdleAction(long /* idlecount */)
{
// SDibWindow::IdleAction(idlecount); // not currently necessary
// load and display the next file
if(!FileList.GetItemsInContainer()) // no files in list
setautocycle(FALSE);
if(!autocycle) // or user may have turned it off
return(TRUE); // #error try returning FALSE, then
// don't waste system time if this isn't the active application, or is minimized
if(IsIconic() || (GetActiveWindow() != GetApplication()->GetMainWindow()->HWindow))
return(TRUE); // FALSE?
// You could change this to FileOpen to allow mixing BMP, PIC files, but no current need for it
if(!makenewdib(FileList.Next().c_str(),0,0,FALSE)) // load the next file, if possible
return(TRUE); // FALSE?
if(Parent) // set up window caption
{
string caption =
string(GetApplication()->GetName()) + string(" - ") + FileList.Current();
Parent->SetCaption(caption.c_str());
}
Invalidate(FALSE);
return(TRUE);
} //IdleAction
//----------------------------------------------------------------------------
// end class SAnimateWindow
//////////////////////////////////////////////////////////////////////////////
// The application object
class TMyApp : public TApplication
{
public:
TMyApp(const char far *title) : TApplication(title) {} // title used in case of error
protected:
virtual BOOL IdleAction(long idlecount);
virtual void InitMainWindow()
{
TFrameWindow* frame = new TFrameWindow(0,GetName(),new SAnimateWindow);
frame->AssignMenu(TResId(MENU_1));
frame->Attr.AccelTable = TResId(MENU_1);
nCmdShow = SW_SHOWMAXIMIZED;
SetMainWindow(frame);
EnableCtl3d(TRUE); // these are better
}
};
//----------------------------------------------------------------------------
BOOL TMyApp::IdleAction(long /* idlecount */)
{
TApplication::IdleAction(0);
return TRUE;
}
//----------------------------------------------------------------------------
// end class TMyApp
//////////////////////////////////////////////////////////////////////////////
// OwlMain
int OwlMain(int /* argc */, char** /* argv */)
{
randomize();
string::set_case_sensitive(0);
// Run() calls: InitApplication(), InitInstance() { (which calls: InitMainWindow() },
// then displays main window.
TMyApp* myapp = new TMyApp(AppName);
int retval = myapp->Run();
delete myapp;
return(retval);
} //OwlMain
#$k+ WAnimate Help Contents
Parts of this Help file are also used by other programs, and may have sections that don't apply to WAnimate. Also, some features (mentioned here or not!) may appear to be available, but either do nothing or are not very useful: dragging with the left mouse button does not zoom; any colors modified with the right mouse button are lost as soon as a new file is loaded.
OverviewHID_OVERVIEW
Files and File FormatsHID_FILEFORMATS
File Menu CommandsHID_FILEMENU
View Menu CommandsHID_VIEWMENU
#$k+ Overview
WAnimate allows you to create a list of BMP files. It then loads and displays the files as fast as it can, in an automatic rotation, thus animating them. Its main use is for animating a sequence of related BMP files (such as those created by my programs WLife2D or WAdapt) so you can see events develop on the screen much faster than they do while the files are originally being created by those programs.
For more versatility in viewing and manipulating BMP files (such as color palette animation, etc.), use Winbrot.exe.
Notes
If you specify any BMP files (wildcards allowed) on the command line when you start the program, the program creates an internal list of the files. For example, you could use FileManager|Run, with the command line: WANIMATE.EXE *.BMP. (You may need to specify a full path for each file if the program is not in the same directory as the data files.).
For best color representation, Windows must be in a mode that allows more than 256 colors on the screen at one time.
#$k+File Menu Commands
Load
Allows you to add BMP files to the rotation list. With each call to Load, you can add files from only one directory; to add files from more than one directory, call File|Load more than once. You can then edit the file order using File|Edit List.
Load is the same as specifying a list of files on the command line, except that files added using Load are automatically alphabetized. You must name them so the order is right, or select and add them one at a time in the order you want, or use Edit List to reorder them.
Edit List
Allows you to directly edit the file rotation list. You can delete files from the list, move files around in the list, or explicitly add files to the list by entering their full path names, one to a line.
#$k+ View Menu Commands
AutoCycle
Starts/stops automatic file cycling.
Fit to Window
An image loaded from disk has a fixed size. The region it describes may be a different size and/or shape than the window you have available to display it in. In these situations, Fit to Window will cause the displayed design to be stretched or compressed so that it fills the window. However, it does not change the resolution of the image. When a very small design is fit to a large window, the pixels will look large and the design will look fuzzy.
Set Display Time Interval
(Not implemented. The program always cycles as fast as it can.)
Use this option to set the number of milliseconds delay between files.
; Precede comments with a semi-colon, like this. [OPTIONS] CONTENTS=HID_CONTENTS TITLE=WAnimate Help [CONFIG] BrowseButtons() [FILES] wanimate.rtf c:\bcs\library\sdibwin.rtf
/**************************************************************************** wanimate.rh This file is part of the WAnimate project. Copyright (C)1997-2001 Steven Whitney. Published under GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY. Initially published by http://25yearsofprogramming.com. produced by Borland Resource Workshop *****************************************************************************/ #include "c:\bcs\library\sdibwin.rh" #define MENU_1 1 #define CM_VIEWAUTOCYCLE 1 #define CM_HELPABOUT 24348
/****************************************************************************
WANIMATE.RC
This file is part of the WAnimate project.
Copyright (C)1997-2001 Steven Whitney.
Published under GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY.
Initially published by http://25yearsofprogramming.com.
produced by Borland Resource Workshop
*****************************************************************************/
#include "wanimate.rh"
MENU_1 MENU
{
POPUP "&File"
{
MENUITEM "&Edit List...\tE", CM_FILEEDITLIST
MENUITEM "&Load...\tL", CM_FILEOPEN
MENUITEM "E&xit", CM_FILEEXIT
}
POPUP "&View"
{
MENUITEM "Auto&Cycle\tG", CM_VIEWAUTOCYCLE
MENUITEM "&Fit to Window\tW", CM_VIEWFITTOWINDOW, CHECKED
}
POPUP "&Help"
{
MENUITEM "&Index\tF1", CM_HELPINDEX
MENUITEM "&About...", CM_HELPABOUT
}
}
STRINGTABLE
{
CM_VIEWAUTOCYCLE, "Starts/Stops automatic cycling"
CM_VIEWFITTOWINDOW, "Forces image to match window size "
}
MENU_1 ACCELERATORS
{
VK_F1, CM_HELPINDEX, VIRTKEY
"g", CM_VIEWAUTOCYCLE
"G", CM_VIEWAUTOCYCLE
"w", CM_VIEWFITTOWINDOW
"W", CM_VIEWFITTOWINDOW
"l", CM_FILEOPEN
"L", CM_FILEOPEN
"e", CM_FILEEDITLIST, ASCII
"E", CM_FILEEDITLIST, ASCII
}
|
|
|
|
|
|