Deutsch   English   Français   Italiano  
<f16848a99a961b30d5beb5213048296c3168a88e.camel@gmail.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wij <wyniijj5@gmail.com>
Newsgroups: comp.lang.c++
Subject: Re: 'Graphics' of libwy
Date: Mon, 23 Dec 2024 02:50:50 +0800
Organization: A noiseless patient Spider
Lines: 241
Message-ID: <f16848a99a961b30d5beb5213048296c3168a88e.camel@gmail.com>
References: <4ffeda4ce7116f70754bcfcaee87cb729081fac3.camel@gmail.com>
			<vjqhau$1ceif$1@dont-email.me> <vjs2do$1p3ce$1@dont-email.me>
			<vjs7a7$1qa1n$1@dont-email.me> <vjs8uq$1qgh4$1@dont-email.me>
			<vjsaa3$1qrhs$1@dont-email.me> <vjtvvk$2787g$1@dont-email.me>
			<vju3t1$27s6m$1@dont-email.me>	<87cyho7l0y.fsf@nosuchdomain.example.com>
			<949627852d304fe2c28e4b02e1c2c8f1b92dcf02.camel@gmail.com>
			<875xngxv69.fsf@nosuchdomain.example.com>
			<46376a6ea82da504381a6431a4f21014d9a30a3f.camel@gmail.com>
			<871py4xq9y.fsf@nosuchdomain.example.com>
			<s_idnQttB9Q9Jfn6nZ2dnZfqnPednZ2d@giganews.com>
			<87wmfvw4aq.fsf@nosuchdomain.example.com>
		 <87seqjw1ee.fsf@nosuchdomain.example.com>
	 <6523746156b3a0a3905a94f90ddb06f4ca6d7949.camel@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sun, 22 Dec 2024 19:50:52 +0100 (CET)
Injection-Info: dont-email.me; posting-host="374666ccd9eff8c1ab6db7be97579a41";
	logging-data="787144"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+YL+gqtEgmQ1jtkuD9+qA9"
User-Agent: Evolution 3.54.2 (3.54.2-1.fc41)
Cancel-Lock: sha1:FgzDdXvyHkuaT8Q2dda4TAVKJjU=
In-Reply-To: <6523746156b3a0a3905a94f90ddb06f4ca6d7949.camel@gmail.com>

On Fri, 2024-12-20 at 11:10 +0800, wij wrote:
> On Thu, 2024-12-19 at 18:09 -0800, Keith Thompson wrote:
> > Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> > > Ross Finlayson <ross.a.finlayson@gmail.com> writes:
> > > > On 12/18/2024 08:14 PM, Keith Thompson wrote:
> > > > > wij <wyniijj5@gmail.com> writes:
> > [...]
> > > > > > But, what is the true thing the program is dealing with? What i=
s 'pixel'?
> > > > >=20
> > > > > Do you really not know what a pixel is?
> > [...]
> > > > Pixel =3D "picture element"
> > >=20
> > > You do know what a pixel is.=C2=A0 So why did you ask?
> >=20
> > My apologies, I didn't pay enough attention to the attribution lines.
> > wij write "What is 'pixel'"; Ross wrote 'Pixel =3D "picture element"'.
>=20
> class Pixel { /* Whatever suitable */ };
> =C2=A0
> int main() {=20
> =C2=A0Array2D<Pixel> img;=20
>=20
> =C2=A0load_picture(img, "mydog.jpg");
> =C2=A0draw_circle(img, cx,cy, dim);
>=20
> =C2=A0// cout.set_graphics_mode(...);=C2=A0 // if necessary=C2=A0=20
> =C2=A0// for(ssize_t y=3Dimg.height()-1; y>=3D0; --y) {
> =C2=A0//=C2=A0 cout << StrSeg(&img(0,y), img.width()) << WY_ENDL;=20
> =C2=A0// }
>=20
> =C2=A0cout << img;=C2=A0 // the about can be simplified to one line
> };
>=20
> 'Pixel' is just something you can write into Array2D
>=20
> ---------- a_rawkey.cpp
> #include <Wy.stdio.h>
> #include <Wy.string.h>
>=20
> using namespace Wy;
>=20
> int main(int, char* [])
> try {
> =C2=A0const char usage[]=3D"Type arrow keys (Up,Down,Left,Down) to move a=
round, 'ESC' to exit." WY_ENDL;
> =C2=A0Errno r;
>=20
> =C2=A0cout << usage;
> =C2=A0constexpr WeeStr KeyESC("\33");
> =C2=A0constexpr WeeStr KeyUp("\33[A");
> =C2=A0constexpr WeeStr KeyDown("\33[B");
> =C2=A0constexpr WeeStr KeyRight("\33[C");
> =C2=A0constexpr WeeStr KeyLeft("\33[D");
>=20
> =C2=A0constexpr WeeStr CursorUp("\33[1A");
> =C2=A0constexpr WeeStr CursorDown("\33[1B");
> =C2=A0constexpr WeeStr CursorRight("\33[1C");
> =C2=A0constexpr WeeStr CursorLeft("\33[1D");
>=20
> =C2=A0WeeStr stroke;
> =C2=A0for(;;) {
> =C2=A0=C2=A0 if((r=3D_get_rawkey(cin,stroke))!=3DOk) {
> =C2=A0=C2=A0=C2=A0=C2=A0 WY_THROW(r);
> =C2=A0=C2=A0 }
> =C2=A0=C2=A0 if(stroke=3D=3DKeyESC) {
> =C2=A0=C2=A0=C2=A0=C2=A0 break;
> =C2=A0=C2=A0 }
>=20
> =C2=A0=C2=A0 if(stroke=3D=3DKeyUp) {
> =C2=A0=C2=A0=C2=A0=C2=A0 cout << CursorUp;
> =C2=A0=C2=A0 } else if(stroke=3D=3DKeyLeft) {
> =C2=A0=C2=A0=C2=A0=C2=A0 cout << CursorLeft;
> =C2=A0=C2=A0 } else if(stroke=3D=3DKeyDown) {
> =C2=A0=C2=A0=C2=A0=C2=A0 cout << CursorDown;
> =C2=A0=C2=A0 } else if(stroke=3D=3DKeyRight) {
> =C2=A0=C2=A0=C2=A0=C2=A0 cout << CursorRight;
> =C2=A0=C2=A0 } else {};
> =C2=A0}
> =C2=A0return 0;
> }
> catch(const Errno& e) {
> =C2=A0cerr << wrd(e) << WY_ENDL;
> =C2=A0return e.c_errno();
> }
> catch(...) {
> =C2=A0cerr << "main caught(...)" WY_ENDL;
> =C2=A0throw;
> };=C2=A0=C2=A0=20
> ------------
>=20
> If the key code from raw mode tty is defined (maybe, but I don't know),=
=C2=A0
> I think C++ writing vi like editor should be much simpler, no need for nc=
urses.
> If back to 'graphics', Pixel can be CSI sequence in this case.
>=20
> My purpose is a 'C++ graphics'. No need to consider various kinds of=C2=
=A0
> graphics accelerators or 'GUI', which cannot be standardized and would be
> wrong goal.
>=20
> What I now trying to experiment is separating graphics things to another=
=C2=A0
> process. By doing so, 'the C++ code' just plays with Array2D<Pixel>, no n=
eed=C2=A0
> to include those (mostly) heavy graphics library.
>=20

I just wrote two program (face_svr.cpp, face_cli.cpp) to test what I though=
t.
It looks plausible using C++ to write graphic programs without using any
graphic library. Dream come true! 'C++ graphics' is possible and easy.

'face' just implemented basic capability of showing image.=C2=A0GUI has man=
y=20
graphics user interactions. From current result, I think simple GUI program
can be done easily.

face_svr.cpp has 140 lines, not shown.

------- face.h
/* Copyright is licensed by GNU LGPL, see file COPYING.       by I.J.Wang 2=
024
=20
   <!!=3Dddd........>
   <RS=3Dn w h pixtype>xxx    // n=3Dsize of next packet, pixtype=3DRGB32
*/
#ifndef WY__FACE_H__
#define WY__FACE_H__

#include <CSCall/Vect.h>
#include <CSCall/WeeStr.h>

constexpr Wy::WeeStr RGB32("RGB32");

typedef Wy::Vect<unsigned char,4> Pixel;

constexpr Pixel RGB32_White({255,255,255,0xff});  // blue,green,red
constexpr Pixel RGB32_Black({0,0,0,0xff});

#endif // WY__FACE_H__

------- face_cli.cpp
include <Wy.stdio.h>
#include <Wy.unistd.h>
#include <Wy.signal.h>
#include <CSCall/DrawPlane.h>
#include <CSCall/Array2D.h>
#include <CSCall/XnStream.h>
#include "face.h"
  =20
using namespace Wy;

// [Syn] Draw demo image
void draw_demo(Array2D<Pixel>& pic) {
 const unsigned int cx=3Dpic.width()/2;
 const unsigned int cy=3Dpic.height()/2;
  =20
 pic.fill(RGB32_Black);
    =20
 draw_solid_circle(pic.header(),cx,cy,30,RGB32_White);
    =20
 for(unsigned int rad=3D45; rad<=3D150; rad+=3D15) {
   draw_circle(pic.header(),cx,cy,rad,RGB32_White);
 }    =20
};    =20

========== REMAINDER OF ARTICLE TRUNCATED ==========