コード例 #1
0
ファイル: bitmap.cpp プロジェクト: gitrider/wxsj2
bool wxBitmap::CreateFromXpm( const char **bits )
{
    UnRef();

    wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") )

    GdkVisual *visual = wxTheApp->GetGdkVisual();

    m_refData = new wxBitmapRefData();

    GdkBitmap *mask = (GdkBitmap*) NULL;

    M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( wxGetRootWindow()->window, &mask, NULL, (gchar **) bits );

    wxCHECK_MSG( M_BMPDATA->m_pixmap, FALSE, wxT("couldn't create pixmap") );

    if (mask)
    {
        M_BMPDATA->m_mask = new wxMask();
        M_BMPDATA->m_mask->m_bitmap = mask;
    }

    gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );

    M_BMPDATA->m_bpp = visual->depth;  // Can we get a different depth from create_from_xpm_d() ?

    return TRUE;
}
コード例 #2
0
ファイル: bitmap.cpp プロジェクト: gitrider/wxsj2
bool wxBitmap::Create( int width, int height, int depth )
{
    UnRef();

    if ( width <= 0 || height <= 0 )
    {
        return false;
    }

    GdkVisual *visual = wxTheApp->GetGdkVisual();

    if (depth == -1)
        depth = visual->depth;

    wxCHECK_MSG( (depth == visual->depth) || (depth == 1) || (depth == 32), FALSE,
                    wxT("invalid bitmap depth") )

    m_refData = new wxBitmapRefData();
    M_BMPDATA->m_mask = (wxMask *) NULL;
    M_BMPDATA->m_width = width;
    M_BMPDATA->m_height = height;
    if (depth == 1)
    {
        M_BMPDATA->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 );
        M_BMPDATA->m_bpp = 1;
    }
#ifdef __WXGTK20__
    else if (depth == 32)
    {
        M_BMPDATA->m_pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, true,
                                              8, width, height);
        M_BMPDATA->m_bpp = 32;
    }
#endif
    else
    {
        M_BMPDATA->m_pixmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, depth );
        M_BMPDATA->m_bpp = visual->depth;
    }

    return Ok();
}
コード例 #3
0
ファイル: fontenum.cpp プロジェクト: AlexHayton/decoda
bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
                                          bool fixedWidthOnly)
{
    if ( encoding != wxFONTENCODING_SYSTEM && encoding != wxFONTENCODING_UTF8 )
    {
        // Pango supports only UTF-8 encoding (and system means any, so we
        // accept it too)
        return false;
    }

#if defined(__WXGTK20__) || !defined(HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE)
    if ( fixedWidthOnly
#if defined(__WXGTK24__)
        && (gtk_check_version(2,4,0) != NULL)
#endif
       )
    {
        OnFacename( wxT("monospace") );
    }
    else // !fixedWidthOnly
#endif // __WXGTK20__ || !HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE
    {
        PangoFontFamily **families = NULL;
        gint n_families = 0;
        pango_context_list_families (
#ifdef __WXGTK20__
            gtk_widget_get_pango_context( wxGetRootWindow() ),
#else
            wxTheApp->GetPangoContext(),
#endif
            &families, &n_families );
        qsort (families, n_families, sizeof (PangoFontFamily *), wxCompareFamilies);

        for (int i=0; i<n_families; i++)
        {
#if defined(__WXGTK24__) || defined(HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE)
            if (!fixedWidthOnly || (
#ifdef __WXGTK24__
                !gtk_check_version(2,4,0) &&
#endif
                pango_font_family_is_monospace(families[i])
                                   ) )
#endif
            {
                const gchar *name = pango_font_family_get_name(families[i]);
                OnFacename(wxString(name, wxConvUTF8));
            }
        }
        g_free(families);
    }

    return true;
}
コード例 #4
0
ファイル: bitmap.cpp プロジェクト: gitrider/wxsj2
// conversion to mono bitmap:
bool wxBitmap::CreateFromImageAsBitmap(const wxImage& img)
{
    // convert alpha channel to mask, if it is present:
    wxImage image(img);
    image.ConvertAlphaToMask();
    
    int width = image.GetWidth();
    int height = image.GetHeight();

    SetHeight( height );
    SetWidth( width );

    SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) );

    SetDepth( 1 );

    GdkVisual *visual = wxTheApp->GetGdkVisual();

    // Create picture image

    unsigned char *data_data = (unsigned char*)malloc( ((width >> 3)+8) * height );

    GdkImage *data_image =
        gdk_image_new_bitmap( visual, data_data, width, height );

    // Create mask image

    GdkImage *mask_image = (GdkImage*) NULL;

    if (image.HasMask())
    {
        unsigned char *mask_data = (unsigned char*)malloc( ((width >> 3)+8) * height );

        mask_image =  gdk_image_new_bitmap( visual, mask_data, width, height );

        wxMask *mask = new wxMask();
        mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 );

        SetMask( mask );
    }
コード例 #5
0
ファイル: app.cpp プロジェクト: SCP-682/Cities3D
GdkVisual *wxApp::GetGdkVisual()
{
    GdkVisual *visual = NULL;

    if (m_glVisualInfo)
        visual = gdkx_visual_get( ((XVisualInfo *) m_glVisualInfo)->visualid );
    else
        visual = gdk_drawable_get_visual( wxGetRootWindow()->window );

    wxASSERT( visual );

    return visual;
}
コード例 #6
0
ファイル: CaptureEvents.cpp プロジェクト: LBoggino/audacity
CaptureEvents::~CaptureEvents()
{
   gdk_event_handler_set((GdkEventFunc)gtk_main_do_event, NULL, NULL);

   // put all unprocessed GDK events back in the queue
   GdkDisplay* disp = gtk_widget_get_display(wxGetRootWindow());
   size_t cnt = queue.GetCount();
   for (size_t i = 0; i < cnt; i++) {
      GdkEvent* event = (GdkEvent*)queue[i];
      // NOTE: gdk_display_put_event makes a copy of the event passed to it
      gdk_display_put_event(disp, event);
      gdk_event_free(event);
   }

#if wxUSE_LOG
   // let the logs be flashed again
   wxLog::Resume();
#endif
}
コード例 #7
0
ファイル: display.cpp プロジェクト: hazeeq090576/wxWidgets
void wxClientDisplayRect(int* x, int* y, int* width, int* height)
{
#if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
    GdkRectangle rect = { 0, 0, 672, 396 };
#else
    GdkRectangle rect;
    GdkWindow* window = gtk_widget_get_window(wxGetRootWindow());
    GdkScreen* screen = gdk_window_get_screen(window);
    int monitor = gdk_screen_get_monitor_at_window(screen, window);
    gdk_screen_get_monitor_workarea(screen, monitor, &rect);
#endif
    if (x)
        *x = rect.x;
    if (y)
        *y = rect.y;
    if (width)
        *width = rect.width;
    if (height)
        *height = rect.height;
}
コード例 #8
0
ファイル: cursor.cpp プロジェクト: CobaltBlues/wxWidgets
void wxCursor::InitFromImage( const wxImage & image )
{
    const int w = image.GetWidth();
    const int h = image.GetHeight();
    const guchar* alpha = image.GetAlpha();
    const bool hasMask = image.HasMask();
    int hotSpotX = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
    int hotSpotY = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
    if (hotSpotX < 0 || hotSpotX > w) hotSpotX = 0;
    if (hotSpotY < 0 || hotSpotY > h) hotSpotY = 0;
    GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image.GetData(), GDK_COLORSPACE_RGB, false, 8, w, h, w * 3, NULL, NULL);
    if (alpha || hasMask)
    {
        guchar r = 0, g = 0, b = 0;
        if (hasMask)
        {
            r = image.GetMaskRed();
            g = image.GetMaskGreen();
            b = image.GetMaskBlue();
        }
        GdkPixbuf* pixbuf0 = pixbuf;
        pixbuf = gdk_pixbuf_add_alpha(pixbuf, hasMask, r, g, b);
        g_object_unref(pixbuf0);
        if (alpha)
        {
            guchar* d = gdk_pixbuf_get_pixels(pixbuf);
            const int stride = gdk_pixbuf_get_rowstride(pixbuf);
            for (int j = 0; j < h; j++, d += stride)
                for (int i = 0; i < w; i++, alpha++)
                    if (d[4 * i + 3])
                        d[4 * i + 3] = *alpha;
        }
    }
    m_refData = new wxCursorRefData;
    M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixbuf(gtk_widget_get_display(wxGetRootWindow()), pixbuf, hotSpotX, hotSpotY);
    g_object_unref(pixbuf);
}
コード例 #9
0
ファイル: bitmap.cpp プロジェクト: gitrider/wxsj2
bool wxMask::Create( const wxBitmap& bitmap )
{
    if (m_bitmap)
    {
        gdk_bitmap_unref( m_bitmap );
        m_bitmap = (GdkBitmap*) NULL;
    }

    if (!bitmap.Ok()) return FALSE;

    wxCHECK_MSG( bitmap.GetBitmap(), FALSE, wxT("Cannot create mask from colour bitmap") );

    m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, bitmap.GetWidth(), bitmap.GetHeight(), 1 );

    if (!m_bitmap) return FALSE;

    GdkGC *gc = gdk_gc_new( m_bitmap );

    gdk_wx_draw_bitmap( m_bitmap, gc, bitmap.GetBitmap(), 0, 0, 0, 0, bitmap.GetWidth(), bitmap.GetHeight() );

    gdk_gc_unref( gc );

    return TRUE;
}
コード例 #10
0
ファイル: bitmap.cpp プロジェクト: AaronDP/wxWidgets
bool wxBitmapRefData::Create(int width, int height, int bpp)
{
    m_width = width;
    m_height = height;
    m_bpp = bpp;

    m_mask = NULL;
#if wxUSE_PALETTE
    m_palette = NULL;
#endif

    // to understand how this compiles you should know that GdkPixmap and
    // GdkBitmap are one and the same type in GTK+ 1
    GdkPixmap **ppix;
    if ( m_bpp != 1 )
    {
        const GdkVisual * const visual = wxTheApp->GetGdkVisual();

        wxCHECK_MSG( (bpp == -1) || (bpp == visual->depth) || (bpp == 32), false,
                        wxT("invalid bitmap depth") );

        m_bpp = visual->depth;

        ppix = &m_pixmap;
        m_bitmap = NULL;
    }
    else // mono bitmap
    {
        ppix = &m_bitmap;
        m_pixmap = NULL;
    }

    *ppix = gdk_pixmap_new( wxGetRootWindow()->window, width, height, m_bpp );

    return *ppix != NULL;
}
コード例 #11
0
ファイル: evtloop.cpp プロジェクト: jonntd/dynamica
bool wxGUIEventLoop::YieldFor(long eventsToProcess)
{
#if wxUSE_THREADS
    if ( !wxThread::IsMain() )
    {
        // can't call gtk_main_iteration() from other threads like this
        return true;
    }
#endif // wxUSE_THREADS

    m_isInsideYield = true;
    m_eventsToProcessInsideYield = eventsToProcess;

#if wxUSE_LOG
    // disable log flushing from here because a call to wxYield() shouldn't
    // normally result in message boxes popping up &c
    wxLog::Suspend();
#endif

    // temporarily replace the global GDK event handler with our function, which
    // categorizes the events and using m_eventsToProcessInsideYield decides
    // if an event should be processed immediately or not
    // NOTE: this approach is better than using gdk_display_get_event() because
    //       gtk_main_iteration() does more than just calling gdk_display_get_event()
    //       and then call gtk_main_do_event()!
    //       In particular in this way we also process input from sources like
    //       GIOChannels (this is needed for e.g. wxGUIAppTraits::WaitForChild).
    gdk_event_handler_set ((GdkEventFunc)wxgtk_main_do_event, this, NULL);
    while (Pending())   // avoid false positives from our idle source
        gtk_main_iteration();
    gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);

    if (eventsToProcess != wxEVT_CATEGORY_CLIPBOARD)
    {
        // It's necessary to call ProcessIdle() to update the frames sizes which
        // might have been changed (it also will update other things set from
        // OnUpdateUI() which is a nice (and desired) side effect). But we
        // call ProcessIdle() only once since this is not meant for longish
        // background jobs (controlled by wxIdleEvent::RequestMore() and the
        // return value of Processidle().
        ProcessIdle();      // ProcessIdle() also calls ProcessPendingEvents()
    }
    //else: if we are inside ~wxClipboardSync() and we call ProcessIdle() and
    //      the user app contains an UI update handler which calls wxClipboard::IsSupported,
    //      then we fall into a never-ending loop...

    // put all unprocessed GDK events back in the queue
    GdkDisplay* disp = gtk_widget_get_display(wxGetRootWindow());
    for (size_t i=0; i<m_arrGdkEvents.GetCount(); i++)
    {
        GdkEvent* ev = (GdkEvent*)m_arrGdkEvents[i];

        // NOTE: gdk_display_put_event makes a copy of the event passed to it
        gdk_display_put_event(disp, ev);
        gdk_event_free(ev);
    }

    m_arrGdkEvents.Clear();

#if wxUSE_LOG
    // let the logs be flashed again
    wxLog::Resume();
#endif

    m_isInsideYield = false;

    return true;
}
コード例 #12
0
ファイル: bitmap.cpp プロジェクト: gitrider/wxsj2
wxBitmap wxBitmap::Rescale( int clipx, int clipy, int clipwidth, int clipheight, int newx, int newy )
{
    wxCHECK_MSG( Ok(), wxNullBitmap, wxT("invalid bitmap") );

    if (newy==M_BMPDATA->m_width && newy==M_BMPDATA->m_height)
        return *this;
    
    int width = wxMax(newx, 1);
    int height = wxMax(newy, 1);
    width = wxMin(width, clipwidth);
    height = wxMin(height, clipheight);
        
    wxBitmap bmp;

#ifdef __WXGTK20__
    if (HasPixbuf())
    {
        bmp.SetWidth(width);
        bmp.SetHeight(height);
        bmp.SetDepth(GetDepth());
        bmp.SetPixbuf(gdk_pixbuf_new(GDK_COLORSPACE_RGB,
                                     gdk_pixbuf_get_has_alpha(GetPixbuf()),
                                     8, width, height));
        gdk_pixbuf_scale(GetPixbuf(), bmp.GetPixbuf(),
                         0, 0, width, height,
                         clipx, clipy, 
                         (double)newx/GetWidth(), (double)newy/GetHeight(),
                         GDK_INTERP_BILINEAR);
    }
    else
#endif // __WXGTK20__
    {
        GdkImage *img = (GdkImage*) NULL;
        if (GetPixmap())
            img = gdk_image_get( GetPixmap(), 0, 0, GetWidth(), GetHeight() );
        else if (GetBitmap())
            img = gdk_image_get( GetBitmap(), 0, 0, GetWidth(), GetHeight() );
        else
            wxFAIL_MSG( wxT("Ill-formed bitmap") );

        wxCHECK_MSG( img, wxNullBitmap, wxT("couldn't create image") );

        int bpp = -1;

        
        GdkGC *gc = NULL;
        GdkPixmap *dstpix = NULL;
        if (GetPixmap())
        {
            GdkVisual *visual = gdk_window_get_visual( GetPixmap() );
            if (visual == NULL)
                visual = wxTheApp->GetGdkVisual();

            bpp = visual->depth;
            bmp = wxBitmap(width,height,bpp);
            dstpix = bmp.GetPixmap();
            gc = gdk_gc_new( dstpix );
        }

        char *dst = NULL;
        long dstbyteperline = 0;
        
        if (GetBitmap())
        {
            bpp = 1;
            dstbyteperline = width/8*M_BMPDATA->m_bpp;
            if (width*M_BMPDATA->m_bpp % 8 != 0)
                dstbyteperline++;
            dst = (char*) malloc(dstbyteperline*height);
        }
                 
        // be careful to use the right scaling factor
        float scx = (float)M_BMPDATA->m_width/(float)newx;
        float scy = (float)M_BMPDATA->m_height/(float)newy;
        // prepare accel-tables
        int *tablex = (int *)calloc(width,sizeof(int));
        int *tabley = (int *)calloc(height,sizeof(int));

        // accel table filled with clipped values
        for (int x = 0; x < width; x++)
            tablex[x] = (int) (scx * (x+clipx));
        for (int y = 0; y < height; y++)
            tabley[y] = (int) (scy * (y+clipy));

        // Main rescaling routine starts here
        for (int h = 0; h < height; h++)
        {
            char outbyte = 0;
            int old_x = -1;
            guint32 old_pixval = 0;

            for (int w = 0; w < width; w++)
            {
                guint32 pixval;
                int x = tablex[w];
                if (x == old_x)
                    pixval = old_pixval;
                else
                {
                    pixval = gdk_image_get_pixel( img, x, tabley[h] );
                    old_pixval = pixval;
                    old_x = x;
                }
                    
                if (bpp == 1)
                {
                    if (!pixval)
                    {
                        char bit=1;
                        char shift = bit << w % 8;
                        outbyte |= shift;
                    }
                    
                    if ((w+1)%8==0)
                    {
                        dst[h*dstbyteperline+w/8] = outbyte;
                        outbyte = 0;
                    }
                }
                else
                {
                    GdkColor col;
                    col.pixel = pixval;
                    gdk_gc_set_foreground( gc, &col );
                    gdk_draw_point( dstpix, gc, w, h);
                }
            }
        
            // do not forget the last byte
            if ((bpp == 1) && (width % 8 != 0))
                dst[h*dstbyteperline+width/8] = outbyte;
        }
        
        gdk_image_destroy( img );
        if (gc) gdk_gc_unref( gc );

        if (bpp == 1)
        {
            bmp = wxBitmap( (const char *)dst, width, height, 1 );
            free( dst );
        }
        
        if (GetMask())
        {
            dstbyteperline = width/8;
            if (width % 8 != 0)
                dstbyteperline++;
            dst = (char*) malloc(dstbyteperline*height);
            img = gdk_image_get( GetMask()->GetBitmap(), 0, 0, GetWidth(), GetHeight() );

            for (int h = 0; h < height; h++)
            {
                char outbyte = 0;
                int old_x = -1;
                guint32 old_pixval = 0;
        
                for (int w = 0; w < width; w++)
                {
                    guint32 pixval;
                    int x = tablex[w];
                    if (x == old_x)
                        pixval = old_pixval;
                    else
                    {
                        pixval = gdk_image_get_pixel( img, x, tabley[h] );
                        old_pixval = pixval;
                        old_x = x;
                    }
                    
                    if (pixval)
                    {
                        char bit=1;
                        char shift = bit << w % 8;
                        outbyte |= shift;
                    }
                    
                    if ((w+1)%8 == 0)
                    {
                        dst[h*dstbyteperline+w/8] = outbyte;
                        outbyte = 0;
                    }
                }
            
                // do not forget the last byte
                if (width % 8 != 0)
                    dst[h*dstbyteperline+width/8] = outbyte;
            }
            wxMask* mask = new wxMask;
            mask->m_bitmap = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) dst, width, height );
            bmp.SetMask(mask);

            free( dst );
            gdk_image_destroy( img );
        }

        free( tablex );
        free( tabley );
    }
    
    return bmp; 
}
コード例 #13
0
int wxDisplayDepth()
{
    return gdk_drawable_get_visual( wxGetRootWindow()->window )->depth;
}
コード例 #14
0
ファイル: utilsgtk.cpp プロジェクト: Annovae/Dolphin-Core
void wxGetMousePosition( int* x, int* y )
{
    gdk_window_get_pointer(gtk_widget_get_root_window(wxGetRootWindow()), x, y, NULL);
}
コード例 #15
0
ファイル: utilsgtk.cpp プロジェクト: Annovae/Dolphin-Core
int wxDisplayDepth()
{
    return gtk_widget_get_visual(wxGetRootWindow())->depth;
}
コード例 #16
0
ファイル: cursor.cpp プロジェクト: CobaltBlues/wxWidgets
wxCursor::wxCursor(const char bits[], int width, int height,
                   int hotSpotX, int hotSpotY,
                   const char maskBits[], const wxColour *fg, const wxColour *bg)
{
    m_refData = new wxCursorRefData;
    if (hotSpotX < 0 || hotSpotX >= width)
        hotSpotX = 0;
    if (hotSpotY < 0 || hotSpotY >= height)
        hotSpotY = 0;
#ifdef __WXGTK3__
    wxBitmap bitmap(bits, width, height);
    if (maskBits)
        bitmap.SetMask(new wxMask(wxBitmap(maskBits, width, height)));
    GdkPixbuf* pixbuf = bitmap.GetPixbuf();
    if (fg || bg)
    {
        const int stride = gdk_pixbuf_get_rowstride(pixbuf);
        const int n_channels = gdk_pixbuf_get_n_channels(pixbuf);
        guchar* data = gdk_pixbuf_get_pixels(pixbuf);
        for (int j = 0; j < height; j++, data += stride)
        {
            guchar* p = data;
            for (int i = 0; i < width; i++, p += n_channels)
            {
                if (p[0])
                {
                    if (fg)
                    {
                        p[0] = fg->Red();
                        p[1] = fg->Green();
                        p[2] = fg->Blue();
                    }
                }
                else
                {
                    if (bg)
                    {
                        p[0] = bg->Red();
                        p[1] = bg->Green();
                        p[2] = bg->Blue();
                    }
                }
            }
        }
    }
    M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixbuf(gtk_widget_get_display(wxGetRootWindow()), pixbuf, hotSpotX, hotSpotY);
#else
    if (!maskBits)
        maskBits = bits;
    if (!fg)
        fg = wxBLACK;
    if (!bg)
        bg = wxWHITE;

    GdkBitmap* data = gdk_bitmap_create_from_data(
        gtk_widget_get_window(wxGetRootWindow()), const_cast<char*>(bits), width, height);
    GdkBitmap* mask = gdk_bitmap_create_from_data(
        gtk_widget_get_window(wxGetRootWindow()), const_cast<char*>(maskBits), width, height);

    M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixmap(
                 data, mask, fg->GetColor(), bg->GetColor(),
                 hotSpotX, hotSpotY );

    g_object_unref (data);
    g_object_unref (mask);
#endif
}
コード例 #17
0
ファイル: bitmap.cpp プロジェクト: gitrider/wxsj2
bool wxMask::Create( const wxBitmap& bitmap,
                     const wxColour& colour )
{
    if (m_bitmap)
    {
        gdk_bitmap_unref( m_bitmap );
        m_bitmap = (GdkBitmap*) NULL;
    }

    wxImage image = bitmap.ConvertToImage();
    if (!image.Ok()) return FALSE;

    m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, image.GetWidth(), image.GetHeight(), 1 );
    GdkGC *gc = gdk_gc_new( m_bitmap );

    GdkColor color;
    color.red = 65000;
    color.green = 65000;
    color.blue = 65000;
    color.pixel = 1;
    gdk_gc_set_foreground( gc, &color );
    gdk_gc_set_fill( gc, GDK_SOLID );
    gdk_draw_rectangle( m_bitmap, gc, TRUE, 0, 0, image.GetWidth(), image.GetHeight() );

    unsigned char *data = image.GetData();
    int index = 0;

    unsigned char red = colour.Red();
    unsigned char green = colour.Green();
    unsigned char blue = colour.Blue();

    GdkVisual *visual = wxTheApp->GetGdkVisual();

    int bpp = visual->depth;
    if ((bpp == 16) && (visual->red_mask != 0xf800))
        bpp = 15;
    if (bpp == 15)
    {
        red = red & 0xf8;
        green = green & 0xf8;
        blue = blue & 0xf8;
    }
    else if (bpp == 16)
    {
        red = red & 0xf8;
        green = green & 0xfc;
        blue = blue & 0xf8;
    }
    else if (bpp == 12)
    {
        red = red & 0xf0;
        green = green & 0xf0;
        blue = blue & 0xf0;
    }

    color.red = 0;
    color.green = 0;
    color.blue = 0;
    color.pixel = 0;
    gdk_gc_set_foreground( gc, &color );

    for (int j = 0; j < image.GetHeight(); j++)
    {
        int start_x = -1;
        int i;
        for (i = 0; i < image.GetWidth(); i++)
        {
            if ((data[index] == red) &&
                (data[index+1] == green) &&
                (data[index+2] == blue))
            {
                if (start_x == -1)
                start_x = i;
            }
            else
            {
                if (start_x != -1)
                {
                    gdk_draw_line( m_bitmap, gc, start_x, j, i-1, j );
                    start_x = -1;
                }
            }
            index += 3;
        }
        if (start_x != -1)
            gdk_draw_line( m_bitmap, gc, start_x, j, i, j );
    }

    gdk_gc_unref( gc );

    return TRUE;
}
コード例 #18
0
ファイル: utilsgtk.cpp プロジェクト: 0ryuO/dolphin-avsync
void *wxGetDisplay()
{
    return GDK_DISPLAY_XDISPLAY(gtk_widget_get_display(wxGetRootWindow()));
}
コード例 #19
0
ファイル: utilsgtk.cpp プロジェクト: 0ryuO/dolphin-avsync
int wxDisplayDepth()
{
    return gdk_visual_get_depth(gtk_widget_get_visual(wxGetRootWindow()));
}
コード例 #20
0
ファイル: bitmap.cpp プロジェクト: AaronDP/wxWidgets
    m_refData = new wxBitmapRefData();
    return M_BMPDATA->Create(width, height, depth);
}

wxBitmap::wxBitmap(const char* const* bits)
{
    wxCHECK2_MSG(bits != NULL, return, wxT("invalid bitmap data"));

    GdkVisual *visual = wxTheApp->GetGdkVisual();

    m_refData = new wxBitmapRefData();

    GdkBitmap *mask = NULL;

    M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( wxGetRootWindow()->window, &mask, NULL, (gchar **) bits );

    wxCHECK2_MSG(M_BMPDATA->m_pixmap, return, wxT("couldn't create pixmap"));

    if (mask)
    {
        M_BMPDATA->m_mask = new wxMask();
        M_BMPDATA->m_mask->m_bitmap = mask;
    }

    gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );

    M_BMPDATA->m_bpp = visual->depth;  // Can we get a different depth from create_from_xpm_d() ?
}

wxBitmap wxBitmap::Rescale( int clipx, int clipy, int clipwidth, int clipheight, int newx, int newy )
コード例 #21
0
bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
      const wxPoint &pos, const wxSize &size,
      long style, const wxString &name )
{
    style = style | wxCAPTION;

    if ((style & wxCAPTION) || (style & wxTINY_CAPTION))
        m_miniTitle = 13;

    m_miniEdge = 3;
    m_isDragging = false;
    m_oldX = -1;
    m_oldY = -1;
    m_diffX = 0;
    m_diffY = 0;

    wxFrame::Create( parent, id, title, pos, size, style, name );

    if (m_parent && (GTK_IS_WINDOW(m_parent->m_widget)))
    {
        gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) );
    }

    if ((style & wxSYSTEM_MENU) &&
        ((style & wxCAPTION) || (style & wxTINY_CAPTION)))
    {
        GdkBitmap *mask = NULL;
        GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d
                            (
                                wxGetRootWindow()->window,
                                &mask,
                                NULL,
                                (char **)cross_xpm
                            );

        GtkWidget *pw = gtk_pixmap_new( pixmap, mask );
        gdk_bitmap_unref( mask );
        gdk_pixmap_unref( pixmap );
        gtk_widget_show( pw );

        GtkWidget *close_button = gtk_button_new();
        gtk_container_add( GTK_CONTAINER(close_button), pw );

        gtk_pizza_put( GTK_PIZZA(m_mainWidget),
                         close_button,
                         size.x-16, 4, 11, 11 );

        gtk_widget_show( close_button );

        gtk_signal_connect( GTK_OBJECT(close_button), "clicked",
          GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
    }

    /* these are called when the borders are drawn */
    gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event",
        GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );

    gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
       GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );

    /* these are required for dragging the mini frame around */
    gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event",
      GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );

    gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_release_event",
      GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );

    gtk_signal_connect( GTK_OBJECT(m_mainWidget), "motion_notify_event",
      GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );

    return true;
}
コード例 #22
0
ファイル: fontutil.cpp プロジェクト: beanhome/dev
wxFontFamily wxNativeFontInfo::GetFamily() const
{
    wxFontFamily ret = wxFONTFAMILY_UNKNOWN;

    const char *family_name = pango_font_description_get_family( description );

    // note: not passing -1 as the 2nd parameter to g_ascii_strdown to work
    // around a bug in the 64-bit glib shipped with solaris 10, -1 causes it
    // to try to allocate 2^32 bytes.
    if ( !family_name )
        return ret;
    wxGtkString family_text(g_ascii_strdown(family_name, strlen(family_name)));

    // Check for some common fonts, to salvage what we can from the current
    // win32 centric wxFont API:
    if (strncasecmp( family_text, "monospace", 9 ) == 0)
        ret = wxFONTFAMILY_TELETYPE;    // begins with "Monospace"
    else if (strncasecmp( family_text, "courier", 7 ) == 0)
        ret = wxFONTFAMILY_TELETYPE;    // begins with "Courier"
#if defined(__WXGTK20__) || defined(HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE)
    else
#ifdef __WXGTK20__
    if (!gtk_check_version(2,4,0))
#endif
    {
        PangoFontFamily **families;
        PangoFontFamily  *family = NULL;
        int n_families;
        pango_context_list_families(
#ifdef __WXGTK20__
                gtk_widget_get_pango_context( wxGetRootWindow() ),
#else
                wxTheApp->GetPangoContext(),
#endif
                &families, &n_families);

        for (int i = 0; i < n_families; ++i)
        {
            if (g_ascii_strcasecmp(pango_font_family_get_name( families[i] ),
                                   pango_font_description_get_family( description )) == 0 )
            {
                family = families[i];
                break;
            }
        }

        g_free(families);

        // Some gtk+ systems might query for a non-existing font from
        // wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) on initialization,
        // don't assert until wxSystemSettings::GetFont is checked for this - MR
        // wxASSERT_MSG( family, "No appropriate PangoFontFamily found for ::description" );

        if (family != NULL && pango_font_family_is_monospace( family ))
            ret = wxFONTFAMILY_TELETYPE; // is deemed a monospace font by pango
    }
#endif // GTK+ 2 || HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE

    if (ret == wxFONTFAMILY_UNKNOWN)
    {
        if (strstr( family_text, "sans" ) != NULL || strstr( family_text, "Sans" ) != NULL)
            // checked before serif, so that "* Sans Serif" fonts are detected correctly
            ret = wxFONTFAMILY_SWISS;       // contains "Sans"
        else if (strstr( family_text, "serif" ) != NULL || strstr( family_text, "Serif" ) != NULL)
            ret = wxFONTFAMILY_ROMAN;       // contains "Serif"
        else if (strncasecmp( family_text, "times", 5 ) == 0)
            ret = wxFONTFAMILY_ROMAN;       // begins with "Times"
        else if (strncasecmp( family_text, "old", 3 ) == 0)
            ret = wxFONTFAMILY_DECORATIVE;  // begins with "Old" - "Old English", "Old Town"
    }

    return ret;
}