Esempio n. 1
0
void CheckOnScreen(wxWindow *win, wxPoint &pos, wxSize &size, const int w0, const int h0)
{
	wxRect rect;
	int scrH, scrW;

	wxSize screenSize = wxGetDisplaySize();
	scrW = screenSize.x;
	scrH = screenSize.y;

	if (pos.x > scrW - w0)
		pos.x = scrW - w0;
	if (pos.y > scrH - h0)
		pos.y = scrH - h0;

	if (pos.x < 0)
		pos.x = 0;
	if (pos.y < 0)
		pos.y = 0;

	if (size.GetWidth() < w0)
		size.SetWidth(w0);
	if (size.GetHeight() < h0)
		size.SetHeight(h0);

	if (size.GetWidth() > scrW)
		size.SetWidth(scrW);
	if (size.GetHeight() > scrH)
		size.SetHeight(scrH);
}
Esempio n. 2
0
bool COptionsPage::CreatePage(COptions* pOptions, CSettingsDialog* pOwner, wxWindow* parent, wxSize& maxSize)
{
	m_pOwner = pOwner;
	m_pOptions = pOptions;

	if (!wxXmlResource::Get()->LoadPanel(this, parent, GetResourceName()))
		return false;

	wxSize size = GetSize();

#ifdef __WXGTK__
	// wxStaticBox draws its own border coords -1.
	// Adjust this window so that the left border is fully visible.
	Move(1, 0);
	size.x += 1;
#endif

	if (size.GetWidth() > maxSize.GetWidth())
		maxSize.SetWidth(size.GetWidth());
	if (size.GetHeight() > maxSize.GetHeight())
		maxSize.SetHeight(size.GetHeight());

	m_was_selected = false;

	return true;
}
Esempio n. 3
0
bool wxDrawerWindow::Create(wxWindow *parent,
 wxWindowID id, const wxString& WXUNUSED(title),
 wxSize size, wxDirection edge, const wxString& name)
{
    wxASSERT_MSG(NULL != parent, wxT("wxDrawerWindows must be attached to a parent window."));

    // Constrain the drawer size to the parent window.
    const wxSize parentSize(parent->GetClientSize());
    if (wxLEFT == edge || wxRIGHT == edge)
    {
        if (size.GetHeight() > parentSize.GetHeight())
            size.SetHeight(parentSize.GetHeight() - (kLeadingOffset + kTrailingOffset));
    }
    else
    {
        if (size.GetWidth() > parentSize.GetWidth())
            size.SetWidth(parentSize.GetWidth() - (kLeadingOffset + kTrailingOffset));
    }

    // Create the drawer window.
    const wxPoint pos(0, 0);
    const wxSize dummySize(0,0);
    const long style = wxFRAME_DRAWER;

    bool success  = wxNonOwnedWindow::Create(parent, id, pos, size, style, name);
    if (success)
    {
        // this->MacCreateRealWindow(pos, size, style, name);
        success = (GetWXWindow() != NULL);
    }

    if (success)
    {
        // Use drawer brush.
        SetBackgroundColour( wxColour( wxMacCreateCGColorFromHITheme( kThemeBrushDrawerBackground ) ) );
        ::SetThemeWindowBackground((WindowRef)GetWXWindow(), kThemeBrushDrawerBackground, false);

        // Leading and trailing offset are gaps from parent window edges
        // to where the drawer starts.
        ::SetDrawerOffsets((WindowRef)GetWXWindow() , kLeadingOffset, kTrailingOffset);

        // Set the drawers parent.
        // Is there a better way to get the parent's WindowRef?
        wxTopLevelWindow* tlwParent = wxDynamicCast(parent, wxTopLevelWindow);
        if (NULL != tlwParent)
        {
            OSStatus status = ::SetDrawerParent((WindowRef) GetWXWindow(),
            (WindowRef)tlwParent->GetWXWindow());
            success = (noErr == status);
        }
        else
            success = false;
    }

    return success && SetPreferredEdge(edge);
}
Esempio n. 4
0
void EffectAssist::AdjustClientSizes(wxSize s)
{
    mSize = s;
    if( mAssistPanel != nullptr )
    {
        s.SetWidth(s.GetWidth()-15);
        s.SetHeight(s.GetHeight()-15);
        mAssistPanel->AdjustSize(s);
    }
}
Esempio n. 5
0
bool TryParse( wxSize& dest, wxStringTokenizer& parts )
{
	long result[2];

	if( !parts.HasMoreTokens() || !parts.GetNextToken().ToLong( &result[0] ) ) return false;
	if( !parts.HasMoreTokens() || !parts.GetNextToken().ToLong( &result[1] ) ) return false;
	dest.SetWidth( result[0] );
	dest.SetHeight( result[1] );

	return true;
}
Esempio n. 6
0
void COptionsPage::UpdateMaxPageSize(wxSize& maxSize)
{
	wxSize size = GetSize();

#ifdef __WXGTK__
	// wxStaticBox draws its own border coords -1.
	// Adjust this window so that the left border is fully visible.
	Move(1, 0);
	size.x += 1;
#endif

	if (size.GetWidth() > maxSize.GetWidth()) {
		maxSize.SetWidth(size.GetWidth());
	}
	if (size.GetHeight() > maxSize.GetHeight()) {
		maxSize.SetHeight(size.GetHeight());
	}
}
Esempio n. 7
0
 void CalculateOverallSize()
 {
     overall_size = wxSize(0, 0);
     size_t btn_count = buttons.Count();
     size_t btn_i;
     for(btn_i = 0; btn_i < btn_count; ++btn_i)
     {
         wxRibbonButtonBarButtonInstance& instance = buttons.Item(btn_i);
         wxSize size = instance.base->sizes[instance.size].size;
         int right = instance.position.x + size.GetWidth();
         int bottom = instance.position.y + size.GetHeight();
         if(right > overall_size.GetWidth())
         {
             overall_size.SetWidth(right);
         }
         if(bottom > overall_size.GetHeight())
         {
             overall_size.SetHeight(bottom);
         }
     }
 }
Esempio n. 8
0
wxImage ScaleImage(wxImage image, double source_scale_factor, double content_scale_factor,
                   wxSize output_size, wxRect usable_rect, LSIFlags flags,
                   const wxColour& fill_color)
{
  if (!image.IsOk())
  {
    wxFAIL_MSG("WxUtils::ScaleImage expects a valid image.");
    return image;
  }

  if (content_scale_factor != 1.0)
  {
    output_size *= content_scale_factor;
    usable_rect.SetPosition(usable_rect.GetPosition() * content_scale_factor);
    usable_rect.SetSize(usable_rect.GetSize() * content_scale_factor);
  }

  // Fix the output size if it's unset.
  wxSize img_size = image.GetSize();
  if (output_size.GetWidth() < 1)
    output_size.SetWidth(
        static_cast<int>(img_size.GetWidth() * (content_scale_factor / source_scale_factor)));
  if (output_size.GetHeight() < 1)
    output_size.SetHeight(
        static_cast<int>(img_size.GetHeight() * (content_scale_factor / source_scale_factor)));

  // Fix the usable rect. If it's empty then the whole canvas is usable.
  if (usable_rect.IsEmpty())
  {
    // Constructs a temp wxRect 0,0->output_size then move assigns it.
    usable_rect = output_size;
  }
  else if (!usable_rect.Intersects(output_size))
  {
    wxFAIL_MSG("Usable Zone Rectangle is not inside the canvas. Check the output size is correct.");
    image.Create(1, 1, false);
    image.SetRGB(0, 0, fill_color.Red(), fill_color.Green(), fill_color.Blue());
    if (fill_color.Alpha() == wxALPHA_TRANSPARENT)
      image.SetMaskColour(fill_color.Red(), fill_color.Green(), fill_color.Blue());
    usable_rect = output_size;
  }

  // Step 1: Scale the image
  if ((flags & LSI_SCALE) != LSI_SCALE_NONE)
  {
    if (flags & LSI_SCALE_NO_ASPECT)
    {
      // Stretch scale without preserving the aspect ratio.
      bool scale_width = (img_size.GetWidth() > usable_rect.GetWidth() && flags & LSI_SCALE_DOWN) ||
                         (img_size.GetWidth() < usable_rect.GetWidth() && flags & LSI_SCALE_UP);
      bool scale_height =
          (img_size.GetHeight() > usable_rect.GetHeight() && flags & LSI_SCALE_DOWN) ||
          (img_size.GetHeight() < usable_rect.GetHeight() && flags & LSI_SCALE_UP);
      if (scale_width || scale_height)
      {
        // NOTE: Using BICUBIC instead of HIGH because it's the same internally
        //   except that downscaling uses a box filter with awful obvious aliasing
        //   for non-integral scale factors.
        image.Rescale(scale_width ? usable_rect.GetWidth() : img_size.GetWidth(),
                      scale_height ? usable_rect.GetHeight() : img_size.GetHeight(),
                      wxIMAGE_QUALITY_BICUBIC);
      }
    }
    else
    {
      // Scale while preserving the aspect ratio.
      double scale = std::min(static_cast<double>(usable_rect.GetWidth()) / img_size.GetWidth(),
                              static_cast<double>(usable_rect.GetHeight()) / img_size.GetHeight());
      int target_width = static_cast<int>(img_size.GetWidth() * scale);
      int target_height = static_cast<int>(img_size.GetHeight() * scale);
      // Bilinear produces sharper images when upscaling, bicubic tends to smear/blur sharp edges.
      if (scale > 1.0 && flags & LSI_SCALE_UP)
        image.Rescale(target_width, target_height, wxIMAGE_QUALITY_BILINEAR);
      else if (scale < 1.0 && flags & LSI_SCALE_DOWN)
        image.Rescale(target_width, target_height, wxIMAGE_QUALITY_BICUBIC);
    }
    img_size = image.GetSize();
  }

  // Step 2: Resize the canvas to match the output size.
  // NOTE: If NOT using LSI_SCALE_DOWN then this will implicitly crop the image
  if (img_size != output_size || usable_rect.GetPosition() != wxPoint())
  {
    wxPoint base = usable_rect.GetPosition();
    if (flags & LSI_ALIGN_HCENTER)
      base.x += (usable_rect.GetWidth() - img_size.GetWidth()) / 2;
    else if (flags & LSI_ALIGN_RIGHT)
      base.x += usable_rect.GetWidth() - img_size.GetWidth();
    if (flags & LSI_ALIGN_VCENTER)
      base.y += (usable_rect.GetHeight() - img_size.GetHeight()) / 2;
    else if (flags & LSI_ALIGN_BOTTOM)
      base.y += usable_rect.GetHeight() - img_size.GetHeight();

    int r = -1, g = -1, b = -1;
    if (fill_color.Alpha() != wxALPHA_TRANSPARENT)
    {
      r = fill_color.Red();
      g = fill_color.Green();
      b = fill_color.Blue();
    }
    image.Resize(output_size, base, r, g, b);
  }

  return image;
}