Exemple #1
0
NyqBench::NyqBench(wxWindow * parent)
    :  wxFrame(NULL,
               wxID_ANY,
               wxEmptyString,
               wxDefaultPosition,
               wxDefaultSize,
               wxDEFAULT_FRAME_STYLE |
               wxMINIMIZE_BOX |
               wxMAXIMIZE_BOX |
               wxRESIZE_BORDER)
{
    mFindDlg = NULL;
    mRunning = false;
    mScriptBox = NULL;
    mOutputBox = NULL;
    mScript = NULL;
    mOutput = NULL;

    // No need to delete...EffectManager will do it
    mEffect = new EffectNyquist(wxT("///nyquist worker///"));
    EffectManager::Get().RegisterEffect(mEffect, HIDDEN_EFFECT);

    mPath = gPrefs->Read(wxT("NyqBench/Path"), wxEmptyString);
    mAutoLoad = (gPrefs->Read(wxT("NyqBench/AutoLoad"), 0L) != 0);
    mAutoWrap = (gPrefs->Read(wxT("NyqBench/AutoWrap"), true) != 0);
    mLargeIcons = (gPrefs->Read(wxT("NyqBench/LargeIcons"), 0L) != 0);
    mSplitMode = gPrefs->Read(wxT("NyqBench/SplitMode"), wxSPLIT_VERTICAL);
    mShowCode = (gPrefs->Read(wxT("NyqBench/ShowScript"), true) != 0);
    mShowOutput = (gPrefs->Read(wxT("NyqBench/ShowOutput"), true) != 0);

    SetIcon(wxICON(AudacityLogo));
    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
    ShuttleGui S(this, eIsCreating);
    PopulateOrExchange(S);
    wxMenuBar *bar = new wxMenuBar();

    wxMenu *menu = new wxMenu();
    menu->Append(wxID_NEW, wxT("&New\tCtrl+N"));
    menu->Append(wxID_OPEN, wxT("&Open...\tCtrl+O"));
    menu->Append(wxID_SAVE, wxT("&Save...\tCtrl+S"));
    menu->Append(wxID_SAVEAS, wxT("Save &As...\tCtrl+Shift+S"));
    menu->AppendSeparator();
    menu->Append(wxID_REVERT_TO_SAVED, _T("&Revert to Saved"));
    menu->AppendSeparator();
    menu->AppendCheckItem(ID_AUTOLOAD, _T("Auto &Load Last File"))->Check(mAutoLoad);
    menu->AppendSeparator();
    menu->Append(wxID_CLOSE, wxT("&Close Window\tCtrl+W"));
    bar->Append(menu, wxT("&File"));

    menu = new wxMenu();
    menu->Append(wxID_UNDO, _("&Undo\tCtrl+Z"));
    menu->Append(wxID_REDO, _("&Redo\tCtrl+Y"));
    menu->AppendSeparator();
    menu->Append(wxID_CUT, _("Cu&t\tCtrl+X"));
    menu->Append(wxID_COPY, _("&Copy\tCtrl+C"));
    menu->Append(wxID_PASTE, _("&Paste\tCtrl+V"));
    menu->Append(wxID_CLEAR, _("Cle&ar\tCtrl+L"));
    menu->AppendSeparator();
    menu->Append(wxID_SELECTALL, _("Select A&ll\tCtrl+A"));
    menu->AppendSeparator();
    menu->Append(wxID_FIND, _("&Find...\tCtrl+F"));
    menu->AppendSeparator();
    wxMenu *sub = new wxMenu();
    sub->Append(ID_MATCH, _("&Matching Paren\tF8"));
    sub->Append(ID_TOP, _("&Top S-expr\tF9"));
    sub->Append(ID_UP, _("&Higher S-expr\tF10"));
    sub->Append(ID_PREVIOUS, _("&Previous S-expr\tF11"));
    sub->Append(ID_NEXT, _("&Next S-expr\tF12"));
    menu->AppendSubMenu(sub, _("&Go to"));
    menu->AppendSeparator();
    menu->AppendCheckItem(ID_AUTOWRAP, _T("Auto &Wrap"))->Check(mAutoWrap);
    bar->Append(menu, wxT("&Edit"));

    menu = new wxMenu();
    menu->Append(ID_FONT, _("Select &Font..."));
    menu->AppendSeparator();
    menu->Append(ID_SPLITV, _("Split &Vertically"));
    menu->Append(ID_SPLITH, _("Split &Horizontally"));
    menu->AppendSeparator();
    menu->AppendCheckItem(ID_TOGGLECODE, _("Show S&cript"));
    menu->AppendCheckItem(ID_TOGGLEOUTPUT, _("Show &Output"));
    menu->AppendSeparator();
    sub = new wxMenu();
    sub->AppendRadioItem(ID_LARGEICONS, _("&Large Icons"));
    sub->AppendRadioItem(ID_SMALLICONS, _("&Small Icons"));
    menu->AppendSubMenu(sub, _("Toolbar"));
    bar->Append(menu, wxT("&View"));

    menu = new wxMenu();
    menu->Append(ID_GO, _("&Go\tF5"));
    menu->Append(ID_STOP, _("&Stop\tF6"));
    bar->Append(menu, wxT("&Run"));

#if defined(__WXMAC__)
    menu->Append(wxID_ABOUT, _("&About"));
#else
    menu = new wxMenu();
    menu->Append(wxID_ABOUT, _("&About"));
    bar->Append(menu, wxT("Help"));
#endif

    SetMenuBar(bar);

    RecreateToolbar(mLargeIcons);

    wxRect r;
    r.SetX(gPrefs->Read(wxT("NyqBench/Window/X"), -1));
    r.SetY(gPrefs->Read(wxT("NyqBench/Window/Y"), -1));
    r.SetWidth(gPrefs->Read(wxT("NyqBench/Window/Width"), -1));
    r.SetHeight(gPrefs->Read(wxT("NyqBench/Window/Height"), -1));
    if (r == wxRect(-1, -1, -1, -1)) {
        Center();
    }
    else {
        SetSize(r);
    }

    bool maximized = false;
    gPrefs->Read(wxT("NyqBench/Window/Maximized"), maximized);
    if (maximized) {
        Maximize();
    }

    long sashpos;
    sashpos = gPrefs->Read(wxT("NyqBench/SplitX"), 0l);
    if (sashpos > 0) {
        mSplitter->SetSashPosition(sashpos);
    }

    wxString dflt = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT).GetNativeFontInfoDesc();
    wxString desc;
    wxTextAttr attr;

    desc = gPrefs->Read(wxT("NyqBench/ScriptFont"), dflt);
    mScriptFont.SetNativeFontInfo(desc);
#if defined(__WXMSW__)
    // Force SYSTEM encoding to prevent conversion to Unicode in wxTextCtrl::DoWriteText().
    // I don't know if this is something I'm doing wrong, but I'll have to look at this
    // later if I get bored.
    mScriptFont.SetEncoding(wxFONTENCODING_SYSTEM);
#endif
    attr.SetFont(mScriptFont);
    mScript->SetDefaultStyle(attr);

    desc = gPrefs->Read(wxT("NyqBench/OutputFont"), dflt);
    mOutputFont.SetNativeFontInfo(desc);
#if defined(__WXMSW__)
    // Force SYSTEM encoding to prevent conversion to Unicode in wxTextCtrl::DoWriteText().
    // I don't know if this is something I'm doing wrong, but I'll have to look at this
    // later if I get bored.
    mOutputFont.SetEncoding(wxFONTENCODING_SYSTEM);
#endif
    attr.SetFont(mOutputFont);
    mOutput->SetDefaultStyle(attr);

    if (mAutoLoad && !mPath.GetFullPath().IsEmpty()) {
        LoadFile();
    }

    SetWindowTitle();
}
Exemple #2
0
wxRect wxNotebook::GetPageRect() const
{
    wxSize size = GetClientSize() ;

    return wxRect( 0 , 0 , size.x , size.y ) ;
}
Exemple #3
0
bool wxRibbonGallery::Layout()
{
    if(m_art == NULL)
        return false;

    wxMemoryDC dc;
    wxPoint origin;
    wxSize client_size = m_art->GetGalleryClientSize(dc, this, GetSize(),
        &origin, &m_scroll_up_button_rect, &m_scroll_down_button_rect,
        &m_extension_button_rect);
    m_client_rect = wxRect(origin, client_size);

    int x_cursor = 0;
    int y_cursor = 0;

    size_t item_count = m_items.Count();
    size_t item_i;
    long art_flags = m_art->GetFlags();
    for(item_i = 0; item_i < item_count; ++item_i)
    {
        wxRibbonGalleryItem *item = m_items.Item(item_i);
        item->SetIsVisible(true);
        if(art_flags & wxRIBBON_BAR_FLOW_VERTICAL)
        {
            if(y_cursor + m_bitmap_padded_size.y > client_size.GetHeight())
            {
                if(y_cursor == 0)
                    break;
                y_cursor = 0;
                x_cursor += m_bitmap_padded_size.x;
            }
            item->SetPosition(origin.x + x_cursor, origin.y + y_cursor,
                m_bitmap_padded_size);
            y_cursor += m_bitmap_padded_size.y;
        }
        else
        {
            if(x_cursor + m_bitmap_padded_size.x > client_size.GetWidth())
            {
                if(x_cursor == 0)
                    break;
                x_cursor = 0;
                y_cursor += m_bitmap_padded_size.y;
            }
            item->SetPosition(origin.x + x_cursor, origin.y + y_cursor,
                m_bitmap_padded_size);
            x_cursor += m_bitmap_padded_size.x;
        }
    }
    for(; item_i < item_count; ++item_i)
    {
        wxRibbonGalleryItem *item = m_items.Item(item_i);
        item->SetIsVisible(false);
    }
    if(art_flags & wxRIBBON_BAR_FLOW_VERTICAL)
        m_scroll_limit = x_cursor;
    else
        m_scroll_limit = y_cursor;
    if(m_scroll_amount >= m_scroll_limit)
    {
        m_scroll_amount = m_scroll_limit;
        m_down_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
    }
    else if(m_down_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
        m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;

    if(m_scroll_amount <= 0)
    {
        m_scroll_amount = 0;
        m_up_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
    }
    else if(m_up_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
        m_up_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;

    return true;
}
bool GribRequestSetting::DoRenderZoneOverlay()
{
    wxPoint p;
    GetCanvasPixLL( m_Vp, &p, m_Lat, m_Lon);

    int x = (m_StartPoint.x < p.x) ? m_StartPoint.x : p.x;
    int y = (m_StartPoint.y < p.y) ? m_StartPoint.y : p.y;

    int zw = fabs( (double ) p.x - m_StartPoint.x );
    int zh = fabs( (double ) p.y - m_StartPoint.y );

    wxPoint center;
    center.x = x + (zw / 2);
    center.y = y + (zh / 2);

    wxFont *font = OCPNGetFont(_("Dialog"), 10);
    wxColour pen_color, back_color;
    GetGlobalColor( _T ( "DASHR" ), &pen_color );
    GetGlobalColor( _T ( "YELO1" ), &back_color );

    int label_offsetx = 5, label_offsety = 1;

    double size;
    EstimateFileSize( &size );

    wxString label( _("Coord. ") );
    label.Append( toMailFormat(1, m_spMaxLat->GetValue()) + _T(" "));
    label.Append( toMailFormat(0, m_spMinLon->GetValue()) + _T(" "));
    label.Append( toMailFormat(1, m_spMinLat->GetValue()) + _T(" "));
    label.Append( toMailFormat(0, m_spMaxLon->GetValue()) + _T("\n"));
    label.Append( _T("Estim. Size ") ).Append((wxString::Format( _T("%1.2f " ) , size ) + _("MB") ) );

    if( m_pdc ) {
        wxPen pen(pen_color);
        pen.SetWidth(3);
        m_pdc->SetPen( pen );
        m_pdc->SetBrush( *wxTRANSPARENT_BRUSH);
        m_pdc->DrawRectangle(x, y, zw, zh);



        int w, h, sl;
#ifdef __WXMAC__
        wxScreenDC sdc;
        sdc.GetMultiLineTextExtent(label, &w, &h, &sl, font);
#else
        m_pdc->GetMultiLineTextExtent(label, &w, &h, &sl, font);
#endif
        w += 2*label_offsetx, h += 2*label_offsety;
        x = center.x - (w / 2);
        y = center.y - (h / 2);

        wxBitmap bm(w, h);
        wxMemoryDC mdc(bm);
        mdc.Clear();

        mdc.SetFont( *font );
        mdc.SetBrush(back_color);
        mdc.SetPen(*wxTRANSPARENT_PEN);
        mdc.SetTextForeground(wxColor( 0, 0, 0 ));
        mdc.DrawRectangle(0, 0, w, h);
        mdc.DrawLabel( label, wxRect( label_offsetx, label_offsety, w, h ) );

        wxImage im = bm.ConvertToImage();
        im.InitAlpha();
        w = im.GetWidth(), h = im.GetHeight();
        for( int j = 0; j < h; j++ )
			for( int i = 0; i < w; i++ )
				im.SetAlpha( i, j, 155 );

        m_pdc->DrawBitmap(im, x, y, true);

    } else {

#ifdef ocpnUSE_GL
    TexFont m_TexFontlabel;
    m_TexFontlabel.Build(*font);

    glColor3ub(pen_color.Red(), pen_color.Green(), pen_color.Blue() );

    glPushAttrib(GL_COLOR_BUFFER_BIT | GL_LINE_BIT | GL_ENABLE_BIT |
                     GL_POLYGON_BIT | GL_HINT_BIT );

   glEnable( GL_LINE_SMOOTH );
   glEnable( GL_BLEND );
   glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
   glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
   glLineWidth( 3.f );

   glBegin( GL_LINES );
   glVertex2d( x, y );
   glVertex2d( x+zw, y );
   glVertex2d( x+zw, y );
   glVertex2d( x+zw, y+zh );
   glVertex2d( x+zw, y+zh );
   glVertex2d( x, y+zh );
   glVertex2d( x, y+zh );
   glVertex2d( x, y );
   glEnd();

   int w, h;
   glColor4ub(back_color.Red(), back_color.Green(), back_color.Blue(), 155 );
   m_TexFontlabel.GetTextExtent(label, &w, &h );

    w += 2*label_offsetx, h += 2*label_offsety;
    x = center.x - (w / 2);
    y = center.y - (h / 2);

   /* draw text background */
   glBegin(GL_QUADS);
   glVertex2i(x,   y);
   glVertex2i(x+w, y);
   glVertex2i(x+w, y+h);
   glVertex2i(x,   y+h);
   glEnd();

   /* draw text */
   glColor3ub( 0, 0, 0 );

   glEnable(GL_TEXTURE_2D);
   m_TexFontlabel.RenderString(label, x + label_offsetx, y + label_offsety);
   glDisable(GL_TEXTURE_2D);

   glDisable( GL_BLEND );

   glPopAttrib();
   
#endif
    }
    return true;
}
Exemple #5
0
EWXWEXPORT(void,wxImage_GetSubImage)(wxImage* self,int x,int y,int w,int h,wxImage* image)
{
	*image = self->GetSubImage(wxRect(x, y, w, h));
}
void ScreenshotCommand::Capture(const wxString &filename,
                          wxWindow *window,
                          int x, int y, int width, int height,
                          bool bg)
{
   if (window) {
      if (window->IsTopLevel()) {
         window->Raise();
      }
      else {
         wxGetTopLevelParent(window)->Raise();
      }
   }

   Yield();

   int screenW, screenH;
   wxDisplaySize(&screenW, &screenH);
   wxBitmap full(screenW, screenH);

   wxScreenDC screenDC;
   wxMemoryDC fullDC;

#if defined(__WXMAC__) && !wxCHECK_VERSION(3, 0, 0)
   full = DoGetAsBitmap(NULL);
#else
   // We grab the whole screen image since there seems to be a problem with
   // using non-zero source coordinates on OSX.  (as of wx2.8.9)
   fullDC.SelectObject(full);
   fullDC.Blit(0, 0, screenW, screenH, &screenDC, 0, 0);
   fullDC.SelectObject(wxNullBitmap);
#endif

   wxRect r(x, y, width, height);

   // Ensure within bounds (x/y are negative on Windows when maximized)
   r.Intersect(wxRect(0, 0, screenW, screenH));

   // Convert to screen coordinates if needed
   if (window && window->GetParent() && !window->IsTopLevel()) {
      r.SetPosition(window->GetParent()->ClientToScreen(r.GetPosition()));
   }

   // Extract the actual image
   wxBitmap part = full.GetSubBitmap(r);

   // Add a background
   if (bg && mBackground) {
      wxRect b = GetBackgroundRect();

      wxBitmap back(width + b.width, height + b.height);
      fullDC.SelectObject(back);

      fullDC.SetBackground(wxBrush(mBackColor, wxSOLID));
      fullDC.Clear();

      fullDC.DrawBitmap(part, b.x, b.y);
      fullDC.SelectObject(wxNullBitmap);

      part = back;
   }

   // Save the final image
   wxImage image = part.ConvertToImage();
   if (image.SaveFile(filename)) {
      mOutput->Status(_("Saved ") + filename);
   }
   else {
      mOutput->Error(_("Error trying to save file: ") + filename);
   }

   ::wxBell();
}
Exemple #7
0
void SAuiTabArt::DrawTab(wxDC& dc,
	wxWindow* wnd,
	const wxAuiNotebookPage& page,
	const wxRect& in_rect,
	int close_button_state,
	wxRect* out_tab_rect,
	wxRect* out_button_rect,
	int* x_extent)
{
	wxCoord normal_textx, normal_texty;
	wxCoord selected_textx, selected_texty;
	wxCoord texty;

	// if the caption is empty, measure some temporary text
	wxString caption = page.caption;
	if (caption.empty())
		caption = wxT("Xj");

	dc.SetFont(m_selectedFont);
	dc.GetTextExtent(caption, &selected_textx, &selected_texty);

	dc.SetFont(m_normalFont);
	dc.GetTextExtent(caption, &normal_textx, &normal_texty);

	bool bluetab = false;
	if (page.window->GetName() == "startpage")
		bluetab = true;

	// figure out the size of the tab
	wxSize tab_size = GetTabSize(dc,
		wnd,
		page.caption,
		page.bitmap,
		page.active,
		close_button_state,
		x_extent);

	wxCoord tab_height = m_tabCtrlHeight + 2;// -1;// -3;
	wxCoord tab_width = tab_size.x;
	wxCoord tab_x = in_rect.x;
	wxCoord tab_y = in_rect.y + in_rect.height - tab_height + 3;


	if (!page.active)
	{
		tab_height -= 2;
		tab_y += 2;
	}

	caption = page.caption;


	// select pen, brush and font for the tab to be drawn
	if (page.active)
	{
		dc.SetFont(m_selectedFont);
		texty = selected_texty;
	}
	else
	{
		dc.SetFont(m_normalFont);
		texty = normal_texty;
	}


	// create points that will make the tab outline
	int clip_width = tab_width;
	if (tab_x + clip_width > in_rect.x + in_rect.width)
		clip_width = (in_rect.x + in_rect.width) - tab_x;
	dc.SetClippingRegion(tab_x, tab_y, clip_width + 1, tab_height - 3);

	wxPoint border_points[6];
	if (m_flags &wxAUI_NB_BOTTOM)
	{
		border_points[0] = wxPoint(tab_x, tab_y);
		border_points[1] = wxPoint(tab_x, tab_y + tab_height - 4);
		border_points[2] = wxPoint(tab_x, tab_y + tab_height - 4);
		border_points[3] = wxPoint(tab_x + tab_width, tab_y + tab_height - 4);
		border_points[4] = wxPoint(tab_x + tab_width, tab_y + tab_height - 4);
		border_points[5] = wxPoint(tab_x + tab_width, tab_y);
	}
	else
	{
		border_points[0] = wxPoint(tab_x, tab_y + tab_height - 4);
		border_points[1] = wxPoint(tab_x, tab_y);
		border_points[2] = wxPoint(tab_x + 2, tab_y);
		border_points[3] = wxPoint(tab_x + tab_width - 2, tab_y);
		border_points[4] = wxPoint(tab_x + tab_width, tab_y);
		border_points[5] = wxPoint(tab_x + tab_width, tab_y + tab_height - 4);
	}

	int drawn_tab_yoff = border_points[1].y + 1;
	int drawn_tab_height = border_points[0].y - border_points[1].y;


	wxColour bgcol;
	if (page.active)
	{
		// draw active tab
		bgcol = m_activeColour;

		// draw base background color
		wxRect r(tab_x, tab_y, tab_width, tab_height);
		dc.SetPen(wxPen(bluetab ? wxColor(224, 238, 255) : m_activeColour));
		dc.SetBrush(wxBrush(bluetab ? wxColor(224, 238, 255) : m_activeColour));
		dc.DrawRectangle(r.x + 1, r.y + 1, r.width - 1, r.height - 5);

		// highlight top of tab
		wxColour col_hilight = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
		dc.SetPen(*wxTRANSPARENT_PEN);// *wxWHITE_PEN);
		dc.SetBrush(wxBrush(col_hilight));// *wxWHITE_BRUSH);
		dc.DrawRectangle(r.x + 1, r.y + 1, r.width - 1, 1);
	}
	else
	{
		bgcol = m_inactiveTabColour;

		wxRect r(tab_x, tab_y, tab_width, tab_height);
		wxPoint mouse = wnd->ScreenToClient(wxGetMousePosition());
		/*if (r.Contains(mouse))
		{
			dc.SetPen(wxPen(m_activeColour));
			dc.SetBrush(wxBrush(m_activeColour));
		}
		else
		{*/
			dc.SetPen(wxPen(m_inactiveTabColour));
			dc.SetBrush(wxBrush(m_inactiveTabColour));
		//}
		dc.DrawRectangle(r.x + 1, r.y + 1, r.width - 1, r.height - 4);
	}

	// draw tab outline
	dc.SetPen(m_borderPen);
	dc.SetBrush(*wxTRANSPARENT_BRUSH);
	dc.DrawPolygon(WXSIZEOF(border_points), border_points);

	// there are two horizontal grey lines at the bottom of the tab control,
	// this gets rid of the top one of those lines in the tab control
	if (page.active)
	{
		if (m_flags &wxAUI_NB_BOTTOM)
			dc.SetPen(wxPen(m_baseColour.ChangeLightness(170)));
		else
			dc.SetPen(wxPen(bluetab ? wxColor(224, 238, 255) : m_activeColour));
		dc.DrawLine(border_points[0].x + 1,
			border_points[0].y,
			border_points[5].x,
			border_points[5].y);
	}


	int text_offset = tab_x + 8;
	int close_button_width = 0;
	if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
	{
		close_button_width = m_activeCloseBmp.GetWidth();
	}

	int bitmap_offset = 0;
	if (page.bitmap.IsOk())
	{
		bitmap_offset = tab_x + 8;

		// draw bitmap
		dc.DrawBitmap(page.bitmap,
			bitmap_offset,
			drawn_tab_yoff + (drawn_tab_height / 2) - (page.bitmap.GetHeight() / 2),
			true);

		text_offset = bitmap_offset + page.bitmap.GetWidth();
		text_offset += 4; // bitmap padding

	}
	else
	{
		text_offset = tab_x + 8;
	}

	dc.SetTextForeground((page.active && bluetab) ? wxColor(0,0,0) : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
	wxString draw_text = wxAuiChopText(dc,
		caption,
		tab_width - (text_offset - tab_x) - close_button_width);

	// draw tab text
	dc.DrawText(draw_text,
		text_offset,
		drawn_tab_yoff + (drawn_tab_height) / 2 - (texty / 2) - 0);

	// draw focus rectangle
	if (page.active && (wnd->FindFocus() == wnd))
	{
		wxRect focusRectText(text_offset, (drawn_tab_yoff + (drawn_tab_height) / 2 - (texty / 2) - 1),
			selected_textx, selected_texty);

		wxRect focusRect;
		wxRect focusRectBitmap;

		if (page.bitmap.IsOk())
			focusRectBitmap = wxRect(bitmap_offset, drawn_tab_yoff + (drawn_tab_height / 2) - (page.bitmap.GetHeight() / 2),
				page.bitmap.GetWidth(), page.bitmap.GetHeight());

		if (page.bitmap.IsOk() && draw_text.IsEmpty())
			focusRect = focusRectBitmap;
		else if (!page.bitmap.IsOk() && !draw_text.IsEmpty())
			focusRect = focusRectText;
		else if (page.bitmap.IsOk() && !draw_text.IsEmpty())
			focusRect = focusRectText.Union(focusRectBitmap);

		focusRect.Inflate(2, 2);

		wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0);
	}

	// draw close button if necessary
	if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
	{
		wxBitmap bmp = m_disabledCloseBmp;

		int offsetY = tab_y;
		if (m_flags & wxAUI_NB_BOTTOM)
			offsetY = 1;

		wxRect rect(tab_x + tab_width - close_button_width - 3,
			offsetY + (tab_height / 2) - (bmp.GetHeight() / 2),
			close_button_width,
			tab_height);

		IndentPressedBitmap(&rect, close_button_state);

		if (close_button_state == wxAUI_BUTTON_STATE_HOVER ||
			close_button_state == wxAUI_BUTTON_STATE_PRESSED)
		{
			/*wxColour bcol = m_borderPen.GetColour();
			float r = ((float)bcol.Red() * 0.2f) + ((float)m_activeColour.Red() * 0.8f);
			float g = ((float)bcol.Green() * 0.2f) + ((float)m_activeColour.Green() * 0.8f);
			float b = ((float)bcol.Blue() * 0.2f) + ((float)m_activeColour.Blue() * 0.8f);*/
			//captionAccentColour = wxColor(r, g, b);

			//dc.SetPen(*wxTRANSPARENT_PEN);
			dc.SetPen(wxPen(Drawing::darkColour(bgcol, 2.0f)));
			dc.SetBrush(wxBrush(Drawing::lightColour(bgcol, 1.0f)));
			dc.DrawRectangle(rect.x, rect.y + 1, rect.width - 1, rect.width - 2);

			bmp = m_activeCloseBmp;
			//dc.DrawBitmap(bmp, rect.x + 1, rect.y, true);
			//dc.DrawBitmap(bmp, rect.x - 1, rect.y, true);
			dc.DrawBitmap(bmp, rect.x, rect.y, true);
		}
		else
		{
			bmp = m_disabledCloseBmp;
			dc.DrawBitmap(bmp, rect.x, rect.y, true);
		}

		*out_button_rect = rect;
	}

	*out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height);

	dc.DestroyClippingRegion();
}
Exemple #8
0
bool wxRibbonPanel::ShowExpanded()
{
    if(!IsMinimised())
    {
        return false;
    }
    if(m_expanded_dummy != NULL || m_expanded_panel != NULL)
    {
        return false;
    }

    wxSize size = GetBestSize();

    // Special case for flexible panel layout, where GetBestSize doesn't work
    if (GetFlags() & wxRIBBON_PANEL_FLEXIBLE)
    {
        size = GetBestSizeForParentSize(wxSize(400, 1000));
    }

    wxPoint pos = GetExpandedPosition(wxRect(GetScreenPosition(), GetSize()),
        size, m_preferred_expand_direction).GetTopLeft();

    // Need a top-level frame to contain the expanded panel
    wxFrame *container = new wxFrame(NULL, wxID_ANY, GetLabel(),
        pos, size, wxFRAME_NO_TASKBAR | wxBORDER_NONE);

    m_expanded_panel = new wxRibbonPanel(container, wxID_ANY,
        GetLabel(), m_minimised_icon, wxPoint(0, 0), size, (m_flags /* & ~wxRIBBON_PANEL_FLEXIBLE */));

    m_expanded_panel->SetArtProvider(m_art);
    m_expanded_panel->m_expanded_dummy = this;

    // Move all children to the new panel.
    // Conceptually it might be simpler to reparent this entire panel to the
    // container and create a new panel to sit in its place while expanded.
    // This approach has a problem though - when the panel is reinserted into
    // its original parent, it'll be at a different position in the child list
    // and thus assume a new position.
    // NB: Children iterators not used as behaviour is not well defined
    // when iterating over a container which is being emptied
    while(!GetChildren().IsEmpty())
    {
        wxWindow *child = GetChildren().GetFirst()->GetData();
        child->Reparent(m_expanded_panel);
        child->Show();
    }

    // Move sizer to new panel
    if(GetSizer())
    {
        wxSizer* sizer = GetSizer();
        SetSizer(NULL, false);
        m_expanded_panel->SetSizer(sizer);
    }

    m_expanded_panel->Realize();
    Refresh();
    container->SetMinClientSize(size);
    container->Show();
    m_expanded_panel->SetFocus();

    return true;
}
Exemple #9
0
void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode, bool enforce)
{

    if (!w)
        cbThrow(_T("Passed NULL pointer to PlaceWindow."));

    ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("app"));
    if (!enforce && cfg->ReadBool(_T("/dialog_placement/do_place")) == false)
        return;

    wxWindow* referenceWindow = Manager::Get()->GetAppWindow();
    if (!referenceWindow)    // no application window available, so this is as good as we can get
        referenceWindow = w;

    int the_mode;
    if (mode == pdlBest)
        the_mode = cfg->ReadInt(_T("/dialog_placement/dialog_position"), (int) pdlCentre);
    else
        the_mode = (int) mode;

    wxRect monitorRect;

    if (wxDisplay::GetCount() > 0)
    {
        int displayIdx = wxDisplay::GetFromWindow(referenceWindow);
        if (displayIdx == wxNOT_FOUND)
            displayIdx = 0;
        wxDisplay display(displayIdx);
        monitorRect = display.GetClientArea();
        // This is needed because on Linux the client area returned for the first monitor in a twin
        // monitor setup with nVidia card is spanning the two monitors.
        // The intersection function will return just the client for the specified monitor.
        monitorRect = display.GetGeometry().Intersect(monitorRect);
    }
    else
    {
        int width, height;
        wxDisplaySize(&width, &height);
        monitorRect = wxRect(0, 0, width, height);
    }

    wxRect windowRect = w->GetRect();

    switch(the_mode)
    {
        case pdlCentre:
        {
            windowRect.x = monitorRect.x + (monitorRect.width  - windowRect.width)/2;
            windowRect.y = monitorRect.y  + (monitorRect.height - windowRect.height)/2;
        }
        break;


        case pdlHead:
        {
            windowRect.x = monitorRect.x + (monitorRect.width  - windowRect.width)/2;
            windowRect.y = monitorRect.y  + (monitorRect.height - windowRect.height)/3;
        }
        break;


        case pdlConstrain:
        {
            int x1 = windowRect.x;
            int x2 = windowRect.x + windowRect.width;
            int y1 = windowRect.y;
            int y2 = windowRect.y + windowRect.height;

            if (windowRect.width > monitorRect.width) // cannot place without clipping, so centre it
            {
                x1 = monitorRect.x + (monitorRect.width  - windowRect.width)/2;
                x2 = x1 + windowRect.width;
            }
            else
            {
                x2 = std::min(monitorRect.GetRight(), windowRect.GetRight());
                x1 = std::max(x2 - windowRect.width, monitorRect.x);
                x2 = x1 + windowRect.width;
            }
            if (windowRect.height > monitorRect.height) // cannot place without clipping, so centre it
            {
                y1 = monitorRect.y + (monitorRect.height  - windowRect.height)/2;
                y2 = y1 + windowRect.height;
            }
            else
            {
                y2 = std::min(monitorRect.GetBottom(), windowRect.GetBottom());
                y1 = std::max(y2 - windowRect.height, monitorRect.y);
                y2 = y1 + windowRect.height;
            }
            windowRect = wxRect(x1, y1, x2-x1, y2-y1);
        }
        break;


        case pdlClip:
        {
            int x1 = windowRect.x;
            int x2 = windowRect.x + windowRect.width;
            int y1 = windowRect.y;
            int y2 = windowRect.y + windowRect.height;

            x1 = std::max(x1, monitorRect.x);
            x2 = std::min(x2, monitorRect.GetRight());
            y1 = std::max(y1, monitorRect.y);
            y2 = std::min(y2, monitorRect.GetBottom());

            windowRect = wxRect(x1, y1, x2-x1, y2-y1);
        }
        break;
    }

    w->SetSize(windowRect.x,  windowRect.y, windowRect.width, windowRect.height, wxSIZE_ALLOW_MINUS_ONE);
}
void wxNotebook::OnSize(wxSizeEvent& event)
{
    if ( GetPageCount() == 0 )
    {
        // Prevents droppings on resize, but does cause some flicker
        // when there are no pages.
        Refresh();
        event.Skip();
        return;
    }
#ifndef __WXWINCE__
    else
    {
        // Without this, we can sometimes get droppings at the edges
        // of a notebook, for example a notebook in a splitter window.
        // This needs to be reconciled with the RefreshRect calls
        // at the end of this function, which weren't enough to prevent
        // the droppings.

        wxSize sz = GetClientSize();

        // Refresh right side
        wxRect rect(sz.x-4, 0, 4, sz.y);
        RefreshRect(rect);

        // Refresh bottom side
        rect = wxRect(0, sz.y-4, sz.x, 4);
        RefreshRect(rect);

        // Refresh left side
        rect = wxRect(0, 0, 4, sz.y);
        RefreshRect(rect);
    }
#endif // !__WXWINCE__

    // fit all the notebook pages to the tab control's display area

    RECT rc;
    rc.left = rc.top = 0;
    GetSize((int *)&rc.right, (int *)&rc.bottom);

    // save the total size, we'll use it below
    int widthNbook = rc.right - rc.left,
        heightNbook = rc.bottom - rc.top;

    // there seems to be a bug in the implementation of TabCtrl_AdjustRect(): it
    // returns completely false values for multiline tab controls after the tabs
    // are added but before getting the first WM_SIZE (off by ~50 pixels, see
    //
    // http://sf.net/tracker/index.php?func=detail&aid=645323&group_id=9863&atid=109863
    //
    // and the only work around I could find was this ugly hack... without it
    // simply toggling the "multiline" checkbox in the notebook sample resulted
    // in a noticeable page displacement
    if ( HasFlag(wxNB_MULTILINE) )
    {
        // avoid an infinite recursion: we get another notification too!
        static bool s_isInOnSize = false;

        if ( !s_isInOnSize )
        {
            s_isInOnSize = true;
            SendMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED,
                    MAKELPARAM(rc.right, rc.bottom));
            s_isInOnSize = false;
        }

        // The best size depends on the number of rows of tabs, which can
        // change when the notepad is resized.
        InvalidateBestSize();
    }

#if wxUSE_UXTHEME
    // background bitmap size has changed, update the brush using it too
    UpdateBgBrush();
#endif // wxUSE_UXTHEME

    TabCtrl_AdjustRect(GetHwnd(), false, &rc);

    int width = rc.right - rc.left,
        height = rc.bottom - rc.top;
    size_t nCount = m_pages.Count();
    for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
        wxNotebookPage *pPage = m_pages[nPage];
        pPage->SetSize(rc.left, rc.top, width, height);
    }


    // unless we had already repainted everything, we now need to refresh
    if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) )
    {
        // invalidate areas not covered by pages
        RefreshRect(wxRect(0, 0, widthNbook, rc.top), false);
        RefreshRect(wxRect(0, rc.top, rc.left, height), false);
        RefreshRect(wxRect(0, rc.bottom, widthNbook, heightNbook - rc.bottom),
                    false);
        RefreshRect(wxRect(rc.right, rc.top, widthNbook - rc.right, height),
                    false);
    }

#if USE_NOTEBOOK_ANTIFLICKER
    // subclass the spin control used by the notebook to scroll pages to
    // prevent it from flickering on resize
    if ( !m_hasSubclassedUpdown )
    {
        // iterate over all child windows to find spin button
        for ( HWND child = ::GetWindow(GetHwnd(), GW_CHILD);
              child;
              child = ::GetWindow(child, GW_HWNDNEXT) )
        {
            wxWindow *childWindow = wxFindWinFromHandle((WXHWND)child);

            // see if it exists, if no wxWindow found then assume it's the spin
            // btn
            if ( !childWindow )
            {
                // subclass the spin button to override WM_ERASEBKGND
                if ( !gs_wndprocNotebookSpinBtn )
                    gs_wndprocNotebookSpinBtn = (WXFARPROC)wxGetWindowProc(child);

                wxSetWindowProc(child, wxNotebookSpinBtnWndProc);
                m_hasSubclassedUpdown = true;
                break;
            }
        }
    }
#endif // USE_NOTEBOOK_ANTIFLICKER

    event.Skip();
}
Exemple #11
0
bool wxGTKCairoDCImpl::DoStretchBlit(int xdest, int ydest, int dstWidth, int dstHeight, wxDC* source, int xsrc, int ysrc, int srcWidth, int srcHeight, wxRasterOperationMode rop, bool useMask, int xsrcMask, int ysrcMask)
{
    wxCHECK_MSG(IsOk(), false, "invalid DC");
    wxCHECK_MSG(source && source->IsOk(), false, "invalid source DC");

    cairo_t* cr = NULL;
    if (m_graphicContext)
        cr = static_cast<cairo_t*>(m_graphicContext->GetNativeContext());
    cairo_t* cr_src = NULL;
    wxGraphicsContext* gc_src = source->GetGraphicsContext();
    if (gc_src)
        cr_src = static_cast<cairo_t*>(gc_src->GetNativeContext());

    if (cr == NULL || cr_src == NULL)
        return false;

    const int xsrc_dev = source->LogicalToDeviceX(xsrc);
    const int ysrc_dev = source->LogicalToDeviceY(ysrc);

    cairo_surface_t* surfaceSrc = cairo_get_target(cr_src);
    cairo_surface_flush(surfaceSrc);

    cairo_surface_t* surfaceTmp = NULL;
    // If destination (this) and source wxDC refer to the same Cairo context
    // it means that we operate on one surface and results of drawing
    // can be invalid if destination and source regions overlap.
    // In such situation we have to copy source surface to the temporary
    // surface and use this copy in the drawing operations.
    if ( cr == cr_src )
    {
        // Check if destination and source regions overlap.
        // If necessary, copy source surface to the temporary one.
        if (wxRect(xdest, ydest, dstWidth, dstHeight)
            .Intersects(wxRect(xsrc, ysrc, srcWidth, srcHeight)))
        {
            const int w = cairo_image_surface_get_width(surfaceSrc);
            const int h = cairo_image_surface_get_height(surfaceSrc);
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
            if ( cairo_version() >= CAIRO_VERSION_ENCODE(1, 12, 0) )
            {
                surfaceTmp = cairo_surface_create_similar_image(surfaceSrc,
                     cairo_image_surface_get_format(surfaceSrc),
                     w, h);
            }
            else
#endif // Cairo 1.12
            {
                surfaceTmp = cairo_surface_create_similar(surfaceSrc,
                     CAIRO_CONTENT_COLOR_ALPHA,
                     w, h);
            }
            cairo_t* crTmp = cairo_create(surfaceTmp);
            cairo_set_source_surface(crTmp, surfaceSrc, 0, 0);
            cairo_rectangle(crTmp, 0.0, 0.0, w, h);
            cairo_set_operator(crTmp, CAIRO_OPERATOR_SOURCE);
            cairo_fill(crTmp);
            cairo_destroy(crTmp);
            cairo_surface_flush(surfaceTmp);
            surfaceSrc = surfaceTmp;
        }
    }
    cairo_save(cr);
    cairo_translate(cr, xdest, ydest);
    cairo_rectangle(cr, 0, 0, dstWidth, dstHeight);
    double sx, sy;
    source->GetUserScale(&sx, &sy);
    cairo_scale(cr, dstWidth / (sx * srcWidth), dstHeight / (sy * srcHeight));
    cairo_set_source_surface(cr, surfaceSrc, -xsrc_dev, -ysrc_dev);
    const wxRasterOperationMode rop_save = m_logicalFunction;
    SetLogicalFunction(rop);
    cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
    cairo_surface_t* maskSurf = NULL;
    if (useMask)
    {
        const wxBitmap& bitmap = source->GetImpl()->GetSelectedBitmap();
        if (bitmap.IsOk())
        {
            wxMask* mask = bitmap.GetMask();
            if (mask)
                maskSurf = *mask;
        }
    }
    if (maskSurf)
    {
        int xsrcMask_dev = xsrc_dev;
        int ysrcMask_dev = ysrc_dev;
        if (xsrcMask != -1)
            xsrcMask_dev = source->LogicalToDeviceX(xsrcMask);
        if (ysrcMask != -1)
            ysrcMask_dev = source->LogicalToDeviceY(ysrcMask);
        cairo_clip(cr);
        cairo_mask_surface(cr, maskSurf, -xsrcMask_dev, -ysrcMask_dev);
    }
    else
    {
        cairo_fill(cr);
    }
    cairo_restore(cr);
    if ( surfaceTmp )
    {
        cairo_surface_destroy(surfaceTmp);
    }
    m_logicalFunction = rop_save;
    return true;
}
Exemple #12
0
void FlatAuiTabArt::DrawButton(wxDC& dc,
                                    wxWindow* WXUNUSED(wnd),
                                    const wxRect& in_rect,
                                    int bitmap_id,
                                    int button_state,
                                    int orientation,
                                    wxRect* out_rect)
{
    wxBitmap bmp;
    wxRect rect;

    switch (bitmap_id)
    {
        case wxAUI_BUTTON_CLOSE:
            if (button_state & wxAUI_BUTTON_STATE_DISABLED)
                bmp = m_disabled_close_bmp;
            else
                bmp = m_active_close_bmp;
            break;
        case wxAUI_BUTTON_LEFT:
            if (button_state & wxAUI_BUTTON_STATE_DISABLED)
                bmp = m_disabled_left_bmp;
            else
                bmp = m_active_left_bmp;
            break;
        case wxAUI_BUTTON_RIGHT:
            if (button_state & wxAUI_BUTTON_STATE_DISABLED)
                bmp = m_disabled_right_bmp;
            else
                bmp = m_active_right_bmp;
            break;
        case wxAUI_BUTTON_WINDOWLIST:
            if (button_state & wxAUI_BUTTON_STATE_DISABLED)
                bmp = m_disabled_windowlist_bmp;
            else
                bmp = m_active_windowlist_bmp;
            break;
    }


    if (!bmp.IsOk())
        return;

    rect = in_rect;

    if (orientation == wxLEFT)
    {
        rect.SetX(in_rect.x);
        rect.SetY(((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2));
        rect.SetWidth(bmp.GetWidth());
        rect.SetHeight(bmp.GetHeight());
    }
    else
    {
        rect = wxRect(in_rect.x + in_rect.width - bmp.GetWidth(),
                      ((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2),
                      bmp.GetWidth(), bmp.GetHeight());
    }

    IndentPressedBitmap(&rect, button_state);
    dc.DrawBitmap(bmp, rect.x, rect.y, true);

    *out_rect = rect;
}
Exemple #13
0
void FlatAuiTabArt::DrawTab(wxDC& dc,
                                 wxWindow* wnd,
                                 const wxAuiNotebookPage& page,
                                 const wxRect& in_rect,
                                 int close_button_state,
                                 wxRect* out_tab_rect,
                                 wxRect* out_button_rect,
                                 int* x_extent)
{
    wxCoord normal_textx, normal_texty;
    wxCoord selected_textx, selected_texty;
    wxCoord texty;
    wxFont m_selected_font = m_normal_font;

    // if the caption is empty, measure some temporary text
    wxString caption = page.caption;
    if (caption.empty())
        caption = wxT("Xj");

    dc.SetFont(m_selected_font);
    dc.GetTextExtent(caption, &selected_textx, &selected_texty);

    dc.SetFont(m_normal_font);
    dc.GetTextExtent(caption, &normal_textx, &normal_texty);

    // figure out the size of the tab
    wxSize tab_size = GetTabSize(dc,
                                 wnd,
                                 page.caption,
                                 page.bitmap,
                                 page.active,
                                 close_button_state,
                                 x_extent);

    wxCoord tab_height = m_tab_ctrl_height - 3;
    wxCoord tab_width = tab_size.x;
    wxCoord tab_x = in_rect.x;
    wxCoord tab_y = in_rect.y + in_rect.height - tab_height;


    caption = page.caption;


    // select pen, brush and font for the tab to be drawn

    if (page.active)
    {
        dc.SetFont(m_selected_font);
        texty = selected_texty;
    }
    else
    {
        dc.SetFont(m_normal_font);
        texty = normal_texty;
    }


    // create points that will make the tab outline

    int clip_width = tab_width;
    if (tab_x + clip_width > in_rect.x + in_rect.width)
        clip_width = (in_rect.x + in_rect.width) - tab_x;

/*
    wxPoint clip_points[6];
    clip_points[0] = wxPoint(tab_x,              tab_y+tab_height-3);
    clip_points[1] = wxPoint(tab_x,              tab_y+2);
    clip_points[2] = wxPoint(tab_x+2,            tab_y);
    clip_points[3] = wxPoint(tab_x+clip_width-1, tab_y);
    clip_points[4] = wxPoint(tab_x+clip_width+1, tab_y+2);
    clip_points[5] = wxPoint(tab_x+clip_width+1, tab_y+tab_height-3);

    // FIXME: these ports don't provide wxRegion ctor from array of points
#if !defined(__WXDFB__) && !defined(__WXCOCOA__)
    // set the clipping region for the tab --
    wxRegion clipping_region(WXSIZEOF(clip_points), clip_points);
    dc.SetClippingRegion(clipping_region);
#endif // !wxDFB && !wxCocoa
*/
    // since the above code above doesn't play well with WXDFB or WXCOCOA,
    // we'll just use a rectangle for the clipping region for now --
    dc.SetClippingRegion(tab_x, tab_y, clip_width+1, tab_height-3);


    wxPoint border_points[4];
    if (m_flags &wxAUI_NB_BOTTOM)
    {
        border_points[0] = wxPoint(tab_x,             tab_y);
        border_points[1] = wxPoint(tab_x,             tab_y+tab_height-4);
        border_points[2] = wxPoint(tab_x+tab_width,   tab_y+tab_height-4);
        border_points[3] = wxPoint(tab_x+tab_width,   tab_y);
    }
    else //if (m_flags & wxAUI_NB_TOP) {}
    {
        border_points[0] = wxPoint(tab_x,             tab_y+tab_height);
        border_points[1] = wxPoint(tab_x,             tab_y);
        border_points[2] = wxPoint(tab_x+tab_width,   tab_y);
        border_points[3] = wxPoint(tab_x+tab_width,   tab_y+tab_height);
    }
    //  else if (m_flags &wxAUI_NB_LEFT) {}
    //  else if (m_flags &wxAUI_NB_RIGHT) {}

    int drawn_tab_yoff = border_points[1].y;
    int drawn_tab_height = border_points[0].y - border_points[1].y;


    if (page.active)
    {
        // draw active tab

        // draw base background color
        wxRect r(tab_x, tab_y, tab_width, tab_height);
        dc.SetPen(wxPen(m_active_colour));
        dc.SetBrush(wxBrush(m_active_colour));
        dc.DrawRectangle(r.x+1, r.y+1, r.width-1, r.height-4);

        // this white helps fill out the gradient at the top of the tab
        dc.SetPen(*wxWHITE_PEN);
        dc.SetBrush(*wxWHITE_BRUSH);
        dc.DrawRectangle(r.x+2, r.y+1, r.width-3, r.height-4);

        // these two points help the rounded corners appear more antialiased
        dc.SetPen(wxPen(m_active_colour));
        dc.DrawPoint(r.x+2, r.y+1);
        dc.DrawPoint(r.x+r.width-2, r.y+1);

        // set rectangle down a bit for gradient drawing
        //r.SetHeight(r.GetHeight()/2);
        r.x += 2;
        r.width -= 2;
        /*r.y += r.height;
        r.y -= 2;*/
        r.y += 1;
        r.height -= 2;

        // draw gradient background
        wxColor top_color = m_active_colour;
        wxColor bottom_color = m_active_colour;
        dc.GradientFillLinear(r, bottom_color, top_color, wxSOUTH);

        // Adapt text color
        int average = (m_active_colour.Red()+m_active_colour.Green()+m_active_colour.Blue())/3;
        if (average < 127) dc.SetTextForeground(*wxWHITE);
        else dc.SetTextForeground(*wxBLACK);
    }
    else
    {
        // draw inactive tab

        wxRect r(tab_x, tab_y+1, tab_width, tab_height-3);

        // start the gradent up a bit and leave the inside border inset
        // by a pixel for a 3D look.  Only the top half of the inactive
        // tab will have a slight gradient
        r.x += 3;
        r.y++;
        r.width -= 4;
        r.height /= 2;
        r.height--;

        // -- draw top gradient fill for glossy look
        wxColor top_color = m_base_colour;
        wxColor bottom_color = gdAuiStepColour(top_color, 160);
        dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH);

        r.y += r.height;
        r.y--;

        // -- draw bottom fill for glossy look
        top_color = m_base_colour;
        bottom_color = m_base_colour;
        dc.GradientFillLinear(r, top_color, bottom_color, wxSOUTH);

        // Adapt text color
        int average = (m_base_colour.Red()+m_base_colour.Green()+m_base_colour.Blue())/3;
        if (average < 127) dc.SetTextForeground(*wxWHITE);
        else dc.SetTextForeground(*wxBLACK);
    }

    // draw tab outline
    dc.SetPen(m_border_pen);
    dc.SetBrush(*wxTRANSPARENT_BRUSH);
    dc.DrawPolygon(WXSIZEOF(border_points), border_points);

    // there are two horizontal grey lines at the bottom of the tab control,
    // this gets rid of the top one of those lines in the tab control
    if (page.active)
    {
        if (m_flags &wxAUI_NB_BOTTOM)
            dc.SetPen(wxPen(wxColour(gdAuiStepColour(m_base_colour, 170))));
        //  else if (m_flags &wxAUI_NB_LEFT) {}
        //  else if (m_flags &wxAUI_NB_RIGHT) {}
        else //for wxAUI_NB_TOP
            dc.SetPen(m_base_colour_pen);

        //GDevelop use white pen so as to conform to white background
        dc.SetPen(*wxWHITE_PEN);

        dc.DrawLine(border_points[0].x+1,
                    border_points[0].y,
                    border_points[5].x,
                    border_points[5].y);
    }


    int text_offset = tab_x + 8;
    int close_button_width = 0;
    if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
    {
        close_button_width = m_active_close_bmp.GetWidth();
    }

    int bitmap_offset = 0;
    if (page.bitmap.IsOk())
    {
        bitmap_offset = tab_x + 8;

        // draw bitmap
        dc.DrawBitmap(page.bitmap,
                      bitmap_offset,
                      drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2),
                      true);

        text_offset = bitmap_offset + page.bitmap.GetWidth();
        text_offset += 3; // bitmap padding

    }
    else
    {
        text_offset = tab_x + 8;
    }


    wxString draw_text = gdAuiChopText(dc,
                          caption,
                          tab_width - (text_offset-tab_x) - close_button_width);

    // draw tab text
    dc.DrawText(draw_text,
                text_offset,
                drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1);

    // draw focus rectangle
    if (page.active && (wnd->FindFocus() == wnd))
    {
        wxRect focusRectText(text_offset, (drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1),
            selected_textx, selected_texty);

        wxRect focusRect;
        wxRect focusRectBitmap;

        if (page.bitmap.IsOk())
            focusRectBitmap = wxRect(bitmap_offset, drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2),
                                            page.bitmap.GetWidth(), page.bitmap.GetHeight());

        if (page.bitmap.IsOk() && draw_text.IsEmpty())
            focusRect = focusRectBitmap;
        else if (!page.bitmap.IsOk() && !draw_text.IsEmpty())
            focusRect = focusRectText;
        else if (page.bitmap.IsOk() && !draw_text.IsEmpty())
            focusRect = focusRectText.Union(focusRectBitmap);

        focusRect.Inflate(2, 2);

        wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0);
    }

    // draw close button if necessary
    if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
    {
        wxBitmap bmp = m_disabled_close_bmp;

        if (close_button_state == wxAUI_BUTTON_STATE_HOVER ||
            close_button_state == wxAUI_BUTTON_STATE_PRESSED)
        {
            bmp = m_active_close_bmp;
        }

        wxRect rect(tab_x + tab_width - close_button_width - 1,
                    tab_y + (tab_height/2) - (bmp.GetHeight()/2),
                    close_button_width,
                    tab_height);
        IndentPressedBitmap(&rect, close_button_state);
        dc.DrawBitmap(bmp, rect.x, rect.y, true);

        *out_button_rect = rect;
    }

    *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height);

    dc.DestroyClippingRegion();
}
Exemple #14
0
void TCWin::OnPaint( wxPaintEvent& event )
{
    int x, y;
    int i;
    char sbuf[100];
    int w;
    float tcmax, tcmin;

    GetClientSize( &x, &y );
//    qDebug() << "OnPaint" << x << y;

#if 0    
    //  establish some graphic element sizes/locations
    int x_graph = x * 1 / 10;
    int y_graph = y * 32 / 100;
    int x_graph_w = x * 8 / 10;
    int y_graph_h = (y * .7)  - (3 * m_button_height);
    m_graph_rect = wxRect(x_graph, y_graph, x_graph_w, y_graph_h);

    wxSize texc_size = wxSize( ( x * 60 / 100 ), ( y *29 / 100 ) );
    if( !m_tList->IsShown()){
        texc_size = wxSize( ( x * 90 / 100 ), ( y *29 / 100 ) );
    }
    
    m_ptextctrl->SetSize(texc_size);
#endif                                  
    
    wxPaintDC dc( this );

    wxString tlocn( pIDX->IDX_station_name, wxConvUTF8 );

//     if(1/*bForceRedraw*/)
    {


        int x_textbox = x * 5 / 100;
        int y_textbox = 6;

        int x_textbox_w = x * 51 / 100;
        int y_textbox_h = y * 25 / 100;

        // box the location text & tide-current table
        dc.SetPen( *pblack_3 );
        dc.SetBrush( *pltgray2 );
        dc.DrawRoundedRectangle( x_textbox, y_textbox, x_textbox_w, y_textbox_h, 4 );    //location text box

        if(m_tList->IsShown()) {
            wxRect tab_rect = m_tList->GetRect();
            dc.DrawRoundedRectangle( tab_rect.x - 4, y_textbox, tab_rect.width + 8, y_textbox_h, 4 ); //tide-current table box
        }

        //    Box the graph
        dc.SetPen( *pblack_1 );
        dc.SetBrush( *pltgray );
        dc.DrawRectangle( m_graph_rect.x, m_graph_rect.y, m_graph_rect.width, m_graph_rect.height );

        int hour_delta = 1;
        
        //  On some platforms, we cannot draw rotated text.
        //  So, reduce the complexity of horizontal axis time labels
#ifndef __WXMSW__
        hour_delta = 4;
#endif        
        
        
        //    Horizontal axis
        dc.SetFont( *pSFont );
        for( i = 0; i < 25; i++ ) {
            int xd = m_graph_rect.x + ( ( i ) * m_graph_rect.width / 25 );
            if( hour_delta != 1 ){
                if( i % hour_delta == 0 ) {
                    dc.SetPen( *pblack_2 );
                    dc.DrawLine( xd, m_graph_rect.y, xd, m_graph_rect.y + m_graph_rect.height + 5 );
                    char sbuf[5];
                    sprintf( sbuf, "%02d", i );
                    int x_shim = -20;
                    dc.DrawText( wxString( sbuf, wxConvUTF8 ), xd + x_shim + ( m_graph_rect.width / 25 ) / 2, m_graph_rect.y + m_graph_rect.height + 8 );
                }
                else{
                    dc.SetPen( *pblack_1 );
                    dc.DrawLine( xd, m_graph_rect.y, xd, m_graph_rect.y + m_graph_rect.height + 5 );
                }
            }
            else{
                dc.SetPen( *pblack_1 );
                dc.DrawLine( xd, m_graph_rect.y, xd, m_graph_rect.y + m_graph_rect.height + 5 );
                wxString sst;
                sst.Printf( _T("%02d"), i );
                dc.DrawRotatedText( sst, xd + ( m_graph_rect.width / 25 ) / 2, m_graph_rect.y + m_graph_rect.height + 8, 270. );
            }
        }

        //    Make a line for "right now"
        time_t t_now = wxDateTime::Now().GetTicks();       // now, in ticks

        float t_ratio = m_graph_rect.width * ( t_now - m_t_graphday_00_at_station ) / ( 25 * 3600 );

        //must eliminate line outside the graph (in that case put it outside the window)
        int xnow = ( t_ratio < 0 || t_ratio > m_graph_rect.width ) ? -1 : m_graph_rect.x + (int) t_ratio;
        dc.SetPen( *pred_2 );
        dc.DrawLine( xnow, m_graph_rect.y, xnow, m_graph_rect.y + m_graph_rect.height );
        dc.SetPen( *pblack_1 );

        //    Build the array of values, capturing max and min and HW/LW list

        if( !btc_valid ) {

            float dir;
            tcmax = -10;
            tcmin = 10;
            float val;
            m_tList->Clear();
            int list_index = 0;
            bool wt;

            wxBeginBusyCursor();

            // get tide flow sens ( flood or ebb ? )
            ptcmgr->GetTideFlowSens( m_t_graphday_00_at_station, BACKWARD_ONE_HOUR_STEP,
                                     pIDX->IDX_rec_num, tcv[0], val, wt );

            for( i = 0; i < 26; i++ ) {
                int tt = m_t_graphday_00_at_station + ( i * FORWARD_ONE_HOUR_STEP );
                ptcmgr->GetTideOrCurrent( tt, pIDX->IDX_rec_num, tcv[i], dir );
                if( tcv[i] > tcmax ) tcmax = tcv[i];

                if( tcv[i] < tcmin ) tcmin = tcv[i];
                if( TIDE_PLOT == m_plot_type ) {
                    if( !( ( tcv[i] > val ) == wt ) )                // if tide flow sens change
                    {
                        float tcvalue;                                  //look backward for HW or LW
                        time_t tctime;
                        ptcmgr->GetHightOrLowTide( tt, BACKWARD_TEN_MINUTES_STEP,
                                                   BACKWARD_ONE_MINUTES_STEP, tcv[i], wt, pIDX->IDX_rec_num, tcvalue,
                                                   tctime );
                        wxDateTime tcd;                                                 //write date
                        wxString s, s1;
                        tcd.Set( tctime + ( m_corr_mins * 60 ) );
                        s.Printf( tcd.Format( _T("%H:%M  ") ) );
                        s1.Printf( _T("%05.2f "), tcvalue );                           //write value
                        s.Append( s1 );
                        Station_Data *pmsd = pIDX->pref_sta_data;                       //write unit
                        if( pmsd ) s.Append( wxString( pmsd->units_abbrv, wxConvUTF8 ) );
                        s.Append( _T("   ") );
                        ( wt ) ? s.Append( _("HW") ) : s.Append( _("LW") );         //write HW or LT

                        m_tList->Insert( s, list_index );                       // update table list
                        list_index++;
                        wt = !wt;                                            //change tide flow sens
                    }
                    val = tcv[i];
                }
                if( CURRENT_PLOT == m_plot_type ) {
                    wxDateTime thx;                                                     //write date
                    wxString s, s1;
                    thx.Set( (time_t) ( tt + ( m_corr_mins * 60 ) ) );
                    s.Printf( thx.Format( _T("%H:%M  ") ) );
                    s1.Printf( _T("%05.2f "), fabs( tcv[i] ) );                        //write value
                    s.Append( s1 );
                    Station_Data *pmsd = pIDX->pref_sta_data;                           //write unit
                    if( pmsd ) s.Append( wxString( pmsd->units_abbrv, wxConvUTF8 ) );
                    s1.Printf( _T("  %03.0f"), dir );                              //write direction
                    s.Append( s1 );
                    m_tList->Insert( s, list_index );                           // update table list
                    list_index++;
                }

            }

            wxEndBusyCursor();

//    Set up the vertical parameters based on Tide or Current plot
            if( CURRENT_PLOT == m_plot_type ) {
                it = __max ( abs (( int ) tcmin - 1 ), abs ( ( int ) tcmax + 1 ) );
                ib = -it;

                im = 2 * it;
                m_plot_y_offset = m_graph_rect.height / 2;
                val_off = 0;
            } else {
                ib = (int) tcmin;
                if( tcmin < 0 ) ib -= 1;
                it = (int) tcmax + 1;

                im = it - ib; //abs ( ib ) + abs ( it );
                m_plot_y_offset = ( m_graph_rect.height * ( it - ib ) ) / im;
                val_off = ib;
            }

//    Build spline list of points

            m_sList.DeleteContents( true );
            m_sList.Clear();

            for( i = 0; i < 26; i++ ) {
                wxPoint *pp = new wxPoint;
                pp->x = m_graph_rect.x + ( ( i ) * m_graph_rect.width / 25 );
                pp->y = m_graph_rect.y + ( m_plot_y_offset )
                - (int) ( ( tcv[i] - val_off ) * m_graph_rect.height / im );

                m_sList.Append( pp );
            }

            btc_valid = true;
        }

        dc.SetTextForeground( GetGlobalColor( _T ( "DILG3" ) ) );

        //    Vertical Axis

        //      Maybe skip some lines and legends if the range is too high
        int height_stext;
         dc.GetTextExtent( _T("1"), NULL, &height_stext );

        int i_skip = 1;
        if( height_stext > m_graph_rect.height / im ) i_skip = 2;

        i = ib;
        while( i < it + 1 ) {
            int yd = m_graph_rect.y + ( m_plot_y_offset ) - ( ( i - val_off ) * m_graph_rect.height / im );

            if( ( m_plot_y_offset + m_graph_rect.y ) == yd ) dc.SetPen( *pblack_2 );
            else
                dc.SetPen( *pblack_1 );

            dc.DrawLine( m_graph_rect.x, yd, m_graph_rect.x + m_graph_rect.width, yd );
            snprintf( sbuf, 99, "%d", i );
            dc.DrawText( wxString( sbuf, wxConvUTF8 ), m_graph_rect.x - 20, yd - 5 );
            i += i_skip;

        }

        //    Draw the Value curve
#if wxCHECK_VERSION(2, 9, 0)
        wxPointList *list = (wxPointList *)&m_sList;
#else
        wxList *list = (wxList *) &m_sList;
#endif

        dc.SetPen( *pblack_2 );
#if wxUSE_SPLINES
        dc.DrawSpline( list );
#else
        dc.DrawLines ( list );
#endif
        //  More Info

///
        int station_offset = ptcmgr->GetStationTimeOffset( pIDX );
        int h = station_offset / 60;
        int m = station_offset - ( h * 60 );
        if( m_graphday.IsDST() ) h += 1;
        m_stz.Printf( _T("Z %+03d:%02d"), h, m );

//    Make the "nice" (for the US) station time-zone string, brutally by hand
        wxString mtz;
        switch( ptcmgr->GetStationTimeOffset( pIDX ) ) {
        case -240:
            mtz = _T( "AST" );
            break;
        case -300:
            mtz = _T( "EST" );
            break;
        case -360:
            mtz = _T( "CST" );
            break;
        }

        if( mtz.Len() ) {
            if( m_graphday.IsDST() ) mtz[1] = 'D';

            m_stz = mtz;
        }

        dc.SetFont( *pSFont );
        dc.GetTextExtent( m_stz, &w, &h );
        dc.DrawText( m_stz, x / 2 - w / 2, y - 2 * m_button_height );

        wxString sdate = m_graphday.Format( _T ( "%m/%d/%Y" ) );
        dc.SetFont( *pMFont );
        dc.GetTextExtent( sdate, &w, &h );
        dc.DrawText( sdate, x / 2 - w / 2, y - 1.5 * m_button_height );

        Station_Data *pmsd = pIDX->pref_sta_data;
        if( pmsd ) {
            dc.GetTextExtent( wxString( pmsd->units_conv, wxConvUTF8 ), &w, &h );
            dc.DrawRotatedText( wxString( pmsd->units_conv, wxConvUTF8 ), 5,
                                m_graph_rect.y + m_graph_rect.height / 2 + w / 2, 90. );
        }

        //      Show flood and ebb directions
        if(( strchr( "c", pIDX->IDX_type ) ) || ( strchr( "C", pIDX->IDX_type ) )) {
            dc.SetFont( *pSFont );

            wxString fdir;
            fdir.Printf( _T("%03d"), pIDX->IDX_flood_dir );
            dc.DrawText( fdir, m_graph_rect.x + m_graph_rect.width + 4, m_graph_rect.y + m_graph_rect.height * 1 / 4 );

            wxString edir;
            edir.Printf( _T("%03d"), pIDX->IDX_ebb_dir );
            dc.DrawText( edir, m_graph_rect.x + m_graph_rect.width + 4, m_graph_rect.y + m_graph_rect.height * 3 / 4 );

        }

//    Today or tomorrow
        wxString sday;
        wxDateTime this_now = wxDateTime::Now();

        int day = m_graphday.GetDayOfYear();
        if( m_graphday.GetYear() == this_now.GetYear() ) {
            if( day == this_now.GetDayOfYear() ) sday.Append( _( "Today" ) );
            else if( day == this_now.GetDayOfYear() + 1 ) sday.Append( _( "Tomorrow" ) );
            else
                sday.Append( m_graphday.GetWeekDayName( m_graphday.GetWeekDay() ) );
        } else if( m_graphday.GetYear() == this_now.GetYear() + 1
                   && day == this_now.Add( wxTimeSpan::Day() ).GetDayOfYear() ) sday.Append(
                           _( "Tomorrow" ) );

        dc.SetFont( *pSFont );
//                dc.GetTextExtent ( wxString ( sday, wxConvUTF8 ), &w, &h );       2.9.1
//                dc.DrawText ( wxString ( sday, wxConvUTF8 ), 55 - w/2, y * 88/100 );    2.9.1
        dc.GetTextExtent( sday, &w, &h );
        dc.DrawText( sday, 55 - w / 2, y - 2 * m_button_height );

    }
}
Exemple #15
0
wxRect wxGetClientDisplayRect()
{
    int x, y, width, height;
    wxClientDisplayRect(&x, &y, &width, &height);  // call plat-specific version
    return wxRect(x, y, width, height);
}
Exemple #16
0
RoutePoint::RoutePoint( double lat, double lon, const wxString& icon_ident, const wxString& name,
        const wxString &pGUID, bool bAddToList )
{
    //  Establish points
    m_lat = lat;
    m_lon = lon;

    //      Normalize the longitude, to fix any old poorly formed points
    if( m_lon < -180. ) m_lon += 360.;
    else
        if( m_lon > 180. ) m_lon -= 360.;

    //  Nice defaults
    m_seg_len = 0.0;
    m_seg_vmg = 0.0;
    m_seg_etd = wxInvalidDateTime;
    m_bDynamicName = false;
    m_bPtIsSelected = false;
    m_bIsBeingEdited = false;
    m_bIsActive = false;
    m_bBlink = false;
    m_bIsInRoute = false;
    m_CreateTimeX = wxDateTime::Now();
    m_bIsolatedMark = false;
    m_bShowName = true;
    m_bKeepXRoute = false;
    m_bIsVisible = true;
    m_bIsListed = true;
    CurrentRect_in_DC = wxRect( 0, 0, 0, 0 );
    m_NameLocationOffsetX = -10;
    m_NameLocationOffsetY = 8;
    m_pMarkFont = NULL;
    m_btemp = false;

    m_SelectNode = NULL;
    m_ManagerNode = NULL;
    m_IconScaleFactor = 1.0;
    
    m_HyperlinkList = new HyperlinkList;

    if( !pGUID.IsEmpty() )
        m_GUID = pGUID;
    else
        m_GUID = pWayPointMan->CreateGUID( this );

    //      Get Icon bitmap
    m_IconName = icon_ident;
    ReLoadIcon();

    SetName( name );

    //  Possibly add the waypoint to the global list maintained by the waypoint manager

    if( bAddToList && NULL != pWayPointMan )
        pWayPointMan->AddRoutePoint( this );

    m_bIsInLayer = g_bIsNewLayer;
    if( m_bIsInLayer ) {
        m_LayerID = g_LayerIdx;
        m_bIsListed = false;
    } else
        m_LayerID = 0;
    
    SetWaypointArrivalRadius( g_n_arrival_circle_radius );

    m_bShowWaypointRangeRings = false;
    m_iWaypointRangeRingsNumber = g_iWaypointRangeRingsNumber;
    m_fWaypointRangeRingsStep = g_fWaypointRangeRingsStep;
    m_iWaypointRangeRingsStepUnits = g_iWaypointRangeRingsStepUnits;
    m_wxcWaypointRangeRingsColour = g_colourWaypointRangeRingsColour;
}
void wxMultiColumnListCtrl::CalculateLayout(wxDC& dc)
{
    if (m_items.GetSelection() == -1)
        m_items.SetSelection(0);

    int columnCount = 1;

    // Spacing between edge of window or between columns
    int xMargin = 4;
    int yMargin = 4;

    // Inter-row spacing
    int rowSpacing = 2;

    wxSize itemSize = m_items.CalculateItemSize(dc);
    m_overallSize = wxSize(350, 200);

    size_t i;
    int currentRow = 0;
    int x = xMargin;
    int y = yMargin;

    bool breaking = false;

    for (i = 0; i < (size_t) m_items.GetItemCount(); i++)
    {
        wxSize oldOverallSize = m_overallSize;

        m_items.GetItem(i).SetRect(wxRect(x, y, itemSize.x, itemSize.y));
        m_items.GetItem(i).SetColPos(columnCount-1);
        m_items.GetItem(i).SetRowPos(currentRow);

        if (m_items.GetItem(i).GetRect().GetBottom() > m_overallSize.y)
            m_overallSize.y = m_items.GetItem(i).GetRect().GetBottom() + yMargin;

        if (m_items.GetItem(i).GetRect().GetRight() > m_overallSize.x)
            m_overallSize.x = m_items.GetItem(i).GetRect().GetRight() + xMargin;

        currentRow ++;

        y += (rowSpacing + itemSize.y);

        bool stopBreaking = breaking;

        if ((currentRow > m_items.GetRowCount()) || (m_items.GetItem(i).GetBreakColumn() && !breaking && (currentRow != 1)))
        {
            currentRow = 0;
            columnCount ++;
            x += (xMargin + itemSize.x);
            y = yMargin;

            // Make sure we don't orphan a group
            if (m_items.GetItem(i).GetIsGroup() || (m_items.GetItem(i).GetBreakColumn() && !breaking))
            {
                m_overallSize = oldOverallSize;

                if (m_items.GetItem(i).GetBreakColumn())
                    breaking = true;

                // Repeat the last item, in the next column
                i --;
            }
        }

        if (stopBreaking)
            breaking = false;
    }

    m_items.SetColumnCount(columnCount);

    InvalidateBestSize();
}
Exemple #18
0
bool Camera_INDIClass::Capture(int duration, usImage& img, int options, const wxRect& subframeArg)
{
    if (Connected) {

        bool takeSubframe = UseSubframes;
        wxRect subframe(subframeArg);

        // we can set the exposure time directly in the camera
        if (expose_prop) {
            if (Binning != m_curBinning)
            {
                FullSize = wxSize(m_maxSize.x / Binning, m_maxSize.y / Binning);
                binning_x->value = Binning;
                binning_y->value = Binning;
                sendNewNumber(binning_prop);
                m_curBinning = Binning;
            }

            if (subframe.width <= 0 || subframe.height <= 0)
            {
                takeSubframe = false;
            }

            // Program the size
            if (!takeSubframe)
            {
                subframe = wxRect(0, 0, FullSize.GetWidth(), FullSize.GetHeight());
            }

            if (subframe != m_roi)
            {
                frame_x->value = subframe.x*Binning;
                frame_y->value = subframe.y*Binning;
                frame_width->value = subframe.width*Binning;
                frame_height->value = subframe.height*Binning;
                sendNewNumber(frame_prop);
                m_roi = subframe;
            }
            //printf("Exposing for %d(ms)\n", duration);

            // set the exposure time, this immediately start the exposure
            expose_prop->np->value = (double)duration/1000;
            sendNewNumber(expose_prop);

            modal = true;  // will be reset when the image blob is received

            unsigned long loopwait = duration > 100 ? 10 : 1;

            CameraWatchdog watchdog(duration, GetTimeoutMs());

            while (modal) {
                wxMilliSleep(loopwait);
                if (WorkerThread::TerminateRequested())
                    return true;
                if (watchdog.Expired())
                {
                    DisconnectWithAlert(CAPT_FAIL_TIMEOUT);
                    return true;
                }
            }
        }
        // for video camera without exposure time setting
        else if (video_prop) {
            takeSubframe = false;
            //printf("Enabling video capture\n");
            ISwitch *v_on = IUFindSwitch(video_prop,"ON");
            ISwitch *v_off = IUFindSwitch(video_prop,"OFF");
            v_on->s = ISS_ON;
            v_off->s = ISS_OFF;
            // start capture, every video frame is received as a blob
            sendNewSwitch(video_prop);

            // wait the required time
            wxMilliSleep(duration); // TODO : add the frames received during exposure

            //printf("Stop video capture\n");
            v_on->s = ISS_OFF;
            v_off->s = ISS_ON;
            sendNewSwitch(video_prop);
        }
        else {
            return true;
        }

        //printf("Exposure end\n");

        if (strcmp(cam_bp->format, ".fits") == 0) {
            //printf("Processing fits file\n");
            // for CCD camera
            if ( ! ReadFITS(img,takeSubframe,subframe) ) {
                if (options & CAPTURE_SUBTRACT_DARK) {
                    //printf("Subtracting dark\n");
                    SubtractDark(img);
                }
                if (options & CAPTURE_RECON) {
                    if (PixSizeX != PixSizeY) SquarePixels(img, PixSizeX, PixSizeY);
                }
                return false;
            } else {
                return true;
            }
        } else if (strcmp(cam_bp->format, ".stream") == 0) {
            //printf("Processing stream file\n");
            // for video camera
            return ReadStream(img);
        } else {
            pFrame->Alert(_("Unknown image format: ") + wxString::FromAscii(cam_bp->format));
            return true;
        }

    }
    else {
        // in case the camera is not connected
        return true;
    }
    // we must never go here
    return true;
}
Exemple #19
0
wxRect GroupCell::HideRect()
{
  return wxRect(m_currentPoint.x - 10, m_currentPoint.y - m_center, 10, 10);
}
void GotoFile::BuildContent(wxWindow* parent, IncrementalSelectIterator *iterator, const wxString &title,
                            const wxString &message)
{
    //(*Initialize(GotoFile)
    wxStaticText* labelCtrl;

    Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX|wxMAXIMIZE_BOX, _T("wxID_ANY"));
    m_sizer = new wxBoxSizer(wxVERTICAL);
    labelCtrl = new wxStaticText(this, wxID_ANY, _("Some text"), wxDefaultPosition, wxDefaultSize, 0, _T("wxID_ANY"));
    m_sizer->Add(labelCtrl, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 5);
    m_Text = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    m_Text->SetFocus();
    m_sizer->Add(m_Text, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 5);
    m_ResultList = new IncrementalListCtrl(this, ID_RESULT_LIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_NO_HEADER|wxLC_SINGLE_SEL|wxLC_VIRTUAL|wxVSCROLL|wxHSCROLL, wxDefaultValidator, _T("ID_RESULT_LIST"));
    m_ResultList->SetMinSize(wxSize(500,300));
    m_sizer->Add(m_ResultList, 1, wxALL|wxEXPAND, 5);
    SetSizer(m_sizer);
    m_sizer->Fit(this);
    m_sizer->SetSizeHints(this);
    //*)

    SetTitle(title);
    labelCtrl->SetLabel(message);

    // Call this here to make sure the column widths are correctly calculated.
    m_ResultList->SetIterator(iterator);
    m_handler.Init(m_ResultList, m_Text);

    const int columnWidth = iterator->GetColumnWidth(0);

    // Add first column
    wxListItem column;
    column.SetId(0);
    column.SetText( _("Column") );
    column.SetWidth(columnWidth);
    m_ResultList->InsertColumn(0, column);
    m_ResultList->SetIterator(iterator);

    // Call Fit to make sure all GetSize methods return correct values.
    m_sizer->Fit(this);

    {
        // Use GetItemRect to account for the spacing between rows. GetCharHeight is used just as
        // precaution if GetItemRect fails.
        wxRect itemRect;
        if (!m_ResultList->GetItemRect(0, itemRect))
            itemRect = wxRect();
        const int charHeight = std::max(m_ResultList->GetCharHeight(), itemRect.GetHeight());
        const int totalHeight = charHeight * m_ResultList->GetItemCount() + charHeight / 2;

        const wxSize minSize = m_ResultList->GetMinSize();
        int minYCorrected = minSize.y;

        // Make the list taller if there are many items in it. This should make it a bit easier to find
        // stuff. The height would be something like 50% of the display's client area height.
        if (totalHeight > minSize.y)
        {
            const wxRect monitorRect = cbGetMonitorRectForWindow(parent);
            const int monitorHeight = int(std::lround(monitorRect.GetHeight() * 0.5));
            minYCorrected = std::max(minYCorrected, std::min(monitorHeight, totalHeight));
        }

        // Resize the window to maximise visible items. Do this using SetSize instead of using
        // SetMinSize to allow the user to make the window smaller if he/she wishes to do so.
        const wxSize windowSize = GetSize();
        // GetSize for the list control could return a window smaller than the minSize, but the
        // window size could be accounting for list control's min size. This means that sizeDiff
        // could be calculated larger than needed. Account for this using std::max. This seems to
        // happen in wx2.8 builds.
        const wxSize listSize(std::max(m_ResultList->GetSize().x, minSize.x),
                              std::max(m_ResultList->GetSize().y, minSize.y));
        // This accounts for non-list UI elements present in the window.
        const wxSize sizeDiff = windowSize - listSize;
        SetSize(wxSize(std::max(columnWidth + sizeDiff.x, windowSize.x), minYCorrected + sizeDiff.y));
    }
}
Exemple #21
0
void wxWindowDFB::DoRefreshWindow()
{
    // NB: DoRefreshRect() takes window coords, not client, so this is correct
    DoRefreshRect(wxRect(GetSize()));
}
void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
{
    int w, h;
    GetClientSize(&w, &h);

#ifdef __WXGTK__
//    int vw;
//    GetVirtualSize(&vw, NULL);
#endif

    wxAutoBufferedPaintDC dc(this);

    dc.SetBackground(GetBackgroundColour());
    dc.Clear();

    // account for the horizontal scrollbar offset in the parent window
    dc.SetDeviceOrigin(m_scrollOffset, 0);

    const unsigned int count = m_numColumns;
    int xpos = 0;
    for ( unsigned int i = 0; i < count; i++ )
    {
        const unsigned idx = m_colIndices[i];
        const wxHeaderColumn& col = GetColumn(idx);
        if ( col.IsHidden() )
            continue;

        int colWidth = col.GetWidth();

        wxHeaderSortIconType sortArrow;
        if ( col.IsSortKey() )
        {
            sortArrow = col.IsSortOrderAscending() ? wxHDR_SORT_ICON_UP
                                                   : wxHDR_SORT_ICON_DOWN;
        }
        else // not sorting by this column
        {
            sortArrow = wxHDR_SORT_ICON_NONE;
        }

        int state = 0;
        if ( IsEnabled() )
        {
            if ( idx == m_hover )
                state = wxCONTROL_CURRENT;
        }
        else // disabled
        {
            state = wxCONTROL_DISABLED;
        }

        if (i == 0)
           state |= wxCONTROL_SPECIAL;

        wxHeaderButtonParams params;
        params.m_labelText = col.GetTitle();
        params.m_labelBitmap = col.GetBitmap();
        params.m_labelAlignment = col.GetAlignment();

#ifdef __WXGTK__
        if (i == count-1)
        {
//            colWidth = wxMax( colWidth, vw - xpos );
            state |= wxCONTROL_DIRTY;
        }
#endif

        wxRendererNative::Get().DrawHeaderButton
                                (
                                    this,
                                    dc,
                                    wxRect(xpos, 0, colWidth, h),
                                    state,
                                    sortArrow,
                                    &params
                                );

        xpos += colWidth;
    }
}
Exemple #23
0
//---------------------------------------------------------
inline wxRect CVIEW_Map_Control::_Get_Client(void)
{
	return( wxRect(wxPoint(0, 0), GetClientSize()) );
}
/// Tests the Operators
/// @return True if all tests were executed, false if not
bool FloatingTextTestSuite::TestCaseOperator()
{
    //------Last Checked------//
    // - Dec 7, 2004
    
    const FontSetting fontSetting(wxT("Arial"), 12, FontSetting::weightBold, true, true, true, wxColor(255,0,0));
    const FontSetting fontSetting2(wxT("Arial2"), 12, FontSetting::weightBold, true, true, true, wxColor(255,0,0));
    
    // TEST CASE: Operator =
	{    
	    FloatingText floatingText(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting);
	    FloatingText floatingText2 = floatingText;
        TEST(wxT("Operator="), 
            (floatingText2.GetText() == wxT("Test")) &&
            (floatingText2.GetRect() == wxRect(10,10,20,20)) &&
            (floatingText2.IsAlignedCenter()) &&
            (floatingText2.HasBorder()) &&
            (floatingText2.GetFontSetting() == fontSetting)
        );
            
		// TEST CASE: Self assignment
		{
		    FloatingText floatingText(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting);
		    floatingText = floatingText;
            TEST(wxT("Operator= (self-assignment)"), 
                (floatingText.GetText() == wxT("Test")) &&
                (floatingText.GetRect() == wxRect(10,10,20,20)) &&
                (floatingText.IsAlignedCenter()) &&
                (floatingText.HasBorder()) &&
                (floatingText.GetFontSetting() == fontSetting)
            );
        }
    }

	// TEST CASE: Operator==
	{
	    FloatingText floatingText(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting);
	    FloatingText floatingText2(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting);
	    FloatingText floatingText3(wxT("Test2"), wxRect(10,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting);
	    FloatingText floatingText4(wxT("Test"), wxRect(11,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting);
	    FloatingText floatingText5(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignLeft | FloatingText::border, fontSetting);
	    FloatingText floatingText6(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignCenter, fontSetting);
	    FloatingText floatingText7(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting2);
	    
		// TEST CASE: floatingText == floatingText
		TEST(wxT("Operator== - floatingText == floatingText"), (floatingText == floatingText2));
		TEST(wxT("Operator== - floatingText != floatingText"), !(floatingText == floatingText3));
		TEST(wxT("Operator== - floatingText != floatingText 2"), !(floatingText == floatingText4));
		TEST(wxT("Operator== - floatingText != floatingText 3"), !(floatingText == floatingText5));
		TEST(wxT("Operator== - floatingText != floatingText 4"), !(floatingText == floatingText6));
		TEST(wxT("Operator== - floatingText != floatingText 5"), !(floatingText == floatingText7));
	}

	// TEST CASE: Operator!=
	{
	    FloatingText floatingText(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting);
	    FloatingText floatingText2(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting);
	    FloatingText floatingText3(wxT("Test2"), wxRect(10,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting);
	    FloatingText floatingText4(wxT("Test"), wxRect(11,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting);
	    FloatingText floatingText5(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignLeft | FloatingText::border, fontSetting);
	    FloatingText floatingText6(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignCenter, fontSetting);
	    FloatingText floatingText7(wxT("Test"), wxRect(10,10,20,20), FloatingText::alignCenter | FloatingText::border, fontSetting2);
	   
	    // TEST CASE: floatingText != floatingText
		TEST(wxT("Operator!= - floatingText == floatingText"), !(floatingText != floatingText2));
		TEST(wxT("Operator!= - floatingText != floatingText"), (floatingText != floatingText3));
		TEST(wxT("Operator!= - floatingText != floatingText 2"), (floatingText != floatingText4));
		TEST(wxT("Operator!= - floatingText != floatingText 3"), (floatingText != floatingText5));
		TEST(wxT("Operator!= - floatingText != floatingText 4"), (floatingText != floatingText6));
		TEST(wxT("Operator!= - floatingText != floatingText 5"), (floatingText != floatingText7));
	}
	    
    return (true);
}
Exemple #25
0
void wxSashWindow::OnMouseEvent(wxMouseEvent& event)
{
    wxCoord x, y;
    event.GetPosition(&x, &y);

    wxSashEdgePosition sashHit = SashHitTest(x, y);

    if (event.LeftDown())
    {
        CaptureMouse();
        m_mouseCaptured = true;

        if ( sashHit != wxSASH_NONE )
        {
            // Required for X to specify that
            // that we wish to draw on top of all windows
            // - and we optimise by specifying the area
            // for creating the overlap window.
            // Find the first frame or dialog and use this to specify
            // the area to draw on.
            wxWindow* parent = this;

            while (parent && !parent->IsKindOf(CLASSINFO(wxDialog)) &&
                             !parent->IsKindOf(CLASSINFO(wxFrame)))
              parent = parent->GetParent();

            wxScreenDC::StartDrawingOnTop(parent);

            // We don't say we're dragging yet; we leave that
            // decision for the Dragging() branch, to ensure
            // the user has dragged a little bit.
            m_dragMode = wxSASH_DRAG_LEFT_DOWN;
            m_draggingEdge = sashHit;
            m_firstX = x;
            m_firstY = y;

            if ( (sashHit == wxSASH_LEFT) || (sashHit == wxSASH_RIGHT) )
            {
                if (m_currentCursor != m_sashCursorWE)
                {
                    SetCursor(*m_sashCursorWE);
                }
                m_currentCursor = m_sashCursorWE;
            }
            else
            {
                if (m_currentCursor != m_sashCursorNS)
                {
                    SetCursor(*m_sashCursorNS);
                }
                m_currentCursor = m_sashCursorNS;
            }
        }
    }
    else if ( event.LeftUp() && m_dragMode == wxSASH_DRAG_LEFT_DOWN )
    {
        // Wasn't a proper drag
        if (m_mouseCaptured)
            ReleaseMouse();
        m_mouseCaptured = false;

        wxScreenDC::EndDrawingOnTop();
        m_dragMode = wxSASH_DRAG_NONE;
        m_draggingEdge = wxSASH_NONE;
    }
    else if (event.LeftUp() && m_dragMode == wxSASH_DRAG_DRAGGING)
    {
        // We can stop dragging now and see what we've got.
        m_dragMode = wxSASH_DRAG_NONE;
        if (m_mouseCaptured)
            ReleaseMouse();
        m_mouseCaptured = false;

        // Erase old tracker
        DrawSashTracker(m_draggingEdge, m_oldX, m_oldY);

        // End drawing on top (frees the window used for drawing
        // over the screen)
        wxScreenDC::EndDrawingOnTop();

        int w, h;
        GetSize(&w, &h);
        int xp, yp;
        GetPosition(&xp, &yp);

        wxSashEdgePosition edge = m_draggingEdge;
        m_draggingEdge = wxSASH_NONE;

        wxRect dragRect;
        wxSashDragStatus status = wxSASH_STATUS_OK;

        // the new height and width of the window - if -1, it didn't change
        int newHeight = wxDefaultCoord,
            newWidth = wxDefaultCoord;

        // NB: x and y may be negative and they're relative to the sash window
        //     upper left corner, while xp and yp are expressed in the parent
        //     window system of coordinates, so adjust them! After this
        //     adjustment, all coordinates are relative to the parent window.
        y += yp;
        x += xp;

        switch (edge)
        {
            case wxSASH_TOP:
                if ( y > yp + h )
                {
                    // top sash shouldn't get below the bottom one
                    status = wxSASH_STATUS_OUT_OF_RANGE;
                }
                else
                {
                    newHeight = h - (y - yp);
                }
                break;

            case wxSASH_BOTTOM:
                if ( y < yp )
                {
                    // bottom sash shouldn't get above the top one
                    status = wxSASH_STATUS_OUT_OF_RANGE;
                }
                else
                {
                    newHeight = y - yp;
                }
                break;

            case wxSASH_LEFT:
                if ( x > xp + w )
                {
                    // left sash shouldn't get beyond the right one
                    status = wxSASH_STATUS_OUT_OF_RANGE;
                }
                else
                {
                    newWidth = w - (x - xp);
                }
                break;

            case wxSASH_RIGHT:
                if ( x < xp )
                {
                    // and the right sash, finally, shouldn't be beyond the
                    // left one
                    status = wxSASH_STATUS_OUT_OF_RANGE;
                }
                else
                {
                    newWidth = x - xp;
                }
                break;

            case wxSASH_NONE:
                // can this happen at all?
                break;
        }

        if ( newHeight == wxDefaultCoord )
        {
            // didn't change
            newHeight = h;
        }
        else
        {
            // make sure it's in m_minimumPaneSizeY..m_maximumPaneSizeY range
            newHeight = wxMax(newHeight, m_minimumPaneSizeY);
            newHeight = wxMin(newHeight, m_maximumPaneSizeY);
        }

        if ( newWidth == wxDefaultCoord )
        {
            // didn't change
            newWidth = w;
        }
        else
        {
            // make sure it's in m_minimumPaneSizeY..m_maximumPaneSizeY range
            newWidth = wxMax(newWidth, m_minimumPaneSizeX);
            newWidth = wxMin(newWidth, m_maximumPaneSizeX);
        }

        dragRect = wxRect(x, y, newWidth, newHeight);

        wxSashEvent event(GetId(), edge);
        event.SetEventObject(this);
        event.SetDragStatus(status);
        event.SetDragRect(dragRect);
        GetEventHandler()->ProcessEvent(event);
    }
    else if ( event.LeftUp() )
    {
        if (m_mouseCaptured)
           ReleaseMouse();
        m_mouseCaptured = false;
    }
    else if (event.Moving() && !event.Dragging())
    {
        // Just change the cursor if required
        if ( sashHit != wxSASH_NONE )
        {
            if ( (sashHit == wxSASH_LEFT) || (sashHit == wxSASH_RIGHT) )
            {
                if (m_currentCursor != m_sashCursorWE)
                {
                    SetCursor(*m_sashCursorWE);
                }
                m_currentCursor = m_sashCursorWE;
            }
            else
            {
                if (m_currentCursor != m_sashCursorNS)
                {
                    SetCursor(*m_sashCursorNS);
                }
                m_currentCursor = m_sashCursorNS;
            }
        }
        else
        {
            SetCursor(wxNullCursor);
            m_currentCursor = NULL;
        }
    }
    else if ( event.Dragging() &&
              ((m_dragMode == wxSASH_DRAG_DRAGGING) ||
               (m_dragMode == wxSASH_DRAG_LEFT_DOWN)) )
    {
        if ( (m_draggingEdge == wxSASH_LEFT) || (m_draggingEdge == wxSASH_RIGHT) )
        {
            if (m_currentCursor != m_sashCursorWE)
            {
                SetCursor(*m_sashCursorWE);
            }
            m_currentCursor = m_sashCursorWE;
        }
        else
        {
            if (m_currentCursor != m_sashCursorNS)
            {
                SetCursor(*m_sashCursorNS);
            }
            m_currentCursor = m_sashCursorNS;
        }

        if (m_dragMode == wxSASH_DRAG_LEFT_DOWN)
        {
            m_dragMode = wxSASH_DRAG_DRAGGING;
            DrawSashTracker(m_draggingEdge, x, y);
        }
        else
        {
            if ( m_dragMode == wxSASH_DRAG_DRAGGING )
            {
                // Erase old tracker
                DrawSashTracker(m_draggingEdge, m_oldX, m_oldY);

                // Draw new one
                DrawSashTracker(m_draggingEdge, x, y);
            }
        }
        m_oldX = x;
        m_oldY = y;
    }
    else if ( event.LeftDClick() )
    {
        // Nothing
    }
    else
    {
    }
}
Exemple #26
0
void IsoLine::drawGLIsoLineLabels(GRIBOverlayFactory *pof, wxColour text_color, wxColour back_color,
                                PlugIn_ViewPort *vp, int density, int first, double coef)
{
    std::list<Segment *>::iterator it;
    int nb = first;
    wxString label;

    label.Printf(_T("%d"), (int)(value*coef+0.5));

    int w, h;

    wxPen penText(text_color);
    wxBrush backBrush(back_color);

    int label_offset = 10;

      if(!m_imageLabel.IsOk())
      {
            wxBitmap bm(100,100);          // big enough
            wxMemoryDC mdc(bm);
            mdc.Clear();

            mdc.GetTextExtent(label, &w, &h);

            mdc.SetPen(penText);
            mdc.SetBrush(backBrush);
            mdc.SetTextForeground(text_color);
            mdc.SetTextBackground(back_color);

            int xd = 0;
            int yd = 0;
//            mdc.DrawRoundedRectangle(xd, yd, w+(label_offset * 2), h, -.25);
            mdc.DrawRectangle(xd, yd, w+(label_offset * 2), h+2);
            mdc.DrawText(label, label_offset/2 + xd, yd-1);
            
            mdc.SelectObject(wxNullBitmap);

            wxBitmap sub_BMLabel = bm.GetSubBitmap(wxRect(0,0,w+(label_offset * 2), h+2));
            m_imageLabel = sub_BMLabel.ConvertToImage();
      }

    //---------------------------------------------------------
    // Ecrit les labels
    //---------------------------------------------------------
    for (it=trace.begin(); it!=trace.end(); it++,nb++)
    {
        if (nb % density == 0)
		{
            Segment *seg = *it;

//            if(vp->vpBBox.PointInBox((seg->px1 + seg->px2)/2., (seg->py1 + seg->py2)/2., 0.))
            {
                  int w = m_imageLabel.GetWidth();
                  int h = m_imageLabel.GetHeight();
                  wxPoint ab;
                  GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
                  wxPoint cd;
                  GetCanvasPixLL(vp, &cd, seg->py1, seg->px1);

                  int xd = (ab.x + cd.x-(w+label_offset * 2))/2;
                  int yd = (ab.y + cd.y - h)/2;

                  glRasterPos2i(xd, yd);
                  glPixelZoom(1, -1); /* draw data from top to bottom */
                  glDrawPixels(w, h, GL_RGB, GL_UNSIGNED_BYTE, m_imageLabel.GetData());
                  glPixelZoom(1, 1);
            }
        }
    }
}
Exemple #27
0
 void SetPosition(int x, int y, const wxSize& size)
 {
     m_position = wxRect(wxPoint(x, y), size);
 }
Exemple #28
0
 wxTabFrame()
 {
     m_tabs = NULL;
     m_rect = wxRect(0,0,200,200);
     m_tab_ctrl_height = 20;
 }
Exemple #29
0
void ODDC::DrawBitmap( const wxBitmap &bitmap, wxCoord x, wxCoord y, bool usemask )
{
#ifdef ocpnUSE_GLES  // Do not attempt to do anything with glDrawPixels if using opengles
        return;
#endif

    wxBitmap bmp;
    if( x < 0 || y < 0 ) {
        int dx = ( x < 0 ? -x : 0 );
        int dy = ( y < 0 ? -y : 0 );
        int w = bitmap.GetWidth() - dx;
        int h = bitmap.GetHeight() - dy;
        /* picture is out of viewport */
        if( w <= 0 || h <= 0 ) return;
        wxBitmap newBitmap = bitmap.GetSubBitmap( wxRect( dx, dy, w, h ) );
        x += dx;
        y += dy;
        bmp = newBitmap;
    } else {
        bmp = bitmap;
    }
    if( dc )
        dc->DrawBitmap( bmp, x, y, usemask );
#ifdef ocpnUSE_GL
    else {
        wxImage image = bmp.ConvertToImage();
        int w = image.GetWidth(), h = image.GetHeight();

        if( usemask ) {
            unsigned char *d = image.GetData();
            unsigned char *a = image.GetAlpha();

            unsigned char mr, mg, mb;
            if( !image.GetOrFindMaskColour( &mr, &mg, &mb ) && !a ) printf(
                    "trying to use mask to draw a bitmap without alpha or mask\n" );

            unsigned char *e = new unsigned char[4 * w * h];
            if(e && d){
                for( int y = 0; y < h; y++ )
                    for( int x = 0; x < w; x++ ) {
                        unsigned char r, g, b;
                        int off = ( y * image.GetWidth() + x );
                        r = d[off * 3 + 0];
                        g = d[off * 3 + 1];
                        b = d[off * 3 + 2];

                        e[off * 4 + 0] = r;
                        e[off * 4 + 1] = g;
                        e[off * 4 + 2] = b;

                        e[off * 4 + 3] =
                                a ? a[off] : ( ( r == mr ) && ( g == mg ) && ( b == mb ) ? 0 : 255 );
                    }
            }

            glColor4f( 1, 1, 1, 1 );
            GLDrawBlendData( x, y, w, h, GL_RGBA, e );
            delete[] ( e );
        } else {
            glRasterPos2i( x, y );
            glPixelZoom( 1, -1 ); /* draw data from top to bottom */
            if(image.GetData())
                glDrawPixels( w, h, GL_RGB, GL_UNSIGNED_BYTE, image.GetData() );
            glPixelZoom( 1, 1 );
        }
    }
#endif    
}
Exemple #30
0
wxRect wxDisplay::GetClientArea() const
{
    wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );

    return m_impl->GetClientArea();
}