Advertisement
Guest User

Emacs 26.3 indent issue

a guest
Mar 3rd, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. namespace rl{
  4. #include <raylib.h>
  5. }
  6. #include <vector>
  7.  
  8. constexpr rl::Color COLOR = rl::SKYBLUE;
  9. constexpr float MOUSE_SCALE_MARK_SIZE = 15;
  10.  
  11. class Figure {
  12. public:
  13.     virtual void Update() = 0;
  14.     virtual void Draw() = 0;
  15. };
  16.  
  17. class Rectangle : public Figure {
  18. public:
  19.     Rectangle(int x, int y,int width, int height)
  20.     : posX(x), posY(y), width(width), height(height) {};
  21.  
  22.     bool mouseScaleReady = false;
  23.     bool mouseScaleMode = false;
  24.     virtual void Update(){
  25.     rl::Vector2 mouse = rl::GetMousePosition();
  26.     rl::Rectangle rec = {posX,posY,width,height};
  27.    
  28.     if (rl::CheckCollisionPointRec(mouse,rec) &&
  29.         rl::CheckCollisionPointRec
  30.         (mouse,
  31.          (rl::Rectangle)
  32.          // WARNING: The following line may screw up Emacs indenting!
  33.          {
  34. rec.x + rec.width - MOUSE_SCALE_MARK_SIZE,
  35.           rec.y + rec.height - MOUSE_SCALE_MARK_SIZE,
  36.           MOUSE_SCALE_MARK_SIZE, MOUSE_SCALE_MARK_SIZE
  37.           }))
  38.     {
  39.         mouseScaleReady = true;
  40.         if (IsMouseButtonPressed(rl::MOUSE_LEFT_BUTTON)) mouseScaleMode = true;
  41.     }
  42.     else mouseScaleReady = false;
  43.     if (mouseScaleMode)
  44.     {
  45.         mouseScaleReady = true;
  46.         width = (mouse.x - posX);
  47.         height = (mouse.y - posY);
  48.  
  49.         if (width < MOUSE_SCALE_MARK_SIZE) width = MOUSE_SCALE_MARK_SIZE;
  50.         if (height < MOUSE_SCALE_MARK_SIZE) height = MOUSE_SCALE_MARK_SIZE;
  51.  
  52.         if (IsMouseButtonReleased(rl::MOUSE_LEFT_BUTTON)) mouseScaleMode = false;
  53.     }
  54.     };
  55.     virtual void Draw(){
  56.     DrawRectangle(posX, posY, width, height, color);
  57.     if (mouseScaleReady){
  58.         rl::Rectangle rec = {posX,posY,width,height};
  59.         rl::DrawRectangleLinesEx(rec,1,rl::BLACK);
  60.         rl::DrawTriangle((rl::Vector2){rec.x + rec.width - MOUSE_SCALE_MARK_SIZE,
  61.                            rec.y + rec.height},
  62.         (rl::Vector2){ rec.x + rec.width, rec.y + rec.height },
  63.         (rl::Vector2){ rec.x + rec.width,
  64.                   rec.y + rec.height - MOUSE_SCALE_MARK_SIZE },
  65.         rl::BLACK);
  66.     }
  67.     };
  68. private:
  69.     float posX;
  70.     float posY;
  71.     float width;
  72.     float height;
  73.     rl::Color color = COLOR;
  74. };
  75.  
  76. class Ellipse {
  77. public:
  78.     virtual void Update(){};
  79.     virtual void Draw()
  80.     {
  81.     puts("Drawing an ellipse");
  82.     };
  83. };
  84.  
  85. class Canvas {
  86. public:
  87.     void Update();
  88.     void Draw();
  89.     void addFigure(Figure *fig){figures.push_back(fig);};
  90. private:
  91.     std::vector<Figure*> figures;
  92. };
  93.  
  94. void Canvas::Update(){
  95.     for(auto fig : figures)
  96.     fig->Update();
  97. }
  98. void Canvas::Draw(){
  99.     rl::BeginDrawing();
  100.     ClearBackground(rl::RAYWHITE);
  101.     for(auto fig : figures)
  102.     {
  103.         fig->Draw();
  104.     }
  105.     rl::EndDrawing();
  106. }
  107.  
  108. int main(void){
  109.     rl::InitWindow(1280,1024, "Grafity");
  110.     rl::SetTargetFPS(60);
  111.     Canvas canvas;
  112.     Rectangle r1(800,300,50,80);
  113.     Rectangle r2(500,400,90,120);
  114.     Rectangle r3(200,100,100,50);
  115.     canvas.addFigure(&r1);
  116.     canvas.addFigure(&r2);
  117.     canvas.addFigure(&r3);
  118.     while (!rl::WindowShouldClose())
  119.     {
  120.     canvas.Update();
  121.     canvas.Draw();
  122.     }
  123.     rl::CloseWindow();
  124.     return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement