HMG Graph based on Bos Taurus

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: HMG Graph based on Bas Taurus

Post by srvet_claudio »

andyglezl wrote:Hola
Será posible que la función BT_DrawText()
"reconozca" los saltos de linea del texto enviado como parametro ?
--------------------------------------------------------------------------------
Hello
It is possible that the function BT_DrawText()
"recognize" the line breaks of the text sent as a parameter ?


cText := ""
cText += "algo de texto..." + HB_OsNewLine()
cText += "algo de texto..." + HB_OsNewLine()
cText += "algo de texto..." + HB_OsNewLine()

BT_DrawText (hDC, Row, Col, cText, cFontName, nFontSize, aFontColor, aBackColor, nTypeText, nAlingText, nOrientation)
Yes, it is possible as in: _hmg_hpdf_drawtext
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: HMG Graph based on Bas Taurus

Post by andyglezl »

Hola Dr. Soto

Ya revise la parte que me indica pero se me dificulta entenderle a las variables "_HMG_SYSDATA [ 150 ]"
y otras cosas, pense que con solo añadir "DT_WORDBREAK" a la funcion BT_DrawText( ) seria suficiente.

Me pudiera dar otras pistas de como hacerlo ? Gracias.
------------------------------------------------------------------------------------------------------------------------------
Hello Dr. Soto

And review the part that tells me but I understand the variables difficult "_HMG_SYSDATA [150]"
and other things, I thought that just add "DT_WORDBREAK" to BT_DrawText () function would be enough.

I could give other clues on how to do? Thank you.
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: HMG Graph based on Bas Taurus

Post by srvet_claudio »

andyglezl wrote:Hola Dr. Soto

Ya revise la parte que me indica pero se me dificulta entenderle a las variables "_HMG_SYSDATA [ 150 ]"
y otras cosas, pense que con solo añadir "DT_WORDBREAK" a la funcion BT_DrawText( ) seria suficiente.

Me pudiera dar otras pistas de como hacerlo ? Gracias.
------------------------------------------------------------------------------------------------------------------------------
Hello Dr. Soto

And review the part that tells me but I understand the variables difficult "_HMG_SYSDATA [150]"
and other things, I thought that just add "DT_WORDBREAK" to BT_DrawText () function would be enough.

I could give other clues on how to do? Thank you.
See this demo:

Code: Select all

*******************************************************************************
* PROGRAMA: Demo ON PAINT event
* LENGUAJE: HMG
* FECHA:    Setiembre 2012
* AUTOR:    Dr. CLAUDIO SOTO
* PAIS:     URUGUAY
* E-MAIL:   srvet@adinet.com.uy
* BLOG:     http://srvet.blogspot.com
*******************************************************************************


#include "hmg.ch"


FUNCTION MAIN

   DEFINE WINDOW Win1;
       AT 0,0;
       WIDTH  800;
       HEIGHT 600;
       MAIN;
       ON PAINT Proc_ON_PAINT ()

   END WINDOW

   CENTER WINDOW Win1
   ACTIVATE WINDOW Win1

RETURN Nil



PROCEDURE Proc_ON_PAINT
LOCAL nTypeText, cText
LOCAL hDC, BTstruct

  hDC = BT_CreateDC ("Win1", BT_HDC_INVALIDCLIENTAREA, @BTstruct)
  
   nTypeText  := /*BT_TEXT_TRANSPARENT +*/ BT_TEXT_BOLD + BT_TEXT_ITALIC + BT_TEXT_UNDERLINE    
   
   cText := "The Power" + hb_osNewLine() + "of HMG"
   
   BT_DrawTextEx (hDC, 150, 150, 1000, 1000, cText, "Comic Sans MS", 42, YELLOW, BLACK, nTypeText, BT_TEXT_LEFT)
   
  BT_DeleteDC (BTstruct) 

RETURN 


Function BT_DrawTextEx (hDC, Row, Col, Width, Height, cText, cFontName, nFontSize, aFontColor, aBackColor, nTypeText, nAlingText, nOrientation)
   aFontColor   := IF (ValType(aFontColor)   == "U", BLACK,                        aFontColor)
   aBackColor   := IF (ValType(aBackColor)   == "U", WHITE,                        aBackColor)
   nTypeText    := IF (ValType(nTypeText)    == "U", BT_TEXT_OPAQUE,               nTypeText)
   nAlingText   := IF (ValType(nAlingText)   == "U", (BT_TEXT_LEFT + BT_TEXT_TOP), nAlingText)
   nOrientation := IF (ValType(nOrientation) == "U", BT_TEXT_NORMAL_ORIENTATION,   nOrientation)
   BT_DRAW_HDC_DRAWTEXT (hDC, Col, Row, Width, Height, cText, cFontName, nFontSize, ArrayRGB_TO_COLORREF(aFontColor), ArrayRGB_TO_COLORREF(aBackColor), nTypeText, nAlingText, nOrientation)
Return Nil



#pragma BEGINDUMP
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"
#include <windows.h>
#include "hbapi.h"


//****************************************************************************************************************
//* BT_DRAW_HDC_DRAWTEXT (hDC, x, y, w, h, Text, FontName, FontSize, Text_Color, Back_color, Type, Align, Action)
//****************************************************************************************************************

// Type
#define BT_TEXT_OPAQUE      0
#define BT_TEXT_TRANSPARENT 1

#define BT_TEXT_BOLD        2
#define BT_TEXT_ITALIC      4
#define BT_TEXT_UNDERLINE   8
#define BT_TEXT_STRIKEOUT   16


// Align
#define BT_TEXT_LEFT        0
#define BT_TEXT_CENTER      6
#define BT_TEXT_RIGHT       2

#define BT_TEXT_TOP         0  
#define BT_TEXT_BASELINE   24
#define BT_TEXT_BOTTOM      8 


HB_FUNC (BT_DRAW_HDC_DRAWTEXT)
{
   HDC  hDC;
   HFONT hFont;
   TCHAR *Text, *FontName;
   INT FontSize;
   INT x, y, w, h;
   COLORREF Text_Color, Back_Color;
   INT Type, Align;
   double Orientation;

   INT Bold = FW_NORMAL;
   INT Italic = 0, Underline = 0, StrikeOut = 0;


   hDC         = (HDC)      HMG_parnl (1);
   x           = (INT)      hb_parni  (2);
   y           = (INT)      hb_parni  (3);
   w           = (INT)      hb_parni  (4);
   h           = (INT)      hb_parni  (5);
   Text        = (TCHAR *)  HMG_parc  (6);
   FontName    = (TCHAR *)  HMG_parc  (7);
   FontSize    = (INT)      hb_parni  (8);
   Text_Color  = (COLORREF) hb_parnl  (9);
   Back_Color  = (COLORREF) hb_parnl (10);
   Type        = (INT)      hb_parni (11);
   Align       = (INT)      hb_parni (12);
   Orientation = (double)   hb_parnd (13);


   if ((Orientation < (double) -360.0) || (Orientation > (double) 360.0))
       Orientation = (double) 0.0;
       
   Orientation = Orientation * (double) 10.0;   // Angle in tenths of degrees
   
   if ((Type & BT_TEXT_TRANSPARENT) == BT_TEXT_TRANSPARENT)
       SetBkMode(hDC, TRANSPARENT);
   else    
       SetBkColor(hDC, Back_Color);
   
   if ((Type & BT_TEXT_BOLD) == BT_TEXT_BOLD)
       Bold = FW_BOLD;
   
   if ((Type & BT_TEXT_ITALIC) == BT_TEXT_ITALIC)    
       Italic = 1;
   
   if ((Type & BT_TEXT_UNDERLINE) == BT_TEXT_UNDERLINE)       
       Underline = 1;
       
   if ((Type & BT_TEXT_STRIKEOUT) == BT_TEXT_STRIKEOUT)    
       StrikeOut = 1;
   
   SetGraphicsMode (hDC, GM_ADVANCED);

   FontSize = FontSize * GetDeviceCaps (hDC, LOGPIXELSY) / 72;

        // CreateFont (Height, Width, Escapement, Orientation, Weight, Italic, Underline, StrikeOut, 
        //             CharSet, OutputPrecision, ClipPrecision, Quality, PitchAndFamily, Face);
   hFont = CreateFont (0-FontSize, 0, (int)Orientation, (int)Orientation, Bold, Italic, Underline, StrikeOut,
           DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, FontName);
   
   SelectObject (hDC, hFont);
  
   SetTextColor (hDC, Text_Color);
   
   RECT rect;
   SetRect (&rect, x, y, x+w, y+h);
   
   DrawText (hDC, Text, -1, &rect, DT_NOCLIP | DT_WORDBREAK | /*DT_EXTERNALLEADING |*/ DT_NOPREFIX | Align);

   DeleteObject (hFont);   
}

#pragma ENDDUMP
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: HMG Graph based on Bas Taurus

Post by andyglezl »

Gracias Dr. Claudio, le daré una vista
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: HMG Graph based on Bas Taurus

Post by andyglezl »

Bueno, despues de muchos dias de desvelo, les muestro lo que logré hacer con
HMG 3.4 y Bos Taurus.
-----------------------------------------------------------------------------------------------
Well, after many sleepless days, I show you what I got to do with
HMG 3.4 and Bos Taurus.
NatGeoSample.jpg
NatGeoSample.jpg (267.6 KiB) Viewed 4408 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HMG Graph based on Bas Taurus

Post by Rathinagiri »

Wow! Looks so professional. The horizontal bar graph is so good! I like it a lot.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: HMG Graph based on Bas Taurus

Post by andyglezl »

Gracias Rathinagiri
Bueno, tal vez tu puedas integrarlo al gran trabajo que has hecho con Graficas y Bos Taurus
-------------------------------------------------------------------------------------------------------------
Thanks Rathinagiri
Well, maybe you can integrate the great work you've done with Bos Taurus and Graphics

Code: Select all


#include "hmg.ch"


FUNCTION MAIN

   DEFINE WINDOW Win1 AT 0,0 WIDTH  600 HEIGHT 400 MAIN	ON PAINT Proc_ON_PAINT () BACKCOLOR { 47, 79, 79 }  TITLE "Gráfica de Barras Horizontal - By AndyGlezL"
	   
   END WINDOW
   CENTER WINDOW Win1
   ACTIVATE WINDOW Win1

RETURN Nil
PROCEDURE Proc_ON_PAINT
	LOCAL nTypeText, cText
	LOCAL hDC, BTstruct
	LOCAL i1, nRen := 0, nCol := 0
	PRIVATE	aCols    := { { 255, 204, 0 } , { 254, 133, 0 } , { 255, 39, 0 } , { 255, 111, 159 }  , {255, 0, 254 } , {82, 0, 82 }, ;
						  { 183, 0, 132 } , { 82, 1, 254 } , { 0, 133, 255 } , { 0, 0, 255 } , { 0, 133, 0 } , { 102, 102, 51 } } 
	PRIVATE	aAyos    := { "2010", "2011", "2012", "2013", "2014", "2015" } 
	PRIVATE	aSerVal  := { 20280, 15420, 12870, 8347, 6540, 4056 }
	
	hDC = BT_CreateDC( "Win1", BT_HDC_INVALIDCLIENTAREA, @BTstruct)
	
		*--------  GRAFICO DE BARRAS HORIZONTAL  ----------------------------------------------------------------
		nRen += 120	;	nCol := 150
		FOR i1 = 1 TO LEN( aSerVal )
			nShadow  := ClrShadow( aCols[ i1 ], 40 )
			nShadow2 := { GetRed( nShadow ), GetGreen( nShadow ), GetBlue( nShadow ) }
			BT_DrawGradientFillHorizontal( hDC, nRen, nCol, aSerVal[ i1 ] / 100, 30, nShadow2, aCols[ i1 ]  )	//  Barra con Gradiente
			BT_DrawLine( hDC, nRen+3 , nCol+1,  nRen+3, nCol+( aSerVal[ i1 ] / 100 )-1, WHITE , 2 )				//	Linea Brillo
			BT_DrawLine( hDC, nRen+28, nCol+1, nRen+28, nCol+( aSerVal[ i1 ] / 100 )-1, { 105, 105, 105 } , 1 )	//	Linea Sombra
			nTypeText  := BT_TEXT_TRANSPARENT + BT_TEXT_BOLD // + BT_TEXT_ITALIC + BT_TEXT_UNDERLINE 			//	nAlingText := BT_TEXT_CENTER + BT_TEXT_BASELINE 
			BT_DrawText( hDC, nRen+4, nCol+5, aAyos[ i1 ], "Verdana", 8, BLUE, WHITE, nTypeText, BT_TEXT_LEFT  )		// Titulos
			BT_DrawText( hDC, nRen+13, nCol+( aSerVal[ i1 ] / 100 ), TRANSFORM( aSerVal[ i1 ], "99,999" )+" ",  ;		// Valores
						"Verdana", 8, BLACK, WHITE, nTypeText, BT_TEXT_RIGHT )
			*------------  BARRAS NEGATIVAS   ---------------------------------------
			nCol2 := nCol + aSerVal[ i1 ] / 100
			IF i1 > 1																														//  Primer Barra sin negativos
				BT_DrawGradientFillHorizontal( hDC, nRen, nCol2+3, ( ( aSerVal[ 1 ] - aSerVal[ i1 ] ) / 100 )-3, 30, { 250, 128, 114 }, RED  )	//  Barra con Gradiente
				BT_DrawLine( hDC, nRen+3 , nCol2+1,  nRen+3, nCol2+( ( aSerVal[ 1 ] - aSerVal[ i1 ] ) / 100 )-3, WHITE , 2 )				//	Linea Brillo
				BT_DrawLine( hDC, nRen+28, nCol2+1, nRen+28, nCol2+( ( aSerVal[ 1 ] - aSerVal[ i1 ] ) / 100 )-3, { 105, 105, 105 } , 1 )	//	Linea Sombra
				nTypeText  := BT_TEXT_TRANSPARENT + BT_TEXT_BOLD // + BT_TEXT_ITALIC + BT_TEXT_UNDERLINE 			//	nAlingText := BT_TEXT_CENTER + BT_TEXT_BASELINE 
				BT_DrawText( hDC, nRen+13, nCol2+( ( aSerVal[ 1 ] - aSerVal[ i1 ] ) / 100 ), TRANSFORM( aSerVal[ 1 ] - aSerVal[ i1 ], "-99,999" )+" ",  ;		// Valores
								"Verdana", 8, WHITE, WHITE, BT_TEXT_TRANSPARENT, BT_TEXT_RIGHT )
			ENDIF
			*---------------------------------------------------
			nRen += 37
		NEXT

	BT_DeleteDC (BTstruct)
RETURN
STATIC FUNCTION ClrShadow( nColor, nFactor )
   LOCAL aHSL, aRGB

   aHSL := RGB2HSL( GetRed(nColor), GetGreen(nColor), GetBlue(nColor) )
   aHSL[3] -= nFactor
   aRGB := HSL2RGB( aHSL[1], aHSL[2], aHSL[3] )

RETURN RGB( aRGB[1], aRGB[2], aRGB[3] )
STATIC FUNCTION RGB2HSL( nR, nG, nB )
   LOCAL nMax, nMin
   LOCAL nH, nS, nL

   IF nR < 0
      nR := Abs( nR )
      nG := GetGreen( nR )
      nB := GetBlue( nR )
      nR := GetRed( nR )
   ENDIF

   nR := nR / 255
   nG := nG / 255
   nB := nB / 255
   nMax := Max( nR, Max( nG, nB ) )
   nMin := Min( nR, Min( nG, nB ) )
   nL := ( nMax + nMin ) / 2

   IF nMax = nMin
      nH := 0
      nS := 0
   ELSE
      IF nL < 0.5
         nS := ( nMax - nMin ) / ( nMax + nMin )
      ELSE
         nS := ( nMax - nMin ) / ( 2.0 - nMax - nMin )
      ENDIF
      DO CASE
         CASE nR = nMax
            nH := ( nG - nB ) / ( nMax - nMin )
         CASE nG = nMax
            nH := 2.0 + ( nB - nR ) / ( nMax - nMin )
         CASE nB = nMax
            nH := 4.0 + ( nR - nG ) / ( nMax - nMin )
      ENDCASE
   ENDIF

   nH := Int( (nH * 239) / 6 )
   IF nH < 0 ; nH += 240 ; ENDIF
   nS := Int( nS * 239 )
   nL := Int( nL * 239 )

RETURN { nH, nS, nL }
STATIC FUNCTION HSL2RGB( nH, nS, nL )
   LOCAL nFor
   LOCAL nR, nG, nB
   LOCAL nTmp1, nTmp2, aTmp3 := { 0, 0, 0 }

   nH /= 239
   nS /= 239
   nL /= 239
   IF nS == 0
      nR := nL
      nG := nL
      nB := nL
   ELSE
      IF nL < 0.5
         nTmp2 := nL * ( 1 + nS )
      ELSE
         nTmp2 := nL + nS - ( nL * nS )
      ENDIF
      nTmp1 := 2 * nL - nTmp2
      aTmp3[1] := nH + 1 / 3
      aTmp3[2] := nH
      aTmp3[3] := nH - 1 / 3
      FOR nFor := 1 TO 3
         IF aTmp3[nFor] < 0
            aTmp3[nFor] += 1
         ENDIF
         IF aTmp3[nFor] > 1
            aTmp3[nFor] -= 1
         ENDIF
         IF 6 * aTmp3[nFor] < 1
            aTmp3[nFor] := nTmp1 + ( nTmp2 - nTmp1 ) * 6 * aTmp3[nFor]
         ELSE
            IF 2 * aTmp3[nFor] < 1
               aTmp3[nFor] := nTmp2
            ELSE
               IF 3 * aTmp3[nFor] < 2
                  aTmp3[nFor] := nTmp1 + ( nTmp2 - nTmp1 ) * ( ( 2 / 3 ) - aTmp3[nFor] ) * 6
               ELSE
                  aTmp3[nFor] := nTmp1
               ENDIF
            ENDIF
         ENDIF
      NEXT nFor
      nR := aTmp3[1]
      nG := aTmp3[2]
      nB := aTmp3[3]
   ENDIF

RETURN { Int( nR * 255 ), Int( nG * 255 ), Int( nB * 255 ) }
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HMG Graph based on Bas Taurus

Post by Rathinagiri »

Thanks a lot Andy. I will sure incorporate your code in the next version.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: HMG Graph based on Bas Taurus

Post by serge_girard »

Thank you Andy!

Serge
There's nothing you can do that can't be done...
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: HMG Graph based on Bas Taurus

Post by bpd2000 »

Thank Mr. Andy for sharing nice code
BPD
Convert Dream into Reality through HMG
Post Reply