Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Muiswieltje draaien verandert de kleurtint (loopt de regenboog af). |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | develop |
Files: | files | file ages | folders |
SHA1: |
9d34b72e1e3349c5ceafc8e969c09aa6 |
User & Date: | tinus 2017-06-11 09:08:04.954 |
Context
2017-06-11
| ||
09:15 | WHEEL_DELTA op 12 ipv 120 gezet voor andere platforms dan Windows. check-in: a95a6beff5 user: tinus tags: develop | |
09:08 | Muiswieltje draaien verandert de kleurtint (loopt de regenboog af). check-in: 9d34b72e1e user: tinus tags: develop | |
08:11 | De muissnelheid on-the-fly kunnen aanpassen met Shift+Alt+Up/Down. Deze onthouden in een .ini. Met Shift+Escape de tekening opslaan en het blad weer leegmaken. check-in: 90ffd07634 user: tinus tags: develop | |
Changes
Changes to src/f_main.pas.
︙ | ︙ | |||
68 69 70 71 72 73 74 | end; var frmTekening: TfrmTekening; implementation uses | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | end; var frmTekening: TfrmTekening; implementation uses LCLIntf, Math; {$R *.lfm} const HLSMAX = 240; // H,L, and S vary over 0-HLSMAX RGBMAX = 255; // R,G, and B vary over 0-RGBMAX // HLSMAX BEST IF DIVISIBLE BY 6 // RGBMAX, HLSMAX must each fit in a byte. { Hue is undefined if Saturation is 0 (grey-scale) This value determines where the Hue scrollbar is initially set for achromatic colors } HLSUndefined = (HLSMAX*2/3); procedure ColorRGBToHLS(const R, G, B: Word; out Hue, Luminance, Saturation: Word); var H, L, S: Double; cMax, cMin: Double; Rdelta, Gdelta, Bdelta: Word; { intermediate value: % of spread from max } begin { calculate lightness } cMax := Max(Max(R, G), B); cMin := Min(Min(R, G), B); L := ( ((cMax + cMin) * HLSMAX) + RGBMAX ) / ( 2 * RGBMAX); Luminance := Trunc(L); if cMax = cMin then { r=g=b --> achromatic case } begin Hue := Trunc(HLSUndefined); Saturation := 0; end else { chromatic case } begin { saturation } if Luminance <= HLSMAX/2 then S := ( ((cMax-cMin)*HLSMAX) + ((cMax+cMin)/2) ) / (cMax+cMin) else S := ( ((cMax-cMin)*HLSMAX) + ((2*RGBMAX-cMax-cMin)/2) ) / (2*RGBMAX-cMax-cMin); { hue } Rdelta := Trunc(( ((cMax-R)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin)); Gdelta := Trunc(( ((cMax-G)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin)); Bdelta := Trunc(( ((cMax-B)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin)); if (R = cMax) then H := Bdelta - Gdelta else if (G = cMax) then H := (HLSMAX/3) + Rdelta - Bdelta else // B == cMax H := ((2 * HLSMAX) / 3) + Gdelta - Rdelta; if (H < 0) then H := H + HLSMAX; if (H > HLSMAX) then H := H - HLSMAX; Hue := Round(H); Saturation := Trunc(S); end; end; function HueToRGB(Lum, Sat, Hue: Double): Integer; var ResultEx: Double; begin { range check: note values passed add/subtract thirds of range } if (hue < 0) then hue := hue + HLSMAX; if (hue > HLSMAX) then hue := hue - HLSMAX; { return r,g, or b value from this tridrant } if (hue < (HLSMAX/6)) then ResultEx := Lum + (((Sat-Lum)*hue+(HLSMAX/12))/(HLSMAX/6)) else if (hue < (HLSMAX/2)) then ResultEx := Sat else if (hue < ((HLSMAX*2)/3)) then ResultEx := Lum + (((Sat-Lum)*(((HLSMAX*2)/3)-hue)+(HLSMAX/12))/(HLSMAX/6)) else ResultEx := Lum; Result := Round(ResultEx); end; function ColorHLSToRGB(Hue, Luminance, Saturation: Word): TColorRef; function RoundColor(Value: Double): Integer; begin if Value > 255 then Result := 255 else Result := Round(Value); end; var R,G,B: Double; { RGB component values } Magic1,Magic2: Double; { calculated magic numbers (really!) } begin if (Saturation = 0) then begin { achromatic case } R := (Luminance * RGBMAX)/HLSMAX; G := R; B := R; if (Hue <> HLSUndefined) then ;{ ERROR } end else begin { chromatic case } { set up magic numbers } if (Luminance <= (HLSMAX/2)) then Magic2 := (Luminance * (HLSMAX + Saturation) + (HLSMAX/2)) / HLSMAX else Magic2 := Luminance + Saturation - ((Luminance * Saturation) + (HLSMAX/2)) / HLSMAX; Magic1 := 2 * Luminance - Magic2; { get RGB, change units from HLSMAX to RGBMAX } R := (HueToRGB(Magic1,Magic2,Hue+(HLSMAX/3))*RGBMAX + (HLSMAX/2))/HLSMAX; G := (HueToRGB(Magic1,Magic2,Hue)*RGBMAX + (HLSMAX/2)) / HLSMAX; B := (HueToRGB(Magic1,Magic2,Hue-(HLSMAX/3))*RGBMAX + (HLSMAX/2))/HLSMAX; end; Result := RGB(RoundColor(R), RoundColor(G), RoundColor(B)); end; { TfrmTekening } procedure TfrmTekening.FormCreate(Sender: TObject); begin SystemParametersInfo(SPI_GETMOUSESPEED, 0, @FOrgMouseSpeed, 0); SystemParametersInfo(SPI_GETMOUSESONAR, 0, @FOrgMouseSonar, 0); |
︙ | ︙ | |||
238 239 240 241 242 243 244 245 | dsDrawing: LineTo(X, Y, SelectedColor); dsErasing: LineTo(X, Y, Self.Color); end; end; procedure TfrmTekening.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); begin | > > > > > > > > | > > > > > > > > > > > > > > > | 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | dsDrawing: LineTo(X, Y, SelectedColor); dsErasing: LineTo(X, Y, Self.Color); end; end; procedure TfrmTekening.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); const WHEEL_DELTA = 120; var R, G, B: Byte; H, L, S: Word; Delta: Integer; begin Delta := WheelDelta div WHEEL_DELTA; // shift hue of current color RedGreenBlue(SelectedColor, R, G, B); ColorRGBToHLS(R, G, B, H, L, S); if H + Delta < 0 then H := H + Delta + HLSMAX else if H + Delta > HLSMAX then H := H + Delta - HLSMAX else H := H + Delta; if L < (HLSMAX div 2) then L := L + Abs(Delta); if S < (HLSMAX div 2) then S := S + Abs(Delta); SelectedColor := ColorHLSToRGB(H, L, S); Handled := True; end; procedure TfrmTekening.FormPaint(Sender: TObject); begin Self.Canvas.Draw(ClientOrigin.X, ClientOrigin.Y, FPNG); end; |
︙ | ︙ |