Topic: Trasparent text in AppGraphics

I run a simple program utilizing AppGraphic:

program main
use appgraphics
implicit none

    integer::myscreen
    
    myscreen = initwindow(400, 300, closeflag=.TRUE.)
    
    !CALL setwritemode(COPY_PUT)
    CALL setwritemode(XOR_PUT)
    CALL line(100, 200, 300, 200)
    CALL outtextxy(200, 200, 'Abcd')
    
    call loop()
    
    call closewindow(myscreen)

end program main

The result is that the text removes a part of the line and there is a gap. I played with setwritemode without desired results. Is there any way to display a text transparently? If not could you please add the subroutine to toggle opaque/transparent mode?

PS. I can't catch how to add the image to the topic.

Re: Trasparent text in AppGraphics

Adding transparent text output to AppGraphics should be possible.  I'll look at the best way to add it in a future release.

To add an image, you can use img tags, but you would need to provide a URL to an image.  We do not host any images here ourselves.

Jeff Armstrong
Approximatrix, LLC

3 (edited by GrzegorzW 2023-10-21 17:23:04)

Re: Trasparent text in AppGraphics

As far as I understand AppGraphics is a wrapper of Windows API. May I ask to add to AppGraphics:

- SetBKMode / GetBkMode
- SetTextAlign / GetTextAlign
- FillRect

The last one I would like to use creating the window with other then default black background. FloodFill, because the algorithm, is rather unaesthetic method.

Re: Trasparent text in AppGraphics

AppGraphics' graphical functions are actually a superset of the Borland Graphics Interface rather than a thin Windows GDI wrapper.  I can see the need for SetBkMode when drawing dashed lines and hashes, but I'd have to see about the best way to implement it.  I actually think it should default to transparent, which makes the whole argument unnecessary.

Text can be aligned with settextjustify already.

To clear a window (or region), I normally use either the combo setbkcolor/clearviewport or simply barfloodfill uses a more complicated procedure because of its capabilities, of course.

Jeff Armstrong
Approximatrix, LLC

Re: Trasparent text in AppGraphics

jeff wrote:

...
Text can be aligned with settextjustify already.
...

May I disagree? settextjustify doesn't perform an alignment.

Re: Trasparent text in AppGraphics

In what particular case are you attempting to justify text?  settextjustify works with the outtext/outtextxy subroutines.  Are you trying to justify text within a control?

Jeff Armstrong
Approximatrix, LLC

Re: Trasparent text in AppGraphics

I had thought that settextjustify is the right function. But I received so astonishing results that I prepared some simple tests. It seems an aligment and a justification are two different beasts.

The first example is a about horizontal aligment/justification. In SF the code is:

    .....
    CALL settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 18)

    CALL settextjustify(LEFT_TEXT, BOTTOM_TEXT)
    CALL outtextxy(50, 50, 'Abcd-l')
    CALL settextjustify(CENTER_TEXT, BOTTOM_TEXT)
    CALL outtextxy(50, 70, 'Abcd-c')
    CALL settextjustify(RIGHT_TEXT, BOTTOM_TEXT)
    CALL outtextxy(50, 90, 'Abcd-r')
    CALL line(50, 0, 50, 299)
    .....

In Delphi Pascal I call Windows API for aligning:

procedure TForm1.FormPaint(Sender: TObject);
var
  h : THandle;

begin
  h:=Form1.Canvas.Handle;

  SetTextAlign(h, TA_LEFT);
  TextOut(h, 50, 50, 'Abcd-l', 6);
  SetTextAlign(h, TA_CENTER);
  TextOut(h, 50, 70, 'Abcd-c', 6);
  SetTextAlign(h, TA_RIGHT);
  TextOut(h, 50, 90, 'Abcd-r', 6);
  MoveToEx(h, 50, 1, NIL);
  LineTo(h, 50, 299)
end;

The vertical line is for better orientation.

The second example is about a vertical aligment/justification.

SF code is as follows:

    .....
    CALL settextjustify(LEFT_TEXT, BOTTOM_TEXT)
    CALL outtextxy(50, 50, 'Abcd-b')
    CALL settextjustify(LEFT_TEXT, CENTER_TEXT)
    CALL outtextxy(150, 50, 'Abcd-c')
    CALL settextjustify(LEFT_TEXT, TOP_TEXT)
    CALL outtextxy(250, 50, 'Abcd-t')
    CALL line(0, 65, 399, 65)
    .....

Delphi code is:

procedure TForm1.FormPaint(Sender: TObject);
var
  h : THandle;

begin
  h:=Form1.Canvas.Handle;

  SetTextAlign(h, TA_BOTTOM);
  TextOut(h, 50, 50, 'Abcd-b', 6);
  SetTextAlign(h, TA_BASELINE);
  TextOut(h, 150, 50, 'Abcd-c', 6);
  SetTextAlign(h, TA_TOP);
  TextOut(h, 250, 50, 'Abcd-t', 6);
  MoveToEx(h, 1, 65, NIL);
  LineTo(h, 399, 65)
end;

The horizontal line is for better orientation.

If you can't run the above examples I will send you screenshots or will try to drop here.

As you can see the results are quite different. My suggerstion concerns "aligment" when I can draw a text that the middle point matches the required one. For example the centre of a labal fits the center of the line.

Re: Trasparent text in AppGraphics

Please send screenshots.  But also be aware that the AppGraphics functions are trying to emulate Borland's BGI interface, not the Windows API.

Jeff Armstrong
Approximatrix, LLC