Jump to content

Array full of colors


Recommended Posts

Hey everyone,

"Lets get straight to the point" (this is actually a paradox cause by saying this, you dont actually get "straight to the point... anyways)

 

So in my Script, i have a Array full of colors. And i would like to draw 10x10 Rects with GDIPlus on a gui with the color extracted from an entry of the array. I already tried it but it just wont work (Im not that good with arrays).

For $i = 0 To 255
    $blue = $colorBytes[$i]
    _ArrayDelete($colorBytes, $i)
    $green = $colorBytes[$i]
    _ArrayDelete($colorBytes, $i+1)
    $curBrush = _GDIPlus_BrushCreateSolid("0xFFFF"&$green&$blue)
    If $i >= 0 And $i <= 32 Then
        $y = 10
    ElseIf $i >= 32 And $i <= 64 Then
        $y = 20
    ElseIf $i >= 96 And $i <= 128 Then
        $y = 30
    ElseIf $i >= 128 And $i <= 160 Then
        $y = 40
    ElseIf $i >= 160 And $i <= 192 Then
        $y = 50
    ElseIf $i >= 192 And $i <= 224 Then
        $y = 60
    ElseIf $i >= 224 And $i <= 256 Then
        $y = 70
    ElseIf $i >= 256 Then
        $y = 80
    EndIf
    _GDIPlus_GraphicsFillRect($graphics, $i*10, $y, $blockSize, $blockSize, $curBrush)
    _GDIPlus_BrushDispose($curBrush)
Next

the array $colorBytes is 256 big, the GUI: Height=320; Width=80

Maybe a nested For loop is the solution?

 

Thanks in advance,

Oracle  :thumbsup:

Link to comment
Share on other sites

First, if you're going to use ArrayDelete in a loop, you MUST run the loop in reverse or you will both get errors and you'll be deleting the wrong elements.

Use:

For $i = 255 to 0 Step - 1

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

 

 

First, if you're going to use ArrayDelete in a loop, you MUST run the loop in reverse or you will both get errors and you'll be deleting the wrong elements.

Use:

For $i = 255 to 0 Step - 1

The reverse order would crash in his script also because the second _ArrayDelete. But i see no sence to delete elements in the array.

Maybe a nested For loop is the solution?

It make it easier for X Y Coordinates, but it's also possible with 1 Loop. Here a small Demo (with GuiCreateButton):

#include <GUIConstantsEx.au3>
#include <Array.au3>

Opt('MustDeclareVars', 1)
Global $aBtnIds[10][3]
$aBtnIds[0][2] = "0101"
$aBtnIds[1][2] = "0100"
$aBtnIds[2][2] = "0110"
$aBtnIds[3][2] = "1100"
$aBtnIds[4][2] = "1100"
$aBtnIds[5][2] = "1100"
$aBtnIds[6][2] = "1100"
$aBtnIds[7][2] = "1100"
$aBtnIds[8][2] = "1100"
$aBtnIds[9][2] = "_Farben"


Global $hGui = GUICreate('Buttontest', 105, 145)
Global $msg

For $i = 0 To 8
    $aBtnIds[$i][0] = GUICtrlCreateButton($i + 1, 10 + Mod($i, 3) * 30, 10 + Int($i / 3) * 30, 25, 25)
    ;$aBtnIds[$i][0] enthält jetzt die ID
    ConsoleWrite($i + 1 & ': ' & $aBtnIds[$i][0] & @CRLF)
    GUICtrlSetBkColor(-1, 0x990000)
    $aBtnIds[$i][1] = False
Next
$aBtnIds[9][0] = GUICtrlCreateButton('OK', 10, 110, 90, 25)
ConsoleWrite('OK: ' & $aBtnIds[$i][0] & @CRLF)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aBtnIds[0][0] To $aBtnIds[8][0]
            _Click($msg - $aBtnIds[0][0], True)
        Case $aBtnIds[9][0]
            ;_Click($msg - $aBtnIds[0][0])
            Call($aBtnIds[9][2])    ;ruft die hinterlegte Func auf
    EndSwitch
WEnd

Func _Click($iBtn, $bColorToggle = False)
    If $bColorToggle Then
        If $aBtnIds[$iBtn][1] Then
            GUICtrlSetBkColor($aBtnIds[$iBtn][0], 0x990000)
        Else
            GUICtrlSetBkColor($aBtnIds[$iBtn][0], 0x059122)
        EndIf
        $aBtnIds[$iBtn][1] = Not $aBtnIds[$iBtn][1]
    EndIf
    MsgBox(0, 'Buttonclick', 'Button with ID ' & $aBtnIds[$iBtn][0] & ' was clicked.' & @CRLF & 'The text of the button is: ' & ControlGetText('Buttontest', '', $aBtnIds[$iBtn][0]) & @CRLF & 'Data: ' & $aBtnIds[$iBtn][2] & @CRLF & 'True/False: ' & $aBtnIds[$iBtn][1], 5, $hGui)
EndFunc   ;==>_Click

Func _Farben()
    Local $sText = '',$aBtns
    For $i = 0 To 8
        $sText &= $aBtnIds[$i][1]
        If $i < 8 Then $sText &= '|'
    Next
    $sText = StringReplace($sText, 'True', 'Grün')
    $sText = StringReplace($sText, 'False', 'Rot')
    ConsoleWrite($sText & @CRLF)
    $aBtns = StringSplit($sText, '|')
    $aBtns[0] = UBound($aBtns)-1
    _ArrayDisplay($aBtns, 'Farben', '', 32)
EndFunc   ;==>_Farben

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...