Creating a graphic library from scratch - page 4

 
Реter Konow:
Who knows why it doesn't work...

The schematic of the library should be drawn up first, and then the codes written. This is usually the way to do it.

works in C++

What makes you think the scheme wasn't drawn up, was there a prerequisite for that???
 
Alexandr Andreev:

works in C++

What makes you think there's no schema, was there a prerequisite for that?
Where is it? I haven't seen it in three pages.
 
Реter Konow:
Where is it? I haven't seen it in three pages.

I was thinking to make a basis for using which would be reduced to minimal code style New_Window<<<Window_Upper.Size; New_Window<<Window_Upper.Position; New_Window.Size<<0.5 (the size automatically becomes half of the above); ...

And this class already takes into account the relationship from the position of the small cross to the higher window (base).

Looks like it's not gonna go smoothly... it happens.
 
Alexandr Andreev:

I was thinking to make a basis for using which would be reduced to minimal code style New_Window<<<Window_Upper.Size; New_Window<<Window_Upper.Position; New_Window.Size<<0.5 (size automatically becomes half of the above); .

And this class already takes into account the relationship from the position of the small cross to the higher window.

Ehhh, heh, heh.... "what does it cost us to build a house, we'll draw it, we'll live..."

I have the same approach myself. Only I pay for it with years of hard work.
 
Алексей Барбашин:

...

Well I have already described many times the "flaws" that from my point of view I see in the standard library and in Anatoly's library.

Both libraries have, in my opinion, one significant disadvantage: interface is built on discrete chart objects,that is, the more controls in the interface, the more isolated objects in the chart itself. On the one hand it's not a problem in itself, but on the other hand it's a problem with drag and drop dialogs, as not a single "form with elements" object is dragged, but many different elements. And this consumes additional resources.

Anatoly's library is very chic, but it is complex in its composition and difficult to integrate into the main program. And the standard library is limited in the controls themselves, although the original architecture is very good in my opinion.

In fact, the best solution would be what Petr Konov tries to do: GUI GUI builder with GUI code generation, but with extended event model, so when integrating with main program, you would not have to dig into huge GUI code (something like MVVM analogue), and of course with objects that users could extend on their own.

Of course, this is a very simplified view on the problem of graphical libraries. It's not about dragging and dropping forms and the lack of kanvas handling, which limits possibilities and functionality of GUI. The bottom line is that MT-objectshave few properties, and library handlers are not sufficiently developed to manage the drawn elements and to support all their diverse capabilities. The complexity of the MT objects and the controlling functionality of the libraries does not reach the minimum level required by the kanvas.

Taking these libraries and rewriting them for kanvas means raising them to a fundamentally new level, which a priori cannot be easy and simple.


ZS. Anatoly started the way to kanvas in his library and was the first to create drawn tables in MKL. However, the method of constructing them is imperfect, due to the fact that cells are semi-independent elements and there are difficulties in addressing each one individually.

I remember what the transition cost Anatoly and how long it took.

 

It's more or less like this

#define  TEMPLATE(T) template<typename T>
#define  TEMPLATE2(T1,T2) template<typename T1, typename T2>

#define  TEMPL(T) TEMPLATE(T)
#define  TEMPL1(T) TEMPLATE(T)
#define  TEMPL2(T,T1) TEMPLATE2(T,T1)
//whats TD (template define)? because TT is busy
//почемуто этот код в шаблонах на мкл не хочет компилироваться поэтому через дефайн - это Плохо надо бы через шаблоны как то придумать.... привет метаквотам
#define  TD1 int
#define  TD2 double 
#define  EMPY -1 
#define  GET this.operator>> 
#define  SET this.operator<< 
class CCoordD; 
class CSizeD;
class CCoordBaseD //полностью внутрений класс
   {
   private:
   #define  ME CCoordBaseD 
   TEMPL1(T)
   bool Chek(T *a)                  {return CheckPointer(a)!=POINTER_INVALID;}
   TEMPL1(T)
   bool Chek(T a)                   {return a!=(T)EMPY;}
   TD1 Error()                      {Print(__FUNCTION__," ",__LINE__," POINTER_INVALID size"); int a[]; a[0]=0; return (TD1)EMPY;};//wtf??? =P CRASH Error
   TD1 GetA()                       {return c.GetA()+ar;}
   TD1 GetP()                       {return c.Result() + size.GetP()*(TD1)pr;}
   public:
   ME()                                   {Init();} 
   ME(TD1 a)                              {Init(a);} 
   ME(TD1 a,CCoordD &b)                   {Init(a,b);} 
   ME(TD1 a,CCoordD &b,CSizeD &x)         {Init(a,b,x);} 
   ME(TD2 a,CSizeD &b)                    {Init(a,b);} 
   ME(TD2 a,CCoordD &b,CSizeD &x)         {Init(a,b,x);} 
   CCoordD *c;//one coord
   CSizeD *size;//size 
   TD1 ar;
   TD2 pr;//percent проценты
   void Init()                            {ar=(TD1)EMPY; pr=(TD2)EMPY; }  
   TD1 Result()                           {return Chek(ar)?Chek(c)?GetA():ar:Chek(pr)?Chek(size)?GetP():Error():(TD1)EMPY;}
   ME *GetMe()                            {return &this;}
   ME *GetCoorBase()                      {return c;}
   ME *GetSizeBase()                      {return size;} 
   CCoordD *GetCoor()                     {return c;}
   CSizeD *GetSize()                      {return size;} 
   void Init(TD1 a)                       {Init(); SET(a);}
   void Init(TD1 a,CCoordD &b)            {Init(); SET(a); SET(b);}
   void Init(TD1 a,CCoordD &b,CSizeD &x)  {Init(); SET(a); SET(b); SET(x);}
   void Init(TD1 a,CSizeD &b,CCoordD &x)  {Init(); SET(a); SET(b); SET(x);}
 //  void Init(TD2 p)                     {Init(); pr=p_;}
   void Init(TD2 a,CSizeD &b)             {Init(); SET(a); SET(b);}
   void Init(TD2 a,CCoordD &b,CSizeD &x)  {Init(); SET(a); SET(b); SET(x);}
   void Init(TD2 a,CSizeD &b,CCoordD &x)  {Init(); SET(a); SET(b); SET(x);}
   void operator >> (TD1 a)               {a=ar;} 
   void operator >> (TD2 a)               {a=pr;}  
   void operator >> (CCoordD &a)          {a=GetPointer(c);}  
   void operator >> (CSizeD &s)           {s=GetPointer(size);}  
   void operator << (TD1 a)               {ar=a;} 
   void operator << (TD2 a)               {pr=a;}  
   void operator << (CCoordD &a)          {c=GetPointer(a);}  
   void operator << (CSizeD &s)           {size=GetPointer(s);}  
   void operator << (ME &a)               {a>>c; a>>ar; a>>pr; a>>size;}  
   void operator = (CCoordD &a)           {SET(a);}
   void operator = (CSizeD &a)            {SET(a);}
   void operator = (ME &a)                {SET(a);} 
   TD1 operator ~ ()                      {return Result();} 
   #undef  ME
   #undef  GET 
   #undef  SET
   };
   
class CSizeD : public CCoordBaseD
   {
   public:
   CSizeD(){};
   };
   
class CCoordD : public CCoordBaseD
   {
   public:
   CCoordD(){};
   };

class CCoord;

class CTX {public:CTX(){}}; 
class CTY {public:CTY(){}};
class CTZ {public:CTZ(){}};
TEMPL(T)
class CCoordA : public T
   {
   public:
   CCoordD ar; 
   CSizeD size;
   CCoordA()                                                {}; 
   CCoordA(TD1 a1,TD1 a2=(TD1)0)                            {Init(a1,a2);} 
   CCoordA(TD1 a1,CCoordD &c1, CSizeD &c2,TD1 a2)           {Init(a1,c1,c2,a2);}  
   CCoordA(TD1 a1,CCoordD &c1, CSizeD &c2,TD2 a2=(TD2)1)    {Init(a1,c1,c2,a2);}  
   CCoordA(TD2 a1,CCoordD &c1, CSizeD &c2,TD1 a2)           {Init(a1,c1,c2,a2);}  
   CCoordA(TD2 a1,CCoordD &c1, CSizeD &c2,TD2 a2=(TD2)1)    {Init(a1,c1,c2,a2);}   
   void Init()                                              {} 
   void Init(TD1 a1,TD1 a2=(TD1)0)                          {ar.Init(a1);        size.Init(a2);} 
   void Init(TD1 a1,CCoordD &c1, CSizeD &c2,TD1 a2)         {ar.Init(a1,c1,c2);  size.Init(a2,c1,c2);}  
   void Init(TD1 a1,CCoordD &c1, CSizeD &c2,TD2 a2=(TD2)1)  {ar.Init(a1,c1,c2);  size.Init(a2,c1,c2);}  
   void Init(TD2 a1,CCoordD &c1, CSizeD &c2,TD1 a2)         {ar.Init(a1,c1,c2);  size.Init(a2,c1,c2);}  
   void Init(TD2 a1,CCoordD &c1, CSizeD &c2,TD2 a2=(TD2)1)  {ar.Init(a1,c1,c2);  size.Init(a2,c1,c2);}  
   void operator <<(CSizeD &a)   {return ;}
   void operator <<(CCoordD &a)  {return ;} 
   bool Chek(int px)             {return (px-=(int)~ar) < 0 && px<(int)~size;}                   
   };
   
class CCoord
   {  
   public: 
   CCoordA<CTX> X;
   CCoordA<CTY> Y; 
   CCoord ()                              {} 
   void operator >> (CCoordA<CTX> &a)     {a=GetPointer(X);}
   void operator >> (CCoordA<CTY> &a)     {a=GetPointer(Y);}
   void operator << (CCoord &a)           {a>>X; a>>Y;}
   bool MouseOn(CMouse &mouse)//px
      {
      return X.Chek(mouse.X) && Y.Chek(mouse.Y);
      }
   };  
CCoord Pro1; 

void Func()
   {
   TD1 bi;//buf int
   TD1 bd;//buf double
   CCoord general;//создали класс координат некого объекта - к примеру окна дженерал
   general.X.Init((int)0,(int)1000); //установили размер
   general.Y.Init((int)0,(int)1000); 
   
   CCoord next;//создали класс координат следующего окна
   next<<general;//сделали его зависимым от главного окна
   next.X.ar<<(double)0.25;//старт по оси Х 25%, если значение типа дабл автоматически считается процент
   next.X.size<<(double)0.5;//размер окна равен 50% от главного.
   }
   #undef  TD1
   #undef  TD2
 
 

That's the end of the coordinate class. I don't even know what's next.

I think we should add positioning, though.

Next, in, left, top. cent.....

 
Alexandr Andreev:

It goes something like this.


#define  TEMPLATE(T) template<typename T>
#define  TEMPLATE2(T1,T2) template<typename T1, typename T2>

#define  TEMPL(T) TEMPLATE(T)
#define  TEMPL1(T) TEMPLATE(T)
#define  TEMPL2(T,T1) TEMPLATE2(T,T1)

You also forgot this:

#define  TE(T) TEMPL(T)
#define  TE1(T) TEMPL1(T)
#define  TE2(T,T1) TEMPL2(T,T1)
 
Alexandr Andreev:

It goes something like this.

#define  TD1 int
#define  TD2 double 

And that's what's missing:

#define  TD3 bool
#define  TD4
 void 
 
Aliaksandr Hryshyn:

And this is what's missing:

I wanted to use templates but they don't compile, the simplified example on the previous page

And it's not sure that it will be exactly int and not some enum, and then you don't want to correct the code

And why do we need a bool there?

Ideally, it should be so

enum EPX{}//px
enum EPR{}//процент
#define  TD1 EPX
#define  TD2 EPR

And no TD3 (in fact the entire class is written for two values). Why did I call TD also written in the code

Reason: