Copy rect / Bitblit operation

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Copy rect / Bitblit operation

      Newbie here.

      How would I go about doing a bit-blit type operation?

      I've got some text drawn over background that is constantly changing (game display), and I need to redraw the background behind the text when it changes.

      I was hoping something simple like GUI_CopyRect() but it doesn't allow copying to an external buffer.

      I saw a post that uses GUI_BMP_SerializeEx() and to a file pointer but I don't really understand how to make use of it for this or if this is correct as my attempts (GUI_DrawBitmap) just draw static on the screen.

      The post was edited 1 time, last by replaysMike ().

    • This surprisingly worked, it's just super slow. I used GUI_BMP_SerializeEx() to copy a rect from the frame buffer then draw it using GUI_DrawBitmap(). I may have done something wrong here that I'll have to play around with.

      C Source Code

      1. void DrawDebugInfo(void) {
      2. GUI_BITMAP bitmap;
      3. GUI_SetTextMode(GUI_TM_TRANS); // set text as transparent
      4. GUI_EnableAlpha(1);
      5. // copy a rect from the frame buffer
      6. GUI_BMP_SerializeEx(_WriteToBuffer, 50, 10, 190, 70, &bitmap);
      7. // draw the bitmap to the screen
      8. GUI_DrawBitmap(&bitmap, 50, 10);
      9. GUI_DispStringAt(debugstr_1, 50, 10);
      10. GUI_DispStringAt(debugstr_2, 50, 30);
      11. GUI_EnableAlpha(0);
      12. }
      13. static void _WriteToBuffer(U8 data, void *p) {
      14. memcpy(&data, p, sizeof(data));
      15. }
      Display All
    • Hi,

      There are several ways to achieve what you want.

      It depends on how much resources are available and how complex the application should be.

      1. Simply draw the background to clear the old text and display the text again. This might be the easiest way but it requires redrawing of the complete background.

      2. Having enough resources (especially RAM) you can use memory device to rescue the screen content without the text. This is almost the same as you tried. But with memory devices. Those devices should be way faster than serializing a BMP byte for byte.

      3. Using the Window Manager. Create a dedicated window for displaying the text and one for the background. The Window Manager takes care about updating the the background when redrawing window with the text.

      Attached is an example for each point. I would use the Window Manager, this might be more complex and a bit harder to learn but makes life way easier later on.

      Please note, that in emWin a bitmap is NOT a BMP. If we talk a bout Bitmap we always mean c-style images. If we talk about BMPs we mean the Microsoft image format.
      So, I'm wondering how your application works at all, because it shouldn't be possible to draw a BMP with a function to display a bitmap ;)


        (39.18 kB, downloaded 115 times, last: )