Draw border

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
esgici
Posts: 4457
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 336 times
Been thanked: 103 times
Contact:

Draw border

Post by esgici » Wed Sep 25, 2013 11:05 am

Hi All

Almost every control has their own border, except a few ones, like Label and image.

This is an humble work to search an easy way to draw a border around controls.

To your interest, critics and suggestions.
Screen shoot of test DrawBorder.png
Screen shoot of Test Draw Border prg
Screen shoot of test DrawBorder.png (153.72 KiB) Viewed 2103 times
TestBorder.zip
Source files for Test Draw Border prg
(66.13 KiB) Downloaded 230 times
By the way, I have a problem; please look at TestBorder.prg line 54-55;

will be appreciated your advice.

Happy HMG'ing :D
Last edited by esgici on Wed Sep 25, 2013 5:40 pm, edited 2 times in total.
Viva INTERNATIONAL HMG :D

User avatar
bpd2000
Posts: 1024
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 165 times
Been thanked: 72 times

Post by bpd2000 » Wed Sep 25, 2013 11:28 am

Nice
Thank you Esgici
Regards
BPD
Convert Dream into Reality through HMG

User avatar
bpd2000
Posts: 1024
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 165 times
Been thanked: 72 times

Post by bpd2000 » Wed Sep 25, 2013 11:47 am

Dear Esgici,
Interesting to me
Where to find more about HB_Default()
BPD
Convert Dream into Reality through HMG

User avatar
serge_girard
Posts: 2114
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 436 times
Been thanked: 95 times
Contact:

Post by serge_girard » Wed Sep 25, 2013 12:44 pm

Esgici,


Try msgbox with str(aColor [1]) + ' ' + str(aColor [2]) + ' ' + str(aColor [3]).

This should help !


Serge

User avatar
mol
Posts: 3042
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 171 times
Been thanked: 92 times
Contact:

Post by mol » Wed Sep 25, 2013 1:00 pm

Hi Esgici!
Your borders look amazing!
Tahks for sharing!
By the way, it's a pity we have no possibility to vertical align of value of label :-( It was possible in HMG4.

Maybe Rathi or Claudio can do such an improvement...

Regards, Marek

User avatar
esgici
Posts: 4457
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 336 times
Been thanked: 103 times
Contact:

Post by esgici » Wed Sep 25, 2013 1:31 pm

Hi Dave
bpd2000 wrote: Where to find more about HB_Default()
Thank to your interest and nice words :)

Sadly not found (at least I don't know) any documentation about HB_Default() :(

Based on my experience :

Code: Select all

#include <hmg.ch>

PROCEDURE Main()
   TestDefa()
RETURN // Main()  

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROCEDURE TestDefa( xParam )

   MsgDebug( "Before", xParam )       // NIL
   HB_Default( @xParam, 123 )         // IF NIL, assign 123
   MsgDebug( "After", xParam )        // 123
   
RETURN // TestDefa()   

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

Happy HMG'ing :D
Last edited by esgici on Wed Sep 25, 2013 1:45 pm, edited 1 time in total.
Viva INTERNATIONAL HMG :D

User avatar
esgici
Posts: 4457
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 336 times
Been thanked: 103 times
Contact:

Post by esgici » Wed Sep 25, 2013 1:32 pm

Hi Marek

Thank to your interest and nice words :)

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D

User avatar
esgici
Posts: 4457
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 336 times
Been thanked: 103 times
Contact:

Post by esgici » Wed Sep 25, 2013 1:42 pm

Hi Serge
serge_girard wrote: Try msgbox with str(aColor [1]) + ' ' + str(aColor [2]) + ' ' + str(aColor [3]).

This should help !
Thank to your interest and suggestion :)

I'm afraid that I couldn't tell :(

Problem isn't about Message function ( MsgDebug() is very good enhancement, thank to Dr. Soto ).

Problem is in border of image.

Please look at below image: while MsgDebug() is in screen, border seen fine,
before.png
Image border if message in it place
before.png (307.87 KiB) Viewed 2053 times
when Msg gone ( or replaced ) the border changes :(
after.png
Image border after message replaced
after.png (457.74 KiB) Viewed 2053 times
PS: don't look border of Label_4; this image is a bit older.

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 179 times

Post by Pablo César » Wed Sep 25, 2013 2:20 pm

Nice work Esgici, I liked !

As you said, the main problem is not based on Msg functions at all (it's my tip too). Even if you do not use msg function and minimize the main window, you will see border will be also changed. I believe it an tipic behaviour of API of OS and probably there is not solution for this... :(

But I find a way to put borders around IMAGEs:
Screen.PNG
Screen.PNG (77.9 KiB) Viewed 2042 times
I put an extra label with same size and position of IMAGE. This could it be not the best practice but could helps until get better solution.

Code: Select all

#include <hmg.ch>
#include "DrawBorder.ch"

Function Main()
* aMyColors := InitColors()

DEFINE WINDOW frmTestBorder AT 100 , 100 WIDTH 583 HEIGHT 385 ;
    TITLE "Test Border Function" ICON NIL MAIN ON INIT Draw_All() ;
    BACKCOLOR {230,230,216} 
    
    ON KEY ESCAPE OF frmTestBorder ACTION ThisWindow.Release

    DEFINE LABEL Label_1
        ROW    20
        COL    40
        WIDTH  120
        HEIGHT 20
        VALUE "Label_1"
        FONTNAME "Verdana"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        HELPID Nil
        VISIBLE .T.
        TRANSPARENT .F.
        ACTION Nil
        AUTOSIZE .F.
        BACKCOLOR NIL
        FONTCOLOR NIL
    END LABEL

    DEFINE LABEL Label_2
        ROW    80
        COL    40
        WIDTH  120
        HEIGHT 30
        VALUE "Label_2"
        FONTNAME "Verdana"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        HELPID Nil
        VISIBLE .T.
        TRANSPARENT .F.
        ACTION Nil
        AUTOSIZE .F.
        BACKCOLOR NIL
        FONTCOLOR NIL
    END LABEL

    DEFINE LABEL Label_3
        ROW    140
        COL    40
        WIDTH  120
        HEIGHT 60
        VALUE "Label_3"
        FONTNAME "Verdana"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        HELPID Nil
        VISIBLE .T.
        TRANSPARENT .F.
        ACTION Nil
        AUTOSIZE .F.
        BACKCOLOR NIL
        FONTCOLOR NIL
    END LABEL

    DEFINE BUTTON Button_1
        ROW    280
        COL    40
        WIDTH  100
        HEIGHT 28
        ACTION Nil
        CAPTION "Button_1"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_2
        ROW    280
        COL    220
        WIDTH  100
        HEIGHT 28
        ACTION Nil
        CAPTION "Button_2"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_3
        ROW    280
        COL    420
        WIDTH  100
        HEIGHT 28
        ACTION DrawWideBorder( "frmTestBorder", "Image_1", { 164, 260, 155 } )
        CAPTION "Button_3"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE LABEL Label_4
        ROW    230
        COL    40
        WIDTH  480
        HEIGHT 20
        VALUE "Label_4"
        FONTNAME "Verdana"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        HELPID Nil
        VISIBLE .T.
        TRANSPARENT .F.
        ACTION Nil
        AUTOSIZE .F.
        BACKCOLOR NIL
        FONTCOLOR NIL
    END LABEL
	
	DEFINE LABEL Label_5
        ROW    41
        COL    221
        WIDTH  300
        HEIGHT 150
        VALUE ""
        FONTNAME "Verdana"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        HELPID Nil
        VISIBLE .T.
        TRANSPARENT .F.
        ACTION Nil
        AUTOSIZE .F.
        BACKCOLOR NIL
        FONTCOLOR NIL
    END LABEL

    DEFINE IMAGE Image_1
        ROW    40
        COL    220
        WIDTH  300
        HEIGHT 150
        PICTURE "HMG_Unicode.PNG"
        HELPID Nil
        VISIBLE .T.
        STRETCH .F.
        ACTION Nil
    END IMAGE

END WINDOW  
*   frmTestBorder.Center
frmTestBorder.Activate
Return Nil

Function Draw_All()
DRAW BORDER WINDOW "frmTestBorder" CONTROL "Label_1" 
DRAW BORDER WINDOW "frmTestBorder" CONTROL "Label_2" PENWIDTH 3 UPCOLOR 1 DOWNCOLOR 0
DRAW BORDER WINDOW "frmTestBorder" CONTROL "Label_3" PENWIDTH 3 UPCOLOR 0 DOWNCOLOR 1
DRAW BORDER WINDOW "frmTestBorder" CONTROL "Label_4" PENWIDTH 3 UPCOLOR { 190, 210, 230 } DOWNCOLOR { 100, 149, 237 } 

DRAW BORDER WINDOW "frmTestBorder" CONTROL "Label_5" PENWIDTH 3 UPCOLOR 1 DOWNCOLOR 0

DRAW BORDER WINDOW "frmTestBorder" CONTROL "Button_1" 
DRAW BORDER WINDOW "frmTestBorder" CONTROL "Button_2" PENWIDTH 3 UPCOLOR 1 DOWNCOLOR 0
DRAW BORDER WINDOW "frmTestBorder" CONTROL "Button_3" PENWIDTH 3 UPCOLOR 0 DOWNCOLOR 1

// DrawWideBorder( "frmTestBorder", "Image_1", { 164, 260, 155 } )
// DrawWideBorder( "frmTestBorder", "Label_5", { 164, 260, 155 } ) 
Return Nil

Function DrawWideBorder( cWindowName, cControlName, aColor, nSpace, nStep )
Local nWidness

HB_DEFAULT( @nSpace, 10 )
HB_DEFAULT( @nStep, 1 )

FOR nWidness := 1 TO nSpace STEP nStep 
    DRAW BORDER WINDOW cWindowName CONTROL cControlName UPCOLOR aColor DOWNCOLOR aColor SPACE nWidness
    aColor[ 1 ] -= 10
    aColor[ 2 ] -= 10
    aColor[ 3 ] += 10
NEXT
* Problem : 
*   results of below changes on color array gone away After that msg  :(

MsgDebug( aColor )
Return Nil
One suggestion is to have as option of rounded border at corner if is possible. ;)

Thank you for your sharing and I also did not know about HB_DEFAULT(), thank again for sharing !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
esgici
Posts: 4457
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 336 times
Been thanked: 103 times
Contact:

Post by esgici » Wed Sep 25, 2013 3:00 pm

Hi Serge
esgici wrote: I'm afraid that I couldn't tell :(
Sorry for inaccurate information :(

Anyway this message was added to see ( and demonstrate ) deterioration in the border :(

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D

Post Reply