@@ -901,6 +901,214 @@ void LCDPutBgImgMusic(){
901
901
}
902
902
}
903
903
904
+ void DrawLine (int x1 , int y1 , int x2 , int y2 , colors color )
905
+ {
906
+ int W = x2 - x1 ;
907
+ int H = y2 - y1 ;
908
+ int dx = 0 ;
909
+ int dy = 0 ;
910
+ int Wy = 0 ;
911
+ int Hx = 0 ;
912
+ if (W >= H )
913
+ {
914
+ for (dx = 0 ; dx <= W ; dx ++ )
915
+ {
916
+ LCDSetGramAddr (x1 + dx , y1 + dy );
917
+ LCDPutCmd (0x0022 );
918
+ LCDPutData (colorc [color ]);
919
+ Hx += H ;
920
+ if (Wy < Hx )
921
+ {
922
+ Wy += W ;
923
+ dy += 1 ;
924
+ }
925
+ }
926
+ }
927
+ else
928
+ {
929
+ for (dy = 0 ; dy <= H ; dy ++ )
930
+ {
931
+ LCDSetGramAddr (x1 + dx , y1 + dy );
932
+ LCDPutCmd (0x0022 );
933
+ LCDPutData (colorc [color ]);
934
+
935
+ Wy += W ;
936
+ if (Hx < Wy )
937
+ {
938
+ Hx += H ;
939
+ dx += 1 ;
940
+ }
941
+ }
942
+ }
943
+ }
944
+
945
+ __attribute__( ( always_inline ) ) __INLINE void LCDPset (uint16_t x , uint16_t y , colors color ){
946
+ LCDSetGramAddr (x , y );
947
+ LCDPutCmd (0x0022 );
948
+ LCDPutData (colorc [color ]);
949
+ }
950
+
951
+ __attribute__( ( always_inline ) ) __INLINE void LCDPset2 (uint16_t x , uint16_t y , uint16_t data ){
952
+ LCDSetGramAddr (x , y );
953
+ LCDPutCmd (0x0022 );
954
+ LCDPutData (data );
955
+ }
956
+
957
+
958
+ __attribute__( ( always_inline ) ) __INLINE uint16_t LCDGetPos (uint16_t x , uint16_t y ){
959
+ LCDSetGramAddr (x , y );
960
+ LCDPutCmd (0x0022 );
961
+ LCD -> RAM ;
962
+ return LCD -> RAM ;
963
+ }
964
+
965
+ void LCDDrawLine2 (int16_t sPosX , int16_t sPosY , int16_t ePosX , int16_t ePosY , colors color ){
966
+ int dw , dh , e , x , y ;
967
+
968
+ dw = ePosX - sPosX ;
969
+ dh = ePosY - sPosY ;
970
+
971
+ e = 0 ;
972
+
973
+ if (dw >= dh ){
974
+ y = sPosY ;
975
+ for (x = sPosX ;x <= ePosX ;x ++ ){
976
+ LCDPset (x , y , color );
977
+
978
+ e += 2 * dh ;
979
+ if (e >= (2 * dw )){
980
+ y ++ ;
981
+ e -= 2 * dw ;
982
+ }
983
+ }
984
+ } else {
985
+
986
+ }
987
+ }
988
+
989
+ void LCDDrawLine (uint16_t sPosX , uint16_t sPosY , uint16_t ePosX , uint16_t ePosY , colors color ){
990
+ int x , y , w , h , offsetY ;
991
+ float delta , alpha ;
992
+ pixel_fmt_typedef pixel_fg , pixel_bg , pixel ;
993
+
994
+ w = ePosX - sPosX ;
995
+ h = ePosY - sPosY ;
996
+
997
+ // debug.printf("\r\n\nPlot");
998
+ // debug.printf("\r\ndelta:%f", delta);
999
+ // debug.printf("\r\noffsetY:%d", offsetY);
1000
+
1001
+ if (abs (w ) >= abs (h )){
1002
+ if (ePosX == sPosX ){
1003
+ offsetY = sPosY + 0.5f ;
1004
+ for (x = sPosX ;x <= ePosX ;x ++ ){
1005
+ y = offsetY ;
1006
+ LCDPset (x , y , color );
1007
+ }
1008
+ return ;
1009
+ }
1010
+
1011
+ delta = (float )h / (float )w ;
1012
+ offsetY = - delta * sPosX + sPosY + 0.5f ;
1013
+
1014
+ if (ePosX >= sPosX ){
1015
+ for (x = sPosX ;x <= ePosX ;x ++ ){
1016
+ y = delta * x + offsetY ;
1017
+ alpha = delta * x + offsetY ;
1018
+ alpha = 1.0f - (alpha - y );
1019
+ pixel_bg .color .d16 = LCDGetPos (x , y );
1020
+ pixel_fg .color .d16 = colorc [color ];
1021
+ pixel .color .R = pixel_fg .color .R * alpha + pixel_bg .color .R * (1.0f - alpha );
1022
+ pixel .color .G = pixel_fg .color .G * alpha + pixel_bg .color .G * (1.0f - alpha );
1023
+ pixel .color .B = pixel_fg .color .B * alpha + pixel_bg .color .B * (1.0f - alpha );
1024
+ LCDPset2 (x , y , pixel .color .d16 );
1025
+ debug .printf ("\r\nA x:%d y:%d delta:%f" , x , y , delta );
1026
+ // LCDPset(x, y, color);
1027
+ }
1028
+ } else {
1029
+ for (x = sPosX ;x >= ePosX ;x -- ){
1030
+ y = delta * x + offsetY ;
1031
+
1032
+ alpha = delta * x + offsetY ;
1033
+ alpha = 1.0f - (alpha - y );
1034
+ pixel_bg .color .d16 = LCDGetPos (x , y );
1035
+ pixel_fg .color .d16 = colorc [color ];
1036
+ pixel .color .R = pixel_fg .color .R * alpha + pixel_bg .color .R * (1.0f - alpha );
1037
+ pixel .color .G = pixel_fg .color .G * alpha + pixel_bg .color .G * (1.0f - alpha );
1038
+ pixel .color .B = pixel_fg .color .B * alpha + pixel_bg .color .B * (1.0f - alpha );
1039
+ LCDPset2 (x , y , pixel .color .d16 );
1040
+
1041
+ debug .printf ("\r\nB x:%d y:%d delta:%f" , x , y , delta );
1042
+ // LCDPset(x, y, color);
1043
+ }
1044
+ }
1045
+ } else {
1046
+ if (ePosY >= sPosY ){
1047
+ if (sPosX == ePosX ){
1048
+ for (y = sPosY ;y <= ePosY ;y ++ ){
1049
+ x = sPosX ;
1050
+ // debug.printf("\r\nC0 x:%d y:%d delta:%f", x, y, delta);
1051
+ LCDPset (x , y , color );
1052
+ }
1053
+ } else {
1054
+ delta = (float )h / (float )w ;
1055
+ offsetY = - delta * sPosX + sPosY + 0.5f ;
1056
+ delta = 1.0f / delta ;
1057
+
1058
+ for (y = sPosY ;y <= ePosY ;y ++ ){
1059
+ x = (y - offsetY ) * delta ;
1060
+ debug .printf ("\r\nC x:%d y:%d delta:%f" , x , y , delta );
1061
+ LCDPset (x , y , color );
1062
+
1063
+ alpha = (y - offsetY ) * delta ;
1064
+ alpha = 1.0f - (alpha - x );
1065
+ pixel_bg .color .d16 = LCDGetPos (x - 1 , y );
1066
+ pixel_fg .color .d16 = colorc [color ];
1067
+ pixel .color .R = pixel_fg .color .R * alpha + pixel_bg .color .R * (1.0f - alpha );
1068
+ pixel .color .G = pixel_fg .color .G * alpha + pixel_bg .color .G * (1.0f - alpha );
1069
+ pixel .color .B = pixel_fg .color .B * alpha + pixel_bg .color .B * (1.0f - alpha );
1070
+ LCDPset2 (x - 1 , y , pixel .color .d16 );
1071
+
1072
+ alpha = 1.0f - alpha ;
1073
+ pixel_bg .color .d16 = LCDGetPos (x + 1 , y );
1074
+ pixel_fg .color .d16 = colorc [color ];
1075
+ pixel .color .R = pixel_fg .color .R * alpha + pixel_bg .color .R * (1.0f - alpha );
1076
+ pixel .color .G = pixel_fg .color .G * alpha + pixel_bg .color .G * (1.0f - alpha );
1077
+ pixel .color .B = pixel_fg .color .B * alpha + pixel_bg .color .B * (1.0f - alpha );
1078
+ LCDPset2 (x + 1 , y , pixel .color .d16 );
1079
+ }
1080
+ }
1081
+ } else {
1082
+ if (sPosX == ePosX ){
1083
+ for (y = sPosY ;y >= ePosY ;y -- ){
1084
+ x = sPosX ;
1085
+ // debug.printf("\r\nD0 x:%d y:%d delta:%f", x, y, delta);
1086
+ LCDPset (x , y , color );
1087
+ }
1088
+ } else {
1089
+ delta = (float )h / (float )w ;
1090
+ offsetY = - delta * sPosX + sPosY + 0.5f ;
1091
+ delta = 1.0f / delta ;
1092
+
1093
+ for (y = sPosY ;y >= ePosY ;y -- ){
1094
+ x = (y - offsetY ) * delta ;
1095
+ alpha = (y - offsetY ) * delta ;
1096
+ alpha = 1.0f - (alpha - x );
1097
+ pixel_bg .color .d16 = LCDGetPos (x , y );
1098
+ pixel_fg .color .d16 = colorc [color ];
1099
+ pixel .color .R = pixel_fg .color .R * alpha + pixel_bg .color .R * (1.0f - alpha );
1100
+ pixel .color .G = pixel_fg .color .G * alpha + pixel_bg .color .G * (1.0f - alpha );
1101
+ pixel .color .B = pixel_fg .color .B * alpha + pixel_bg .color .B * (1.0f - alpha );
1102
+ LCDPset2 (x , y , pixel .color .d16 );
1103
+
1104
+ debug .printf ("\r\nD x:%d y:%d delta:%f" , x , y , delta );
1105
+ // LCDPset(x, y, color);
1106
+ }
1107
+ }
1108
+ }
1109
+ }
1110
+
1111
+ }
904
1112
905
1113
void LCDDrawSquare (uint16_t x , uint16_t y , uint16_t width , uint16_t height , colors color )
906
1114
{
0 commit comments