00001 #ifndef __NOTEPAD_UTILS_H__
00002 #define __NOTEPAD_UTILS_H__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <glib.h>
00033 #include <gtk/gtk.h>
00034 #include <liberscribble/scb.h>
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;
00075 np_rotation rotation;
00076 int width;
00077 int height;
00078 int margin;
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
00105
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
00118
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
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__