Path: news.eternal-september.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: wij 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: References: <4ffeda4ce7116f70754bcfcaee87cb729081fac3.camel@gmail.com> <87cyho7l0y.fsf@nosuchdomain.example.com> <949627852d304fe2c28e4b02e1c2c8f1b92dcf02.camel@gmail.com> <875xngxv69.fsf@nosuchdomain.example.com> <46376a6ea82da504381a6431a4f21014d9a30a3f.camel@gmail.com> <871py4xq9y.fsf@nosuchdomain.example.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 writes: > > > Ross Finlayson writes: > > > > On 12/18/2024 08:14 PM, Keith Thompson wrote: > > > > > wij 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 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 > #include >=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, 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 xxx // n=3Dsize of next packet, pixtype=3DRGB32 */ #ifndef WY__FACE_H__ #define WY__FACE_H__ #include #include constexpr Wy::WeeStr RGB32("RGB32"); typedef Wy::Vect 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 #include #include #include #include #include #include "face.h" =20 using namespace Wy; // [Syn] Draw demo image void draw_demo(Array2D& 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 ==========