Heyho!
Vielleicht erinnern sich noch ein paar von euch an das hier: Klick!
Ich habe nochmal was gecodet, diesmal umfangreicher, dafür mit abgeänderter Funktion: Hier darf man nicht die Farben selbst bestimmen, alles Random.:P
Um die etwas umfangreichere (Und unübersichtlichere :D) UI zu erklären, bediene ich mich hier den Möglichkeiten eines Bildes:
[Blockierte Grafik: http://sninfando.magix.net/public/RPic.JPG]
- 1 - Das Hauptfeld: Input und Output zugleich. Sofern man sich im Edit-Modus befindet, kann man hier durch Klicken einzelne Kacheln ändern.
- 2 - New: Prinzipiell nichts anderes, als wie wenn man manuell auf jede Kachel klickt.
- 3 - Tendenz: Hiermit wird die Tendenz der Random-Funktion festgelegt: "No" -> Keine Tendenz, "R" -> Rot-Tendenz, "G" -> Grün-Tendenz, "B" -> Blau-Tendenz. Ein Rechtsklick auf dieses Control ermöglicht das Einstellen der Maximalwerte der Random-Funktionen für die Sekundärfarben (Beispiel: Tendenz zu Rot -> Rot = Primärfarbe, Grün & Blau = Sekundärfarbe).
- 4 - Output als String: Ausgabe des obigen Bildes als 174-Stelliger Code.*
- 5 - Code-Output/Input: Hier erfolgt die Ausgabe, bzw. Eingabe eines Farbcodes.*
- 6 - Input als String: Eingabe eines Farbcodes, aus dem ein Bild generiert wird.*
- 7 - Edit-Modus: Aktiviert den manuellen Edit-Modus, in dem man durch Klicken einer Kachel eine neue Random-Farbe zuweisen kann.
*Um das Input-Feld 5 zu aktivieren, muss ein Klick auf Schaltfläche 4 oder 6 erfolgen und nacher mit derselben Schaltfläche bestätigt werden, um die andere wieder frei zu schalten!
So, wenn noch Fragen bestehen, dann fragt!
Code
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
AutoItSetOption("GUIResizeMode", 802)
[/autoit] [autoit][/autoit] [autoit]Global $iRandomDec_R_MAX, $iRandomDec_G_MAX, $iRandomDec_B_MAX
[/autoit] [autoit][/autoit] [autoit]_SetColorMax(255, 255, 255)
[/autoit] [autoit][/autoit] [autoit]$hGUI = GUICreate("RPic", 350, 450)
$hNew = GUICtrlCreateLabel("New", 0, 350, 150, 50, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 20)
$hEditMode = GUICtrlCreateLabel("Edit Off", 200, 350, 150, 50, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 20)
$hTendenzLabel = GUICtrlCreateLabel("No", 150, 350, 50, 50, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 20)
$hOutputString = GUICtrlCreateLabel("Output String", 0, 400, 175, 50, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 20)
$hInputString = GUICtrlCreateLabel("Input String", 175, 400, 175, 50, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 20)
$hStringEdit = GUICtrlCreateInput("", 0, 450, 350, 50, -1, $WS_EX_TRANSPARENT)
GUICtrlSetBkColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 20)
GUICtrlSetLimit(-1, 174)
Dim $ahFields[5][5], $aiColors[25], $aiPos
$iBase = 50
For $x = 0 To 4
For $y = 0 To 4
$ahFields[$x][$y] = GUICtrlCreateLabel("", $x * $iBase + $iBase, $y * $iBase + $iBase, 50, 50)
_Recolor($ahFields[$x][$y])
GUICtrlSetCursor($ahFields[$x][$y], 2) ;Nur zur Sauberkeit
Next
Next
GUISetState()
[/autoit] [autoit][/autoit] [autoit]$fEditModeEnable = False
$fInputVisible = False
$iCntTendenz = 0
$iMaxSecColor = 100
$hTendenzGUI = GUICreate("Tendenz", 100, 100)
$hOKLabel = GUICtrlCreateLabel("OK", 0, 50, 100, 50, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 20)
$hInputMaxSecColor = GUICtrlCreateInput($iMaxSecColor, 0, 0, 100, 50, BitOR($SS_CENTER, $SS_CENTERIMAGE), $WS_EX_TRANSPARENT)
GUICtrlSetBkColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 20)
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case -3
Exit
Case $hNew
_RecolorAll()
Case $hEditMode
_SwitchEditMode()
Case $hOutputString
_SwitchInOut($hOutputString, $hInputString)
If $fInputVisible Then GUICtrlSetData($hStringEdit, _StreamToString())
Case $hInputString
_SwitchInOut($hInputString, $hOutputString)
If $fInputVisible Then
GUICtrlSetData($hStringEdit, "")
Else
_StreamFromString(GUICtrlRead($hStringEdit))
EndIf
Case $hTendenzLabel
$iCntTendenz += 1
If $iCntTendenz >= 4 Then $iCntTendenz = 0
Switch $iCntTendenz
Case 0
GUICtrlSetBkColor($hTendenzLabel, 0xFFFFFF)
GUICtrlSetData($hTendenzLabel, "No")
_SetColorMax(255, 255, 255)
Case 1
GUICtrlSetBkColor($hTendenzLabel, 0xFF0000)
GUICtrlSetData($hTendenzLabel, "R")
_SetColorMax(255, $iMaxSecColor, $iMaxSecColor)
Case 2
GUICtrlSetBkColor($hTendenzLabel, 0x00FF00)
GUICtrlSetData($hTendenzLabel, "G")
_SetColorMax($iMaxSecColor, 255, $iMaxSecColor)
Case 3
GUICtrlSetBkColor($hTendenzLabel, 0x0000FF)
GUICtrlSetData($hTendenzLabel, "B")
_SetColorMax($iMaxSecColor, $iMaxSecColor, 255)
EndSwitch
Case $GUI_EVENT_SECONDARYDOWN
$aiCursor = GUIGetCursorInfo($hGUI)
If IsArray($aiCursor) Then
If $aiCursor[4] = $hTendenzLabel Then
GUISetState(@SW_DISABLE, $hGUI)
GUISetState(@SW_SHOW, $hTendenzGUI)
While 1
$iMsgEx = GUIGetMsg()
Switch $iMsgEx
Case -3
GUISetState(@SW_ENABLE, $hGUI)
GUISetState(@SW_HIDE, $hTendenzGUI)
ExitLoop
Case $hOKLabel
Global $iMaxSecColor = GUICtrlRead($hInputMaxSecColor)
GUISetState(@SW_ENABLE, $hGUI)
GUISetState(@SW_HIDE, $hTendenzGUI)
ExitLoop
EndSwitch
WEnd
EndIf
EndIf
EndSwitch
If $fEditModeEnable = True Then
For $x = 0 To 4
For $y = 0 To 4
If $iMsg = $ahFields[$x][$y] Then
_Recolor($ahFields[$x][$y])
EndIf
Next
Next
EndIf
WEnd
Func _Recolor($hControl)
$iRandomDec_R = Random(0, $iRandomDec_R_MAX, 1)
$iRandomDec_G = Random(0, $iRandomDec_G_MAX, 1)
$iRandomDec_B = Random(0, $iRandomDec_B_MAX, 1)
$iRandomHex = Hex($iRandomDec_R, 2) & Hex($iRandomDec_G, 2) & Hex($iRandomDec_B, 2)
;~ $iRandomHex = Hex(String($iRandomDec), 6)
GUICtrlSetBkColor($hControl, "0x" & $iRandomHex)
$aiColors[$hControl - $ahFields[0][0]] = $iRandomHex
EndFunc ;==>_Recolor
Func _SwitchEditMode()
$fEditModeEnable = Not $fEditModeEnable
If $fEditModeEnable Then
GUICtrlSetBkColor($hEditMode, 0xFF0000)
GUICtrlSetData($hEditMode, "Edit On")
_SetCursorAll(0)
Else
GUICtrlSetBkColor($hEditMode, 0x0000FF)
GUICtrlSetData($hEditMode, "Edit Off")
_SetCursorAll(2)
EndIf
EndFunc ;==>_SwitchEditMode
Func _RecolorAll()
For $x = 0 To 4
For $y = 0 To 4
_Recolor($ahFields[$x][$y])
Next
Next
EndFunc ;==>_RecolorAll
Func _SetCursorAll($iCursor)
For $x = 0 To 4
For $y = 0 To 4
GUICtrlSetCursor($ahFields[$x][$y], $iCursor)
Next
Next
EndFunc ;==>_SetCursorAll
Func _SwitchInOut($hControlClicked, $hControlOther)
$fInputVisible = Not $fInputVisible
Dim $aiPos
$aiPos = WinGetPos("RPic")
If $fInputVisible Then
WinMove("RPic", "", $aiPos[0], $aiPos[1], $aiPos[2], $aiPos[3] + 50)
GUICtrlSetBkColor($hControlClicked, 0xFF0000)
GUICtrlSetState($hControlOther, $GUI_DISABLE)
Else
WinMove("RPic", "", $aiPos[0], $aiPos[1], $aiPos[2], $aiPos[3] - 50)
GUICtrlSetBkColor($hControlClicked, 0x0000FF)
GUICtrlSetState($hControlOther, $GUI_ENABLE)
EndIf
EndFunc ;==>_SwitchInOut
Func _StreamToString()
Local $sReturn = ""
For $i = 0 To 24
$sReturn &= $aiColors[$i] & ":"
Next
Return StringTrimRight($sReturn, 1)
EndFunc ;==>_StreamToString
Func _StreamFromString($sString)
Local $aiColorRead = StringSplit($sString, ":")
If $sString = "" Then Return
If $aiColorRead[0] <> 25 Then
MsgBox(0, "Error", "Cannot read string!")
_WriteError()
Return
EndIf
For $iCtrlID = 0 To 24
$aiColors[$iCtrlID] = $aiColorRead[$iCtrlID + 1]
GUICtrlSetBkColor($ahFields[0][0] + $iCtrlID, "0x" & $aiColorRead[$iCtrlID + 1])
Next
EndFunc ;==>_StreamFromString
Func _WriteError()
Local $iBkColor = "000000"
Local $iFontColor = "FF0000"
Local $sEnd = _StringRepeat($iBkColor & ":", 5) & _StringRepeat($iFontColor & ":", 6) & $iBkColor & ":" & $iFontColor & ":" & $iBkColor & ":" & $iFontColor & ":" & $iFontColor & ":" & $iBkColor & ":" & $iFontColor & ":" & $iBkColor & ":" & $iFontColor & ":" & _StringRepeat($iBkColor & ":", 4) & $iBkColor
_StreamFromString($sEnd)
EndFunc ;==>_WriteError
Func _SetColorMax($iRed, $iGreen, $iBlue)
Global $iRandomDec_R_MAX = $iRed
Global $iRandomDec_G_MAX = $iGreen
Global $iRandomDec_B_MAX = $iBlue
EndFunc ;==>_SetColorMax
lg chess
Edit: Ach ja!:D
Was haltet ihr von der Idee, Labels anstatt Button zu benutzen? Klar, nicht so übersichtlich, vom Design her aber eigentlich schöner (Aufjedenfall, wenn man mit Farben hantiert. ;))