GED 2006 (C++)
File detail
Source code
/*
* File: appwnd.h - Application window
* Project: GED - bitmap editor (ICP)
* Author: Kamil Dudka, xdudka00
* Team: xdudka00, xfilak01, xhefka00, xhradi08
* Created: 2006-04-08
*/
#ifndef APPWND_H
#define APPWND_H
#include <string>
#include <list>
#include <FL/Fl_Pack.H>
#include <FL/Fl_Window.H>
#include "docwnd.h"
class Image;
class Document;
class AppMenu;
class ToolSelect;
class BrushSelect;
class Fl_Button;
class Fl_Valuator;
class Fl_PNG_Image;
/**
* Application window (singleton)
*/
class AppWnd: public Fl_Window {
public:
~AppWnd ();
/**
* Access point to singleton AppWnd.
* \return Return pointer to singleton.
*/
static AppWnd *ptr ();
/**
* Destroy singleton AppWnd. It has no effect if object is not allocated.
*/
static void destroy ();
/**
* Try to close all documents attached to AppWnd singleton.
* \return Return true if all documents are closed.
*/
bool closeAll ();
/**
* Try to close all documents. If success, close HelpBrowser singleton and AppWnd singleton.
*/
void exit ();
/**
* Search pointer to window in document list.
* \param wnd Pointer to window.
* \return Return true if pointer points to Document object.
*/
bool isDocument (Fl_Window *wnd);
/**
* \return Return DrawContext structure containing current draw tool properties.
*/
DrawContext drawContext () const;
/**
* Set current draw tool.
* \param et Draw tool enumeration.
*/
void selectTool (EDrawTool et);
/**
* \return Return unique file name for new document.
*/
static std::string newDocName ();
protected:
/**
* Singleton can not be allocated static. Use method AppWnd::ptr() method to obtain singleton address.
*/
AppWnd ();
/**
* Add pointer to Document object to document list.
* \param doc Pointer to document to add.
*/
void addDoc (Document *doc);
/**
* Remove pointer to Document object from document list.
* \param doc Pointer to document to remove.
*/
void remDoc (Document *doc);
/**
* Needed to add/remove documents automatically.
*/
friend class Document;
private:
static AppWnd *_instance;
static int _iNewDocIterator;
std::list<Document *> _docList;
DrawContext _drawContext;
AppMenu *_menu;
ToolSelect *_toolSelect;
BrushSelect *_fgBrushSelect;
BrushSelect *_bgBrushSelect;
};
/**
* Document class is very similar to DocWnd.
* When an Document object is created, it is automatically added to document list.
* And it is automatically removed from document list, when object is deleted.
*/
class Document: public DocWnd {
public:
/**
* Create Document object. Read the DocWnd class description for more information.
*/
Document (Image *img): DocWnd (img) {
AppWnd::ptr() -> addDoc (this);
}
virtual ~Document () {
AppWnd::ptr() -> remDoc (this);
}
};
/**
* Tool selection widget
*/
class ToolSelect: public Fl_Pack {
public:
/**
* Create widget.
* \param x Widget position.
* \param y Widget position.
* \param dt Pointer to data of this widget. It is used for reading and writeing.
*/
ToolSelect (int x, int y, EDrawTool *dt);
~ToolSelect ();
/**
* Redraw widget. This shloud be called if tool is changed outside this widget.
*/
virtual void redraw ();
static const int iRowCnt = 2 ; ///< Toolbar rows count.
static const int iColCnt = 4 ; ///< Toolbar columns count.
static const int iButtonSize = 64; ///< Toolbar button size.
static const int iButtonCnt = iRowCnt * iColCnt; ///< Toolbar buttons count.
static const int width = iColCnt * iButtonSize; ///< Widget width.
static const int height = iRowCnt * iButtonSize; ///< Widget height.
private:
static void cb_button (Fl_Widget *, void *); ///< Button callback
void setTool (Fl_Button *butt);
EDrawTool *_drawTool;
Fl_Button *_tbButt [iButtonCnt];
Fl_PNG_Image *_tbIcon [iButtonCnt];
};
/**
* Brush selection widget
*/
class BrushSelect: public Fl_Pack {
public:
/**
* Create widget.
* \param x Widget position.
* \param y Widget position.
* \param width Widget width.
* \param height Widget height.
* \param szTitle Color chooser button text.
* \param pBrushSize Pointer to variable containing brush width.
* \param pBrushColor Pointer to variable containing brush color.
*/
BrushSelect (int x, int y, int width, int height, const char *szTitle, int *pBrushSize, Pixel *pBrushColor);
~BrushSelect ();
private:
int *_pBrushSize;
Pixel *_pBrushColor;
Fl_Button *_pButt;
Fl_Valuator *_pVal;
void askForColor ();
void setButtonColor ();
void readBrushWidht ();
static void cb_button (Fl_Widget *, void *);
static void cb_valuator (Fl_Widget *, void *);
};
#endif