notepad_utils.h

Go to the documentation of this file.
00001 #ifndef __NOTEPAD_UTILS_H__
00002 #define __NOTEPAD_UTILS_H__
00003 
00004 /**
00005  * File Name  : notepad_utils.h
00006  *
00007  * Description: notepad utility classes
00008  */
00009 
00010 /*
00011  * This file is part of notepad.
00012  *
00013  * notepad 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  * notepad 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) 2010 IREX Technologies B.V.
00029  * All rights reserved.
00030  */
00031  
00032 #include <glib.h>
00033 #include <gtk/gtk.h> // for gboolean
00034 #include <liberscribble/scb.h> // for draw_line
00035 
00036 
00037 namespace notepad 
00038 {
00039     typedef enum
00040     {
00041         NP_PORTRAIT = 0,
00042         NP_CLOCKWISE,
00043         NP_ANTICLOCKWISE
00044     } np_rotation;
00045 
00046     typedef enum
00047     {
00048         NP_OK = 0,
00049         NP_IS_NOT_DIR,
00050         NP_FILE_EXISTS,
00051         NP_CREATE_FAILED,
00052         NP_OPEN_FAILED,
00053         NP_CLOSE_FAILED,
00054         NP_READ_FAILED,
00055         NP_RENAME_FAILED,
00056         NP_DELETE_FAILED,
00057         NP_NO_DOCUMENT,
00058         NP_NO_FILENAME,
00059         NP_SAVE_FAILED,
00060         NP_ALLOC_FAILED,
00061         NP_NO_PAGE,
00062         NP_ERROR
00063     } np_result;
00064 
00065 
00066 
00067     class GCtx
00068     {
00069         private:
00070             int         size;
00071             gint32      color;
00072 
00073         public:
00074             GdkGC*      gc;         ///< X11 graphics context.
00075             np_rotation rotation;   ///< rotation
00076             int         width;      ///< width, max y when in landscape, max x otherwise
00077             int         height;     ///< height, max x when in landscape, max y otherwise
00078             int         margin;     ///< border
00079 
00080             GCtx() 
00081                 : size(0)
00082                 , gc(0)
00083                 , rotation(NP_PORTRAIT)
00084                 , width(0)
00085                 , height(0)
00086                 , margin(0)
00087             {
00088             }
00089 
00090             ~GCtx() 
00091             {
00092                 if (gc) { g_object_unref(gc); gc = 0; } 
00093             }
00094 
00095         private:
00096             GCtx(const GCtx& source);
00097             GCtx& operator=(const GCtx& source);
00098 
00099 
00100 
00101         public:
00102             void set_color(const ScbDevColor c);
00103 
00104             /// @brief Change the X11 gc to use new line attributes. 
00105             /// Currently, only change the width. Always use LineSolid.
00106             inline void set_line_attributes(const int width)
00107             {
00108                 this->size = width ;
00109 
00110                 gdk_gc_set_line_attributes(gc
00111                         , this->size
00112                         , GDK_LINE_SOLID
00113                         , GDK_CAP_PROJECTING
00114                         , GDK_JOIN_MITER);
00115             }
00116 
00117             /// @brief Draw line on image by using current line color, line width and 
00118             /// line style.
00119             void draw_line(GdkImage* image, const int x1, const int y1, const int x2, const int y2);
00120 
00121             inline void draw_line(GdkImage* image, const ScbPoint& p1, const ScbPoint& p2)
00122             {
00123                 draw_line(image, p1.x, p1.y, p2.x, p2.y);
00124             }
00125 
00126             void draw_brush(GdkImage* image, const int x, const int y);
00127             void draw_points(GdkImage* image, const GdkPoint* shape, const int npoints_in_shape);
00128     };
00129 
00130     /// Point structure.
00131     struct Point
00132     {
00133         Point()
00134             : x(0), y(0)
00135         {}
00136 
00137         Point(const int ptx, const int pty)
00138             : x(ptx), y(pty)
00139         {}
00140 
00141         void reset(const int ptx, const int pty)
00142         {
00143             x = ptx; y = pty;
00144         }
00145 
00146         void move_x(const int ptx)
00147         {
00148             x = ptx;
00149         }
00150 
00151         void move_y(const int pty)
00152         {
00153             y = pty;
00154         }
00155 
00156         void move(const int x_offset, const int y_offset)
00157         {
00158             x += x_offset;
00159             y += y_offset;
00160         }
00161 
00162         int x, y;
00163     };
00164 
00165 }
00166 
00167 #endif // __NOTEPAD_UTILS_H__
Generated by  doxygen 1.6.2-20100208