const SHAPE_LINE_CHAIN SHAPE_ARC::ConvertToPolyline( double aAccuracy ) const { SHAPE_LINE_CHAIN rv; double r = GetRadius(); double sa = GetStartAngle(); auto c = GetCenter(); int n; if( r == 0.0 ) { n = 0; } else { n = GetArcToSegmentCount( r, From_User_Unit( MILLIMETRES, aAccuracy ), m_centralAngle ); } for( int i = 0; i <= n ; i++ ) { double a = sa + m_centralAngle * (double) i / (double) n; double x = c.x + r * cos( a * M_PI / 180.0 ); double y = c.y + r * sin( a * M_PI / 180.0 ); rv.Append( (int) x, (int) y ); } return rv; }
double SHAPE_ARC::GetEndAngle() const { double a = GetStartAngle() + m_centralAngle; if( a < 0.0 ) a += 360.0; else if ( a >= 360.0 ) a -= 360.0; return a; }
void Sector::Draw(ALLEGRO_BITMAP* dest, const ALLEGRO_COLOR& color, bool filled) { Line initial(GetPosition(), GetStartPoint().GetPosition(), color); Line terminal(GetPosition(), GetEndPoint().GetPosition(), color); initial.Draw(dest, initial.GetColor(), false); terminal.Draw(dest, terminal.GetColor(), false); _arc.Draw(dest, color, filled); ALLEGRO_BITMAP* old_target = al_get_target_bitmap(); filled ? al_draw_filled_pieslice(a2de::Math::ToScreenScale(GetX()), a2de::Math::ToScreenScale(GetY()), a2de::Math::ToScreenScale(GetRadius()), GetStartAngle(), GetEndAngle() - GetStartAngle(), color) : al_draw_pieslice(a2de::Math::ToScreenScale(GetX()), a2de::Math::ToScreenScale(GetY()), a2de::Math::ToScreenScale(GetRadius()), GetStartAngle(), GetEndAngle() - GetStartAngle(), color, 0.0); al_set_target_bitmap(old_target); }
void QArcItem::compile(QSqlDatabase &db, int nSceneId,int &count,int index) { count++; //QBasicGraphicsItem::compile(db, nSceneId, count, index); QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO polygon(nItemId ,nSceneId,ePolygonClass,eLineType ,nLineWidth,nLineColor," "eStyle,nBackColor,nForeColor,nAlpha,nPointX,nPointY,nWidth,nHeight,nRadius,eCornerType," "nZvalue,nCollidindId)" "VALUES (:nItemId,:nSceneId,:ePolygonClass ,:eLineType ,:nLineWidth,:nLineColor,:eStyle," ":nBackColor,:nForeColor,:nAlpha,:nPointX,:nPointY,:nWidth,:nHeight,:nRadius,:eCornerType," ":nZvalue,:nCollidindId)"); sqlquery.bindValue(":nItemId",QVariant(count));// 表 id sqlquery.bindValue(":nSceneId",QVariant(nSceneId));// 所在场景 id sqlquery.bindValue(":ePolygonClass",QVariant(6)); //6 代表类型为扇形 sqlquery.bindValue(":eLineType",QVariant(nLineType+1));// 线形 sqlquery.bindValue(":nLineWidth",QVariant(GetLineWidth()));// 线宽 sqlquery.bindValue(":nLineColor",QVariant(ColorToInt(GetLineColor()))); //颜色 sqlquery.bindValue(":eStyle",QVariant(GetPattern()+1));// 样式 sqlquery.bindValue(":nBackColor",QVariant(ColorToInt(GetBackColor()))); //背景色 sqlquery.bindValue(":nForeColor",QVariant(ColorToInt(GetFrontColor()))); //前景色 sqlquery.bindValue(":nAlpha",QVariant(GetAlpha()));// 透明度 QRect rect = this->sceneBoundingRect().toRect(); sqlquery.bindValue(":nWidth",QVariant(GetStartAngle())); //起始角度 sqlquery.bindValue(":nHeight",QVariant(GetSpanAngle())); //角度 sqlquery.bindValue(":nPointX",QVariant(rect.x())); //X sqlquery.bindValue(":nPointY",QVariant(rect.y())); //Y sqlquery.bindValue(":nRadius",QVariant(rect.height()/2)); //半径 sqlquery.bindValue(":nZvalue",QVariant(zValue()));//层次 sqlquery.bindValue(":nCollidindId",QVariant(index));//碰撞ID bool result = false; result = sqlquery.exec(); qDebug() << "insert ArcItem table :"<<result; SamDrawScene *pScene = dynamic_cast<SamDrawScene *>(scene()); if(pScene && pScene->nIsSceneOrWindow == 2) { //是自定义键盘的item //先新建键盘——item关联表 item表在派生类中创建 //QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO kbAndItem(nKeyBoardId , nItemId ,nItemTableType ) " "VALUES (:nKeyBoardId ,:nItemId ,:nItemTableType)"); sqlquery.bindValue(":nKeyBoardId",QVariant(nSceneId)); sqlquery.bindValue(":nItemId",QVariant(count)); sqlquery.bindValue(":nId",QVariant(id()));// 控件ID sqlquery.bindValue(":nItemTableType",QVariant((int)SAM_DRAW_OBJECT_ARC)); bool result = false; result = sqlquery.exec(); qDebug() << "insert kbAndItem table :"<<result; } if(pScene && pScene->nIsSceneOrWindow != 2) { //窗口或者场景item //先新建键盘——item关联表 //item表在派生类中创建 //QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO sceneAndItem(nSceneId,nId,nItemId,nItemTableType)" "VALUES(:nSceneId,:nId,:nItemId,:nItemTableType)"); sqlquery.bindValue(":nSceneId",QVariant(nSceneId)); sqlquery.bindValue(":nItemId",QVariant(count)); sqlquery.bindValue(":nId",QVariant(id()));// 控件ID //int t = this->GroupType(); sqlquery.bindValue(":nItemTableType",QVariant((int)SAM_DRAW_OBJECT_ARC)); bool result = false; result = sqlquery.exec(); qDebug() << "insert sceneAndItem table :"<<result; } }