Skip to content

Commit

Permalink
Added simple method to draw triangles
Browse files Browse the repository at this point in the history
  • Loading branch information
amerino committed May 18, 2017
1 parent 4fc47cd commit 3bd9645
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 12 deletions.
95 changes: 83 additions & 12 deletions ugui.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* -------------------------------------------------------------------------------- */
/* -- µGUI - Generic GUI module (C)Achim Döbler, 2015 -- */
/* -- µGUI - Generic GUI module (C)Achim Döbler, 2015 -- */
/* -------------------------------------------------------------------------------- */
// µGUI is a generic GUI module for embedded systems.
// µGUI is a generic GUI module for embedded systems.
// This is a free software that is open for education, research and commercial
// developments under license policy of following terms.
//
// Copyright (C) 2015, Achim Döbler, all rights reserved.
// URL: http://www.embeddedlightning.com/
//
// * The µGUI module is a free software and there is NO WARRANTY.
// * The µGUI module is a free software and there is NO WARRANTY.
// * No restriction on use. You can use, modify and redistribute it for
// personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
// * Redistributions of source code must retain the above copyright notice.
Expand All @@ -27,7 +27,7 @@
// for giving valuable suggestions regarding real-time os support.
//
// Samuel Kleiser
// for reporting bugs and giving examples how to improve µGUI.
// for reporting bugs and giving examples how to improve µGUI.
/* -------------------------------------------------------------------------------- */
/* -- REVISION HISTORY -- */
/* -------------------------------------------------------------------------------- */
Expand Down Expand Up @@ -4734,6 +4734,77 @@ void UG_DrawFrame( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_COLOR c )
UG_DrawLine(x2,y1,x2,y2,c);
}

void UG_DrawTriangle( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_U8 h, UG_COLOR c )
{
if (h == 0) {
UG_DrawLine(x1,y1,x2,y1,c); //horizontal
UG_DrawLine(x1,y1,(x2-x1)/2+x1,y2,c);
UG_DrawLine(x2,y1,(x2-x1)/2+x1,y2,c);
} else {
UG_DrawLine(x1,y1,x1,y2,c); //vertical
UG_DrawLine(x1,y1,x2,(y2-y1)/2+y1,c);
UG_DrawLine(x1,y2,x2,(y2-y1)/2+y1,c);
}
}

void UG_FillTriangle(UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_U8 h, UG_COLOR c )
{
UG_S16 n,m;

/* Is hardware acceleration available? */
/*if ( gui->driver[DRIVER_FILL_FRAME].state & DRIVER_ENABLED )
{
if( ((UG_RESULT(*)(UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_COLOR c))gui->driver[DRIVER_FILL_FRAME].driver)(x1,y1,x2,y2,c) == UG_RESULT_OK ) return;
}*/
if (h == 0) {

if ( x2 < x1 )
{
n = x2;
x2 = x1;
x1 = n;
}
/*if ( y2 > y1 )
{
n = y2;
y2 = y1;
y1 = n;
}*/

for( n=x1; n<=x2; n++ )
{
UG_DrawLine(n,y1,(x2-x1)/2+x1,y2,c);
//gui->pset(n,m,c);
}
} else {

/*if ( x2 < x1 )
{
n = x2;
x2 = x1;
x1 = n;
}*/
if ( y1 > y2 )
{
n = y1;
y1 = y2;
y2 = n;
}

for( n=y1; n<=y2; n++ )
{
UG_DrawLine(x1,n,x2,(y2-y1)/2+y1,c);
//gui->pset(n,m,c);
}


}

//x1++;
//x2--;
//}
}

void UG_DrawRoundFrame( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_S16 r, UG_COLOR c )
{
UG_S16 n;
Expand Down Expand Up @@ -5277,14 +5348,14 @@ void _UG_PutChar( char chr, UG_S16 x, UG_S16 y, UG_COLOR fc, UG_COLOR bc, const

switch ( bt )
{
case 0xF6: bt = 0x94; break; //
case 0xD6: bt = 0x99; break; //
case 0xFC: bt = 0x81; break; //
case 0xDC: bt = 0x9A; break; //
case 0xE4: bt = 0x84; break; //
case 0xC4: bt = 0x8E; break; //
case 0xB5: bt = 0xE6; break; //
case 0xB0: bt = 0xF8; break; //
case 0xF6: bt = 0x94; break; // ö
case 0xD6: bt = 0x99; break; // Ö
case 0xFC: bt = 0x81; break; // ü
case 0xDC: bt = 0x9A; break; // Ü
case 0xE4: bt = 0x84; break; // ä
case 0xC4: bt = 0x8E; break; // Ä
case 0xB5: bt = 0xE6; break; // µ
case 0xB0: bt = 0xF8; break; // °
}

if (bt < font->start_char || bt > font->end_char) return;
Expand Down
2 changes: 2 additions & 0 deletions ugui.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,8 @@ UG_GUI* UG_GetGUI( );
void UG_FontSelect( const UG_FONT* font );
void UG_FillScreen( UG_COLOR c );
void UG_FillFrame( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_COLOR c );
void UG_DrawTriangle(UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_U8 h, UG_COLOR c );
void UG_FillTriangle( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_U8 h, UG_COLOR c );
void UG_FillRoundFrame( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_S16 r, UG_COLOR c );
void UG_DrawMesh( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_COLOR c );
void UG_DrawFrame( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_COLOR c );
Expand Down

0 comments on commit 3bd9645

Please sign in to comment.