File arachne.h of Package arachne
/*
arachne.h
Author: Hayden Walles
Date: 5 March 2008
Main internal header file for the Arachne program. These declarations were originally in arachne.c, back when it was a one-file wonder.
*/
/*
Copyright (C) 2007, 2008 Hayden Walles
This file is part of Arachne.
Arachne is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Arachne 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdarg.h>
#include <stdio.h>
#include "config.h"
#include "image.h"
#include <seamstress.h>
/*Some miscellaneous definitions.*/
#define VERSION_STRING VERSION
#define TOSTR(x) #x
#define HELP_PATH DIR_PKG_DATA "/t1.html"
/*Arachne is supposed to be a portable application. With a graphical program, that's still difficult, but it's possible. A lot of that portability is created by clever definitions here.
At the moment it can only use GTK+, but soon it will be able to use Windows as well.
*/
/*Eventually the GUI to use will be specified via config.h, but for the moment we'll tell it manually here.*/
//#define USE_GTK 0
//#define USE_WINDOWS 1
/*This pixel type is intended to be generic. If it isn't it may have to be moved inside the USE_ conditionals later.*/
typedef unsigned char PIXEL[3];
/*There are some easy access macros defined inside the USE_ conditionals to set pixels that respect the different byte order required by GTK+ and Windows*/
/*Define some generic UI types that make it easier to deal with the GUI from the main application code.*/
#if USE_GTK
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf/gdk-pixdata.h>
typedef GtkWindow *WINDOW;
typedef GtkWidget *BUTTON,*MENUITEM;
typedef struct {
GtkDrawingArea *drawable;
GtkProgressBar *progress;
GtkStatusbar *statusbar;
int statuscontext;
guchar *view;
int viewwidth,viewheight;
int oldx,oldy; //stores the old pointer position.
} GUI_PRIVATE;
/*This next one will probably end up somewhere else eventually.*/
#define GDK_BUTTON_MASK (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK|GDK_BUTTON3_MASK|GDK_BUTTON4_MASK|GDK_BUTTON5_MASK)
/*These macro are used to access generic pixels.*/
#define guiPixel(loom,row,col) ((loom)->private.view+(row*(loom)->private.viewwidth+(col))*3)
#define guiSetViewPixel(loom,row,col,r,g,b) (guiPixel(loom,row,col)[0]=r,guiPixel(loom,row,col)[1]=g,guiPixel(loom,row,col)[2]=b)
#define guiGetWorkspace(loom, wptr, hptr) gdk_drawable_get_size(GTK_WIDGET(loom->private.drawable)->window,wptr,hptr);
/*These macros map generic GUI operations to GTK+ function calls. If necessary these could be implemented as functions, but GTK+ makes it easy to do inline.*/
#define toolbar_toggle_is_active(widget) gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget))
#define toolbar_activate_toggle(widget) gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(widget),TRUE);
#define toolbar_deactivate_toggle(widget) gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(widget),FALSE);
#define menu_check_item(widget) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget),TRUE)
#define menu_uncheck_item(widget) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget),FALSE)
#define toolbar_set_button_enabled(widget,bool) gtk_widget_set_sensitive(widget,bool)
#define menu_set_item_enabled(widget,bool) gtk_widget_set_sensitive(widget,bool)
#define progress_set_position(lm,part,whole) gtk_progress_bar_set_fraction(lm->private.progress,(double)part/whole)
#define progress_set_text(lm,string) gtk_progress_bar_set_text(lm->private.progress,string)
typedef gboolean aboolean;
#elif USE_WINDOWS
/*I'm targetting Windows XP as a minimum.*/
#define NTDDI_VERSION NTDDI_WINXP
#define _WIN32_WINNT 0x501
#define _WIN32_IE 0x0500
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
/*include windows.h etc. here*/
typedef HWND WINDOW;
typedef struct {
HWND hToolbar;
int id;
} BUTTON;
typedef struct {
HMENU hMenu;
int id;
int first,last;
} MENUITEM;
typedef BOOL aboolean;
typedef struct {
HWND hProgressDlg,hProgressBar,hStatusbar,hToolbar;
RECT work;
POINT minwork;
BITMAPINFO dib; //device-independent bitmap used to mediate
unsigned char *dibbits;
int bytesperrow;
BOOL drawing,tracking;
int oldx,oldy; //stores the old pointer position.
} GUI_PRIVATE;
/*These macros are used to access generic pixels.*/
#define guiPixel(loom,row,col) ((loom)->private.dibbits+(row*(loom)->private.bytesperrow)+(col*3))
#define guiSetViewPixel(loom,row,col,r,g,b) (guiPixel(loom,row,col)[2]=r,guiPixel(loom,row,col)[1]=g,guiPixel(loom,row,col)[0]=b)
/*Macros for the minor GUI operations that can be defined inline.*/
#define toolbar_toggle_is_active(widget) SendMessage(widget.hToolbar,TB_ISBUTTONCHECKED,widget.id,0)
#define toolbar_activate_toggle(widget) SendMessage(widget.hToolbar,TB_CHECKBUTTON,widget.id,MAKELONG(1,0))
#define toolbar_deactivate_toggle(widget) SendMessage(widget.hToolbar,TB_CHECKBUTTON,widget.id,MAKELONG(0,0))
#define toolbar_set_button_enabled(widget,bool) SendMessage(widget.hToolbar,TB_ENABLEBUTTON,widget.id,MAKELONG(bool,0))
#define menu_set_item_enabled(widget,bool) EnableMenuItem(widget.hMenu,widget.id,MF_BYCOMMAND|(bool ? MF_ENABLED:MF_GRAYED))
#define progress_set_position(lm,part,whole) SendMessage(GetDlgItem(lm->private.hProgressDlg,ID_DLG_PROGRESS_BAR),PBM_SETPOS,100*part/whole,0)
#define progress_set_text(lm,string) SetWindowText(GetDlgItem(lm->private.hProgressDlg,ID_DLG_PROGRESS_TEXT),string)
/*And prototyes for the operations that are implemented as functions.*/
void menu_check_item(MENUITEM item);
void menu_uncheck_item(MENUITEM item);
#endif
/*This is the main datatype used for keeping track of ongoing operations. There is one for each window open.*/
typedef struct tagLOOM{
SEAM_MAP *map;
int mapdirection;
IMAGE *image;
int span;
char *filename;
SEAM_MARKS *marks;
/*UI stuff below.*/
/*First, generic UI information about tools and modes.*/
int working,abort;
int flags;
int mode;
int tool;
int toolwidth;
/*Next generic handles to the main window for this loom, and for controls. This allows the application code to have a fairly fine-grained control over the user interface without knowing the nitty-gritty.*/
WINDOW window;
BUTTON horzmodebtn, vertmodebtn,origmodebtn;
BUTTON protectbtn, exposebtn, clearbtn;
MENUITEM protectmenu, exposemenu, clearmenu;
MENUITEM horzmodemenu,vertmodemenu,origmodemenu;
/*Finally a structure containing information private to the particular GUI backend being used.*/
GUI_PRIVATE private;
/*The LL pointer.*/
struct tagLOOM *next;
} LOOM;
#define LOOM_MODE_NONE 0
#define LOOM_MODE_HORZ 1
#define LOOM_MODE_VERT 2
#define LOOM_MODE_ORIG 3
#define LOOM_TOOL_PROTECT 1
#define LOOM_TOOL_HIDE 2
#define LOOM_TOOL_CLEAR 3
#define LOOM_HORIZONAL 1
#define LOOM_VERTICAL 0
#define LOOM_MASK_DIRECTION 1
#define LOOM_DYNAMIC_ENERGY 2
/*Prototypes*/
/*gui-*.c*/
int guiInitialiseLoom(LOOM *new);
void initIcons(void);
void guiReportError(LOOM *loom,char *fmt, ...);
void guiClearWaiting(void);
void guiSetWindowMinimum(LOOM *loom, int minwidth, int minheight);
void guiSetStatus(LOOM *loom,char *fmt, ...);
void guiBeginComputation(LOOM *loom);
void guiEndComputation(LOOM *loom);
int guiReloadLoom(LOOM *new);
#if USE_WINDOWS
void guiGetWorkspace(struct tagLOOM *loom, int *width, int *height);
#endif
/*arachne.c*/
/*This is called to do application initialisation*/
int arachneStart(int argc, char **argv);
/*These are used by callbacks to perform generic operations.*/
void pickupProtectTool(LOOM *sm);
void pickupHideTool(LOOM *sm);
void pickupClearTool(LOOM *sm);
void switchDynamicEnergy(LOOM *sm);
void arachneResizeView(LOOM *loom,int width, int height);
void changeModeH(LOOM *sm);
void changeModeV(LOOM *sm);
void changeModeO(LOOM *sm);
void arachneAnnotate(LOOM *sm, int x, int y);
int replaceLoomFromFile(LOOM *new,char *filename);
/*These are just defined at the wrong end of the file.*/
void annotatePreView(LOOM *sm, int x, int y,int type);
int preView(LOOM *loom);
/*viewhtml.c*/
int viewHtml(char *link);