scbmacro.h

Go to the documentation of this file.
00001 #ifndef SCBMACRO_H_
00002 #define SCBMACRO_H_
00003 
00004 /*
00005  * File Name  : scbmacro.h
00006  * 
00007  * Description: Scribble library macros
00008  */
00009 
00010 /*
00011  * This file is part of liberscribble.
00012  *
00013  * liberscribble is free software: you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation, either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * liberscribble is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00025  */
00026 
00027 /**
00028  * Copyright (C) 2008 iRex Technologies B.V.
00029  * All rights reserved.
00030  */
00031  
00032 
00033 #ifdef __cplusplus
00034 extern "C"
00035 {
00036 #endif
00037 
00038 //////////////////////////////////////////////////////////////////////////
00039 // using gtk to draw page
00040 // all the parameters are pointers
00041 #define ERSCRIBBLE_GTK_DRAW_PAGE(doc, pageId, drawable, gc)\
00042 {\
00043     if (doc)\
00044     {\
00045         ScbPagePtr erscribble_page = erscribble_doc_get_page(doc, pageId);\
00046         if (erscribble_page)\
00047         {\
00048             ScbStrokesPtr erscribble_strokes = erscribble_page_get_strokes(erscribble_page);\
00049             if (erscribble_strokes)\
00050             {\
00051                 ScbStrokePtr erscribble_stroke = NULL;\
00052                 GdkColor GDK_color;\
00053                 ScbColor erscribble_color;\
00054                 GdkLineStyle GDK_lineStyle = GDK_LINE_SOLID; \
00055                 GList *erscribble_ptr = g_list_first(erscribble_strokes->strokes);\
00056                 while (erscribble_ptr)\
00057                 {\
00058                     erscribble_stroke = (ScbStrokePtr)erscribble_ptr->data;\
00059                     if (erscribble_stroke)\
00060                     {\
00061                         erscribble_dev_color_to_color(&erscribble_color, erscribble_stroke->style.color);\
00062                         GDK_color.pixel = erscribble_color.pixel;\
00063                         GDK_color.red = erscribble_color.red;\
00064                         GDK_color.green = erscribble_color.green;\
00065                         GDK_color.blue = erscribble_color.blue;\
00066                         gdk_gc_set_rgb_fg_color(gc, &GDK_color);\
00067                         gdk_gc_set_line_attributes (gc, \
00068                             erscribble_stroke->style.penSize, \
00069                             GDK_lineStyle, \
00070                             GDK_CAP_PROJECTING, \
00071                             GDK_JOIN_MITER);\
00072                         gdk_draw_lines(drawable, \
00073                             gc, \
00074                             (GdkPoint *)erscribble_stroke_get_point_data(erscribble_stroke), \
00075                             erscribble_stroke_get_point_count(erscribble_stroke));\
00076                     }\
00077                     erscribble_ptr = g_list_next(erscribble_ptr);\
00078                 }\
00079             }\
00080         }\
00081     }\
00082 }
00083 
00084 
00085 //////////////////////////////////////////////////////////////////////////
00086 // macro for toolbar
00087 //////////////////////////////////////////////////////////////////////////
00088 
00089 // ScbDocPtr doc 
00090 // erClientChannel_t channel
00091 // int/enum appId
00092 #define ERSCRIBBLE_TOOLBAR_INIT(doc, channel, id)\
00093 {\
00094     doc->context.appId = id;\
00095     ERSCRIBBLE_TOOLBAR_UPDATE(doc, channel);\
00096 }
00097 
00098 #define ERSCRIBBLE_TOOLBAR_MAP(doc, s, i)\
00099 {\
00100     ScbTBSItem item;\
00101     item.state  = s;\
00102     item.iconId = i;\
00103     erscribble_doc_add_map_item(doc, &item);\
00104 }
00105 
00106 #define erscribble_TOOLBAR_UPDATE(doc, channel)\
00107 {\
00108     tbRemovePlatformIcon(channel, doc->context.appId, iconID_pen);\
00109     tbRemovePlatformIcon(channel, doc->context.appId, iconID_pen1pixel);\
00110     tbRemovePlatformIcon(channel, doc->context.appId, iconID_pen3pixel);\
00111     tbRemovePlatformIcon(channel, doc->context.appId, iconID_pen5pixel);\
00112     tbRemovePlatformIcon(channel, doc->context.appId, iconID_pen7pixel);\
00113     tbRemovePlatformIcon(channel, doc->context.appId, iconID_pencolorbl);\
00114     tbRemovePlatformIcon(channel, doc->context.appId, iconID_pencolordg);\
00115     tbRemovePlatformIcon(channel, doc->context.appId, iconID_pencolorlg);\
00116     tbRemovePlatformIcon(channel, doc->context.appId, iconID_pencolorwh);\
00117     tbRemovePlatformIcon(channel, doc->context.appId, iconID_eraseline);\
00118     int __tbi;\
00119     ScbTBSItemPtr __tbitem = (ScbTBSItemPtr)doc->context.table->data;\
00120     for(__tbi = 0; __tbi < doc->context.table->len; ++__tbi)\
00121     {\
00122         if (erscribble_TBS_SCRIBBLE == __tbitem->state)\
00123         {\
00124             tbAppendPlatformIcon(channel, doc->context.appId, __tbitem->iconId, ccVwrToolbar);\
00125         }\
00126         ++__tbitem;\
00127     }\
00128     if (erscribble_TBS_SCRIBBLE == doc->context.curState)\
00129     {\
00130         tbSetStatePlatformIcon(channel, doc->context.appId, iconID_pen, iconState_selected);\
00131     }\
00132     int __tbIconIndex = (int)iconID_pen1pixel + doc->context.curStrokeStyle.penSize/2;\
00133     __tbitem = (ScbTBSItemPtr)doc->context.table->data;\
00134     if (erscribble_TBS_SELECT_PEN_SIZE == doc->context.curState)\
00135     {\
00136         for(__tbi = 0; __tbi < doc->context.table->len; ++__tbi)\
00137         {\
00138             if (erscribble_TBS_SELECT_PEN_SIZE == __tbitem->state)\
00139             {\
00140                 tbAppendPlatformIcon(channel, doc->context.appId, __tbitem->iconId, ccVwrToolbar);\
00141             }\
00142             ++__tbitem;\
00143         }\
00144         tbSetStatePlatformIcon(channel, doc->context.appId, __tbIconIndex, iconState_selected);\
00145     }\
00146     else\
00147     {\
00148         for(__tbi = 0; __tbi < doc->context.table->len; ++__tbi)\
00149         {\
00150             if (__tbIconIndex == __tbitem->iconId)\
00151             {\
00152                 tbAppendPlatformIcon(channel, doc->context.appId, __tbitem->iconId, ccVwrToolbar);\
00153                 break;\
00154             }\
00155             ++__tbitem;\
00156         }\
00157     }\
00158     __tbIconIndex = (int)iconID_pencolorbl + (int)erscribble_DEV_COLOR_BLACK - (int)doc->context.curStrokeStyle.color;\
00159     __tbitem = (ScbTBSItemPtr)doc->context.table->data;\
00160     if (erscribble_TBS_SELECT_LINE_COLOR == doc->context.curState)\
00161     {\
00162         for(__tbi = 0; __tbi < doc->context.table->len; ++__tbi)\
00163         {\
00164             if (erscribble_TBS_SELECT_LINE_COLOR == __tbitem->state)\
00165             {\
00166                 tbAppendPlatformIcon(channel, doc->context.appId, __tbitem->iconId, ccVwrToolbar);\
00167             }\
00168             ++__tbitem;\
00169         }\
00170         tbSetStatePlatformIcon(channel, doc->context.appId, __tbIconIndex, iconState_selected);\
00171     }\
00172     else\
00173     {\
00174         for(__tbi = 0; __tbi < doc->context.table->len; ++__tbi)\
00175         {\
00176             if (__tbIconIndex == __tbitem->iconId)\
00177             {\
00178                 tbAppendPlatformIcon(channel, doc->context.appId, __tbitem->iconId, ccVwrToolbar);\
00179                 break;\
00180             }\
00181             ++__tbitem;\
00182         }\
00183     }\
00184     __tbitem = (ScbTBSItemPtr)doc->context.table->data;\
00185     for(__tbi = 0; __tbi < doc->context.table->len; ++__tbi)\
00186     {\
00187         if (erscribble_TBS_ERASE == __tbitem->state)\
00188         {\
00189             tbAppendPlatformIcon(channel, doc->context.appId, __tbitem->iconId, ccVwrToolbar);\
00190         }\
00191         ++__tbitem;\
00192     }\
00193     if (erscribble_TBS_ERASE == doc->context.curState)\
00194     {\
00195         tbSetStatePlatformIcon(channel, doc->context.appId, iconID_eraseline, iconState_selected);\
00196     }\
00197 }
00198 
00199 //////////////////////////////////////////////////////////////////////////
00200 // take action when current state is scribble
00201 // action: !scribble
00202 // shrink all icons
00203 // set icon(only scribble) state to selected
00204 //////////////////////////////////////////////////////////////////////////
00205 #define ERSCRIBBLE_ACTION_SCRIBBLE(doc, channel, iconId)\
00206 {\
00207     if (ERSCRIBBLE_TBS_SCRIBBLE == doc->context.curState)\
00208     {\
00209         doc->context.curState = ERSCRIBBLE_TBS_NONE;\
00210     }\
00211     else\
00212     {\
00213         doc->context.curState = ERSCRIBBLE_TBS_SCRIBBLE;\
00214     }\
00215     ERSCRIBBLE_TOOLBAR_UPDATE(doc, channel)\
00216 }
00217 
00218 //////////////////////////////////////////////////////////////////////////
00219 // take action when current state is selecting pen size
00220 //////////////////////////////////////////////////////////////////////////
00221 #define ERSCRIBBLE_ACTION_SELECT_PEN_SIZE(doc, channel, iconId)\
00222 {\
00223     if (ERSCRIBBLE_TBS_SELECT_PEN_SIZE != doc->context.curState)\
00224     {\
00225         doc->context.curState = ERSCRIBBLE_TBS_SELECT_PEN_SIZE;\
00226     }\
00227     else\
00228     {\
00229         doc->context.curState = ERSCRIBBLE_TBS_SCRIBBLE;\
00230         doc->context.curStrokeStyle.penSize = ((int)iconId - (int)iconID_pen1pixel) * 2 + 1;\
00231     }\
00232     ERSCRIBBLE_TOOLBAR_UPDATE(doc, channel)\
00233 }    
00234 
00235 //////////////////////////////////////////////////////////////////////////
00236 // take action when current state is selecting line color
00237 //////////////////////////////////////////////////////////////////////////
00238 #define ERSCRIBBLE_ACTION_SELECT_LINE_COLOR(doc, channel, iconId)\
00239 {\
00240     if (ERSCRIBBLE_TBS_SELECT_LINE_COLOR != doc->context.curState)\
00241     {\
00242         doc->context.curState = ERSCRIBBLE_TBS_SELECT_LINE_COLOR;\
00243     }\
00244     else\
00245     {\
00246         doc->context.curState = ERSCRIBBLE_TBS_SCRIBBLE;\
00247         doc->context.curStrokeStyle.color = ERSCRIBBLE_DEV_COLOR_BLACK - ((int)iconId - (int)iconID_pencolorbl);\
00248     }\
00249     ERSCRIBBLE_TOOLBAR_UPDATE(doc, channel)\
00250 }
00251 
00252 //////////////////////////////////////////////////////////////////////////
00253 // take action when current state is erasing
00254 //////////////////////////////////////////////////////////////////////////
00255 #define ERSCRIBBLE_ACTION_ERASE(doc, channel, iconId)\
00256 {\
00257     if (ERSCRIBBLE_TBS_ERASE != doc->context.curState)\
00258     {\
00259         doc->context.curState = ERSCRIBBLE_TBS_ERASE;\
00260     }\
00261     else\
00262     {\
00263         doc->context.curState = ERSCRIBBLE_TBS_SCRIBBLE;\
00264     }\
00265     ERSCRIBBLE_TOOLBAR_UPDATE(doc, channel)\
00266 }
00267 
00268 //////////////////////////////////////////////////////////////////////////
00269 // receive command and change state according to current state and input state
00270 //////////////////////////////////////////////////////////////////////////
00271 #define ERSCRIBBLE_TOOLBAR_ON_RECEIVE_MSG(doc, channel, iconId)\
00272 {\
00273     if (iconID_pen == iconId)\
00274     {\
00275         ERSCRIBBLE_ACTION_SCRIBBLE(doc, channel, iconId);\
00276     }\
00277     else if ((int)iconID_pen1pixel <= iconId && (int)iconID_pen7pixel >= iconId)\
00278     {\
00279         ERSCRIBBLE_ACTION_SELECT_PEN_SIZE(doc, channel, iconId);\
00280     }\
00281     else if ((int)iconID_pencolorbl <= iconId && (int)iconID_pencolorwh >= iconId)\
00282     {\
00283         ERSCRIBBLE_ACTION_SELECT_LINE_COLOR(doc, channel, iconId);\
00284     }\
00285     else if (iconID_eraseline == iconId)\
00286     {\
00287         ERSCRIBBLE_ACTION_ERASE(doc, channel, iconId);\
00288     }\
00289 }
00290 
00291 
00292 #ifdef __cplusplus
00293 }
00294 #endif
00295 
00296 #endif 
Generated by  doxygen 1.6.2-20100208