void Board::showHint() { undrawConnection(); if(getHint_I(connection)) drawConnection(1000); }
void Board::marked(int x, int y) { // make sure that the previous connection is correctly undrawn undrawConnection(); if(getField(x, y) == EMPTY) return; if(x == mark_x && y == mark_y) { // unmark the piece mark_x = -1; mark_y = -1; updateField(x, y, false); return; } if(mark_x == -1) { mark_x = x; mark_y = y; updateField(x, y, false); return; } int fld1 = getField(mark_x, mark_y); int fld2 = getField(x, y); // both field same? if(fld1 != fld2) return; // trace if(findPath(mark_x, mark_y, x, y, connection)) { madeMove(mark_x, mark_y, x, y); drawConnection(getDelay()); setField(mark_x, mark_y, EMPTY); setField(x, y, EMPTY); grav_col_1 = x; grav_col_2 = mark_x; mark_x = -1; mark_y = -1; // game is over? // Must delay until after tiles fall to make this test // See undrawConnection GP. } else { connection.clear(); } }
void NodeGraphNodeConnector::draw( const NodeGraphDrawContext& context ) { const he::RectI& bound(he::RectI(getLayoutBound().transform(context.transform))); context.canvas->setColor(m_Style.m_ConnectorBackgroundColor[m_State]); context.canvas->fillRect(bound); context.canvas->setColor(m_Style.m_ConnectorBorderColor[m_State]); context.canvas->strokeRect(bound); if (m_Type == eNodeGraphNodeConnectorType_Input && isConnected()) { drawConnection(context, *m_Connections[0]); } }
void MaterialWindow::OnPaint(wxPaintEvent &WXUNUSED(event)) { wxBufferedPaintDC bpdc(this); wxGCDC gdc; wxGraphicsRenderer* const renderer = wxGraphicsRenderer::GetDefaultRenderer(); wxGraphicsContext* context; if ( wxMemoryDC *memdc = wxDynamicCast(&bpdc, wxMemoryDC) ) { context = renderer->CreateContext(*memdc); } gdc.SetGraphicsContext(context); // Draw Background gdc.SetBackground(wxBrush(wxColour(38, 38, 38))); gdc.Clear(); // Draw Background Grid int gridOffsetX = (int)mWindowX % 20; int gridOffsetY = (int)mWindowY % 20; gdc.SetPen(wxPen( wxColour(128, 128, 128, 128), 1) ); wxSize windowSize = GetSize(); // Vertical Lines for(int x = 0; x < (windowSize.x + 40); x += 20) gdc.DrawLine(gridOffsetX + x - 20, gridOffsetY - 20, gridOffsetX + x - 20, gridOffsetY + windowSize.y + 40); // Horizontal Lines for(int y = 0; y < (windowSize.y + 40); y += 20) gdc.DrawLine(gridOffsetX - 20, gridOffsetY + y - 20, gridOffsetX + windowSize.x + 40, gridOffsetY + y - 20); // Draw Nodes for(S32 n = 0; n < nodeList.size(); ++n ) { Node* node = &nodeList[n]; drawNode(gdc, node); } // Draw Connections for(S32 n = 0; n < connectionList.size(); ++n ) { Connection* connection = &connectionList[n]; drawConnection(gdc, context, connection); } }
void KisSketchPaintOp::paintLine(const KisPaintInformation &pi1, const KisPaintInformation &pi2, KisDistanceInformation *currentDistance) { Q_UNUSED(currentDistance); if (!m_brush || !painter()) return; if (!m_dab) { m_dab = source()->createCompositionSourceDevice(); m_painter = new KisPainter(m_dab); m_painter->setPaintColor(painter()->paintColor()); } else { m_dab->clear(); } QPointF prevMouse = pi1.pos(); QPointF mousePosition = pi2.pos(); m_points.append(mousePosition); const double scale = m_sizeOption.apply(pi2); const double rotation = m_rotationOption.apply(pi2); const double currentProbability = m_densityOption.apply(pi2, m_sketchProperties.probability); const double currentLineWidth = m_lineWidthOption.apply(pi2, m_sketchProperties.lineWidth); const double currentOffsetScale = m_offsetScaleOption.apply(pi2, m_sketchProperties.offset); if ((scale * m_brush->width()) <= 0.01 || (scale * m_brush->height()) <= 0.01) return; // shaded: does not draw this line, chrome does, fur does if (m_sketchProperties.makeConnection){ drawConnection(prevMouse, mousePosition, currentLineWidth); } setCurrentScale(scale); setCurrentRotation(rotation); qreal thresholdDistance = 0.0; // update the mask for simple mode only once // determine the radius if (m_count == 0 && m_sketchProperties.simpleMode){ updateBrushMask(pi2,1.0,0.0); //m_radius = qMax(m_maskDab->bounds().width(),m_maskDab->bounds().height()) * 0.5; m_radius = 0.5 * qMax(m_brush->width(), m_brush->height()); } if (!m_sketchProperties.simpleMode){ updateBrushMask(pi2,scale,rotation); m_radius = qMax(m_maskDab->bounds().width(),m_maskDab->bounds().height()) * 0.5; thresholdDistance = pow(m_radius,2); } if (m_sketchProperties.simpleMode){ // update the radius according scale in simple mode thresholdDistance = pow(m_radius * scale,2); } // determine density const qreal density = thresholdDistance * currentProbability; // probability behaviour qreal probability = 1.0 - currentProbability; QColor painterColor = painter()->paintColor().toQColor(); QColor randomColor; KoColor color(m_dab->colorSpace()); int w = m_maskDab->bounds().width(); quint8 opacityU8 = 0; quint8 * pixel; qreal distance; QPoint positionInMask; QPointF diff; int size = m_points.size(); // MAIN LOOP for (int i = 0; i < size; i++) { diff = m_points.at(i) - mousePosition; distance = diff.x() * diff.x() + diff.y() * diff.y(); // circle test bool makeConnection = false; if (m_sketchProperties.simpleMode){ if (distance < thresholdDistance){ makeConnection = true; } // mask test }else{ if ( m_brushBoundingBox.contains( m_points.at(i) ) ){ positionInMask = (diff + m_hotSpot).toPoint(); pixel = m_maskDab->data() + ((positionInMask.y() * w + positionInMask.x()) * m_maskDab->pixelSize()); opacityU8 = m_maskDab->colorSpace()->opacityU8( pixel ); if (opacityU8 != 0){ makeConnection = true; } } } if (!makeConnection){ // check next point continue; } if (m_sketchProperties.distanceDensity){ probability = distance / density; } // density check if (drand48() >= probability) { QPointF offsetPt = diff * currentOffsetScale; if (m_sketchProperties.randomRGB){ // some color transformation per line goes here randomColor.setRgbF(drand48() * painterColor.redF(), drand48() * painterColor.greenF(), drand48() * painterColor.blueF() ); color.fromQColor(randomColor); m_painter->setPaintColor(color); } // distance based opacity quint8 opacity = OPACITY_OPAQUE_U8; if (m_sketchProperties.distanceOpacity){ opacity *= qRound((1.0 - (distance / thresholdDistance))); } if (m_sketchProperties.randomOpacity){ opacity *= drand48(); } m_painter->setOpacity(opacity); if (m_sketchProperties.magnetify) { drawConnection(mousePosition + offsetPt, m_points.at(i) - offsetPt, currentLineWidth); }else{ drawConnection(mousePosition + offsetPt, mousePosition - offsetPt, currentLineWidth); } } }// end of MAIN LOOP m_count++; QRect rc = m_dab->extent(); quint8 origOpacity = m_opacityOption.apply(painter(), pi2); painter()->bitBlt(rc.x(), rc.y(), m_dab, rc.x(), rc.y(), rc.width(), rc.height()); painter()->renderMirrorMask(rc, m_dab); painter()->setOpacity(origOpacity); }
void NodeGraphNodeConnector::drawConnection( const NodeGraphDrawContext& context, const NodeGraphNodeConnector& other ) { he::vec2 pos1(other.m_LayoutBound.x + m_LayoutBound.width / 2.0f, other.m_LayoutBound.y + m_LayoutBound.height / 2.0f); drawConnection(context, pos1); }