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;
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);
}
}
}
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();
}
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);
}
}
}
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);
}
}
p.s.
I noticed there are new stantements not documented :
for examples Glcd_Write_Text_Return_Pos