Esempio n. 1
0
void tpanelnotebook::PostSplitSizeCorrect() {
	#if TPANEL_COPIOUS_LOGGING
		LogMsgFormat(LOGT::TPANELTRACE, "TCL: tpanelnotebook::PostSplitSizeCorrect(): START");
	#endif
	wxSize totalsize=GetClientSize();

	wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes();
	size_t pane_count = all_panes.GetCount();
	size_t tabctrl_count = 0;
	std::forward_list<wxAuiPaneInfo *> tabctrlarray;
	for (size_t i = 0; i < pane_count; ++i) {
		if (all_panes.Item(i).name != wxT("dummy")) {
			tabctrl_count++;
			tabctrlarray.push_front(&(all_panes.Item(i)));
			#if TPANEL_COPIOUS_LOGGING
				LogMsgFormat(LOGT::TPANELTRACE, "TCL: PostSplitSizeCorrect1 %d %d %d %d", all_panes.Item(i).dock_direction, all_panes.Item(i).dock_layer,
						all_panes.Item(i).dock_row, all_panes.Item(i).dock_pos);
			#endif
		}
	}
	for (auto &it : tabctrlarray) {
		wxAuiPaneInfo &pane = *it;
		pane.BestSize(totalsize.GetWidth() / tabctrl_count, totalsize.GetHeight());
		pane.MaxSize(totalsize.GetWidth() / tabctrl_count, totalsize.GetHeight());
		pane.DockFixed();
		if (pane.dock_direction != wxAUI_DOCK_LEFT && pane.dock_direction != wxAUI_DOCK_RIGHT && pane.dock_direction != wxAUI_DOCK_CENTRE) {
			pane.Right();
			pane.dock_row = 0;
			pane.dock_pos = 1;    //trigger code below
		}
		if (pane.dock_pos > 0) {    //make a new row, bumping up any others to make room
			if (pane.dock_direction == wxAUI_DOCK_LEFT) {
				for (auto &jt : tabctrlarray) {
					if (jt->dock_direction == pane.dock_direction && jt->dock_row > pane.dock_row && jt->dock_layer == pane.dock_layer) {
						jt->dock_row++;
					}
				}
				pane.dock_pos = 0;
				pane.dock_row++;
			} else {
				for (auto &jt : tabctrlarray) {
					if (jt->dock_direction == pane.dock_direction && jt->dock_row >= pane.dock_row &&
							jt->dock_layer == pane.dock_layer && jt->dock_pos == 0) {
						jt->dock_row++;
					}
				}
				pane.dock_pos = 0;
			}
		}
	}
	for (auto &it : tabctrlarray) {
		m_mgr.InsertPane(it->window, *it, wxAUI_INSERT_ROW);
	}
	m_mgr.Update();

	for (size_t i = 0; i < pane_count; ++i) {
		if (all_panes.Item(i).name != wxT("dummy")) {
			#if TPANEL_COPIOUS_LOGGING
				LogMsgFormat(LOGT::TPANELTRACE, "TCL: PostSplitSizeCorrect2 %d %d %d %d", all_panes.Item(i).dock_direction, all_panes.Item(i).dock_layer,
						all_panes.Item(i).dock_row, all_panes.Item(i).dock_pos);
			#endif
		}
	}

	DoSizing();
	owner->Refresh();
	#if TPANEL_COPIOUS_LOGGING
		LogMsgFormat(LOGT::TPANELTRACE, "TCL: tpanelnotebook::PostSplitSizeCorrect(): END");
	#endif
}
Esempio n. 2
0
AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
                                 const wxPoint & pos,
                                 const wxSize & size):
   wxFrame(parent,
           id,
           "Audacity",
           pos,
           size),
   mRate((double) gPrefs->Read("/SamplingRate/DefaultProjectSampleRate",
                               44100)),
   mDirty(false),
   mAPalette(NULL),
   mDrag(NULL),
   mTrackPanel(NULL),
   mHistoryWindow(NULL),
   mAutoScrolling(false)
{

   //
   // Create track list
   //

   mTracks = new TrackList();
   mLastSavedTracks = NULL;

   //
   // Initialize view info (shared with TrackPanel)
   //

   // Selection
   mViewInfo.sel0 = 0.0;
   mViewInfo.sel1 = 0.0;

   // Horizontal scrollbar
   mViewInfo.total = 1.0;
   mViewInfo.screen = 1.0;
   mViewInfo.h = 0.0;
   mViewInfo.zoom = 44100.0 / 512.0;
   mViewInfo.lastZoom = mViewInfo.zoom;

   // Vertical scrollbar
   mViewInfo.vpos = 0;

   mViewInfo.scrollStep = 16;

   mViewInfo.sbarH = 0;
   mViewInfo.sbarScreen = 1;
   mViewInfo.sbarTotal = 1;

   mMenuBar = NULL;
   CreateMenuBar();

   int left = 0, top = 0, width, height;
   GetClientSize(&width, &height);

   //
   // Create the Palette (if we're not using a windowed palette)
   // 

   if (!gWindowedPalette) {
      int h = GetAPaletteHeight();

      int ptop = 0;
#ifdef __WXMSW__
      ptop++;
#endif

      mAPalette = new APalette(this, 0,
                               wxPoint(10, ptop), wxSize(width - 10, h));

      top += h + 1 + ptop;
      height -= h + 1 + ptop;
   }
   //
   // Create the status bar
   //

   int sh = GetStatusHeight();

   mStatus = new AStatus(this, 0,
                         wxPoint(0, height - sh),
                         wxSize(width, sh), mRate, this);
   height -= sh;

   mStatus->SetField("Welcome to Audacity version "
                     AUDACITY_VERSION_STRING, 0);

   //
   // Create the TrackPanel and the scrollbars
   //

   mTrackPanel = new TrackPanel(this, TrackPanelID,
                                wxPoint(left, top),
                                wxSize(width - sbarSpaceWidth,
                                       height - sbarSpaceWidth), mTracks,
                                &mViewInfo, this);

   int hoffset = mTrackPanel->GetLeftOffset() - 1;
   int voffset = mTrackPanel->GetRulerHeight();

#ifdef __WXMAC__
   width++;
   height++;
#endif

   mHsbar =
       new wxScrollBar(this, HSBarID,
                       wxPoint(hoffset, top + height - sbarSpaceWidth),
                       wxSize(width - hoffset - sbarSpaceWidth +
                              sbarExtraLen, sbarControlWidth),
                       wxSB_HORIZONTAL);

   mVsbar =
       new wxScrollBar(this, VSBarID,
                       wxPoint(width - sbarSpaceWidth, top + voffset),
                       wxSize(sbarControlWidth,
                              height - sbarSpaceWidth - voffset +
                              sbarExtraLen), wxSB_VERTICAL);

   InitialState();
   FixScrollbars();

   //
   // Set the Icon
   //

   // loads either the XPM or the windows resource, depending on the platform
   #ifndef __WXMAC__
   wxIcon ic(wxICON(AudacityLogo));
   SetIcon(ic);
   #endif

   // Min size, max size
   SetSizeHints(250, 200, 20000, 20000);

   // Create tags object
   mTags = new Tags();

#ifdef __WXMSW__
   // Accept drag 'n' drop files
   DragAcceptFiles(true);
#endif

   gAudacityProjects.Add(this);
}
Esempio n. 3
0
void GLAnimationCanvas::OnMouse(wxMouseEvent& event)
{
    if (m_iType == TYPE_CURVE)
    {
        wxPoint wxpt = event.GetPosition();
        Spline::Point pt(wxpt.x, wxpt.y);
        if (event.ButtonDown(wxMOUSE_BTN_LEFT))
        {
            size_t index;
            if(m_spline->findKont(pt, index))
            {
                m_selectedIndex = index;
            }
            else
            {
                m_selectedIndex = -1;
            }
        }
        else if(event.ButtonDown(wxMOUSE_BTN_RIGHT))
        {
            size_t index;
            if(m_spline->findKont(pt, index))
            {
                m_spline->removeKnot(index);
                m_selectedIndex = -1;
            }
            else
            {
                m_selectedIndex = m_spline->addKnots(pt);
            }
        }
        else if (event.Dragging())
        {
            if(m_selectedIndex >= 0)
            {
                m_spline->setKnot(m_selectedIndex, pt);    
            }
        }
    }
    else if (m_iType == TYPE_ANIMATION)
    {
        if(event.ButtonDown(wxMOUSE_BTN_RIGHT))
        {
            ShowCursor(false);
            SetFocus();
            if (!HasCapture())
            {
                CaptureMouse();
            }
            m_bRightDown = true;
        }
        else if(event.ButtonUp(wxMOUSE_BTN_RIGHT))
        {
            ShowCursor(true);
            if (HasCapture())
            {
                ReleaseMouse(); 
            }
            ResetKeyStates();
            m_bRightDown = false;
        }
        else if(event.ButtonDown(wxMOUSE_BTN_LEFT))
        {
            ShowCursor(false);
            SetFocus();
            if (!HasCapture())
            {
                CaptureMouse();
            }
            m_bLeftDown = true;
        }
        else if(event.ButtonUp(wxMOUSE_BTN_LEFT))
        {
            ShowCursor(true);
            if (!HasCapture())
            {
                CaptureMouse();
            }
            ResetKeyStates();
            m_bLeftDown = false;
        }
        else if(event.Dragging())
        {
            wxPoint curPos = event.GetPosition();
            wxPoint pnt = ClientToScreen(curPos);
            SetCursorPos(pnt.x, pnt.y);
            CRenderManager* pRenderMgr = CRenderManager::GetInstance();
            if (m_bRightDown)
            {
                int nDeltaX = curPos.x - m_lastPosition.x;
                int nDeltaY = curPos.y - m_lastPosition.y;
                wxSize clientSize = GetClientSize();
                pRenderMgr->GetCamera()->Yaw((float)nDeltaX / clientSize.x);
                pRenderMgr->GetCamera()->Pitch((float)nDeltaY / clientSize.y);
            }
        }
        else if(event.GetWheelAxis() == wxMOUSE_WHEEL_VERTICAL)
        {
            kmVec3 vec3Speed;
            kmVec3Fill(&vec3Speed, SHIFTWHEELSPEED, SHIFTWHEELSPEED, SHIFTWHEELSPEED);
            if (event.GetWheelRotation() > 0)
            {
                CRenderManager::GetInstance()->GetCamera()->Update(vec3Speed, (1 << CCamera::eCMT_STRAIGHT));
            }
            else if (event.GetWheelRotation() < 0)
            {
                kmVec3Scale(&vec3Speed, &vec3Speed, -1.0f);
                CRenderManager::GetInstance()->GetCamera()->Update(vec3Speed, (1 << CCamera::eCMT_STRAIGHT));
            }
        }
        m_lastPosition = event.GetPosition();
    }
}
Esempio n. 4
0
void DashboardInstrument_Dial::DrawData(wxGCDC* dc, double value,
            wxString unit, wxString format, DialPositionOption position)
{
      if (position == DIAL_POSITION_NONE)
            return;

      dc->SetFont(*g_pFontLabel);
      wxColour cl;
      GetGlobalColor(_T("DASHF"), &cl);
      dc->SetTextForeground(cl);

      wxSize size = GetClientSize();

      wxString text;
      if(!wxIsNaN(value))
      {
          if (unit == _T("\u00B0"))
               text = wxString::Format(format, value)+DEGREE_SIGN;
          else if (unit == _T("\u00B0L")) // No special display for now, might be XX°< (as in text-only instrument)
               text = wxString::Format(format, value)+DEGREE_SIGN;
          else if (unit == _T("\u00B0R")) // No special display for now, might be >XX°
               text = wxString::Format(format, value)+DEGREE_SIGN;
          else if (unit == _T("\u00B0T"))
               text = wxString::Format(format, value)+DEGREE_SIGN+_T("T");
          else if (unit == _T("\u00B0M"))
               text = wxString::Format(format, value)+DEGREE_SIGN+_T("M");
          else if (unit == _T("N")) // Knots
               text = wxString::Format(format, value)+_T(" Kts");
          else
               text = wxString::Format(format, value)+_T(" ")+unit;
      }
      else
           text = _T("---");

      int width, height;
      dc->GetMultiLineTextExtent(text, &width, &height, NULL, g_pFontLabel);

      wxRect TextPoint;
      TextPoint.width = width;
      TextPoint.height = height;
      switch (position)
      {
            case DIAL_POSITION_NONE:
                  // This case was already handled before, it's here just
                  // to avoid compiler warning.
                  return;
            case DIAL_POSITION_INSIDE:
            {
                  TextPoint.x = m_cx - (width / 2) - 1;
                  TextPoint.y = (size.y * .75) - height;
                  GetGlobalColor(_T("DASHL"), &cl);
                  int penwidth = size.x / 100;
                  wxPen* pen = wxThePenList->FindOrCreatePen( cl, penwidth, wxPENSTYLE_SOLID );
                  dc->SetPen( *pen );
                  GetGlobalColor(_T("DASHB"), &cl);
                  dc->SetBrush(cl);
                  // There might be a background drawn below
                  // so we must clear it first.
                  dc->DrawRoundedRectangle(TextPoint.x-2, TextPoint.y-2, width+4, height+4, 3);
                  break;
            }
            case DIAL_POSITION_TOPLEFT:
                  TextPoint.x = 0;
                  TextPoint.y = m_TitleHeight;
                  break;
            case DIAL_POSITION_TOPRIGHT:
                  TextPoint.x = size.x-width-1;
                  TextPoint.y = m_TitleHeight;
                  break;
            case DIAL_POSITION_BOTTOMLEFT:
                  TextPoint.x = 0;
                  TextPoint.y = size.y-height;
                  break;
            case DIAL_POSITION_BOTTOMRIGHT:
                  TextPoint.x = size.x-width-1;
                  TextPoint.y = size.x-height;
                  break;
      }

     wxColour c2;
     GetGlobalColor( _T("DASHB"), &c2 );
     wxColour c3;
     GetGlobalColor( _T("DASHF"), &c3 );

     wxStringTokenizer tkz( text, _T("\n") );
      wxString token;

      token = tkz.GetNextToken();
      while(token.Length()) {
        dc->GetTextExtent(token, &width, &height, NULL, NULL, g_pFontLabel);

#ifdef __WXMSW__
        if( g_pFontLabel->GetPointSize() <= 12 ) {
            wxBitmap tbm( width, height, -1 );
            wxMemoryDC tdc( tbm );

            tdc.SetBackground( c2 );
            tdc.Clear();
            tdc.SetFont(*g_pFontLabel );
            tdc.SetTextForeground( c3 );

            tdc.DrawText(token, 0, 0 );
            tdc.SelectObject( wxNullBitmap );

            dc->DrawBitmap(tbm, TextPoint.x, TextPoint.y, false);
        }
        else
#endif
            dc->DrawText(token, TextPoint.x, TextPoint.y );


        TextPoint.y += height;
        token = tkz.GetNextToken();
      }
}
Esempio n. 5
0
// Position and size subwindows.
// Note that the border size applies to each subwindow, not
// including the edges next to the sash.
void wxSplitterWindow::SizeWindows()
{
    // check if we have delayed setting the real sash position
    if ( m_requestedSashPosition != INT_MAX )
    {
        int newSashPosition = ConvertSashPosition(m_requestedSashPosition);
        if ( newSashPosition != m_sashPosition )
        {
            DoSetSashPosition(newSashPosition);
        }

        if ( newSashPosition <= m_sashPosition
            && newSashPosition >= m_sashPosition - GetBorderSize() )
        {
            // don't update it any more
            m_requestedSashPosition = INT_MAX;
        }
    }

    int w, h;
    GetClientSize(&w, &h);

    if ( GetWindow1() && !GetWindow2() )
    {
        GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
                              w - 2*GetBorderSize(), h - 2*GetBorderSize());
    }
    else if ( GetWindow1() && GetWindow2() )
    {
        const int border = GetBorderSize(),
                  sash = GetSashSize();

        int size1 = GetSashPosition() - border,
            size2 = GetSashPosition() + sash;

        int x2, y2, w1, h1, w2, h2;
        if ( GetSplitMode() == wxSPLIT_VERTICAL )
        {
            w1 = size1;
            w2 = w - 2*border - sash - w1;
            if (w2 < 0)
                w2 = 0;
            h2 = h - 2*border;
            if (h2 < 0)
                h2 = 0;
            h1 = h2;
            x2 = size2;
            y2 = border;
        }
        else // horz splitter
        {
            w2 = w - 2*border;
            if (w2 < 0)
                w2 = 0;
            w1 = w2;
            h1 = size1;
            h2 = h - 2*border - sash - h1;
            if (h2 < 0)
                h2 = 0;
            x2 = border;
            y2 = size2;
        }

        GetWindow2()->SetSize(x2, y2, w2, h2);
        GetWindow1()->SetSize(border, border, w1, h1);
    }

    wxClientDC dc(this);
    DrawSash(dc);
}
Esempio n. 6
0
// Position and size subwindows.
// Note that the border size applies to each subwindow, not
// including the edges next to the sash.
void wxSashWindow::SizeWindows()
{
    int cw, ch;
    GetClientSize(&cw, &ch);

    if (GetChildren().GetCount() == 1)
    {
        wxWindow* child = GetChildren().GetFirst()->GetData();

        int x = 0;
        int y = 0;
        int width = cw;
        int height = ch;

        // Top
        if (m_sashes[0].m_show)
        {
            y = m_borderSize;
            height -= m_borderSize;
        }
        y += m_extraBorderSize;

        // Left
        if (m_sashes[3].m_show)
        {
            x = m_borderSize;
            width -= m_borderSize;
        }
        x += m_extraBorderSize;

        // Right
        if (m_sashes[1].m_show)
        {
            width -= m_borderSize;
        }
        width -= 2*m_extraBorderSize;

        // Bottom
        if (m_sashes[2].m_show)
        {
            height -= m_borderSize;
        }
        height -= 2*m_extraBorderSize;

        child->SetSize(x, y, width, height);
    }
    else if (GetChildren().GetCount() > 1)
    {
        // Perhaps multiple children are themselves sash windows.
        // TODO: this doesn't really work because the subwindows sizes/positions
        // must be set to leave a gap for the parent's sash (hit-test and decorations).
        // Perhaps we can allow for this within LayoutWindow, testing whether the parent
        // is a sash window, and if so, allowing some space for the edges.
        wxLayoutAlgorithm layout;
        layout.LayoutWindow(this);
    }

    wxClientDC dc(this);
    DrawBorders(dc);
    DrawSashes(dc);
}
Esempio n. 7
0
void
GraphCanvas::Center(int x, int y)
{
	wxSize size = GetClientSize();
	Scroll(x * m_Zoom - size.GetWidth() / 2, y * m_Zoom - size.GetHeight() / 2);
}
Esempio n. 8
0
void LineChart::OnPaint(wxPaintEvent &event){

	wxPaintDC old_dc(this);

	float zoomFactor = (float)_zoomPercentage / 100;

	int w,h ;
	GetClientSize(&w,&h);

	if (w != _currentWidth || h != _currentHeight){
		delete (_memBitmap);
		_currentWidth = w;
		_currentHeight = h;
		_memBitmap = new wxBitmap(_currentWidth, _currentHeight);
	}
	/////////////////
	// Create a memory DC
	wxMemoryDC dc;
	dc.SelectObject(*_memBitmap);

	wxColor backColor = GetBackgroundColour();
	dc.SetBackground(*wxTheBrushList->FindOrCreateBrush(backColor,wxSOLID));
	dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(backColor,wxSOLID));
	dc.Clear();
	DrawGrid(dc);

	if (m_showScale){
		m_leftEdge = DrawScale(dc);
	}
	else{
		m_leftEdge = 0;
	}

	size_t largestBufferSize = GetMaxSeriesBufferSize();
	double lastValue = 0;
	for (SeriesMap::iterator it = m_seriesMap.begin(); it != m_seriesMap.end(); ++it){

		float currentX = (float)m_leftEdge;
		int lastX = (int)currentX;
		int lastY;

		Series *series = it->second;
		dc.SetPen(*wxThePenList->FindOrCreatePen(series->GetColor(), 1, wxSOLID));
		size_t bufSize = series->GetBufferSize();
		Range *range = m_rangeArray[series->GetRangeId()];
		if (bufSize > 0){

			double minValue = range->GetMin();
			double maxValue = range->GetMax();

			double loggedValue = series->GetValueAt(0);

			double percentageOfMax = (loggedValue - minValue) / (maxValue - minValue);
			lastY = h - (int)(((double)h) * percentageOfMax);

			size_t i = (size_t)(((double)largestBufferSize) * m_viewOffsetFactor);

			while (i < bufSize && currentX < _currentWidth ){
				if (i == m_markerIndex){
					wxPen pen = dc.GetPen();
					dc.SetPen(*wxThePenList->FindOrCreatePen(*wxLIGHT_GREY, 1, wxSOLID));
					dc.DrawLine(currentX, 0, currentX, _currentHeight);
					DrawCurrentValues(dc, i, currentX, CURRENT_VALUES_TOP_OFFSET);
					dc.SetPen(pen);
				}

				loggedValue = series->GetValueAt(i);

				if (DatalogValue::NULL_VALUE == loggedValue){
					loggedValue = lastValue;
				}
				else{
					lastValue = loggedValue;
				}

				double percentageOfMax = (loggedValue - minValue) / (maxValue - minValue);

				int y = h - (int)(((double)h) * percentageOfMax);

				dc.DrawLine(lastX, lastY, (int)currentX, y);
				lastX = (int)currentX;
				lastY = y;
				currentX += zoomFactor;
				i++;
			}
		}
	}
	if (m_showData) DrawMouseoverMarker(dc);
	//blit into the real DC
	old_dc.Blit(0,0,_currentWidth,_currentHeight,&dc,0,0);

}
Esempio n. 9
0
void GCDCGraphs::DrawYAxisVals(wxGraphicsContext& dc) {
	Draw* draw = m_draws_wdg->GetSelectedDraw();
	if (draw == NULL) 
		return;
	DrawInfo *di = draw->GetDrawInfo();

	if (!di->IsValid())
		return;

	double min = di->GetMin();
	double max = di->GetMax();
	if( max <= min  ) {
		// FIXME:  Draw3 should atomaticly detect axes in that case, but
		//         it currently doesnt :(
		wxLogWarning(_T("Parameter %s has invalid min/max values: min %f, max %f. Min is set to 0, and max to 100."), di->GetName().c_str(), min, max);
		min = 0;
		max = 100;
	}

	//procedure for calculating distance between marks stolen from SzarpDraw2
	double x = max - min;
	double step;
	int i = 0;

	if (x < 1)
		for (;x < 1; x *=10, --i);
	else
		for (;(int)x / 10; x /=10, ++i);

	if (x <= 1.5)
		step = .1;
	else if (x <= 3.)
		step = .2;
	else if (x <= 7.5)
		step = .5;
	else
		step = 1.;

	double acc = 1;

	int prec = di->GetPrec();
				
	for (int p = prec; p > 0; --p)
		acc /= 10;

	double factor  = (i > 0) ? 10 : .1;

	for (;i; i -= i / abs(i))
		step *= factor;

	if (step < acc)
		step = acc;

    	dc.SetPen(wxPen(*wxWHITE, 1, wxSOLID));

	int w, h;
	GetClientSize(&w, &h);

	h -= m_screen_margins.bottommargin + m_screen_margins.topmargin;

	for (double val = max; (min - val) < acc; val -= step) {

		int y = GetY(val, di);

		dc.StrokeLine(m_screen_margins.leftmargin - 8, y, m_screen_margins.leftmargin, y);

		wxString sval = di->GetValueStr(val, _T("- -"));
		double textw, texth, textd, textel;
		dc.GetTextExtent(sval, &textw, &texth, &textd, &textel);
		dc.DrawText(sval, m_screen_margins.leftmargin - textw - 1, y + 2);
	}

}
Esempio n. 10
0
void wxSTEditorFrame::CreateOptions( const wxSTEditorOptions& options )
{
    m_options = options;

    wxConfigBase *config = GetConfigBase();
    wxSTEditorMenuManager *steMM = GetOptions().GetMenuManager();

    if (steMM && GetOptions().HasFrameOption(STF_CREATE_MENUBAR))
    {
        wxMenuBar *menuBar = GetMenuBar();

        if (!menuBar)
            menuBar = new wxMenuBar(wxMB_DOCKABLE);

        steMM->CreateMenuBar(menuBar, true);

        SetMenuBar(menuBar);
        wxAcceleratorHelper::SetAcceleratorTable(this, *steMM->GetAcceleratorArray());
        wxAcceleratorHelper::SetAccelText(menuBar, *steMM->GetAcceleratorArray());

        if (GetOptions().HasFrameOption(STF_CREATE_FILEHISTORY) && !GetOptions().GetFileHistory())
        {
            // If there is wxID_OPEN then we can use wxFileHistory to save them
            wxMenu* menu = NULL;
            wxMenuItem* item = menuBar->FindItem(wxID_OPEN, &menu);

            if (menu && item)
            {
                int open_index = menu->GetMenuItems().IndexOf(item);

                if (open_index != wxNOT_FOUND)
                {
                    wxMenu* submenu = new wxMenu();
                    menu->Insert(open_index + 1, wxID_ANY, _("Open &Recent"), submenu);
                    GetOptions().SetFileHistory(new wxFileHistory(9), false);
                    GetOptions().GetFileHistory()->UseMenu(submenu);
                    if (config)
                    {
                        GetOptions().LoadFileConfig(*config);
                    }
                }
            }

            GetOptions().SetMenuBar(menuBar);
        }
    }
    if (steMM && GetOptions().HasFrameOption(STF_CREATE_TOOLBAR))
    {
        wxToolBar* toolBar = (GetToolBar() != NULL) ? GetToolBar() : CreateToolBar();
        steMM->CreateToolBar(toolBar);
        GetOptions().SetToolBar(toolBar);
    }
    if ((GetStatusBar() == NULL) && GetOptions().HasFrameOption(STF_CREATE_STATUSBAR))
    {
        CreateStatusBar(1);
        GetOptions().SetStatusBar(GetStatusBar());
    }
    if (steMM)
    {
        if (GetOptions().HasEditorOption(STE_CREATE_POPUPMENU))
        {
            wxMenu* menu = steMM->CreateEditorPopupMenu();

            wxAcceleratorHelper::SetAccelText(menu, *steMM->GetAcceleratorArray());
            GetOptions().SetEditorPopupMenu(menu, false);
        }
        if (GetOptions().HasSplitterOption(STS_CREATE_POPUPMENU))
            GetOptions().SetSplitterPopupMenu(steMM->CreateSplitterPopupMenu(), false);
        if (GetOptions().HasNotebookOption(STN_CREATE_POPUPMENU))
            GetOptions().SetNotebookPopupMenu(steMM->CreateNotebookPopupMenu(), false);
    }

    if (!m_sideSplitter && GetOptions().HasFrameOption(STF_CREATE_SIDEBAR))
    {
        m_sideSplitter = new wxSplitterWindow(this, ID_STF_SIDE_SPLITTER);
        m_sideSplitter->SetMinimumPaneSize(10);
        m_sideNotebook = new wxNotebook(m_sideSplitter, ID_STF_SIDE_NOTEBOOK);
        m_steTreeCtrl  = new wxSTEditorTreeCtrl(m_sideNotebook, ID_STF_FILE_TREECTRL);
        m_dirCtrl      = new wxGenericDirCtrl(m_sideNotebook, ID_STF_FILE_DIRCTRL,
                                              wxFileName::GetCwd(),
                                              wxDefaultPosition, wxDefaultSize,
                                              wxDIRCTRL_3D_INTERNAL
#if wxCHECK_VERSION(2, 9, 2)
                                              |(GetOptions().HasFrameOption(STF_CREATE_NOTEBOOK) ? wxDIRCTRL_MULTIPLE : 0)
#endif // wxCHECK_VERSION(2, 9, 2)
                                              );

        m_sideNotebook->AddPage(m_steTreeCtrl, _("Files"));
        m_sideNotebook->AddPage(m_dirCtrl,     _("Open"));

        m_sideSplitterWin1 = m_sideNotebook;
    }

    if (!m_steNotebook && GetOptions().HasFrameOption(STF_CREATE_NOTEBOOK))
    {
        m_mainSplitter = new wxSplitterWindow(m_sideSplitter ? (wxWindow*)m_sideSplitter : (wxWindow*)this, ID_STF_MAIN_SPLITTER);
        m_mainSplitter->SetMinimumPaneSize(1);

        m_steNotebook = new wxSTEditorNotebook(m_mainSplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize,
                                               wxCLIP_CHILDREN);
        m_steNotebook->CreateOptions(m_options);
        (void)m_steNotebook->InsertEditorSplitter(-1, wxID_ANY, GetOptions().GetDefaultFileName(), true);
        // update after adding a single page
        m_steNotebook->UpdateAllItems();
        m_mainSplitter->Initialize(m_steNotebook);
        m_mainSplitterWin1 = m_steNotebook;
        m_sideSplitterWin2 = m_mainSplitter;

        if (m_steTreeCtrl)
            m_steTreeCtrl->SetSTENotebook(m_steNotebook);
    }
    else if (!m_steSplitter && GetOptions().HasFrameOption(STF_CREATE_SINGLEPAGE))
    {
        m_mainSplitter = new wxSplitterWindow(m_sideSplitter ? (wxWindow*)m_sideSplitter : (wxWindow*)this, ID_STF_MAIN_SPLITTER);
        m_mainSplitter->SetMinimumPaneSize(1);

        m_steSplitter = new wxSTEditorSplitter(m_mainSplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
        m_steSplitter->CreateOptions(m_options);
        m_mainSplitter->Initialize(m_steSplitter);
        m_mainSplitterWin1 = m_steSplitter;
    }
    //else user will set up the rest

    if (m_mainSplitter && m_mainSplitterWin1 && !m_resultsNotebook && GetOptions().HasFrameOption(STF_CREATE_RESULT_NOTEBOOK))
    {
        m_resultsNotebook = new wxNotebook(m_mainSplitter, wxID_ANY);

        m_findResultsEditor = new wxSTEditorFindResultsEditor(m_resultsNotebook, wxID_ANY);
        m_findResultsEditor->CreateOptionsFromEditorOptions(options);
        m_resultsNotebook->AddPage(m_findResultsEditor, _("Search Results"));

        wxSTEditorFindReplacePanel::SetFindResultsEditor(m_findResultsEditor);
        m_mainSplitter->SplitHorizontally(m_mainSplitterWin1, m_resultsNotebook, GetClientSize().GetHeight()*2/3);
        m_mainSplitterWin2 = m_resultsNotebook;
    }

    if (GetOptions().HasFrameOption(STF_CREATE_SIDEBAR) && GetSideSplitter() && m_sideSplitterWin1 && m_sideSplitterWin2)
    {
        GetSideSplitter()->SplitVertically(m_sideSplitterWin1, m_sideSplitterWin2, m_sideSplitter_pos);
    }

#if wxUSE_DRAG_AND_DROP
    if (GetOptions().HasFrameOption(STF_DO_DRAG_AND_DROP))
    {
        SetDropTarget(new wxSTEditorFileDropTarget(this));
    }
#endif //wxUSE_DRAG_AND_DROP

    if (GetOptions().HasConfigOption(STE_CONFIG_FINDREPLACE) && config)
    {
        if (GetOptions().GetFindReplaceData() &&
            !GetOptions().GetFindReplaceData()->HasLoadedConfig())
            GetOptions().GetFindReplaceData()->LoadConfig(*config);
    }

    if (config)
        LoadConfig(*config);

    // The config may change the frame size so relayout the splitters
    if (m_mainSplitter && m_mainSplitter->IsSplit()) //m_mainSplitterWin1 && m_resultsNotebook)
        m_mainSplitter->SetSashPosition(GetClientSize().GetHeight()*2/3);

    UpdateAllItems();

    // if we've got an editor let it update gui
    wxSTEditor *editor = GetEditor();
    if (editor)
        editor->UpdateAllItems();
}
    HK_PROMPT_DIALOG( wxWindow* aParent, wxWindowID aId, const wxString& aTitle,
            const wxString& aName, const wxString& aCurrentKey )
        :   DIALOG_SHIM( aParent, aId, aTitle, wxDefaultPosition, wxDefaultSize )
    {
        wxPanel* panel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize );
        wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );

        /* Dialog layout:
         *
         * inst_label........................
         * ----------------------------------
         *
         * cmd_label_0      cmd_label_1         \
         *                                      | fgsizer
         * key_label_0      key_label_1         /
         */

        wxStaticText* inst_label = new wxStaticText( panel, wxID_ANY, wxEmptyString,
                wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL );

        inst_label->SetLabelText( _( "Press a new hotkey, or press Esc to cancel..." ) );
        sizer->Add( inst_label, 0, wxALL, 5 );

        sizer->Add( new wxStaticLine( panel ), 0, wxALL | wxEXPAND, 2 );

        wxFlexGridSizer* fgsizer = new wxFlexGridSizer( 2 );

        wxStaticText* cmd_label_0 = new wxStaticText( panel, wxID_ANY, _( "Command:" ) );
        fgsizer->Add( cmd_label_0, 0, wxALL | wxALIGN_CENTRE_VERTICAL, 5 );

        wxStaticText* cmd_label_1 = new wxStaticText( panel, wxID_ANY, wxEmptyString );
        cmd_label_1->SetFont( cmd_label_1->GetFont().Bold() );
        cmd_label_1->SetLabel( aName );
        fgsizer->Add( cmd_label_1, 0, wxALL | wxALIGN_CENTRE_VERTICAL, 5 );

        wxStaticText* key_label_0 = new wxStaticText( panel, wxID_ANY, _( "Current key:" ) );
        fgsizer->Add( key_label_0, 0, wxALL | wxALIGN_CENTRE_VERTICAL, 5 );

        wxStaticText* key_label_1 = new wxStaticText( panel, wxID_ANY, wxEmptyString );
        key_label_1->SetFont( key_label_1->GetFont().Bold() );
        key_label_1->SetLabel( aCurrentKey );
        fgsizer->Add( key_label_1, 0, wxALL | wxALIGN_CENTRE_VERTICAL, 5 );

        sizer->Add( fgsizer, 1, wxEXPAND );

        // Wrap the sizer in a second to give a larger border around the whole dialog
        wxBoxSizer* outer_sizer = new wxBoxSizer( wxVERTICAL );
        outer_sizer->Add( sizer, 0, wxALL | wxEXPAND, 10 );
        panel->SetSizer( outer_sizer );

        Layout();
        outer_sizer->Fit( this );
        Center();

        SetMinClientSize( GetClientSize() );

        // Binding both EVT_CHAR and EVT_CHAR_HOOK ensures that all key events,
        // including specials like Tab and Return, are received, particularly
        // on MSW.
        panel->Bind( wxEVT_CHAR, &HK_PROMPT_DIALOG::OnChar, this );
        panel->Bind( wxEVT_CHAR_HOOK, &HK_PROMPT_DIALOG::OnCharHook, this );
    }
Esempio n. 12
0
void wxWindow::Refresh(bool eraseBackground, const wxRect *rect)
{
    wxRect rectClient; // the same rectangle in client coordinates
    wxPoint origin = GetClientAreaOrigin();

    wxSize size = GetClientSize();

    if ( rect )
    {
        // the rectangle passed as argument is in client coordinates
        rectClient = *rect;

        // don't refresh anything beyond the client area (scrollbars for
        // example)
        if ( rectClient.GetRight() > size.x )
            rectClient.SetRight(size.x);
        if ( rectClient.GetBottom() > size.y )
            rectClient.SetBottom(size.y);

    }
    else // refresh the entire client area
    {
        // x,y is already set to 0 by default
        rectClient.SetSize(size);
    }

    // convert refresh rectangle to window coordinates:
    wxRect rectWin(rectClient);
    rectWin.Offset(origin);

    // debugging helper
#ifdef WXDEBUG_REFRESH
    static bool s_refreshDebug = false;
    if ( s_refreshDebug )
    {
        wxWindowDC dc(this);
        dc.SetBrush(*wxCYAN_BRUSH);
        dc.SetPen(*wxTRANSPARENT_PEN);
        dc.DrawRectangle(rectWin);

        // under Unix we use "--sync" X option for this
#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
        ::GdiFlush();
        ::Sleep(200);
#endif // __WXMSW__
    }
#endif // WXDEBUG_REFRESH

    wxWindowNative::Refresh(eraseBackground, &rectWin);

    // Refresh all sub controls if any.
    wxWindowList& children = GetChildren();
    for ( wxWindowList::iterator i = children.begin(); i != children.end(); ++i )
    {
        wxWindow *child = *i;
        // only refresh subcontrols if they are visible:
        if ( child->IsTopLevel() || !child->IsShown() || child->IsFrozen() )
            continue;

        // ...and when the subcontrols are in the update region:
        wxRect childrect(child->GetRect());
        childrect.Intersect(rectClient);
        if ( childrect.IsEmpty() )
            continue;

        // refresh the subcontrol now:
        childrect.Offset(-child->GetPosition());
        // NB: We must call wxWindowNative version because we need to refresh
        //     the entire control, not just its client area, and this is why we
        //     don't account for child client area origin here neither. Also
        //     note that we don't pass eraseBackground to the child, but use
        //     true instead: this is because we can't be sure that
        //     eraseBackground=false is safe for children as well and not only
        //     for the parent.
        child->wxWindowNative::Refresh(eraseBackground, &childrect);
    }
}
Esempio n. 13
0
wxRect wxWindow::ScrollNoRefresh(int dx, int dy, const wxRect *rectTotal)
{
    wxASSERT_MSG( !dx || !dy, _T("can't be used for diag scrolling") );

    // the rect to refresh (which we will calculate)
    wxRect rect;

    if ( !dx && !dy )
    {
        // nothing to do
        return rect;
    }

    // calculate the part of the window which we can just redraw in the new
    // location
    wxSize sizeTotal = rectTotal ? rectTotal->GetSize() : GetClientSize();

    wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
               sizeTotal.x, sizeTotal.y, dx, dy);

    // the initial and end point of the region we move in client coords
    wxPoint ptSource, ptDest;
    if ( rectTotal )
    {
        ptSource = rectTotal->GetPosition();
        ptDest = rectTotal->GetPosition();
    }

    // the size of this region
    wxSize size;
    size.x = sizeTotal.x - abs(dx);
    size.y = sizeTotal.y - abs(dy);
    if ( size.x <= 0 || size.y <= 0 )
    {
        // just redraw everything as nothing of the displayed image will stay
        wxLogTrace(_T("scroll"), _T("refreshing everything"));

        rect = rectTotal ? *rectTotal : wxRect(0, 0, sizeTotal.x, sizeTotal.y);
    }
    else // move the part which doesn't change to the new location
    {
        // note that when we scroll the canvas in some direction we move the
        // block which doesn't need to be refreshed in the opposite direction

        if ( dx < 0 )
        {
            // scroll to the right, move to the left
            ptSource.x -= dx;
        }
        else
        {
            // scroll to the left, move to the right
            ptDest.x += dx;
        }

        if ( dy < 0 )
        {
            // scroll down, move up
            ptSource.y -= dy;
        }
        else
        {
            // scroll up, move down
            ptDest.y += dy;
        }

#if wxUSE_CARET
        // we need to hide the caret before moving or it will erase itself at
        // the wrong (old) location
        wxCaret *caret = GetCaret();
        if ( caret )
            caret->Hide();
#endif // wxUSE_CARET

        // do move
        wxClientDC dc(this);
        wxBitmap bmp(size.x, size.y);
        wxMemoryDC dcMem;
        dcMem.SelectObject(bmp);

        dcMem.Blit(wxPoint(0,0), size, &dc, ptSource
#if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
                   + GetClientAreaOrigin()
#endif // broken wxGTK wxDC::Blit
                  );
        dc.Blit(ptDest, size, &dcMem, wxPoint(0,0));

        wxLogTrace(_T("scroll"),
                   _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
                   ptSource.x, ptSource.y,
                   size.x, size.y,
                   ptDest.x, ptDest.y);

        // and now repaint the uncovered area

        // FIXME: We repaint the intersection of these rectangles twice - is
        //        it bad? I don't think so as it is rare to scroll the window
        //        diagonally anyhow and so adding extra logic to compute
        //        rectangle intersection is probably not worth the effort

        rect.x = ptSource.x;
        rect.y = ptSource.y;

        if ( dx )
        {
            if ( dx < 0 )
            {
                // refresh the area along the right border
                rect.x += size.x + dx;
                rect.width = -dx;
            }
            else
            {
                // refresh the area along the left border
                rect.width = dx;
            }

            rect.height = sizeTotal.y;

            wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
                       rect.x, rect.y,
                       rect.GetRight() + 1, rect.GetBottom() + 1);
        }

        if ( dy )
        {
            if ( dy < 0 )
            {
                // refresh the area along the bottom border
                rect.y += size.y + dy;
                rect.height = -dy;
            }
            else
            {
                // refresh the area along the top border
                rect.height = dy;
            }

            rect.width = sizeTotal.x;

            wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
                       rect.x, rect.y,
                       rect.GetRight() + 1, rect.GetBottom() + 1);
        }

#if wxUSE_CARET
        if ( caret )
            caret->Show();
#endif // wxUSE_CARET
    }

    return rect;
}
Esempio n. 14
0
void GLCanvas::SyncWithOptions()
{
	SetZoomSize( GetClientSize().GetWidth(), GetClientSize().GetHeight() );
}
void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
{
    wxPaintDC( this );

    // SwapBuffer requires the window to be shown before calling
    if( !IsShownOnScreen() )
    {
        wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnPaint !IsShown" ) );
        return;
    }

    // "Makes the OpenGL state that is represented by the OpenGL rendering
    //  context context current, i.e. it will be used by all subsequent OpenGL calls.
    //  This function may only be called when the window is shown on screen"
    GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );

    // Set the OpenGL viewport according to the client size of this canvas.
    // This is done here rather than in a wxSizeEvent handler because our
    // OpenGL rendering context (and thus viewport setting) is used with
    // multiple canvases: If we updated the viewport in the wxSizeEvent
    // handler, changing the size of one canvas causes a viewport setting that
    // is wrong when next another canvas is repainted.
    wxSize clientSize = GetClientSize();

    if( !m_ogl_initialized )
    {
        m_ogl_initialized = true;
        ogl_initialize();
    }

    if( m_reload_is_needed )
    {
        wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnPaint m_reload_is_needed" ) );

        m_reload_is_needed = false;
        m_ogl_3dmodel = new C_OGL_3DMODEL( *m_3d_model );

        // It convert a model as it was a board, so get the max size dimension of the board
        // and compute the conversion scale
        m_BiuTo3Dunits = (double)RANGE_SCALE_3D / ((double)m_ogl_3dmodel->GetBBox().GetMaxDimension() * UNITS3D_TO_UNITSPCB);
    }

    glViewport( 0, 0, clientSize.x, clientSize.y );

    m_trackBallCamera.SetCurWindowSize( clientSize );

    // clear color and depth buffers
    // /////////////////////////////////////////////////////////////////////////
    glEnable( GL_DEPTH_TEST );

    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
    glClearDepth( 1.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Set projection and modelview matrixes
    // /////////////////////////////////////////////////////////////////////////
    glMatrixMode( GL_PROJECTION );
    glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetProjectionMatrix() ) );

    glMatrixMode( GL_MODELVIEW );
    glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetViewMatrix() ) );

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    // Render Model
    if( m_ogl_3dmodel )
    {
        glPushMatrix();

        double modelunit_to_3d_units_factor = m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;

        glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor, modelunit_to_3d_units_factor);

        // Center model in the render viewport
        const SFVEC3F model_center = m_ogl_3dmodel->GetBBox().GetCenter();
        glTranslatef( -model_center.x, -model_center.y, -model_center.z );

        // !TODO: draw transparent models
        m_ogl_3dmodel->Draw_opaque();
        m_ogl_3dmodel->Draw_transparent();
        //m_ogl_3dmodel->Draw_bboxes();

        glPopMatrix();
    }


    glViewport( 0, 0, clientSize.y / 8 , clientSize.y / 8 );                    // YxY squared view port
    glClear( GL_DEPTH_BUFFER_BIT );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 45.0f, 1.0f, 0.01f, RANGE_SCALE_3D * 2.0f );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    const glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f), SFVEC3F( 0.0f, 0.0f, -RANGE_SCALE_3D ) );
    const glm::mat4 ViewMatrix = TranslationMatrix * m_trackBallCamera.GetRotationMatrix();

    glLoadMatrixf( glm::value_ptr( ViewMatrix ) );

    ogl_set_arrow_material();

    glColor3f( 0.9f, 0.0f, 0.0f );
    OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
                    SFVEC3F( RANGE_SCALE_3D / 2.65f, 0.0f, 0.0f ),
                    0.275f );

    glColor3f( 0.0f, 0.9f, 0.0f );
    OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
                    SFVEC3F( 0.0f, RANGE_SCALE_3D / 2.65f, 0.0f ),
                    0.275f );

    glColor3f( 0.0f, 0.0f, 0.9f );
    OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
                    SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 2.65f ),
                    0.275f );

    // "Swaps the double-buffer of this window, making the back-buffer the
    //  front-buffer and vice versa, so that the output of the previous OpenGL
    //  commands is displayed on the window."
    SwapBuffers();
    GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );

    event.Skip();
}
Esempio n. 16
0
void GCDCGraphs::DrawSeasonLimitInfo(wxGraphicsContext &dc, int i, int month, int day, bool summer) {

	const double stripe_width = 2; 

	double x1 = GetX(i);
	double x2 = GetX(i + 1);

	double x = (x1 + x2) / 2;

	int w, h;
	GetClientSize(&w, &h);

	wxColour color = summer ? *wxBLUE : *wxRED;

	dc.SetFont(GetFont(), color);

	dc.SetPen(wxPen(color, 1, wxSOLID));

	wxBrush brush(color);
	dc.SetBrush(brush);
	dc.DrawRectangle(x + 1, m_screen_margins.topmargin, stripe_width, w - m_screen_margins.topmargin - m_screen_margins.bottommargin);

	wxString str;
	if (summer)
		str = wxString(_("summer season"));
	else
		str = wxString(_("winter season"));

	str += wxString::Format(_T(" %d "), day);

	switch (month) {
		case 1:
			str += _("january");
			break;
		case 2:
			str += _("february");
			break;
		case 3:
			str += _("march");
			break;
		case 4:
			str += _("april");
			break;
		case 5:
			str += _("may");
			break;
		case 6:
			str += _("june");
			break;
		case 7:
			str += _("july");
			break;
		case 8:
			str += _("august");
			break;
		case 9:
			str += _("septermber");
			break;
		case 10:
			str += _("october");
			break;
		case 11:
			str += _("november");
			break;
		case 12:
			str += _("december");
			break;
		default:
			assert(false);
	}

	double tw, th, td, tsel;
	dc.GetTextExtent(_T("W"), &tw, &th, &td, &tsel);

	int ty = m_screen_margins.topmargin + 1;
	for (size_t i = 0; i < str.Len(); ++i) {
		double lw, lh, ld, lsel;
		wxString letter = str.Mid(i, 1);
		dc.GetTextExtent(letter, &lw, &lh, &ld, &lsel);
		dc.DrawText(letter, x + stripe_width + 2 + (tw - lw) / 2, ty);
		ty += th + 2;
	}

}
Esempio n. 17
0
// Draw the sash
void wxSashWindow::DrawSash(wxSashEdgePosition edge, wxDC& dc)
{
    int w, h;
    GetClientSize(&w, &h);

    wxPen facePen(m_faceColour, 1, wxSOLID);
    wxBrush faceBrush(m_faceColour, wxSOLID);
    wxPen mediumShadowPen(m_mediumShadowColour, 1, wxSOLID);
    wxPen darkShadowPen(m_darkShadowColour, 1, wxSOLID);
    wxPen lightShadowPen(m_lightShadowColour, 1, wxSOLID);
    wxPen hilightPen(m_hilightColour, 1, wxSOLID);
    wxColour blackClr(0, 0, 0);
    wxColour whiteClr(255, 255, 255);
    wxPen blackPen(blackClr, 1, wxSOLID);
    wxPen whitePen(whiteClr, 1, wxSOLID);

    if ( edge == wxSASH_LEFT || edge == wxSASH_RIGHT )
    {
        int sashPosition = (edge == wxSASH_LEFT) ? 0 : ( w - GetEdgeMargin(edge) );

        dc.SetPen(facePen);
        dc.SetBrush(faceBrush);
        dc.DrawRectangle(sashPosition, 0, GetEdgeMargin(edge), h);

        if (GetWindowStyleFlag() & wxSW_3DSASH)
        {
            if (edge == wxSASH_LEFT)
            {
                // Draw a dark grey line on the left to indicate that the
                // sash is raised
                dc.SetPen(mediumShadowPen);
                dc.DrawLine(GetEdgeMargin(edge), 0, GetEdgeMargin(edge), h);
            }
            else
            {
                // Draw a highlight line on the right to indicate that the
                // sash is raised
                dc.SetPen(hilightPen);
                dc.DrawLine(w - GetEdgeMargin(edge), 0, w - GetEdgeMargin(edge), h);
            }
        }
    }
    else // top or bottom
    {
        int sashPosition = (edge == wxSASH_TOP) ? 0 : ( h - GetEdgeMargin(edge) );

        dc.SetPen(facePen);
        dc.SetBrush(faceBrush);
        dc.DrawRectangle(0, sashPosition, w, GetEdgeMargin(edge));

        if (GetWindowStyleFlag() & wxSW_3DSASH)
        {
            if (edge == wxSASH_BOTTOM)
            {
                // Draw a highlight line on the bottom to indicate that the
                // sash is raised
                dc.SetPen(hilightPen);
                dc.DrawLine(0, h - GetEdgeMargin(edge), w, h - GetEdgeMargin(edge));
            }
            else
            {
                // Draw a drak grey line on the top to indicate that the
                // sash is raised
                dc.SetPen(mediumShadowPen);
                dc.DrawLine(1, GetEdgeMargin(edge), w-1, GetEdgeMargin(edge));
            }
        }
    }

    dc.SetPen(wxNullPen);
    dc.SetBrush(wxNullBrush);
}
Esempio n. 18
0
void GCDCGraphs::OnMouseLeftDown(wxMouseEvent& event) {
	/* get widget size */
	int w, h;
	GetClientSize(&w, &h);

	/* check for 'move cursor left' event */
	if (event.GetX() < m_screen_margins.leftmargin) {
		m_draws_wdg->MoveCursorLeft();
		return;
	}

	/* check for 'move cursor right' event */
	if (event.GetX() > (w - m_screen_margins.rightmargin)) {
		m_draws_wdg->MoveCursorRight();
		return;
	}

	int index = m_draws_wdg->GetSelectedDrawIndex();
	if (index < 0)
		return;

	wxDateTime ct = m_draws_wdg->GetSelectedDraw()->GetCurrentTime();
	if (!ct.IsValid())
		return;

	struct VoteInfo {
		double dist;
		wxDateTime time;
	};

	VoteInfo infos[m_draws.size()];

	int x = event.GetX();
	int y = event.GetY();

	int remark_idx = GetRemarkClickedIndex(x, y);
	if (remark_idx != -1) {
		m_draws_wdg->ShowRemarks(remark_idx);
		return;
	}

	for (size_t i = 0; i < m_draws.size(); ++i) {

		VoteInfo & in = infos[i];
		in.dist = -1;

		if (m_draws[i]->GetEnable())
			GetDistance(i, x, y, in.dist, in.time);
	}

	double min = INFINITY;
	int j = -1;

	int selected_draw = m_draws_wdg->GetSelectedDrawIndex();

	for (size_t i = 1; i <= m_draws.size(); ++i) {
		size_t k = (i + selected_draw) % m_draws.size();

		VoteInfo & in = infos[k];
		if (in.dist < 0)
			continue;

		if (in.dist < 9 * 9
				&& in.time == ct) {
			j = k;
			break;
		}

		if ((int)k == selected_draw && in.dist == 0) {
			j = k;
			break;
		}

		if (min > in.dist) {
			j = k;
			min = in.dist;
		}
	}

	if (j == -1) 
		return;

	if (selected_draw != j && infos[j].dist < 1000) {
		m_draws_wdg->SelectDraw(j, true, infos[j].time);
	} else
		m_draws_wdg->SelectDraw(selected_draw, true, infos[selected_draw].time);


}
Esempio n. 19
0
void
GraphCanvas::OnPaint(wxPaintEvent& evt)
{
	// __REMARK__
	// Previously we were using a wxMetafileDC to both evaluate the
	// graph size and serve as a cache to draw it to a wxBitmapDC and
	// avoid having to parse the xdot file again. The wxBitmapDC then
	// was used on all paint operations until the user changed the
	// zoom value.
	wxAutoBufferedPaintDC dc(this);
	DoPrepareDC(dc);
	// Get the size of the client area.
	int clwidth, clheight;
	GetClientSize(&clwidth, &clheight);
	// The deltas start at 0.
	int dx = 0, dy = 0;
	// If the width of the drawing is less than the width
	// of the client area, we compute the delta to
	// centralize horizontally. width and height are
	// computed in another place.
	if (m_Width < clwidth)
	{
		dx = (clwidth - m_Width) / 2;
	}
	// The same for the height.
	if (m_Height < clheight)
	{
		dy = (clheight - m_Height) / 2;
	}
	// Get the pre-computed offset.
	wxCoord x, y;
	dc.GetDeviceOrigin(&x, &y);
	// Set the user scale.
	dc.SetUserScale(m_Zoom, m_Zoom);
	// Clear the client area.
	dc.SetBackground(*wxWHITE_BRUSH);
	dc.Clear();
	// Set the offset to the original one plus the deltas plus the border.
	int zborder = (int)(m_BorderSize * m_Zoom);
	dc.SetDeviceOrigin(x + dx + zborder, y + dy + zborder);
	// Paint will draw whatever it wants to draw.
	Paint(dc);
	// Draw a dot at the bottom-right of the DC to account for the border.
	if (m_BorderSize > 0)
	{
		int x = dc.MaxX() + zborder - 1;
		int y = dc.MaxY() + zborder - 1;
		wxColor color;
		dc.GetPixel(x, y, &color);
		wxPen pen(color);
		dc.SetPen(pen);
		dc.DrawPoint(x, y);
		dc.SetPen(wxNullPen);
	}
	// Set the user scale back to 1.0, 1.0 to avoid
	// pixalation.
	// __REMARK__
	// Windows doesn't need it but on Linux
	// we get a pixelated image if we don't do it.
	dc.SetUserScale(1.0, 1.0);
}
Esempio n. 20
0
// Print the canvas contents to a bitmap:
void gateImage::generateImage() {
//WARNING!!! Heavily platform-dependent code ahead! This only works in MS Windows because of the
// DIB Section OpenGL rendering.

	wxSize sz = GetClientSize();

	// Create a DIB section.
	// (The Windows wxBitmap implementation will create a DIB section for a bitmap if you set
	// a color depth of 24 or greater.)
	wxBitmap theBM( GATEIMAGESIZE, GATEIMAGESIZE, 32 );
	
	// Get a memory hardware device context for writing to the bitmap DIB Section:
	wxMemoryDC myDC;
	myDC.SelectObject(theBM);
	WXHDC theHDC = myDC.GetHDC();

	// The basics of setting up OpenGL to render to the bitmap are found at:
	// http://www.nullterminator.net/opengl32.html
	// http://www.codeguru.com/cpp/g-m/opengl/article.php/c5587/

    PIXELFORMATDESCRIPTOR pfd;
    int iFormat;

    // set the pixel format for the DC
    ::ZeroMemory( &pfd, sizeof( pfd ) );
    pfd.nSize = sizeof( pfd );
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 32;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;
    iFormat = ::ChoosePixelFormat( (HDC) theHDC, &pfd );
    ::SetPixelFormat( (HDC) theHDC, iFormat, &pfd );

    // create and enable the render context (RC)
    HGLRC hRC = ::wglCreateContext( (HDC) theHDC );
    HGLRC oldhRC = ::wglGetCurrentContext();
    HDC oldDC = ::wglGetCurrentDC();
    ::wglMakeCurrent( (HDC) theHDC, hRC );

	// Setup the viewport for rendering:
	setViewport();
	// Reset the glViewport to the size of the bitmap:
	glViewport(0, 0, GATEIMAGESIZE, GATEIMAGESIZE);
	
	// Set the bitmap clear color:
	glClearColor (1.0, 1.0, 1.0, 0.0);
	glColor3b(0, 0, 0);

	glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
		
	//TODO: Check if alpha is hardware supported, and
	// don't enable it if not!
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);

	glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
	
	//*********************************
	//Edit by Joshua Lansford 4/09/07
	//anti-alis ing is nice
	//glEnable( GL_LINE_SMOOTH );
	//End of edit

	// Load the font texture
	guiText::loadFont(wxGetApp().appSettings.textFontFile);
	
	// Do the rendering here.
	renderMap();

	// Flush the OpenGL buffer to make sure the rendering has happened:	
	glFlush();
	
	// Destroy the OpenGL rendering context, release the memDC, and
	// convert the DIB Section into a wxImage to return to the caller:
    ::wglMakeCurrent( oldDC, oldhRC );
    //::wglMakeCurrent( NULL, NULL );
    ::wglDeleteContext( hRC );
	myDC.SelectObject(wxNullBitmap);
	gImage = theBM.ConvertToImage();
}
Esempio n. 21
0
void DashboardInstrument_Dial::DrawLabels(wxGCDC* dc)
{
      if (m_LabelOption == DIAL_LABEL_NONE)
            return;

      wxPoint TextPoint;
      wxPen pen;
      wxColor cl;
      GetGlobalColor(_T("DASHF"), &cl);

#ifdef __WXMSW__
      wxSize size = GetClientSize();
      //        Create a new bitmap for this method graphics
      wxBitmap tbm( size.x, size.y, -1 );
      wxMemoryDC tdc( tbm );

      wxColour cback;
      GetGlobalColor( _T("DASHB"), &cback );
      tdc.SetBackground( cback );
      tdc.Clear();
      tdc.SetFont(*g_pFontSmall);
      tdc.SetTextForeground(cl);
#endif

      dc->SetFont(*g_pFontSmall);
      dc->SetTextForeground(cl);

      int diff_angle = m_AngleStart + m_AngleRange - ANGLE_OFFSET;
      // angle between markers
      double abm = m_AngleRange * m_LabelStep / (m_MainValueMax - m_MainValueMin);
      // don't draw last value, it's already done as first
      if (m_AngleRange == 360) diff_angle -= abm;

      int offset = 0;
      int value = m_MainValueMin;
      int width, height;
      for(double angle = m_AngleStart - ANGLE_OFFSET; angle <= diff_angle; angle += abm)
      {
            wxString label = (m_LabelArray.GetCount() ? m_LabelArray.Item(offset) : wxString::Format(_T("%d"), value));
#ifdef __WXMSW__
            if( g_pFontSmall->GetPointSize() <= 12 )
              tdc.GetTextExtent(label, &width, &height, 0, 0, g_pFontSmall);
            else
#endif
              dc->GetTextExtent(label, &width, &height, 0, 0, g_pFontSmall);

            double halfW = width / 2;
            if (m_LabelOption == DIAL_LABEL_HORIZONTAL)
            {
                  double halfH = height / 2;
                  //double delta = sqrt(width*width+height*height);
                  double delta = sqrt(halfW*halfW+halfH*halfH);
                  TextPoint.x = m_cx + ((m_radius * 0.90) - delta) * cos(deg2rad(angle)) - halfW;
                  TextPoint.y = m_cy + ((m_radius * 0.90) - delta) * sin(deg2rad(angle)) - halfH;

#ifdef __WXMSW__
                  if( g_pFontSmall->GetPointSize() <= 12 )
                    tdc.DrawText(label, TextPoint);
                  else
#endif
                    dc->DrawText(label, TextPoint);


            }
            else if (m_LabelOption == DIAL_LABEL_ROTATED)
            {
                  // The coordinates of dc->DrawRotatedText refer to the top-left corner
                  // of the rectangle bounding the string. So we must calculate the
                  // right coordinates depending of the angle.
                  // Move left from the Marker so that the position is in the Middle of Text
                  long double tmpangle = angle - rad2deg(asin(halfW / (0.90 * m_radius)));
                  TextPoint.x = m_cx + m_radius * 0.90 * cos(deg2rad(tmpangle));
                  TextPoint.y = m_cy + m_radius * 0.90 * sin(deg2rad(tmpangle));

#ifdef __WXMSW__
                 if( g_pFontSmall->GetPointSize() <= 12 )
                     tdc.DrawRotatedText(label, TextPoint, -90 - angle);
                 else
#endif
                     dc->DrawRotatedText(label, TextPoint, -90 - angle);

            }
            offset++;
            value += m_LabelStep;
      }

#ifdef __WXMSW__
      tdc.SelectObject( wxNullBitmap );

      if( g_pFontSmall->GetPointSize() <= 12 )
            dc->DrawBitmap(tbm, 0, 0, false);
#endif

}
Esempio n. 22
0
AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
                                     const wxPoint & pos,
                                     const wxSize & size):wxFrame(parent,
                                                                  id,
                                                                  "Audacity",
                                                                  pos,
                                                                  size),
mRate((double) gPrefs->
      Read("/SamplingRate/DefaultProjectSampleRate", 44100)),
mDirty(false), mDrag(NULL), mTrackPanel(NULL), mHistoryWindow(NULL),
mAutoScrolling(false), mTotalToolBarHeight(0), mDraggingToolBar(NoneID)
{

   //
   // Create track list
   //

   mTracks = new TrackList();
   mLastSavedTracks = NULL;

   //
   // Initialize view info (shared with TrackPanel)
   //

   // Selection
   mViewInfo.sel0 = 0.0;
   mViewInfo.sel1 = 0.0;

   // Horizontal scrollbar
   mViewInfo.total = 1.0;
   mViewInfo.screen = 1.0;
   mViewInfo.h = 0.0;
   mViewInfo.zoom = 44100.0 / 512.0;
   mViewInfo.lastZoom = mViewInfo.zoom;

   // Vertical scrollbar
   mViewInfo.vpos = 0;

   mViewInfo.scrollStep = 16;

   mViewInfo.sbarH = 0;
   mViewInfo.sbarScreen = 1;
   mViewInfo.sbarTotal = 1;

   // Some GUI prefs
   gPrefs->Read("/GUI/UpdateSpectrogram", &mViewInfo.bUpdateSpectrogram, true);
   gPrefs->Read("/GUI/AutoScroll", &mViewInfo.bUpdateTrackIndicator, true);

   // Some extra information
   mViewInfo.bIsPlaying = false;
   mViewInfo.bRedrawWaveform = false;

   mMenuBar = NULL;
   CreateMenuBar();

   int left = 0, top = 0, width, height;
   GetClientSize(&width, &height);

   //
   // Create the Control Toolbar (if we're not using a windowed toolbar)
   // The control toolbar should be automatically loaded--other toolbars are optional.



   if (!gControlToolBarStub->GetWindowedStatus()) 
      {
         int h = gControlToolBarStub->GetHeight();
         ToolBar *tb = new ControlToolBar(this, 0, wxPoint(10, top), wxSize(width - 10, h));
         mToolBarArray.Add((ToolBar *) tb);
         
         top += h + 1;
         height -= h + 1;
         mTotalToolBarHeight += h;
      }
   
   if (gEditToolBarStub) {
      if(gEditToolBarStub->GetLoadedStatus() 
         && !gEditToolBarStub->GetWindowedStatus())
         {
            int h = gEditToolBarStub->GetHeight();
            ToolBar *etb = new EditToolBar(this,0 ,wxPoint(10,top), wxSize(width-10,h));
            mToolBarArray.Add((ToolBar *) etb);
            
            top +=h + 1;
            height -= h + 1;
            mTotalToolBarHeight +=h;
         }
   }


   //
   // Create the status bar
   //

   int sh = GetStatusHeight();

   mStatus = new AStatus(this, 0,
                         wxPoint(0, height - sh),
                         wxSize(width, sh), mRate, this);
   height -= sh;

   mStatus->SetField(wxString::Format("Welcome to Audacity version %s",
                                      AUDACITY_VERSION_STRING), 0);

   //
   // Create the TrackPanel and the scrollbars
   //

   mTrackPanel = new TrackPanel(this, TrackPanelID,
                                wxPoint(left, top),
                                wxSize(width - sbarSpaceWidth,
                                       height - sbarSpaceWidth), mTracks,
                                &mViewInfo, this);

   int hoffset = mTrackPanel->GetLeftOffset() - 1;
   int voffset = mTrackPanel->GetRulerHeight();

#ifdef __WXMAC__
   width++;
   height++;
#endif

   mHsbar =
       new wxScrollBar(this, HSBarID,
                       wxPoint(hoffset, top + height - sbarSpaceWidth),
                       wxSize(width - hoffset - sbarSpaceWidth +
                              sbarExtraLen, sbarControlWidth),
                       wxSB_HORIZONTAL);

   mVsbar =
       new wxScrollBar(this, VSBarID,
                       wxPoint(width - sbarSpaceWidth, top + voffset),
                       wxSize(sbarControlWidth,
                              height - sbarSpaceWidth - voffset +
                              sbarExtraLen), wxSB_VERTICAL);

   InitialState();
   FixScrollbars();

   //
   // Set the Icon
   //

   // loads either the XPM or the windows resource, depending on the platform
#ifndef __WXMAC__
   wxIcon ic(wxICON(AudacityLogo));
   SetIcon(ic);
#endif

   // Min size, max size
   SetSizeHints(250, 200, 20000, 20000);

   // Create tags object
   mTags = new Tags();

#ifdef __WXMSW__
   // Accept drag 'n' drop files
   DragAcceptFiles(true);
#endif

   gAudacityProjects.Add(this);
}
Esempio n. 23
0
int wxSplitterWindow::GetWindowSize() const
{
    wxSize size = GetClientSize();

    return m_splitMode == wxSPLIT_VERTICAL ? size.x : size.y;
}
Esempio n. 24
0
void AudacityProject::OnPaint(wxPaintEvent & event)
{
   wxPaintDC dc(this);

   int top = 0;
   int h = 0;
   int i, j;
   int toolbartop, toolbarbottom, toolbarheight;
   wxRect r;

   int width, height;
   GetClientSize(&width, &height);

   //Deal with the ToolBars 
   for (i = 0; i < mToolBarArray.GetCount(); i++) {

      AColor::Medium(&dc, false);
      toolbartop = h;
      h += mToolBarArray[i]->GetHeight();
      toolbarbottom = h;
      toolbarheight = toolbarbottom - toolbartop;

      //Adjust a little for Windows (tm) 
#ifdef __WXMSW__
      h++;
#endif

      //Draw a rectangle the space of scrollbar
      r.x = width - sbarSpaceWidth;
      r.y = toolbartop;
      r.width = sbarSpaceWidth;
      r.height = toolbarheight;
      dc.DrawRectangle(r);



      //Draw a rectangle around the "grab-bar"
      r.x = 0;
      r.y = toolbartop;
      r.width = 10;
      r.height = toolbarheight;
      dc.DrawRectangle(r);


      // Draw little bumps to the left of the toolbar to
      // make it a "grab-bar".

      //adjust min and max so that they aren't too close to the edges
      int minbump = (toolbarheight % 2 == 0) ? 3 : 4;
      int maxbump =
          (toolbarheight % 2 == 0) ? toolbarheight - 3 : toolbarheight - 4;

      AColor::Light(&dc, false);
      for (j = minbump; j < maxbump; j += 4)
         dc.DrawLine(3, toolbartop + j, 6, toolbartop + j);

      AColor::Dark(&dc, false);
      for (j = minbump + 1; j < maxbump + 1; j += 4)
         dc.DrawLine(3, toolbartop + j, 6, toolbartop + j);

      //Draw a black line to the right of the grab-bar
      dc.SetPen(*wxBLACK_PEN);
      dc.DrawLine(9, toolbartop, 9, toolbarbottom);

      //Draw some more lines for Windows (tm)
#ifdef __WXMSW__
      dc.DrawLine(0, toolbartop, width, toolbartop);
      dc.DrawLine(0, toolbartop, 0, toolbarbottom);
#endif


      dc.DrawLine(0, toolbarbottom, width, toolbarbottom);
      h++;
   }


   //Now, h is equal to the total height of all the toolbars
   top += h;
   height -= h;

   int sh = GetStatusHeight();
   height -= sh;



   // Fill in space on sides of scrollbars

   dc.SetPen(*wxBLACK_PEN);
   dc.DrawLine(width - sbarSpaceWidth, top,
               width - sbarSpaceWidth, top + height - sbarSpaceWidth + 1);
   dc.DrawLine(0, top + height - sbarSpaceWidth,
               width - sbarSpaceWidth, top + height - sbarSpaceWidth);


   wxRect f;
   f.x = 0;
   f.y = top + height - sbarSpaceWidth + 1;
   f.width = mTrackPanel->GetLeftOffset() - 2;
   f.height = sbarSpaceWidth - 2;
   AColor::Medium(&dc, false);
   dc.DrawRectangle(f);
   AColor::Bevel(dc, true, f);

}
Esempio n. 25
0
void TextEditorStc::OnSize(wxSizeEvent& evt)
{
	edwnd->SetSize(GetClientSize());
}
Esempio n. 26
0
// draw focus background on area in a way typical on platform
void
wxComboCtrl::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const
{
#if wxUSE_UXTHEME
    wxUxThemeHandle hTheme(this, L"COMBOBOX");
#endif

    wxSize sz = GetClientSize();
    bool isEnabled;
    bool doDrawFocusRect; // also selected

    // For smaller size control (and for disabled background) use less spacing
    int focusSpacingX;
    int focusSpacingY;

    if ( !(flags & wxCONTROL_ISSUBMENU) )
    {
        // Drawing control
        isEnabled = IsEnabled();
        doDrawFocusRect = ShouldDrawFocus();

#if wxUSE_UXTHEME
        // Windows-style: for smaller size control (and for disabled background) use less spacing
        if ( hTheme )
        {
            // WinXP  Theme
            focusSpacingX = isEnabled ? 2 : 1;
            focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1;
        }
        else
#endif
        {
            // Classic Theme
            if ( isEnabled )
            {
                focusSpacingX = 1;
                focusSpacingY = 1;
            }
            else
            {
                focusSpacingX = 0;
                focusSpacingY = 0;
            }
        }
    }
    else
    {
        // Drawing a list item
        isEnabled = true; // they are never disabled
        doDrawFocusRect = flags & wxCONTROL_SELECTED ? true : false;

        focusSpacingX = 0;
        focusSpacingY = 0;
    }

    // Set the background sub-rectangle for selection, disabled etc
    wxRect selRect(rect);
    selRect.y += focusSpacingY;
    selRect.height -= (focusSpacingY*2);

    int wcp = 0;

    if ( !(flags & wxCONTROL_ISSUBMENU) )
        wcp += m_widthCustomPaint;

    selRect.x += wcp + focusSpacingX;
    selRect.width -= wcp + (focusSpacingX*2);

    //wxUxThemeEngine* theme = NULL;
    //if ( hTheme )
    //    theme = wxUxThemeEngine::GetIfActive();

    wxColour bgCol;
    bool doDrawDottedEdge = false;
    bool doDrawSelRect = true;

    // TODO: doDrawDottedEdge = true when focus has arrived to control via tab.
    //       (and other cases which are not that apparent).

    if ( isEnabled )
    {
        // If popup is hidden and this control is focused,
        // then draw the focus-indicator (selbgcolor background etc.).
        if ( doDrawFocusRect )
        {
            // NB: We can't really use XP visual styles to get TMT_TEXTCOLOR since
            //     it is not properly defined for combo boxes. Instead, they expect
            //     you to use DrawThemeText.
            //
            //    Here is, however, sample code how to get theme colours:
            //
            //    COLORREF cref;
            //    theme->GetThemeColor(hTheme,EP_EDITTEXT,ETS_NORMAL,TMT_TEXTCOLOR,&cref);
            //    dc.SetTextForeground( wxRGBToColour(cref) );
            if ( (m_iFlags & wxCC_FULL_BUTTON) && !(flags & wxCONTROL_ISSUBMENU) )
            {
                // Vista style read-only combo
                doDrawSelRect = false;
                doDrawDottedEdge = true;
            }
            else
            {
                dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) );
                bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
            }
        }
        else
        {
            dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) );
            bgCol = GetBackgroundColour();
            doDrawSelRect = false;
        }
    }
    else
    {
        dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT) );
        bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
    }

    dc.SetBrush(bgCol);
    if ( doDrawSelRect )
    {
        dc.SetPen(bgCol);
        dc.DrawRectangle(selRect);
    }

    if ( doDrawDottedEdge )
        wxMSWDrawFocusRect(dc, selRect);

    // Don't clip exactly to the selection rectangle so we can draw
    // to the non-selected area in front of it.
    wxRect clipRect(rect.x,rect.y,
                    (selRect.x+selRect.width)-rect.x-1,rect.height);
    dc.SetClippingRegion(clipRect);
}
Esempio n. 27
0
void AudacityProject::OnPaint(wxPaintEvent & event)
{
   // Draw a colored strip on the right and bottom edges of
   // the window to fill in the small area not covered by
   // the TrackPanel or the scrollbars.

   wxPaintDC dc(this);
   int width, height;
   GetClientSize(&width, &height);

   AColor::Medium(&dc, false);

   int top = 0;

   if (!gWindowedPalette) {
      int h = GetAPaletteHeight();

#ifdef __WXMSW__
      h++;
#endif

      top += h + 1;
      height -= h + 1;
   }

   int sh = GetStatusHeight();
   height -= sh;

   wxRect r;
   r.x = width - sbarSpaceWidth;
   r.y = 0;
   r.width = sbarSpaceWidth;
   r.height = height;
   dc.DrawRectangle(r);

   // If we're displaying the palette inside the window,
   // draw little bumps to the left of the palette to
   // indicate it's grabable

   if (!gWindowedPalette) {
      int h = GetAPaletteHeight();

      r.x = 0;
      r.y = 0;
      r.width = 10;
      r.height = h;
      dc.DrawRectangle(r);

      int i;

      AColor::Light(&dc, false);
      for (i = h / 2 - 20; i < h / 2 + 20; i += 4)
         dc.DrawLine(3, i, 6, i);
      AColor::Dark(&dc, false);
      for (i = h / 2 - 19; i < h / 2 + 21; i += 4)
         dc.DrawLine(3, i, 6, i);

      dc.SetPen(*wxBLACK_PEN);
      dc.DrawLine(9, 0, 9, h);

#ifdef __WXMSW__
      dc.DrawLine(0, 0, width, 0);
      dc.DrawLine(0, 0, 0, h);
#endif

      dc.DrawLine(0, h, width, h);
   }
   // Fill in space on sides of scrollbars

   dc.SetPen(*wxBLACK_PEN);
   dc.DrawLine(width - sbarSpaceWidth, top,
               width - sbarSpaceWidth, top + height - sbarSpaceWidth + 1);
   dc.DrawLine(0, top + height - sbarSpaceWidth,
               width - sbarSpaceWidth, top + height - sbarSpaceWidth);

   wxRect f;
   f.x = 0;
   f.y = top + height - sbarSpaceWidth + 1;
   f.width = mTrackPanel->GetLeftOffset() - 2;
   f.height = sbarSpaceWidth - 2;
   AColor::Medium(&dc, false);
   dc.DrawRectangle(f);
   AColor::Bevel(dc, true, f);
}
Esempio n. 28
0
void wxComboCtrl::OnPaintEvent( wxPaintEvent& WXUNUSED(event) )
{
    // TODO: Convert drawing in this function to Windows API Code

    wxSize sz = GetClientSize();
    wxAutoBufferedPaintDC dc(this);

    const wxRect& rectButton = m_btnArea;
    wxRect rectTextField = m_tcArea;
    wxColour bgCol = GetBackgroundColour();

#if wxUSE_UXTHEME
    const bool isEnabled = IsEnabled();

    wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
    HDC hDc = GetHdcOf(*impl);
    HWND hWnd = GetHwndOf(this);

    wxUxThemeEngine* theme = NULL;
    wxUxThemeHandle hTheme(this, L"COMBOBOX");

    if ( hTheme )
        theme = wxUxThemeEngine::GetIfActive();
#endif // wxUSE_UXTHEME

    wxRect borderRect(0,0,sz.x,sz.y);

    if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE )
    {
        borderRect = m_tcArea;
        borderRect.Inflate(1);
    }

    int drawButFlags = 0;

#if wxUSE_UXTHEME
    if ( hTheme )
    {
        const bool useVistaComboBox = ::wxGetWinVersion() >= wxWinVersion_Vista;

        RECT rFull;
        wxCopyRectToRECT(borderRect, rFull);

        RECT rButton;
        wxCopyRectToRECT(rectButton, rButton);

        RECT rBorder;
        wxCopyRectToRECT(borderRect, rBorder);

        bool isNonStdButton = (m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE) ||
                              (m_iFlags & wxCC_IFLAG_HAS_NONSTANDARD_BUTTON);

        //
        // Get some states for themed drawing
        int butState;

        if ( !isEnabled )
        {
            butState = CBXS_DISABLED;
        }
        // Vista will display the drop-button as depressed always
        // when the popup window is visilbe
        else if ( (m_btnState & wxCONTROL_PRESSED) ||
                  (useVistaComboBox && !IsPopupWindowState(Hidden)) )
        {
            butState = CBXS_PRESSED;
        }
        else if ( m_btnState & wxCONTROL_CURRENT )
        {
            butState = CBXS_HOT;
        }
        else
        {
            butState = CBXS_NORMAL;
        }

        int comboBoxPart = 0;  // For XP, use the 'default' part
        RECT* rUseForBg = &rBorder;

        bool drawFullButton = false;
        int bgState = butState;
        const bool isFocused = (FindFocus() == GetMainWindowOfCompositeControl()) ? true : false;

        if ( useVistaComboBox )
        {
            // FIXME: Either SetBackgroundColour or GetBackgroundColour
            //        doesn't work under Vista, so here's a temporary
            //        workaround.
            bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);

            // Draw the entire control as a single button?
            if ( !isNonStdButton )
            {
                if ( HasFlag(wxCB_READONLY) )
                    drawFullButton = true;
            }

            if ( drawFullButton )
            {
                comboBoxPart = CP_READONLY;
                rUseForBg = &rFull;

                // It should be safe enough to update this flag here.
                m_iFlags |= wxCC_FULL_BUTTON;
            }
            else
            {
                comboBoxPart = CP_BORDER;
                m_iFlags &= ~wxCC_FULL_BUTTON;

                if ( isFocused )
                    bgState = CBB_FOCUSED;
                else
                    bgState = CBB_NORMAL;
            }
        }

        //
        // Draw parent's background, if necessary
        RECT* rUseForTb = NULL;

        if ( theme->IsThemeBackgroundPartiallyTransparent( hTheme, comboBoxPart, bgState ) )
            rUseForTb = &rFull;
        else if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE )
            rUseForTb = &rButton;

        if ( rUseForTb )
            theme->DrawThemeParentBackground( hWnd, hDc, rUseForTb );

        //
        // Draw the control background (including the border)
        if ( m_widthCustomBorder > 0 )
        {
            theme->DrawThemeBackground( hTheme, hDc, comboBoxPart, bgState, rUseForBg, NULL );
        }
        else
        {
            // No border. We can't use theme, since it cannot be relied on
            // to deliver borderless drawing, even with DrawThemeBackgroundEx.
            dc.SetBrush(bgCol);
            dc.SetPen(bgCol);
            dc.DrawRectangle(borderRect);
        }

        //
        // Draw the drop-button
        if ( !isNonStdButton )
        {
            drawButFlags = Button_BitmapOnly;

            int butPart = CP_DROPDOWNBUTTON;

            if ( useVistaComboBox )
            {
                if ( drawFullButton )
                {
                    // We need to alter the button style slightly before
                    // drawing the actual button (but it was good above
                    // when background etc was done).
                    if ( butState == CBXS_HOT || butState == CBXS_PRESSED )
                        butState = CBXS_NORMAL;
                }

                if ( m_btnSide == wxRIGHT )
                    butPart = CP_DROPDOWNBUTTONRIGHT;
                else
                    butPart = CP_DROPDOWNBUTTONLEFT;

            }
            theme->DrawThemeBackground( hTheme, hDc, butPart, butState, &rButton, NULL );
        }
        else if ( useVistaComboBox &&
                  (m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE) )
        {
            // We'll do this, because DrawThemeParentBackground
            // doesn't seem to be reliable on Vista.
            drawButFlags |= Button_PaintBackground;
        }
    }
    else
#endif
    {
        // Windows 2000 and earlier
        drawButFlags = Button_PaintBackground;

        dc.SetBrush(bgCol);
        dc.SetPen(bgCol);
        dc.DrawRectangle(borderRect);
    }

    // Button rendering (may only do the bitmap on button, depending on the flags)
    DrawButton( dc, rectButton, drawButFlags );

    // Paint required portion of the custom image on the control
    if ( (!m_text || m_widthCustomPaint) )
    {
        wxASSERT( m_widthCustomPaint >= 0 );

        // this is intentionally here to allow drawed rectangle's
        // right edge to be hidden
        if ( m_text )
            rectTextField.width = m_widthCustomPaint;

        dc.SetFont( GetFont() );

        dc.SetClippingRegion(rectTextField);
        if ( m_popupInterface )
            m_popupInterface->PaintComboControl(dc,rectTextField);
        else
            wxComboPopup::DefaultPaintComboControl(this,dc,rectTextField);
    }
}
Esempio n. 29
0
void GlyphPreviewWindow::OnPaint(wxPaintEvent& evt)
{
	wxPaintDC dc(this);
	if (m_entry.IsOK() && m_font.IsOk())
	{
		wxUint32 glyph = m_font.GetGlyphIndex(m_entry.GetCode());
		wxSize glyphSize = m_font.GetGlyphSize(glyph);
		wxSize clientSize = GetClientSize();

		if (glyphSize.GetHeight() != 0 && glyphSize.GetWidth() != 0)
		{
			float scale;
			if (glyphSize.GetWidth() > glyphSize.GetHeight())
			{
				scale = (float)clientSize.GetWidth()/glyphSize.GetWidth();
			}
			else {
				scale = (float) clientSize.GetHeight() / glyphSize.GetHeight();
			}
			scale *= 0.9f;
			int size = m_font.GetGlyphBitmap(glyph, NULL, NULL, NULL);
			if (size > 0)
			{
				int width, height;
				wxUint8 *bitmap = new wxUint8[size];
				wxSize glyphSize = m_font.GetGlyphSize(glyph);
				wxPoint bearing = m_font.GetGlyphBearing(glyph);
				m_font.GetGlyphBitmap(glyph, bitmap, &width, &height);

				wxImage image(width, height);
				unsigned char *rgb = image.GetData();
				for (int y = 0; y < height; y++)
				{
					for (int x = 0; x < width; x++)
					{
						int offset = ((y) * image.GetWidth() + x) * 3;
						wxASSERT(offset+2 < image.GetWidth()*image.GetHeight()*3);
						wxASSERT(offset >= 0);
						rgb[0 + offset] = 255 - bitmap[y * width + x];
						rgb[1 + offset] = 255 - bitmap[y * width + x];
						rgb[2 + offset] = 255 - bitmap[y * width + x];
					}
				}
				image.Rescale(width*scale, height*scale);
				
				wxPoint origin((clientSize.GetWidth() - glyphSize.GetWidth()*scale)/2,
					(clientSize.GetHeight() - glyphSize.GetHeight()*scale)/2);
				origin.y += bearing.y*scale;

				wxPoint glyphPos = origin + wxPoint(bearing.x, -bearing.y)*scale;
				dc.DrawBitmap(wxBitmap(image), glyphPos);
				dc.SetPen(*wxRED_PEN);
				dc.SetBrush(*wxTRANSPARENT_BRUSH);
				dc.DrawRectangle(glyphPos, wxSize(image.GetWidth(), image.GetHeight()));
				dc.SetPen(*wxGREEN_PEN);
				dc.DrawLine(0, origin.y, clientSize.GetWidth(), origin.y);
				dc.DrawLine(origin.x, 0, origin.x, clientSize.GetHeight());
				wxPoint advancePoint = origin += m_font.GetGlyphAdvance(glyph)*scale;
				dc.SetPen(*wxBLUE_PEN);
				dc.DrawLine(advancePoint.x - 10, advancePoint.y, advancePoint.x + 10, advancePoint.y);
				dc.DrawLine(advancePoint.x, advancePoint.y - 10, advancePoint.x, advancePoint.y + 10);


				delete [] bitmap;
			}
		}
	}
}
Esempio n. 30
0
void CMusikListCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
{
	wxBufferedPaintDC dc(this);

	MSWDefWindowProc(WM_ERASEBKGND, (WPARAM) (HDC) dc.GetHDC(), 0);
	MSWDefWindowProc(WM_PAINT, (WPARAM) (HDC) dc.GetHDC(), 0);

	/* copied from original wxwindows code */
    // Reset the device origin since it may have been set
	dc.SetDeviceOrigin(0, 0);
    bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0);
    bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0);

    if (!drawHRules && !drawVRules)
        return;
    if ((GetWindowStyle() & wxLC_REPORT) == 0)
        return;
    

    wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
    dc.SetPen(pen);
    dc.SetBrush(* wxTRANSPARENT_BRUSH);

    wxSize clientSize = GetClientSize();
    wxRect itemRect;
    int cy=0;

    int itemCount = GetItemCount();
    int i;
    if (drawHRules)
    {
        long top = GetTopItem();
        for (i = top; i < top + GetCountPerPage() + 1; i++)
        {
            if (GetItemRect(i, itemRect))
            {
                cy = itemRect.GetTop();
                if (i != 0) // Don't draw the first one
                {
                    dc.DrawLine(0, cy, clientSize.x, cy);
                }
                // Draw last line
                if (i == itemCount - 1)
                {
                    cy = itemRect.GetBottom();
                    dc.DrawLine(0, cy, clientSize.x, cy);
                }
            }
        }
    }
    i = itemCount - 1;
    if (drawVRules && (i > -1))
    {
        wxRect firstItemRect;
        GetItemRect(0, firstItemRect);

        if (GetItemRect(i, itemRect))
        {
            int col;
            int x = itemRect.GetX();
            for (col = 0; col < GetColumnCount(); col++)
            {
                int colWidth = GetColumnWidth(col);
                x += colWidth ;
                dc.DrawLine(x-1, firstItemRect.GetY() - 2, x-1, itemRect.GetBottom());
            }
        }
    }
}