GtkMgr Class Reference

#include <GtkMgr.h>

List of all members.

Public Member Functions

void dfb_copyImage (unsigned char *mem, SplashBitmap *bitmap, int xSrc=0, int ySrc=0, int xDest=0, int yDest=0, int width=-1, int height=-1)
 GtkMgr (void)
 ~GtkMgr (void)
void setupWindow ()
void clearBkground ()
void drawImage (SplashBitmap *bitmap, int xSrc=0, int ySrc=0, int xDest=0, int yDest=0, int width=-1, int height=-1, GBool bDrawBorder=gTrue)
void setLineColor (const int color)
void setLineAttributes (const int width, const int style=LineSolid)
void drawLine (const int x1, const int y1, const int x2, const int y2)

Public Attributes

GtkWidget * window
GdkGC * gc
GdkDrawable * pixmap
Display * display
Visual * visual
int screenNum
int depth
GdkColor lineColor
int bkColor
unsigned char * fb_mem
int fb


Detailed Description

Definition at line 10 of file GtkMgr.h.


Constructor & Destructor Documentation

GtkMgr::GtkMgr ( void   ) 

Definition at line 32 of file GtkMgr.cpp.

00033 : window(NULL)
00034 , gc(NULL)
00035 , pixmap(NULL)
00036 , visual(NULL)
00037 , bkColor(-1)
00038 , fb_mem(NULL)
00039 , fb(0)
00040 {
00041     fb = open ("/dev/fb0", O_RDWR);
00042     fb_mem = (unsigned char *)mmap(NULL, SCREEN_WIDTH * CLIENT_AREA, PROT_READ|PROT_WRITE,MAP_SHARED,fb,0);
00043 }

GtkMgr::~GtkMgr ( void   ) 

Definition at line 45 of file GtkMgr.cpp.

00046 {
00047     munmap(fb_mem, SCREEN_WIDTH * CLIENT_AREA);
00048     close(fb);
00049 }


Member Function Documentation

void GtkMgr::dfb_copyImage ( unsigned char *  mem,
SplashBitmap *  bitmap,
int  xSrc = 0,
int  ySrc = 0,
int  xDest = 0,
int  yDest = 0,
int  width = -1,
int  height = -1 
)

Definition at line 103 of file GtkMgr.cpp.

00107 {
00108     // PV_LOGPRINTF("xSrc %d ySrc %d xDest %d yDest %d width %d height %d\n", xSrc, ySrc, 
00109     //    xDest, yDest, width, height);
00110     if (width < 0) 
00111     {
00112         width = bitmap->getWidth();
00113     }       
00114     if (height < 0) 
00115     {
00116         height = bitmap->getHeight();
00117     }       
00118 
00119     if (xDest < 0) 
00120     {
00121         xSrc -= xDest; width += xDest; xDest = 0; 
00122     }
00123     else if (xDest > SCREEN_WIDTH) 
00124     {
00125         return;
00126     }
00127     
00128     if (yDest < 0) 
00129     { 
00130         ySrc -= yDest; height += yDest; yDest = 0; 
00131     }
00132     else if (yDest > CLIENT_AREA) 
00133     {
00134         return;
00135     }
00136 
00137     if (xDest + width >= SCREEN_WIDTH) { width = SCREEN_WIDTH - xDest; }
00138     if (yDest + height >= CLIENT_AREA) { height = CLIENT_AREA - yDest; }
00139 
00140     unsigned char *p = (unsigned char *)(bitmap->getDataPtr() + ySrc * bitmap->getRowSize() + xSrc);
00141     mem = mem + yDest * SCREEN_WIDTH + xDest;
00142 
00143     // PV_LOGPRINTF("xSrc %d ySrc %d xDest %d yDest %d width %d height %d\n", xSrc, ySrc, 
00144     //    xDest, yDest, width, height);
00145 
00146     for(int i = 0; i < height; ++i)
00147     {
00148         memcpy(mem, p, width);
00149         p += bitmap->getRowSize();
00150         mem += SCREEN_WIDTH;
00151     }
00152 }

void GtkMgr::setupWindow (  ) 

Definition at line 51 of file GtkMgr.cpp.

00052 {
00053     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00054     gtk_window_set_title(GTK_WINDOW(window), PACKAGE " " VERSION );
00055     gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
00056     gtk_container_set_border_width(GTK_CONTAINER(window), 0);
00057     gtk_widget_set_size_request(GTK_WIDGET(window), SCREEN_WIDTH, SCREEN_HEIGHT - TOOLBAR_HEIGTH - PAGEBAR_HEIGHT);
00058     gtk_window_set_modal(GTK_WINDOW(window), FALSE);
00059     gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
00060     gtk_widget_set_events (window,
00061         GDK_EXPOSURE_MASK | GDK_BUTTON_MOTION_MASK |
00062         GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
00063         GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
00064 
00065     // disable double buffering
00066     GTK_WIDGET_UNSET_FLAGS(window, GTK_DOUBLE_BUFFERED);        
00067     
00068     gtk_widget_show(window);
00069 
00070     pixmap = gdk_pixmap_new (window->window,
00071         window->allocation.width,
00072         window->allocation.height, -1);
00073     gc = gdk_gc_new (pixmap);
00074     lineColor.pixel = gdk_rgb_xpixel_from_rgb (0x0);
00075     gdk_gc_set_foreground(gc, &lineColor);
00076     
00077     // init
00078     display = gdk_x11_display_get_xdisplay(gdk_display_get_default());
00079     screenNum = DefaultScreen(display);
00080     visual = DefaultVisual(display, screenNum);
00081 
00082     // hide cursor
00083     Pixmap bm_no;
00084     Colormap cmap;
00085     Cursor no_ptr;
00086     XColor black, dummy;
00087     static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
00088 
00089     cmap = DefaultColormap(display, DefaultScreen(display));
00090     XAllocNamedColor(display, cmap, "black", &black, &dummy);
00091     bm_no = XCreateBitmapFromData(display, GDK_WINDOW_XWINDOW(window->window), bm_no_data, 8, 8);
00092     no_ptr = XCreatePixmapCursor(display, bm_no, bm_no, &black, &black, 0, 0);
00093 
00094     XDefineCursor(display, GDK_WINDOW_XWINDOW(window->window), no_ptr);
00095     XFreeCursor(display, no_ptr);
00096     if (bm_no != None)
00097     {
00098         XFreePixmap(display, bm_no);
00099     }        
00100     XFreeColors(display, cmap, &black.pixel, 1, 0);
00101 }

void GtkMgr::clearBkground (  ) 

Definition at line 154 of file GtkMgr.cpp.

00155 {
00156     memset(fb_mem, bkColor, SCREEN_WIDTH * CLIENT_AREA);
00157 }

void GtkMgr::drawImage ( SplashBitmap *  bitmap,
int  xSrc = 0,
int  ySrc = 0,
int  xDest = 0,
int  yDest = 0,
int  width = -1,
int  height = -1,
GBool  bDrawBorder = gTrue 
)

Definition at line 159 of file GtkMgr.cpp.

00164 {
00165     if (bitmap) 
00166     {
00167         if (width < 0) width = bitmap->getWidth();
00168         if (height < 0) height = bitmap->getHeight();
00169 
00170         dfb_copyImage(fb_mem, bitmap, xSrc, ySrc, xDest, yDest, width, height);
00171 
00172         if (bDrawBorder)
00173         {
00174             // line 
00175             XSetForeground(display, GDK_GC_XGC(gc), 0);
00176             XSetLineAttributes(display, GDK_GC_XGC(gc), 1, LineSolid, CapProjecting, JoinMiter);
00177             XDrawRectangle(display, GDK_WINDOW_XWINDOW(window->window), GDK_GC_XGC(gc), 
00178                 xDest, yDest, width, height);
00179         }
00180     } 
00181 }

Here is the call graph for this function:

void GtkMgr::setLineColor ( const int  color  ) 

Definition at line 183 of file GtkMgr.cpp.

00184 {
00185     XSetForeground(display, GDK_GC_XGC(gc), color);
00186 }

void GtkMgr::setLineAttributes ( const int  width,
const int  style = LineSolid 
)

Definition at line 188 of file GtkMgr.cpp.

00189 {
00190     XSetLineAttributes(display, GDK_GC_XGC(gc), width, style, CapProjecting, JoinMiter);
00191 }

void GtkMgr::drawLine ( const int  x1,
const int  y1,
const int  x2,
const int  y2 
)

Definition at line 193 of file GtkMgr.cpp.

00194 {
00195     XDrawLine(display, GDK_WINDOW_XWINDOW(window->window), GDK_GC_XGC(gc), x1, y1, x2, y2);
00196 }


Member Data Documentation

GtkWidget* GtkMgr::window

Definition at line 13 of file GtkMgr.h.

GdkGC* GtkMgr::gc

Definition at line 14 of file GtkMgr.h.

GdkDrawable* GtkMgr::pixmap

Definition at line 15 of file GtkMgr.h.

Display* GtkMgr::display

Definition at line 16 of file GtkMgr.h.

Visual* GtkMgr::visual

Definition at line 17 of file GtkMgr.h.

Definition at line 18 of file GtkMgr.h.

Definition at line 21 of file GtkMgr.h.

Definition at line 22 of file GtkMgr.h.

Definition at line 23 of file GtkMgr.h.

unsigned char* GtkMgr::fb_mem

Definition at line 26 of file GtkMgr.h.

Definition at line 27 of file GtkMgr.h.


The documentation for this class was generated from the following files:

Generated on Wed Feb 4 18:26:35 2009 by  doxygen 1.5.6