microwindows icon indicating copy to clipboard operation
microwindows copied to clipboard

How to set the width of dashed lines & Why do the dashed lines blink

Open ChauncyZhang opened this issue 1 year ago • 5 comments

`GrSetGCForeground(gc_, BLACK); GrFillRect(back_buffer_id_, gc_, 0, 0, screen_info_.cols, screen_info_.rows); GrArea(back_buffer_id_, gc_, 0, 0, screen_info_.cols, screen_info_.rows, (void*)frame.data, MWPF_PIXELVAL);

DrawText("Please press confirm after overlap", screen_info_.cols / 2, 200); GrSetGCForeground(gc_, GR_COLOR_RED); DrawDashedLine(wid_, gc_, x - 200, y, x + 200, y); DrawDashedLine(wid_, gc_, x, y - 200, x, y + 200);

GrCopyArea(wid_, gc_, 0, 0, screen_info_.cols, screen_info_.rows, back_buffer_id_, 0, 0, MWROP_SRC);

GrFlush();`

The text and image show well, but the dashed lines always blink, and seem like the layer is below the image, but I can see the dashed line. I have two questions, 1. Why does the dashed line blink, 2. How to set the width of dashed lines?

ChauncyZhang avatar Jul 28 '24 11:07 ChauncyZhang

Hello @ChauncyZhang,

I am not sure why dashed lines blink, as Nano-X doesn't support blinking directly with graphics draw. Can you describe your framebuffer hardware, does it support hardware blinking with some color combinations? Perhaps try drawing with a different color than GR_COLOR_RED to see if any difference results.

Please post a screenshot or photo so I can get a better understanding of how layer is below image.

To set the dashed line width and/or dash count, use GrSetGCDash and see the documentation for it.

Thank you!

ghaerr avatar Jul 28 '24 15:07 ghaerr

https://github.com/user-attachments/assets/c1285709-e0b0-47e6-a418-cf994f463751 Hello, Like that, I don't want it blink.

ChauncyZhang avatar Jul 28 '24 16:07 ChauncyZhang

Hmmm, it seems that the blinking may be the result of the background being erased and then the image redrawn, which produces a flicker. Flicker is not the same as blink, so I misunderstood your problem. In order to remove flicker, one must either 1) redraw the background that changed, then redraw the foreground without background bits, or 2) redraw the entire background and foreground at the same time, without erasing the screen beforehand.

That said, does this occur only when using dashed lines, or have you looked at the result using solid lines instead with no problems?

ghaerr avatar Jul 29 '24 03:07 ghaerr

`GrSetGCForeground(gc_, BLACK); GrFillRect(back_buffer_id_, gc_, 0, 0, screen_info_.cols, screen_info_.rows); GrArea(back_buffer_id_, gc_, 0, 0, screen_info_.cols, screen_info_.rows, (void*)frame.data, MWPF_PIXELVAL);

DrawText("Please press confirm after overlap", screen_info_.cols / 2, 200);
CrossDividingLine(screen_info_.cols / 2, screen_info_.rows / 2);

GrCopyArea(wid_, gc_, 0, 0, screen_info_.cols, screen_info_.rows,
           back_buffer_id_, 0, 0, MWROP_SRC);

GrFlush();`

`void ns::Render::CrossDividingLine(int x, int y) { GrSetGCForeground(gc_, GR_COLOR_RED); DrawDashedLine(wid_, gc_, x - 200, y, x + 200, y); DrawDashedLine(wid_, gc_, x, y - 200, x, y + 200); }

void Render::DrawDashedLine(GR_WINDOW_ID window, GR_GC_ID gc, int x1, int y1, int x2, int y2) { char dash2[2] = {10, 4}; GrSetGCDash(gc, dash2, 2); GrSetGCLineAttributes(gc, GR_LINE_ONOFF_DASH); GrLine(window, gc, x1, y1, x2, y2); }`

Every frame is refreshed. When drawing, I will delete the screen and copy back_buffer to the window, what is the problem with the process? Thanks!

ChauncyZhang avatar Jul 30 '24 13:07 ChauncyZhang

what is the problem with the process?

I am not sure, I don't have the time to debug your code right now. You haven't answered the question I asked, does this happen only with dashed lines or will it work without them? We need to eliminate variables to get root of the problem.

When drawing, I will delete the screen

What do you mean "delete the screen"? If that involves a repaint of background, then you will see flicker, even when using a back buffer.

You might try setting background color to WHITE instead of black, this method shows sometimes when background is being drawn differently by different graphics calls to help debug why the display is flickering.

ghaerr avatar Jul 30 '24 22:07 ghaerr