From 3bd9645079cd36549a682b6d9894198fdf5bd4a3 Mon Sep 17 00:00:00 2001 From: amerino Date: Thu, 18 May 2017 16:44:06 +0200 Subject: [PATCH] Added simple method to draw triangles --- ugui.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- ugui.h | 2 ++ 2 files changed, 85 insertions(+), 12 deletions(-) diff --git a/ugui.c b/ugui.c index c33c8ba..afc15a4 100644 --- a/ugui.c +++ b/ugui.c @@ -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. @@ -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 -- */ /* -------------------------------------------------------------------------------- */ @@ -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; @@ -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; diff --git a/ugui.h b/ugui.h index c0df1d1..81d0997 100644 --- a/ugui.h +++ b/ugui.h @@ -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 );