- 主函数
int main( int argc, char *argv[] ) { gtk_init( &argc, &argv ); dsFrame frm; frm.show(); gtk_main(); return 0; }
- base 类定义
class dsBase { public: dsBase(); GtkWidget* win( void ) { return p_win; } dsShell* shell( void ) { return p_shell; } protected: void draw_round_rect( cairo_t *cr, int w, int h, int r = 10, bool bclose = true, int x = 0, int y = 0 ); void win( GtkWidget *p ) { p_win = p; } private: GtkWidget *p_win; };
base 类实现
dsBase::dsBase( dsShell *p/* = 0*/ ) : p_win( 0 ) { } void dsBase::draw_round_rect( cairo_t *cr, int w, int h, int r /*= 10*/, bool bclose /* = true*/, int x /* = 0*/, int y /* = 0*/ ) { cairo_move_to( cr, x, y + r ); cairo_arc( cr, x + r, y + r, r, 180 * ( M_PI / 180.0 ), 270 * ( M_PI / 180.0 ) ); cairo_move_to( cr, x, y + r ); cairo_line_to( cr, x, y + h ); if ( bclose ) { cairo_line_to( cr, x + w, y + h ); } else { cairo_move_to( cr, x + w, y + h ); } cairo_line_to( cr, x + w, y + r ); cairo_arc_negative( cr, x + w - r, y + r, r, 0 * ( M_PI / 180.0 ), 270 * ( M_PI / 180.0 ) ); cairo_line_to( cr, x + r, y ); }
frame 类定义
class dsFrame : public dsBase { public: dsFrame( int w = 600, int h = 500 ); ~dsFrame(); void show( void ); private: static bool on_expose( GtkWidget* widget, GdkEventExpose *event, gpointer data ); static bool on_configure( GtkWidget* widget, GdkEventConfigure* event, gpointer data ); static bool on_button_press( GtkWidget* widget, GdkEventButton * event, gpointer data ); static bool on_move( GtkWidget* widget, GdkEventMotion *event, gpointer data ); static bool on_screen_changed( GtkWidget *widget, GdkScreen *old_screen, gpointer userdata ); GdkRectangle close_rect( GtkWidget *widget ); GdkRectangle max_rect( GtkWidget *widget ); GdkRectangle min_rect( GtkWidget *widget ); bool point_inside( const GdkRectangle &rect, int x, int y ); bool bottom_right( int x, int y ); bool bottom_left( int x, int y ); bool top_right( int x, int y ); bool top_left( int x, int y ); bool top( int x, int y ); bool bottom( int x, int y ); bool left( int x, int y ); bool right( int x, int y ); bool title( int x, int y ); bool min( int x, int y ); bool max( int x, int y ); bool close( int x, int y ); bool update( void ) const { return b_update; } bool max( void ) const { return b_max; } void update( bool v ) { b_update = v; } void max( bool v ) { b_max = v; } private: bool b_update; bool b_max; };
frmae类实现
dsFrame:
自绘标题栏,不规则窗口,背景透明
最新推荐文章于 2023-04-09 12:00:52 发布