How to write just the labels I want

General discussion on Visual GLCD Software.
Post Reply
Author
Message
Massimo
Posts: 126
Joined: 23 Jul 2008 22:49

How to write just the labels I want

#1 Post by Massimo » 11 Sep 2011 17:00

I everyone ,


I have to design a complex screen with some fields changing but I don't want to redraw the all screen when some field changes. So I thought the following
1) add a new propety called chnged to Label for each label i need to change. For the static ones I use the static property set to true

Code: Select all

typedef struct  Label {
  TScreen*  OwnerScreen;
  char          Order;
  char          Left;
  char          Top;
  char          Width;
  char          Height;
  char          chnged;
  char          *Caption;
  const char    *FontName;
  unsigned char Font_Color;
  char          Visible;
  char          Active;
  void          (*OnUpPtr)();
  void          (*OnDownPtr)();
  void          (*OnClickPtr)();
  void          (*OnPressPtr)();
} TLabel;
2) Each label is initialized adding the new property and set it to 1
3) modify the DrawScreen function as follow

Code: Select all

//  Glcd_Fill(0x00);

  while (order < CurrentScreen->ObjectsCount) {
    if (label_idx < CurrentScreen->LabelsCount) {
      local_label = GetLabel(label_idx);
      if (order == local_label->Order) {
        label_idx++;
        order++;
        if(local_label->chnged==1){
           DrawLabel(local_label);
           local_label->chnged=0;
           }
      }
    }

    if (clabel_idx < CurrentScreen->CLabelsCount) {
      local_clabel = GetCLabel(clabel_idx);
      if (order == local_clabel->Order) {
        clabel_idx++;
        order++;
  //       DrawCLabel(local_clabel);
      }
    }

  }
  
4) modify the Start_TP function as follow

Code: Select all

void Start_TP() {
  Init_MCU();

  InitializeTouchPanel();

  // You can get calibration constants using touch panel calibration example
  TP_Set_Calibration_Consts(76, 917, 108, 906);    // Set calibration constants

  InitializeObjects();

}
5) modify the DrawLabel function as follow

Code: Select all

void DrawLabel(TLabel *ALabel) {
int x_pos, y_pos;
  x_pos = 0;
  y_pos = 0;
  if (ALabel->Visible == 1) {
    Glcd_Set_Font_Adv(ALabel->FontName, ALabel->Font_Color, _GLCD_HORIZONTAL);
    Glcd_Write_Text_Return_Pos(ALabel->Caption, ALabel->Left, ALabel->Top);
    x_pos = (int)ALabel->Left + ((int)(ALabel->Width - Glcd_caption_length) / 2);
    y_pos = (int)ALabel->Top + ((int)(ALabel->Height - Glcd_caption_height) / 2);
    if (x_pos > ALabel->Left) {
    Glcd_Write_Text_Adv("   ", x_pos, y_pos);
    //  glcd_rectangle(x_pos,y_pos,strlen(ALabel->Caption),y_pos+8,1);
     Glcd_Write_Text_Adv(ALabel->Caption, x_pos, y_pos);
    }
    else {
    Glcd_Write_Text_Adv("  ", ALabel->Left, ALabel->Top);
    //Glcd_Write_Text_Adv(ALabel->Caption, ALabel->Left, ALabel->Top);
    }
  }
}
6) modify the main function as follow

Code: Select all

void main() {
int j=0;
  char txt[7];
  Start_TP();
  DrawCLabel(&Label1);  // I draw the static labels just when I want
  while (1) {
     j++;
     if(j==255)
       j=0;
    Check_TP();
    IntToStr(j, Label2_Caption);
    Label2.chnged=1;
    DrawScreen(&Screen1); //I redraw the screen just with the objects I want

    Delay_ms(100);
  }

}
In this way I would redraw only the labels with the propery changed set to 1 but it doesn't run as i want because I don't succeed in clearing the label written before.

p.s.

I noticed there are new stantements not documented :
for examples Glcd_Write_Text_Return_Pos

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: How to write just the labels I want

#2 Post by janko.kaljevic » 12 Sep 2011 10:50

Hello Massimo,

Thanks for suggesting and your effort. I have forwarded this to our developers and we will consider it for one of the next releases.

We will also provide documentation for all visible functions in GLCD library.

Best regards.

Massimo
Posts: 126
Joined: 23 Jul 2008 22:49

Re: How to write just the labels I want

#3 Post by Massimo » 13 Sep 2011 22:28

Hi janko.kaljevic
thanks for answering but the aim of my issue was the impossibility to hide the drawing of a Label when there is a screen refresh.
Infact I comment the following statements :

Code: Select all

////  Glcd_Fill(0x00);
and

Code: Select all

//       DrawCLabel(local_clabel);
In this way I avoid to clear the screen and to draw all the CLabels but I don't succed in clearing the previous value of a Label
using the following code

Code: Select all

      Glcd_Write_Text_Adv("   ", x_pos, y_pos);
      Glcd_Write_Text_Adv(ALabel->Caption, x_pos, y_pos);
With the first Glcd_Write_Text_Adv statement I would clear the previous value and
with the second Glcd_Write_Text_Adv statement I would write the next value but it doesn't work as I would because it results overwriting the values instead of cleaning the previous value and then overwriting the new one

sovary
Posts: 7
Joined: 16 Aug 2010 11:36
Location: Iran

Re: How to write just the labels I want

#4 Post by sovary » 14 Sep 2011 15:29

Hi Massimo,
I read your modified code and it's very good idea but have some note that is:
1- if I want to redraw current screen or if I go to another screen and come back to current screen I have to set all the objects chnged property to 1. right? I know we can define a void function that can set all chnged property of current screen objects for first entrance to this screen, and I think it can be a good idea :wink:

2- about last part of your code:
Massimo wrote: In this way I avoid to clear the screen and to draw all the CLabels but I don't succed in clearing the previous value of a Label
using the following code

Code: Select all

      Glcd_Write_Text_Adv("   ", x_pos, y_pos);
      Glcd_Write_Text_Adv(ALabel->Caption, x_pos, y_pos);
With the first Glcd_Write_Text_Adv statement I would clear the previous value and
with the second Glcd_Write_Text_Adv statement I would write the next value but it doesn't work as I would because it results overwriting the values instead of cleaning the previous value and then overwriting the new one
you can use the following code:

Code: Select all

char temp[255] = "";
void DrawLabel(TLabel *ALabel) {
int x_pos, y_pos;
  x_pos = 0;
  y_pos = 0;
  if (ALabel->Visible == 1) {
    ALabel->Color = _clClear;
    Glcd_Set_Font_Adv(ALabel->FontName, ALabel->Font_Color, _GLCD_HORIZONTAL);
    Glcd_Write_Text_Return_Pos(ALabel->Caption, ALabel->Left, ALabel->Top);
    x_pos = (int)ALabel->Left + ((int)(ALabel->Width - Glcd_caption_length) / 2);
    y_pos = (int)ALabel->Top + ((int)(ALabel->Height - Glcd_caption_height) / 2);
    if (x_pos > ALabel->Left) {
     Glcd_Write_Text_Adv(temp, x_pos, y_pos);
    }
    else {
     Glcd_Write_Text_Adv(temp, ALabel->Left, ALabel->Top);
    } 

    ALabel->Color = _clDraw;   
    Glcd_Set_Font_Adv(ALabel->FontName, ALabel->Font_Color, _GLCD_HORIZONTAL);
    Glcd_Write_Text_Return_Pos(ALabel->Caption, ALabel->Left, ALabel->Top);
    x_pos = (int)ALabel->Left + ((int)(ALabel->Width - Glcd_caption_length) / 2);
    y_pos = (int)ALabel->Top + ((int)(ALabel->Height - Glcd_caption_height) / 2);
    if (x_pos > ALabel->Left) {
     Glcd_Write_Text_Adv(ALabel->Caption, x_pos, y_pos);
    }
    else {
     Glcd_Write_Text_Adv(ALabel->Caption, ALabel->Left, ALabel->Top);
    }
   strcpy(temp,ALabel->Caption);
  }
}
I think it can work for ks108,
I'm now working with T6963 240x128 for a project and I solve such these problem with the ability of this Glcd chip that have two page of Graphic panel and I can switch to one of them and write on that panel but show the other panel and when I toggle the panel I can clear last written panel that it doesn't seen! also it prevent blinking of changing objects! I'll write more about my work on this project soon, sorry I'm now in factory and have not enough time for more.

sorry for my weak english,
I'm iranian, and here we speak english rarely.

regards,
Shervin

Massimo
Posts: 126
Joined: 23 Jul 2008 22:49

Re: How to write just the labels I want

#5 Post by Massimo » 26 Sep 2011 22:32

Hi Shervin,
thanks for your suggestion but it doesn't work
Can everyone give me an advice since I don't succeed in resolving the issue?


thanks

Post Reply

Return to “Visual GLCD General”