Results 1 to 6 of 6

Thread: Drawing outside of Smart

  1. #1
    Join Date
    Feb 2012
    Posts
    170
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default Drawing outside of Smart

    I want to draw an array of TBoxes that I have built, but my bot doesn't utilize smart, so I can't use the smart_draw functions. What other options do I have?

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    You can try your hand at writing a bitmap class.. Other than that, you cannot do it with Simba because you need the device context of the screen you wish to draw on and simba does not return any of those.. Smart does because Benland made it return an HDC to smart's debug.. AFAIK you can't do it unless Wizzup? creates a function that returns a handle to a DC for you to draw on. Maybe an extension can be made to grab an HDC for you but I'm not sure on this.

    If you don't care what language you draw in and want to draw anyway then try this CPP code:
    Code:
    #ifndef BITMAPS_H_INCLUDED#define BITMAPS_H_INCLUDED
    
    
    #include "GDIPlus.h"
    
    
    typedef struct
    {
        BYTE R, G, B;
    } RGB, *PRGB;
    
    
    typedef struct
    {
        BYTE R, G, B, A;
    } RGBA, *PRGBA;
    
    
    class Bitmap
    {
        private:
            int width;
            int height;
            BYTE* Bits;
    
    
            BITMAPFILEHEADER bFileHeader;
            BITMAPINFOHEADER bInfoHeader;
            BITMAPINFO Info;
    
    
        protected:
            HDC DC;
            HBITMAP Image;
    
    
        public:
            ~Bitmap()
            {
                if (Bits)
                    delete[] Bits;
                DeleteDC(DC);
                DeleteObject(Image);
            }
    
    
            Bitmap(int Width, int Height) : width(Width), height(Height)
            {
                       memset(&Info, 0, sizeof(BITMAPINFO));
                       Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
                       Info.bmiHeader.biPlanes = 1;
                       Info.bmiHeader.biBitCount = 32;
                       Info.bmiHeader.biCompression = BI_RGB;
                       Info.bmiHeader.biWidth = width;
                       Info.bmiHeader.biHeight = -height;
                       DC = CreateCompatibleDC(0);
                       Image = CreateDIBSection(DC, &Info, DIB_RGB_COLORS, (void**)&Bits, 0, 0);
                       SelectObject(DC, Image);
            }
    
    
            Bitmap(int Width, int Height, string Data) : width(Width), height(Height)
            {
            }
    
    
            Bitmap(const char* FilePath)
            {
                HANDLE hFile = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
    
    
                if (hFile == 0)
                {
                    cout<<"Error Bitmap Does Not Exist";
                    return;
                }
    
    
                DWORD Read;
                ReadFile(hFile, &bFileHeader, sizeof(bFileHeader), &Read, 0);
                ReadFile(hFile, &bInfoHeader, sizeof(bInfoHeader), &Read, 0);
    
    
                if (bInfoHeader.biBitCount < 32)
                {
                    CloseHandle(hFile);
                    cout<<"The Image Loaded cannot be less than 32bits.";
                    return;
                }
    
    
                if (bFileHeader.bfType != 0x4D42)
                {
                    CloseHandle(hFile);
                    cout<<"The File Is Not A Bitmap.";
                    return;
                }
    
    
                if (bInfoHeader.biCompression != BI_RGB)
                {
                    CloseHandle(hFile);
                    return;
                }
    
    
                width = bInfoHeader.biWidth;
                height = bInfoHeader.biHeight;
    
    
                memset(&Info, 0, sizeof(BITMAPINFO));
                Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
                Info.bmiHeader.biPlanes = 1;
                Info.bmiHeader.biBitCount = 32;
                Info.bmiHeader.biCompression = BI_RGB;
                Info.bmiHeader.biWidth = width;
                Info.bmiHeader.biHeight = -height;
                Info.bmiHeader.biSizeImage = bInfoHeader.biSizeImage;
    
    
                Bits = new BYTE[Info.bmiHeader.biSizeImage];
                SetFilePointer(hFile, bFileHeader.bfOffBits, 0, FILE_BEGIN);
                ReadFile(hFile, Bits, Info.bmiHeader.biSizeImage, &Read, 0);
    
    
                DC = GetDC(0);
                Image = CreateDIBitmap(DC, &Info.bmiHeader, CBM_INIT, Bits, &Info, DIB_RGB_COLORS);
                CloseHandle(hFile);
            }
    
    
            bool DrawBitmap(HWND Window, Point Position = Point(0, 0))
            {
                HDC DContext = GetDC(Window);
                if ((DContext == NULL))
                    return false;
    
    
                HDC dcmem = CreateCompatibleDC(NULL);
    
    
                if (SelectObject(dcmem, Image) == NULL)
                {
                    DeleteObject(Image);
                    DeleteDC(dcmem);
                    return false;
                }
    
    
                BITMAP bm;
                GetObject(Image, sizeof(bm), &bm);
                if (BitBlt(DContext, Position.X, Position.Y, bm.bmWidth, bm.bmHeight, dcmem, 0, 0, SRCCOPY) == 0)
                {
                    DeleteObject(Image);
                    DeleteDC(dcmem);
                    return false;
                }
    
    
                DeleteDC(dcmem);
                ReleaseDC(Window, DContext);
                return true;
            }
    
    
            bool SaveBitmap(const char* FilePath)
            {
                DWORD Written;
    
    
                HANDLE hFile = CreateFile(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
                if (hFile == 0)
                {
                    CloseHandle(hFile);
                    return false;
                }
    
    
                if (!WriteFile(hFile, &bFileHeader, sizeof(BITMAPFILEHEADER), &Written, 0))
                {
                    CloseHandle(hFile);
                    return false;
                }
    
    
                if (!WriteFile(hFile, &bInfoHeader, sizeof (BITMAPINFOHEADER), &Written, 0))
                {
                    CloseHandle(hFile);
                    return false;
                }
    
    
                if (!WriteFile(hFile, Bits, bInfoHeader.biSizeImage, &Written, 0))
                {
                    CloseHandle(hFile);
                    return false;
                }
                return true;
            }
    
    
            HDC ReturnDC(){return DC;}
    
    
            int Width(){return width;}
    
    
            int Height(){return height;}
    
    
            void Size(int& Width, int& Height){Width = width; Height = height;}
    };
    
    
    class Pens
    {
        private:
            HDC     hDC;
            HPEN    NewPen;
            HPEN    OldPen;
    
    
        public:
            Pens(HDC hdc, COLORREF colour) : hDC(hdc)
            {
                NewPen = CreatePen(PS_SOLID, 0, colour);
                OldPen = (HPEN)SelectObject (hDC, NewPen);
            }
    
    
            Pens(HDC hdc, DWORD Style, DWORD Width, COLORREF colour) : hDC(hdc)
            {
                NewPen = CreatePen(Style, Width, colour);
                OldPen = (HPEN)SelectObject (hDC, NewPen);
            }
    
    
            ~Pens()
            {
                SelectObject(hDC, OldPen);
                DeleteObject(NewPen);
            }
    
    
            void ColourPixel(Point ColourPoint)
            {
                SetPixel(hDC, ColourPoint.X, ColourPoint.Y, ColourPoint.Color);
            }
    
    
            void DrawLine(Point Begin, Point End)
            {
                MoveToEx (hDC, Begin.X, Begin.Y, 0);
                LineTo (hDC, End.X, End.Y);
            }
    
    
            void DrawRectangle(Box B)
            {
                Rectangle(hDC, B.X1, B.Y1, B.X2, B.Y2);
            }
    
    
            void DrawElipse(Point UpperLeftBound, Point LowerRightBound)
            {
                Ellipse(hDC, UpperLeftBound.X, UpperLeftBound.Y, LowerRightBound.X, LowerRightBound.Y);
            }
    
    
            void DrawArcAngle(Point CenterPoint, DWORD Radius, float StartAngle, float EndAngle)
            {
                AngleArc(hDC, CenterPoint.X, CenterPoint.Y, Radius, StartAngle, EndAngle);
            }
    
    
            void DrawArc(Point UpperLeftBound, Point LowerRightBound, Point ArcStartPoint, Point ArcEndPoint)
            {
                Arc(hDC, UpperLeftBound.X, UpperLeftBound.Y, LowerRightBound.X, LowerRightBound.Y, ArcStartPoint.X, ArcStartPoint.Y, ArcEndPoint.X, ArcEndPoint.Y);
            }
    
    
            void DrawArcTo(Point UpperLeftBound, Point LowerRightBound, Point ArcStartPoint, Point ArcEndPoint)
            {
                ArcTo(hDC, UpperLeftBound.X, UpperLeftBound.Y, LowerRightBound.X, LowerRightBound.Y, ArcStartPoint.X, ArcStartPoint.Y, ArcEndPoint.X, ArcEndPoint.Y);
            }
    };
    
    
    class Brushes
    {
        private:
            HDC     hDC;
            HBRUSH  NewBrush;
            HBRUSH  OldBrush;
    
    
        public:
            Brushes(HDC hdc, COLORREF colour) : hDC(hdc)
            {
                NewBrush = CreateSolidBrush(colour);
                OldBrush = (HBRUSH)SelectObject (hDC, NewBrush);
            }
            ~Brushes()
            {
                SelectObject(hDC, OldBrush);
                DeleteObject(NewBrush);
            }
    
    
            void ColourPixel(Point ColourPoint)
            {
                SetPixel(hDC, ColourPoint.X, ColourPoint.Y, ColourPoint.Color);
            }
    
    
            void DrawLine(Point Begin, Point End)
            {
                MoveToEx (hDC, Begin.X, Begin.Y, 0);
                LineTo (hDC, End.X, End.Y);
            }
    
    
            void DrawRectangle(Box B, bool Fill = false)
            {
                if (!Fill)
                {
                    DrawLine(Point(B.X1, B.Y1), Point(B.X2, B.Y1)); //Draw the Top.
                    DrawLine(Point(B.X1, B.Y1), Point(B.X1, B.Y2)); //Draw the Left.
                    DrawLine(Point(B.X2, B.Y1), Point(B.X2, B.Y2)); //Draw the Right.
                    DrawLine(Point(B.X1, B.Y2), Point(B.X2, B.Y2)); //Draw the Bottom.
                    ColourPixel(Point(B.X2, B.Y2, 0));          //Last Pixel.
                }
                else
                    Rectangle(hDC, B.X1, B.Y1, B.X2, B.Y2);
            }
    
    
            void DrawElipse(Point UpperLeftBound, Point LowerRightBound)
            {
                Ellipse(hDC, UpperLeftBound.X, UpperLeftBound.Y, LowerRightBound.X, LowerRightBound.Y);
            }
    
    
            void DrawArcAngle(Point CenterPoint, DWORD Radius, float StartAngle, float EndAngle)
            {
                AngleArc(hDC, CenterPoint.X, CenterPoint.Y, Radius, StartAngle, EndAngle);
            }
    
    
            void DrawArc(Point UpperLeftBound, Point LowerRightBound, Point ArcStartPoint, Point ArcEndPoint)
            {
                Arc(hDC, UpperLeftBound.X, UpperLeftBound.Y, LowerRightBound.X, LowerRightBound.Y, ArcStartPoint.X, ArcStartPoint.Y, ArcEndPoint.X, ArcEndPoint.Y);
            }
    
    
            void DrawArcTo(Point UpperLeftBound, Point LowerRightBound, Point ArcStartPoint, Point ArcEndPoint)
            {
                ArcTo(hDC, UpperLeftBound.X, UpperLeftBound.Y, LowerRightBound.X, LowerRightBound.Y, ArcStartPoint.X, ArcStartPoint.Y, ArcEndPoint.X, ArcEndPoint.Y);
            }
    };
    
    
    #endif // BITMAPS_H_INCLUDED

  3. #3
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    You can copy client image to bitmap and draw your boxes on it ,then save this to file ,or show in simba:
    Simba Code:
    program new;
      {$i srl/srl.simba}
        {$I srl/srl/misc/debug.simba}
    var
    w,h,bmp :
    begin
      GetClientDimensions(w,h);
      bmp := BitmapFromClient(1,1,w-1,h-1);
      {...}  // draw something to bitmap here
      DebugBitmap(bmp);
    end.

  4. #4
    Join Date
    Feb 2012
    Posts
    170
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    But draw using what function? Sorry I'm kinda lost and ggzz's fix looks complicated :s

  5. #5
    Join Date
    May 2008
    Location
    ;)
    Posts
    576
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by xdarkshadowx View Post
    But draw using what function? Sorry I'm kinda lost and ggzz's fix looks complicated :s
    I get your question.

    And here is your answer, in tutorial form: http://villavu.com/forum/showthread....ghlight=canvas

    Basically, you do what beginner said. You're creating a canvas on top of the client, which you will draw on using FastSetPixel/FastSetPixels

  6. #6
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Quote Originally Posted by xdarkshadowx View Post
    But draw using what function? Sorry I'm kinda lost and ggzz's fix looks complicated :s
    There is no function ,which draws TBox ,so you should convert TBox to TPA and use DrawTPABitmap();

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •