void CamArtProvider::Draw(wxDC& dc, const wxRect & rect, ResourceID Resource, CamArtFlags Flags, const wxString &text) { dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); dc.SetPen(*wxTRANSPARENT_PEN); // dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height); // dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); dc.SetBrush(*wxTRANSPARENT_BRUSH); // Needed in case we need to paint 3D furniture, but not the button top (ALWAYS3D) wxRect brect = rect; UINT32 bitmapoffsetX=0; UINT32 bitmapoffsetY=0; if ((Flags & CAF_PUSHBUTTON) && !rect.IsEmpty()) { // 3Dness brect.width-=1; brect.height-=1; if (Flags & CAF_SELECTED) { // It's pushed in brect.x++; brect.y++; } UINT32 InternalBorderX = (Flags & CAF_NOINTERNALBORDER)?0:2; UINT32 InternalBorderY = (Flags & CAF_NOINTERNALBORDER)?0:1; bitmapoffsetX=1+((InternalBorderX+1)>>1); // this is a completely independent offset to the brect stuff, which gives the bitmap a border bitmapoffsetY=1+((InternalBorderY+1)>>1); // this is a completely independent offset to the brect stuff, which gives the bitmap a border // BOOL FaceSelected = ( (Flags & CAF_SELECTED) || (Flags & CAF_BUTTONHOVER) ); // BOOL Border3D = ( (Flags & CAF_SELECTED) || (Flags & CAF_ALWAYS3D)); BOOL FaceSelected = ( (Flags & CAF_SELECTED) || ((Flags & CAF_ALWAYS3D) && (Flags & CAF_BUTTONHOVER)) ); // highlight face on hover if always3D BOOL Border3D = ( (Flags & CAF_SELECTED) || (Flags & CAF_ALWAYS3D) || (Flags & CAF_BUTTONHOVER)); // Change the brush if the face is selected if (FaceSelected) { if (Flags & CAF_TOOLBACKGROUND) dc.SetBrush(wxColour(255,255,192)); // A light yellow - we should load this from somewhere else else { if (Flags & CAF_BUTTONHOVER) dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT)); else dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); } } if (Border3D) { // draw the light highlights dc.SetPen(wxSystemSettings::GetColour((Flags & CAF_SELECTED)?wxSYS_COLOUR_3DHIGHLIGHT:wxSYS_COLOUR_3DDKSHADOW)); // draw the background behind the button undisplaced dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height); // now draw the left & top bits dc.SetPen(wxSystemSettings::GetColour((Flags & CAF_SELECTED)?wxSYS_COLOUR_3DDKSHADOW:wxSYS_COLOUR_3DHIGHLIGHT)); dc.DrawLine(rect.x, rect.y, rect.x+rect.width-1, rect.y); dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height-1); } else if (FaceSelected) // if not FaceSelected, we've already drawn it { // draw the background behind the button displaced dc.DrawRectangle(brect.x, brect.y, brect.width, brect.height); } }
bool LfnTech::Copy( void* destBase, const void* srcBase, const wxRect& destBounds, const wxRect& srcBounds, const wxPoint& destPoint, const wxRect& srcRect, int destStride, int srcStride, int bytesPerPixel) { bool result = false; if (!destBounds.IsEmpty() && !srcBounds.IsEmpty()) { wxPoint destPointClipped(destPoint); wxPoint srcPointClipped(srcRect.GetPosition()); wxSize sizeClipped(srcRect.GetSize()); // Clip against src bounds, then against dest bounds, then once again // against src bounds in case the dest clip translation moved it significantly. Clip(srcBounds, srcPointClipped, sizeClipped, destPointClipped); Clip(destBounds, destPointClipped, sizeClipped, srcPointClipped); Clip(srcBounds, srcPointClipped, sizeClipped, destPointClipped); result = Copy(destBase, srcBase, destPointClipped, wxRect(srcPointClipped, sizeClipped), destStride, srcStride, bytesPerPixel); } return result; }
bool wxRegion::DoUnionWithRect(const wxRect& r) { // workaround for a strange GTK/X11 bug: taking union with an empty // rectangle results in an empty region which is definitely not what we // want if ( r.IsEmpty() ) return TRUE; if ( !m_refData ) { InitRect(r.x, r.y, r.width, r.height); } else { AllocExclusive(); GdkRectangle rect; rect.x = r.x; rect.y = r.y; rect.width = r.width; rect.height = r.height; GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; } return TRUE; }
bool wxRegion::DoUnionWithRect(const wxRect& r) { // work around for XUnionRectWithRegion() bug: taking a union with an empty // rect results in an empty region (at least XFree 3.3.6 and 4.0 have this // problem) if ( r.IsEmpty() ) return true; XRectangle rect; rect.x = (short)r.x; rect.y = (short)r.y; rect.width = (unsigned short)r.width; rect.height = (unsigned short)r.height; if (!m_refData) { m_refData = new wxRegionRefData(); M_REGIONDATA->m_region = XCreateRegion(); } else { AllocExclusive(); } XUnionRectWithRegion( &rect, M_REGIONDATA->m_region, M_REGIONDATA->m_region ); return true; }
void wxTaskBarButtonImpl::SetThumbnailClip(const wxRect& rect) { m_thumbnailClipRect = rect; RECT rc; wxCopyRectToRECT(rect, rc); m_taskbarList->SetThumbnailClip(m_parent->GetHWND(), rect.IsEmpty() ? NULL : &rc); }
bool wxRegion::DoUnionWithRect(const wxRect& r) { // workaround for a strange GTK/X11 bug: taking union with an empty // rectangle results in an empty region which is definitely not what we // want if ( r.IsEmpty() ) return true; if ( !m_refData ) { InitRect(r.x, r.y, r.width, r.height); } else { AllocExclusive(); GdkRectangle rect; rect.x = r.x; rect.y = r.y; rect.width = r.width; rect.height = r.height; #ifdef __WXGTK3__ cairo_region_union_rectangle(M_REGIONDATA->m_region, &rect); #else gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); #endif } return true; }
void Reset() { // Make sure we can call this method only once if(m_used) { m_dc.DestroyClippingRegion(); if(!m_oldRect.IsEmpty()) { m_dc.SetClippingRegion(m_oldRect); } m_used = false; } }
void wxNotebook::AdjustPageSize(wxNotebookPage *page) { wxCHECK_RET( page, wxT("NULL page in wxNotebook::AdjustPageSize") ); const wxRect r = GetPageSize(); if ( !r.IsEmpty() ) { page->SetSize(r); } }
bool JobTicket::DoJob() { if(!rect.IsEmpty()) return DoJob(rect); // otherwise this ticket covers all the rects in the chart ChartBase *pchart = ChartData->OpenChartFromDB( m_ChartPath, FULL_INIT ); if(!pchart) return false; ChartBaseBSB *pBSBChart = dynamic_cast<ChartBaseBSB*>( pchart ); if(!pBSBChart) return false; int size_X = pBSBChart->GetSize_X(); int size_Y = pBSBChart->GetSize_Y(); int dim = g_GLOptions.m_iTextureDimension; int nx_tex = ceil( (float)size_X / dim ); int ny_tex = ceil( (float)size_Y / dim ); int nt = ny_tex * nx_tex; wxRect rect; rect.y = 0; rect.width = dim; rect.height = dim; for( int y = 0; y < ny_tex; y++ ) { rect.x = 0; for( int x = 0; x < nx_tex; x++ ) { if(!DoJob(rect)) return false; pFact->UpdateCacheAllLevels(rect, global_color_scheme, compcomp_bits_array, compcomp_size_array); for(int i=0 ; i < g_mipmap_max_level+1 ; i++) { free(comp_bits_array[i]), comp_bits_array[i] = 0; free(compcomp_bits_array[i]), compcomp_bits_array[i] = 0; } rect.x += rect.width; } rect.y += rect.height; } return true; }
wxToolInfo(HWND hwndOwner, unsigned int id, const wxRect& rc) { // initialize all members ::ZeroMemory(this, sizeof(TOOLINFO)); // the structure TOOLINFO has been extended with a 4 byte field in // version 4.70 of comctl32.dll and another one in 5.01 but we don't // use these extended fields so use the old struct size to ensure that // the tooltips work on old (Windows 95) systems too cbSize = TTTOOLINFO_V1_SIZE; hwnd = hwndOwner; if (rc.IsEmpty()) { uFlags = TTF_IDISHWND; uId = (UINT_PTR)hwndOwner; } else { // this tooltip must be shown only if the mouse hovers a specific rect // of the hwnd parameter! rect.left = rc.GetLeft(); rect.right = rc.GetRight(); rect.top = rc.GetTop(); rect.bottom = rc.GetBottom(); // note that not setting TTF_IDISHWND from the uFlags member means that the // ti.uId field should not contain the HWND but rather as MSDN says an // "Application-defined identifier of the tool"; this is used internally by // Windows to distinguish the different tooltips attached to the same window uId = id; } // we use TTF_TRANSPARENT to fix a problem which arises at least with // the text controls but may presumably happen with other controls // which display the tooltip at mouse position: it can start flashing // then as the control gets "focus lost" events and dismisses the // tooltip which then reappears because mouse remains hovering over the // control, see SF patch 1821229 if ( wxApp::GetComCtl32Version() >= 470 ) { uFlags |= TTF_TRANSPARENT; } }
bool Camera_QHY::Capture(int duration, usImage& img, int options, const wxRect& subframe) { bool useSubframe = UseSubframes && !subframe.IsEmpty(); if (Binning != m_curBin) { FullSize = wxSize(m_maxSize.GetX() / Binning, m_maxSize.GetY() / Binning); m_curBin = Binning; useSubframe = false; // subframe may be out of bounds now } if (img.Init(FullSize)) { DisconnectWithAlert(CAPT_FAIL_MEMORY); return true; } wxRect frame = useSubframe ? subframe : wxRect(FullSize); if (useSubframe) img.Clear(); wxRect roi; if (useSubframe) { // Use a larger ROI around the subframe to avoid changing the ROI as the centroid // wobbles around. Changing the ROI introduces a lag of several seconds. // This also satifies the constraint that ROI width and height must be multiples of 4. enum { PAD = 1 << 5 }; roi.SetLeft(round_down(subframe.GetLeft(), PAD)); roi.SetRight(round_up(subframe.GetRight() + 1, PAD) - 1); roi.SetTop(round_down(subframe.GetTop(), PAD)); roi.SetBottom(round_up(subframe.GetBottom() + 1, PAD) - 1); } else { roi = frame; } uint32_t ret = QHYCCD_ERROR; // lzr from QHY says this needs to be set for every exposure ret = SetQHYCCDBinMode(m_camhandle, Binning, Binning); if (ret != QHYCCD_SUCCESS) { Debug.Write(wxString::Format("SetQHYCCDBinMode failed! ret = %d\n", (int)ret)); } if (m_roi != roi) { // when roi changes, must call this ret = CancelQHYCCDExposingAndReadout(m_camhandle); if (ret == QHYCCD_SUCCESS) { Debug.Write("CancelQHYCCDExposingAndReadout success\n"); } else { Debug.Write("CancelQHYCCDExposingAndReadout failed\n"); } ret = SetQHYCCDResolution(m_camhandle, roi.GetLeft(), roi.GetTop(), roi.GetWidth(), roi.GetHeight()); if (ret == QHYCCD_SUCCESS) { m_roi = roi; } else { Debug.Write(wxString::Format("SetQHYCCDResolution(%d,%d,%d,%d) failed! ret = %d\n", roi.GetLeft(), roi.GetTop(), roi.GetWidth(), roi.GetHeight(), (int)ret)); } } if (duration != m_curExposure) { ret = SetQHYCCDParam(m_camhandle, CONTROL_EXPOSURE, duration * 1000.0); // QHY duration is usec if (ret == QHYCCD_SUCCESS) { m_curExposure = duration; } else { Debug.Write(wxString::Format("QHY set exposure ret %d\n", (int)ret)); pFrame->Alert(_("Failed to set camera exposure")); } } if (GuideCameraGain != m_curGain) { double gain = m_gainMin + GuideCameraGain * (m_gainMax - m_gainMin) / 100.0; gain = floor(gain / m_gainStep) * m_gainStep; Debug.Write(wxString::Format("QHY set gain %g (%g..%g incr %g)\n", gain, m_gainMin, m_gainMax, m_gainStep)); ret = SetQHYCCDParam(m_camhandle, CONTROL_GAIN, gain); if (ret == QHYCCD_SUCCESS) { m_curGain = GuideCameraGain; } else { Debug.Write(wxString::Format("QHY set gain ret %d\n", (int)ret)); pFrame->Alert(_("Failed to set camera gain")); } } ret = ExpQHYCCDSingleFrame(m_camhandle); if (ret == QHYCCD_ERROR) { Debug.Write(wxString::Format("QHY exp single frame ret %d\n", (int)ret)); DisconnectWithAlert(_("QHY exposure failed"), NO_RECONNECT); return true; } if (ret == QHYCCD_SUCCESS) { Debug.Write(wxString::Format("QHY: 200ms delay needed\n")); WorkerThread::MilliSleep(200); } if (ret == QHYCCD_READ_DIRECTLY) { //Debug.Write("QHYCCD_READ_DIRECTLY\n"); } uint32_t w, h, bpp, channels; ret = GetQHYCCDSingleFrame(m_camhandle, &w, &h, &bpp, &channels, RawBuffer); if (ret != QHYCCD_SUCCESS || (bpp != 8 && bpp != 16)) { Debug.Write(wxString::Format("QHY get single frame ret %d bpp %u\n", ret, bpp)); // users report that reconnecting the camera after this failure allows // them to resume guiding so we'll try to reconnect automatically DisconnectWithAlert(_("QHY get frame failed"), RECONNECT); return true; } if (useSubframe) { img.Subframe = frame; int xofs = subframe.GetLeft() - roi.GetLeft(); int yofs = subframe.GetTop() - roi.GetTop(); int dxr = w - frame.width - xofs; if (bpp == 8) { const unsigned char *src = RawBuffer + yofs * w; unsigned short *dst = img.ImageData + frame.GetTop() * FullSize.GetWidth() + frame.GetLeft(); for (int y = 0; y < frame.height; y++) { unsigned short *d = dst; src += xofs; for (int x = 0; x < frame.width; x++) *d++ = (unsigned short) *src++; src += dxr; dst += FullSize.GetWidth(); } } else // bpp == 16 { const unsigned short *src = (const unsigned short *) RawBuffer + yofs * w; unsigned short *dst = img.ImageData + frame.GetTop() * FullSize.GetWidth() + frame.GetLeft(); for (int y = 0; y < frame.height; y++) { src += xofs; memcpy(dst, src, frame.width * sizeof(unsigned short)); src += frame.width + dxr; dst += FullSize.GetWidth(); } } } else { if (bpp == 8) { const unsigned char *src = RawBuffer; unsigned short *dst = img.ImageData; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { *dst++ = (unsigned short) *src++; } } } else // bpp == 16 { memcpy(img.ImageData, RawBuffer, w * h * sizeof(unsigned short)); } } if (options & CAPTURE_SUBTRACT_DARK) SubtractDark(img); if (Color && Binning == 1 && (options & CAPTURE_RECON)) QuickLRecon(img); return false; }
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; }
void wxSFShapeBase::_GetCompleteBoundingBox(wxRect &rct, int mask) { //wxASSERT(m_pParentManager); if(!m_pParentManager)return; if( m_lstProcessed.IndexOf(this) != wxNOT_FOUND )return; else m_lstProcessed.Append(this); ShapeList lstChildren; //SerializableList lstConnections; // firts, get bounding box of the current shape if(mask & bbSELF) { if(rct.IsEmpty())rct = this->GetBoundingBox().Inflate( abs(m_nHBorder), abs(m_nVBorder) ); else rct.Union(this->GetBoundingBox().Inflate( abs(m_nHBorder), abs(m_nVBorder)) ); // add also shadow offset if neccessary if( (mask & bbSHADOW) && (m_nStyle & sfsSHOW_SHADOW) && GetParentCanvas() ) { wxRealPoint nOffset = GetParentCanvas()->GetShadowOffset(); if( nOffset.x < 0 ) { rct.SetX(rct.GetX() + (int)nOffset.x); rct.SetWidth(rct.GetWidth() - (int)nOffset.x); } else rct.SetWidth(rct.GetWidth() + (int)nOffset.x); if( nOffset.y < 0 ) { rct.SetY(rct.GetY() + (int)nOffset.y); rct.SetHeight(rct.GetHeight() - (int)nOffset.y); } else rct.SetHeight(rct.GetHeight() + (int)nOffset.y);; } } else mask |= bbSELF; // get list of all connection lines assigned to the shape and find their child shapes if(mask & bbCONNECTIONS) { wxSFShapeBase *pLine; ShapeList lstLines; GetAssignedConnections( CLASSINFO(wxSFLineShape), lineBOTH, lstLines ); ShapeList::compatibility_iterator node = lstLines.GetFirst(); while(node) { pLine = node->GetData(); //rct.Union(pLine->GetBoundingBox()); lstChildren.Append(pLine); // get children of the connections pLine->GetChildShapes(sfANY, lstChildren); node = node->GetNext(); } } // get children of this shape if(mask & bbCHILDREN) { this->GetChildShapes(sfANY, lstChildren, sfNORECURSIVE); // now, call this function for all children recursively... ShapeList::compatibility_iterator node = lstChildren.GetFirst(); while(node) { node->GetData()->_GetCompleteBoundingBox(rct, mask); node = node->GetNext(); } } }