static void area_selector(SDL_Surface *s, int x0, int y0) { int x, y, r; print(s, x0, y0, "EU"); print(s, x0, y0+9, "JP"); print(s, x0, y0+18, "US"); switch (wlan_area) { case area_off: return; case area_eu: y = 0; break; case area_jp: y = 1; break; case area_us: y = 2; break; default: abort(); } y = y0+9*y+3; x = x0-8; r = 6; filledTrigonColor(s, x, y, x-r, y+r/2, x-r, y-r/2, SEL_RGBA); }
void GUIDropDown::Draw(SDL_Surface *dst){ boxColor(dst,posX1,posY1,posX2,posY2,0xFFFFFFFF); rectangleColor(dst,posX1,posY1,posX2,posY2,BORDER); selectedText.Blit(dst,posX1+3,posY1+2,posX2-posX1-3,posY2-posY1-2,false,true); if(isPressed)boxColor(dst,arrX1,arrY1,arrX2,arrY2,CLICKABLE_DOWN); else boxColor(dst,arrX1,arrY1,arrX2,arrY2,CLICKABLE_UP); rectangleColor(dst,arrX1,arrY1,arrX2,arrY2,BORDER); filledTrigonColor(dst,triX1,triY1,triX2,triY2,triX3,triY3,0x00000080); if(listBox.doDraw&&!hasRegistered)listBox.Draw(dst); }
void GUIDropDown::Draw(SDL_Surface *dst){ boxColor(dst,posX1,posY1,posX2,posY2,0xFFFFFFFF); GUIDrawBorder(dst,posX1,posY1,posX2,posY2,0x404040FF,0x808080FF,0xFFFFFFFF,0,true); selectedText.Blit(dst,posX1+3,posY1+2,posX2-posX1-3,posY2-posY1-2,false,true); boxColor(dst,arrX1,arrY1,arrX2,arrY2,0xD4D0C8FF); if(isPressed)GUIDrawBorder(dst,arrX1,arrY1,arrX2,arrY2,0x404040FF,0x808080FF,0xFFFFFFFF,0,true); else GUIDrawBorder(dst,arrX1,arrY1,arrX2,arrY2,0xFFFFFFFF,0,0x404040FF,0x808080FF); filledTrigonColor(dst,triX1,triY1,triX2,triY2,triX3,triY3,0x00000080); if(listBox.doDraw&&!hasRegistered)listBox.Draw(dst); }
int GeoLayer::trigon_fill(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint32_t col) { if(!surf) { error("%s can't run: layer not initialized", __PRETTY_FUNCTION__); return -1; } res = filledTrigonColor(surf, x1, y1, x2, y2, x3, y3, col); if(res < 0) error("error in %s", __PRETTY_FUNCTION__); return(res); }
void GUIScrollBar::Draw(SDL_Surface *dst){ boxColor(dst,trackX1,trackY1,trackX2,trackY2,0xFFFFFFFF); rectangleColor(dst,trackX1,trackY1,trackX2,trackY2,BORDER); if(arrowW>0){ if(arrADown)boxColor(dst,arrAX1,arrAY1,arrAX2,arrAY2,CLICKABLE_DOWN); else boxColor(dst,arrAX1,arrAY1,arrAX2,arrAY2,CLICKABLE_UP); if(arrBDown) boxColor(dst,arrBX1,arrBY1,arrBX2,arrBY2,CLICKABLE_DOWN); else boxColor(dst,arrBX1,arrBY1,arrBX2,arrBY2,CLICKABLE_UP); rectangleColor(dst,arrBX1,arrBY1,arrBX2,arrBY2,BORDER); rectangleColor(dst,arrAX1,arrAY1,arrAX2,arrAY2,BORDER); filledTrigonColor(dst,triAX1,triAY1,triAX2,triAY2,triAX3,triAY3,0x00000080); filledTrigonColor(dst,triBX1,triBY1,triBX2,triBY2,triBX3,triBY3,0x00000080); } if(!isDisabled){ boxColor(dst,slidX1,slidY1,slidX2,slidY2,0xD4D0C8FF); rectangleColor(dst,slidX1,slidY1,slidX2,slidY2,0x404040FF); } }
void GUIScrollBar::Draw(SDL_Surface *dst){ boxColor(dst,trackX1,trackY1,trackX2,trackY2,0xE0E0E0FF); GUIDrawBorder(dst,trackX1,trackY1,trackX2,trackY2,0x808080FF,0,0xFFFFFFFF,0); if(arrowW>0){ boxColor(dst,arrAX1,arrAY1,arrAX2,arrAY2,0xD4D0C8FF); boxColor(dst,arrBX1,arrBY1,arrBX2,arrBY2,0xD4D0C8FF); if(arrADown)GUIDrawBorder(dst,arrAX1,arrAY1,arrAX2,arrAY2,0x404040FF,0x808080FF,0xFFFFFFFF,0,true); else GUIDrawBorder(dst,arrAX1,arrAY1,arrAX2,arrAY2,0xFFFFFFFF,0,0x404040FF,0x808080FF); if(arrBDown)GUIDrawBorder(dst,arrBX1,arrBY1,arrBX2,arrBY2,0x404040FF,0x808080FF,0xFFFFFFFF,0,true); else GUIDrawBorder(dst,arrBX1,arrBY1,arrBX2,arrBY2,0xFFFFFFFF,0,0x404040FF,0x808080FF); filledTrigonColor(dst,triAX1,triAY1,triAX2,triAY2,triAX3,triAY3,0x00000080); filledTrigonColor(dst,triBX1,triBY1,triBX2,triBY2,triBX3,triBY3,0x00000080); } if(!isDisabled){ boxColor(dst,slidX1,slidY1,slidX2,slidY2,0xD4D0C8FF); GUIDrawBorder(dst,slidX1,slidY1,slidX2,slidY2,0xFFFFFFFF,0,0x404040FF,0x808080FF); } }
void foldicon(int folded, int exposure_level, int x, int top, int height, int y, SDL_Surface *surface, style *st, int highlighted) { // x is a left edge, y is a centre SDL_Surface *icon; int colour_index; if(folded) icon = st->collapsedicon; else icon = st->expandedicon; colour_index = folded ? st->foldcollapsedcolour : st->foldexpandedcolour; if(highlighted) colour_index = st->highlightcolour; if(!folded) { Uint32 pen; exposure_level++; if(exposure_level == 1) pen = colour->pens->item(st->foldexposed1colour); else if(exposure_level == 2) pen = colour->pens->item(st->foldexposed2colour); else pen = colour->pens->item(st->foldexposed3colour); /* boxColor(surface, x + 7, y, x + 13, y + (st->text_ascent - st->text_descent), pen); */ boxColor(surface, x + 7, y, x + 13, top + height - 1, pen); } if(icon == NULL) { boxColor(surface, x, y - 10, x + 20, y + 10, colour->pens->item(colour_index)); rectangleColor(surface, x, y - 10, x + 20, y + 10, colour->black_pen); filledTrigonColor(surface, x + 3, y - 6, x + 17, y - 6, x + 10, y + 6, colour->white_pen); aatrigonColor(surface, x + 3, y - 6, x + 17, y - 6, x + 10, y + 6, colour->black_pen); } else { SDL_Rect dst; dst.x = x + 10 - (icon->w / 2); dst.y = y - (icon->h / 2); SDL_BlitSurface(icon, NULL, surface, &dst); } }
static PyObject* _gfx_filledtrigoncolor (PyObject *self, PyObject* args) { PyObject *surface, *color, *p1, *p2, *p3; int x1, x2, x3, _y1, y2, y3; pguint32 c; ASSERT_VIDEO_INIT (NULL); if (!PyArg_ParseTuple (args, "OOOOO:filled_trigon", &surface, &p1, &p2, &p3, &color)) { PyErr_Clear (); if (!PyArg_ParseTuple (args, "OiiiiiiO:filled_trigon", &surface, &x1, &_y1, &x2, &y2, &x3, &y3, &color)) return NULL; } else { if (!PointFromObj (p1, &x1, &_y1) || !PointFromObj (p2, &x2, &y2) || !PointFromObj (p3, &x3, &y3)) return NULL; } if (!PySDLSurface_Check (surface)) { PyErr_SetString (PyExc_TypeError, "surface must be a Surface"); return NULL; } if (!ColorFromObj (color, &c)) return NULL; if (filledTrigonColor (((PySDLSurface*)surface)->surface, (Sint16)x1, (Sint16)_y1, (Sint16)x2, (Sint16)y2, (Sint16)x3, (Sint16)y3, (Uint32)c) == -1) { PyErr_SetString (PyExc_PyGameError, SDL_GetError ()); return NULL; } Py_RETURN_NONE; }
void pointer(int x, int y) { int dx, dy, dlen, ex, ey, incx = 0, incy = 0, x1, y1, x2, y2; const int shaft_width = 10; const int arrow_head = 50; double aspect, angle; Uint32 pen = colour->yellow_pen; dx = x - SCREEN_WIDTH / 2; dy = y - SCREEN_HEIGHT / 2; if(dx == 0) dx = 1; if(dy == 0) dy = 1; angle = (double)abs(dx) / (double)abs(dy); aspect = (double)SCREEN_WIDTH / (double)SCREEN_HEIGHT; if(angle < aspect) { if(dy < 0) { // Top edge: ex = SCREEN_WIDTH / 2 + (dx * SCREEN_HEIGHT) / 2 / (-dy); ey = 0; } else { // Bottom edge: ex = SCREEN_WIDTH / 2 + (dx * SCREEN_HEIGHT) / 2 / dy; ey = SCREEN_HEIGHT - 1; } incx = 1; } else { if(dx > 0) { // Right edge: ex = SCREEN_WIDTH - 1; ey = SCREEN_HEIGHT / 2 + (dy * SCREEN_WIDTH) / 2 / dx; } else { // Left edge: ex = 0; ey = SCREEN_HEIGHT / 2 + (dy * SCREEN_WIDTH) / 2 / (-dx); } incy = 1; } lineColor(screen, ex, ey, x, y, pen); for(int i = 1; i < shaft_width; i++) { lineColor(screen, ex + i * incx, ey + i * incy, x, y, pen); lineColor(screen, ex - i * incx, ey - i * incy, x, y, pen); } lineColor(screen, ex + shaft_width * incx, ey + shaft_width * incy, x, y, colour->black_pen); lineColor(screen, ex - shaft_width * incx, ey - shaft_width * incy, x, y, colour->black_pen); // Arrow head: dlen = dx * dx + dy * dy; dlen = (int)ceil(sqrt(dlen)); dx *= arrow_head; dy *= arrow_head; dx /= dlen; dy /= dlen; x1 = x + dx + dy / 2; y1 = y + dy - dx / 2; x2 = x + dx - dy / 2; y2 = y + dy + dx / 2; filledTrigonColor(screen, x, y, x1, y1, x2, y2, pen); trigonColor(screen, x, y, x1, y1, x2, y2, colour->black_pen); // SDL_Flip(screen); }
/* *This function calculates a dynamic lightning cast from player. *Do raycasts to all close corners (lightpoints) to the player and *draw triangles on blendmode to the target renderer texture. */ void Lightning::calculateLightSource(GameEngine* game, SDL_Texture *texture, Map map, Player player) { //Setup new texture as render target SDL_SetRenderTarget(game->renderer, texture); SDL_SetRenderDrawBlendMode(game->renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawColor(game->renderer, 50, 50, 50, 255); SDL_RenderFillRect(game->renderer, NULL); SDL_SetRenderDrawColor(game->renderer, 255, 255, 255, 255); int length = 2000; vector<Position> lightPos; int player_pos_x = player.position.x+15; int player_pos_y = player.position.y+48; //Go through all lightpoints on map for(int i = 0; i < map.lightPoints.size(); i++) { //Convert ligthpoints to vector2 in local space Vector2 lightVector((float)(map.lightPoints[i].x - player_pos_x), (float)(map.lightPoints[i].y - player_pos_y)); if(lightVector.Length() < 900) { lightVector = lightVector.Normalize(); //Do raycast to all close lightpoints. vector<Raycast::Position> ray; ray = raycast.bresenhamLine(player_pos_y, player_pos_x, (lightVector.Y*length)+player_pos_y, (lightVector.X*length)+player_pos_x); bool passedLightPoint = false; int j = 0; j = (ray[0].y == player_pos_y && ray[0].x == player_pos_x) ? 0 : ray.size()-1; while(true) { int x = ray[j].x; int y = ray[j].y; if(map.isWall(map.mapTilePosition[y/map.getTileSize()][x/map.getTileSize()]) && !passedLightPoint) { break; } else if(ray[j].y == map.lightPoints[i].y && ray[j].x == map.lightPoints[i].x) { Position pos; if(ray[0].y == player_pos_y && ray[0].x == player_pos_x) { pos.x = ray[j-1].x; pos.y = ray[j-1].y; } else { pos.x = ray[j+1].x; pos.y = ray[j+1].y; } pos.lightPoint = true; pos.id = i; lightPos.push_back(pos); passedLightPoint = true; /*if(map.isWall(map.mapTilePosition[(int)(ray[j+4].y/map.getTileSize())][(int)(ray[j+4].x/map.getTileSize())])) break; if(map.isWall(map.mapTilePosition[(int)(ray[j-4].y/map.getTileSize())][(int)(ray[j-4].x/map.getTileSize())])) break;*/ } else if(passedLightPoint) { if(map.isWall(map.mapTilePosition[y/map.getTileSize()][x/map.getTileSize()])) { Position pos; if(ray[0].y == player_pos_y && ray[0].x == player_pos_x) { pos.x = ray[j-1].x; pos.y = ray[j-1].y; } else { pos.x = ray[j+1].x; pos.y = ray[j+1].y; } pos.id = i; pos.lightPoint = false; lightPos.push_back(pos); break; } } if(ray[0].y == player_pos_y && ray[0].x == player_pos_x) { j++; if(j >= ray.size()) break; } else { j--; if(j < 0) break; } } } } /* for(int i = 0; i < lightPos.size(); i++) { for(int j = 0; j < lightPos.size()-1; j++) { Vector2 tempvector1((float)(lightPos[j+1].x - player_pos_x), (float)(lightPos[j+1].y - player_pos_y)); Vector2 tempvector2((float)(lightPos[j].x - player_pos_x), (float)(lightPos[j].y - player_pos_y)); if(floor(tempvector1.Normalize().Direction()) > floor(tempvector2.Normalize().Direction())) { Position tmp = lightPos[j]; lightPos[j] = lightPos[j+1]; lightPos[j+1] = tmp; } } } } */ //Draw light to texture for(int i = 0; i < lightPos.size(); i++) { //int i = 7; /* SDL_RenderDrawLine(game->renderer, lightPos[i].x+game->camera.getXPosition(), lightPos[i].y+game->camera.getYPosition(), player.position.x+15+game->camera.getXPosition(), player.position.y+50+game->camera.getYPosition()); */ for(int j = i; j < lightPos.size(); j++) { if(raycast.raycast_insight(lightPos[i].x, lightPos[i].y, lightPos[j].x, lightPos[j].y, map)) { filledTrigonColor(game->renderer, player_pos_x+game->camera.getXPosition(), player_pos_y+game->camera.getYPosition(), lightPos[i].x+game->camera.getXPosition(), lightPos[i].y+game->camera.getYPosition(), lightPos[j].x+game->camera.getXPosition(), lightPos[j].y+game->camera.getYPosition(), 0xFFFFFFFF); //break; } } // else if(raycast.raycast_insight(lightPos[i].x, lightPos[i].y, lightPos[x].x, lightPos[x].y, map)) /* else { p++; if(p == lightPos.size()) p = 0; }*/ // } /* filledTrigonColor(game->renderer, player_pos_x+game->camera.getXPosition(), player_pos_y+game->camera.getYPosition(), lightPos[i].x+game->camera.getXPosition(), lightPos[i].y+game->camera.getYPosition(), lightPos[p].x+game->camera.getXPosition(), lightPos[p].y+game->camera.getYPosition(), 0xFFFFFFFF);*/ } }
void Boid::DrawDebug(SDL_Renderer* renderer) { if (currentBehaviour == Behaviour::OBSTACLE_AVOIDANCE) { if (obstacleAvoidanceCollision == true) { filledCircleColor(renderer, avoidTarget.x, avoidTarget.y, 10, Colors::TURQUOISE); } } else if (currentBehaviour == Behaviour::COLLISION_AVOIDANCE || currentBehaviour == Behaviour::PRIORITY_COLLISION) { static int timerColor = 0; int maxTime = 10; Uint32 collisionColor = Colors::BELIZE_HOLE; if (collisionDetected == true || timerColor > 0) { collisionColor = Colors::ORANGE; if (collisionDetected == true) { timerColor = maxTime; } } --timerColor; Vector2D triangleX1 = { position.x + coneHeight, position.y - tanf(coneHalfAngle * DEG2RAD) * coneHeight }; Vector2D triangleX2 = { position.x + coneHeight, position.y + tanf(coneHalfAngle * DEG2RAD) * coneHeight }; Vector2D rotatedTriangle1 = Vector2DUtils::RotatePoint(position, triangleX1, angle); Vector2D rotatedTriangle2 = Vector2DUtils::RotatePoint(position, triangleX2, angle); filledTrigonColor(renderer, position.x, position.y, rotatedTriangle1.x, rotatedTriangle1.y, rotatedTriangle2.x, rotatedTriangle2.y, collisionColor); return; } else if (currentBehaviour == Behaviour::ARRIVE) { circleRGBA(renderer, target->position.x, target->position.y, slowingRadius, 255, 255, 0, 255); sprintf(textBuffer, "Speed = %.2f", desiredVelocity.Length()); RotatedText_SetText(&informationText4, textBuffer); RotatedText_DrawText(&informationText4, position.x + 10.0f, position.y + 10.0f, 0.0f, 0, 0, 255, 255); } else if (currentBehaviour == Behaviour::WANDER) { circleRGBA(renderer, wanderCircleCenter.x, wanderCircleCenter.y, wanderCircleRadius, 255, 255, 0, 255); filledCircleRGBA(renderer, wanderDisplacementVector.x, wanderDisplacementVector.y, 10, 128, 0, 128, 255); SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); SDL_RenderDrawLine(renderer, position.x, position.y, wanderDisplacementVector.x, wanderDisplacementVector.y); } else if (currentBehaviour != Behaviour::PRIORITY_OBSTACLE) { int currentTextAngle; SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); SDL_RenderDrawLine(renderer, position.x, position.y, position.x + speed.x, position.y + speed.y); if (isSteering == true) { SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255); SDL_RenderDrawLine(renderer, position.x, position.y, position.x + desiredVelocity.x, position.y + desiredVelocity.y); SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255); SDL_RenderDrawLine(renderer, position.x + speed.x, position.y + speed.y, position.x + desiredVelocity.x, position.y + desiredVelocity.y); currentTextAngle = atan2f(desiredVelocity.y, desiredVelocity.x) * RAD2DEG; if (currentTextAngle < -90 || (currentTextAngle > 90 && currentTextAngle < 180)) { currentTextAngle = currentTextAngle - 180; } RotatedText_DrawText(&informationText2, (2 * position.x + (desiredVelocity.x)) / 2, (2 * position.y + desiredVelocity.y) / 2, currentTextAngle, 255, 255, 0, 255); currentTextAngle = atan2f((desiredVelocity.y - speed.y), (desiredVelocity.x - speed.x)) * RAD2DEG; if (currentTextAngle < -90 || (currentTextAngle > 90 && currentTextAngle < 180)) { currentTextAngle = currentTextAngle - 180; } RotatedText_DrawText(&informationText3, (position.x + (speed.x) + position.x + (desiredVelocity.x)) / 2, (position.y + speed.y + position.y + desiredVelocity.y) / 2, currentTextAngle, 255, 0, 255, 255); if (currentBehaviour == Behaviour::PURSUE || currentBehaviour == Behaviour::EVADE) { filledCircleRGBA(renderer, futurePosition.x, futurePosition.y, 20, 255, 255, 0, 255); } } currentTextAngle = angle; if (currentTextAngle < -90 || (currentTextAngle > 90 && currentTextAngle < 180)) { currentTextAngle = currentTextAngle - 180; } RotatedText_DrawText(&informationText1, (2 * position.x + (speed.x)) / 2, (2 * position.y + speed.y) / 2, currentTextAngle, 255, 0, 0, 255); } }
static void corner(SDL_Surface *s, int ax, int ay, int bx, int by, int cx, int cy, int mx, int my, uint32_t color) { filledTrigonColor(s, X(ax), Y(ay), X(bx), Y(by), X(cx), Y(cy), color); filledTrigonColor(s, X(mx), Y(my), X(bx), Y(by), X(cx), Y(cy), color); }