

Willicious
Members-
Content Count
150 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Willicious
-
Change "FadeOut" code to "FadeIn" code
Willicious replied to Willicious's topic in Delphi IDE and APIs
Just giving this a bump. I need it to fill the screen with a black bitmap (for which I also need control of the alpha channel). Do I need to specify a temporary bitmap image first which I then drawto, or is it possible to just fill the screen directly? procedure TGameBaseScreen.FadeIn; var A: TColor32; R: TColor32; G: TColor32; B: TColor32; i: Integer; begin for i := 0 to Width * Height - 1 do begin A := 0; R := 0; G := 0; B := 0; end; end; -
Replying so I can follow the topic
-
I have a form with a treeview, which can be browsed using the arrow keys. Once an item in the treeview is selected, hitting an "OK" button on the form (which has the modal result mrOK) will close the form, and load the currently selected item into the app. What I want to do is assign VK_RETURN (which I believe is the [Enter] key...?) to the OK button, so that when browsing the treeview using keys, the user can just hit Enter/Return to load the currently selected item. btnOKClick has its own procedure, detailed here: procedure TFLevelSelect.btnOKClick(Sender: TObject); begin WriteToParams; ModalResult := mrOk; end; I can enter "WriteToParams;" into the Treeview's OnKeyDown procedure, but this doesn't actually have any effect until the OK button is pressed. So, one option is to tell the OnKeyDown procedure to also "virtually press the OK button" (which I'm not sure is even possible...?) - this would be my preferred method, if it can be done. Another option is to assign a hotkey to btnOKClick. The only problem with this is that there are multiple other buttons on the form, all of which already respond to [Enter] when Tab-selected. If I assign [Enter] as a hotkey to btnOKClick, then [Enter] either can't then be used for any of the other buttons on the form - or, worse, the app will crash because it won't know which button to press if the Tab is on a different button than 'OK', and the user hits [Enter]. Any and all suggestions/help welcome. I apologise if I haven't provided any necessary information.
-
Change "FadeOut" code to "FadeIn" code
Willicious replied to Willicious's topic in Delphi IDE and APIs
I see, thanks. This helps. I'll have a look at it later today 🙂👍 I wanted to fill the screen with a black bitmap. If I can do that, then the next step is to either gradually make it more and more transparent using opacity or alpha values (thus revealing the screen image underneath), or use your example code to modulate the black pixels to those of the screen image bitmap. Whichever of these options I go with, it needs to be portable to all of the various game screens across several different units. To begin with though, I just need to draw a black bitmap. If I can do that, then I'll move on to the next step. -
Hi all, I'm running RAD Studio 10.4 Version 27.0.40680.4203. I daren't update it in case I can no longer compile the project I'm working on after the update. Debugging breakpoints have always worked, but today for some reason they stopped working. Now, when I enter a breakpoint (red dot at the left of the line), the red dot gets a cross ('X') in the centre of it and the program doesn't break at the appropriate point when running in Debug mode. As far as I know, I haven't changed any project settings since being able to use breakpoints and now not being able to use them. Any ideas...? Apologies if I haven't provided any necessary information.
-
Change "FadeOut" code to "FadeIn" code
Willicious replied to Willicious's topic in Delphi IDE and APIs
OK, changing it into a procedure instead of a function gets rid of the error. I now have this: procedure TGameBaseScreen.FadeIn; var A: TColor32; R: TColor32; G: TColor32; B: TColor32; Value: Integer; begin Value := 0; if Value = 0 then Inc(Value); //I can see what I'm doing wrong here: "Value" needs something that it can increase towards incrementally, //and then I obviously need to put in a tick count as well A := 255; R := Round(R * Value); //<--- Incompatible types error G := Round(G * Value); //<--- Incompatible types error B := Round(B * Value); //<--- Incompatible types error end; Maybe I should start simple and just see if I can draw a plain black bitmap to the screen. Tried this, it doesn't work (also tried it with A := 255). Not sure what I'm doing wrong here, but it's probably something really basic: procedure TGameBaseScreen.FadeIn; var A: TColor32; R: TColor32; G: TColor32; B: TColor32; i: Integer; begin for i := 0 to Width * Height - 1 do begin A := 0; R := 0; G := 0; B := 0; end; end; -
Change "FadeOut" code to "FadeIn" code
Willicious replied to Willicious's topic in Delphi IDE and APIs
OK, thanks 🙂 I'm getting an "Unsatisfied forward or external declaration" when I try to add either function to the program. Not sure what to do about this at present, but I do at least understand what the functions are meant to be doing. @Anders Melander Thanks for your help btw, apologies for my noobishness -
Change "FadeOut" code to "FadeIn" code
Willicious replied to Willicious's topic in Delphi IDE and APIs
@Anders Melander Ah, maybe there's been a misunderstanding. The idea is not to fade the current image to black, and then fade the same image back in. The idea is to fade the current image to black, and then fade the next image in. In fact, the way that the FadeOut; is written, it's always applied to any image which happens to be onscreen, at the point when that screen is closed. It doesn't need to know what the image is or what its exact colour values are. What's needed is a similarly-written FadeIn; procedure which can be applied to any screen.image, at the point when that screen is opened. Maybe it can be done by simply drawing a black canvas over the screen.image, and then gradually reducing the opacity until it's revealed (i.e. rather than having to get the actual colour values for each image)...? -
Change "FadeOut" code to "FadeIn" code
Willicious replied to Willicious's topic in Delphi IDE and APIs
I see what you mean, but I'm trying to fade from black to... some unknown colour (unknown in the sense that the bitmap contains many different colours). So, do I have to set those colour values first, and then call them something like "aValue"? If so, how do you do that for many different colours at once? Your example works for fading to black (and for modulating between known values). -
Change "FadeOut" code to "FadeIn" code
Willicious replied to Willicious's topic in Delphi IDE and APIs
Yeah, this seems useful. This is using FOpacity... would I need to draw a large black bitmap over the main one and then reduce the opacity of that bitmap to gradually reveal the one underneath?? I'm not sure how this works. Right, and I'm guessing that the "Value" needs to be explicitly stated? The bitmap has many different colour values, though. I need a way of saying "for each pixel, get the colour, and set this to some value. Now go from 0 to that value." It's not always going to be "1", so I'm not sure how to make use of your example...? -
Brilliant, thank you @programmerdelphi2k! This one worked: procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = vk_return { and other verifications... } then Button1.Click; end; And now, I know how to virtually click buttons, which is incredibly helpful 🙂👍
-
Yes, fair enough. If others can benefit from this post, then great 👍 Deleting the .dcu files didn't help, and this was indeed the info I was getting from various sources. So, I tried just applying breakpoints to a bunch of random lines to see if it was something to do with the lines I was choosing to add breakpoints to, and it turns out that was the problem. I didn't realise that breakpoints were so selective. Ideally, if the user has chosen a line incorrectly (say, a "begin" line), the IDE would just intelligently choose the next available line that can be a breakpoint (or something) rather than just fail without explanation.
-
OK, figured it out. It seems that certain lines don't actually allow breakpoints. MODS: Happy for this topic to be deleted.
-
Output from Tree View when using Arrow Keys (as well as Mouse Click)
Willicious posted a topic in Delphi IDE and APIs
Hi all, The app I'm working on has a tree view which displays relevant info when an item in that tree is clicked with the mouse. It's also possible to scroll through the treeview list items using the arrow keys (which is obviously quicker than point-clicking every item to get the displayed info), however the info is not displayed when using the arrow keys. It's necessary to actually click an item to get it to display the info. Here's the relevant procedure: procedure TFLevelSelect.tvLevelSelectClick(Sender: TObject); begin SetInfo; end; As you can see, SetInfo is only called when the tree view is actually clicked. Do I need to add procedures for VK_DOWN and VK_UP which call this function, or can the hotkeys be added in here somewhere? Many thanks, Will -
Output from Tree View when using Arrow Keys (as well as Mouse Click)
Willicious replied to Willicious's topic in Delphi IDE and APIs
Yes, thank you! The following code worked (i.e. setting an OnChange event for the treeview) 🙂 procedure TFLevelSelect.tvLevelSelectChange(Sender: TObject); begin SetInfo; end; -
Hi all, I'm attempting to hue shift a pre-loaded font graphic at a certain point on the screen where it appears as scroller text. I'm pretty sure I've entered everything correctly, but all I'm getting is completely blank text instead of hue-shifted text: procedure TGameMenuScreen.PrepareNextReelText; const HUE_SHIFT = 0.250; var i, realI: Integer; S: String; SizeRect: TRect; ScrollerText: TBitmap32; HueShift: TColorDiff; x, y: Integer; begin FillChar(HueShift, SizeOf(TColorDiff), 0); HueShift.HShift := HUE_SHIFT; ScrollerText := TBitmap32.Create; for i := 1 to fScrollerTextList.Count do begin if i = fScrollerTextList.Count then begin fDisableScroller := true; Exit; end; if fReelForceDirection < 0 then begin realI := (fReelTextIndex - i); if realI < 0 then realI := realI + fScrollerTextList.Count; end else realI := (fReelTextIndex + i) mod fScrollerTextList.Count; if Trim(fScrollerTextList[realI]) <> '' then begin S := Trim(fScrollerTextList[realI]); fReelTextIndex := realI; Break; end; end; try SizeRect := MenuFont.GetTextSize(S); ScrollerText.SetSize(SizeRect.Width, SizeRect.Height + 4); ScrollerText.Clear(0); MenuFont.DrawText(ScrollerText, S, 0, 4); for y := 0 to ScrollerText.Height-1 do for x := 0 to ScrollerText.Width-1 do begin ScrollerText[x, y] := ApplyColorShift(ScrollerText[x, y], HueShift); end; ScrollerText.DrawMode := dmBlend; finally ScrollerText.Free; end; if (fReelForceDirection < 0) then fReelTextPos := -ScrollerText.Width else fReelTextPos := LayoutInfo.ScrollerWidth; fLastReelUpdateTickCount := GetTickCount64; fSwitchedTextSinceForce := true; end; Any ideas what I'm either a) doing wrong or b) not doing at all? Thanks in advance!
-
Applying hue change to font graphic on the fly
Willicious replied to Willicious's topic in Delphi IDE and APIs
OK... here's a perfect example of what beginners to programming are up against. "Classes" are something important, that much I can gather. But, I don't know what a "class" is or why it's important, so I look it up and here's what's presented: This raises far more questions than it answers. Now I need to know what "fields, methods and properties" are. I also need to know why you would have different instances of a class, and remember that these are referred to as "objects." I also need to remember that, as well as being called "fields, methods and properties", these things - whatever they are - may also be referred to as "components or members". And, there's 391 pages of this, with no index! So, as a beginner, I'm bound to think "maybe some of this stuff doesn't actually matter, and is just jargon. I'll just start changing things in the project and see what happens. If I need to 'know' something, I can just pick it up later, when it matters." So yes, I might occasionally not be aware that I'm incorrectly using a particular element of the language. But, I'm at a loss as to how else I could possibly learn everything. As someone should probably have once said, if they haven't already: "Si quieres aprender a hablar Español, ve a España!!" -
Applying hue change to font graphic on the fly
Willicious replied to Willicious's topic in Delphi IDE and APIs
The problem here is not that I don't understand Delphi, as such. It's more that I'm working on a very old program which has had several developers in the past, and whose codebase is therefore that bit more impenetrable to a beginner. As it happens, one of the previous devs was able to point me in the right direction with this. Basically, the Create; and Free; parts needed to be removed, since this is handled elsewhere. It only took a few small tweaks to what I'd done to put it right. Unfortunately, contact with the previous devs is limited at best, and I do want to try to solve some of this stuff without always going to them for help. To be quite honest, I didn't know that Result is only available in a function, but I do now, so thanks for pointing this out. I do take your point that something simple regarding structure is something I could perhaps learn better by swotting up a bit first, and I do plan on boosting my theoretical knowledge at some point, but this is likely to cost money (I'd prefer structured lessons with specific goals than just aimlessly reading books and/or worse, PDFs on a screen), so I'd prefer to wait until I can justify the expense a bit more. Since I'm currently working on a hobby project and getting a feel for programming in general, it doesn't seem worth shelling out just yet. With that said, I've watched several introductory videos on Delphi and other coding languages, and I find that I instantly forget most of what is said in these videos because I'm not actually using any of it. I just remember that something vague was said about classes, functions, something about semicolons and brackets, and yeah I can print "Hello World" to the screen, but what good is that when you're working on a game or website or complex desktop application? Don't get me wrong, I'm a former music teacher and I do understand the importance of theory in developing your skills, but my own personal preference is to have a go first, and then track back and see what I'm doing wrong if it doesn't work. I learn way more this way than by attempting to find that one video, article, chapter in a book, or - god forbid - Stack Overflow post that may or may not provide me with the knowledge I need to progress. Apologies for the rant here, I'm just finding learning programming very frustrating tbh. --- EDIT: I have downloaded the Delphi Language Guide. I'm taking a look at it 👍 -
Applying hue change to font graphic on the fly
Willicious replied to Willicious's topic in Delphi IDE and APIs
function ApplyColorShift(aBase: TColor32; aDiff: TColorDiff): TColor32; var H, S, V: Single; begin RGBToHSV(aBase, H, S, V); H := H + aDiff.HShift; S := S + aDiff.SShift; V := V + aDiff.VShift; while H >= 1 do H := H - 1; while H < 0 do H := H + 1; S := Max(0, Min(S, 1)); V := Max(0, Min(V, 1)); Result := (HSVToRGB(H, S, V) and $FFFFFF) or (aBase and $FF000000); Result := TColor32(Integer(Result) + (aDiff.RAdj * $10000) + (aDiff.GAdj * $100) + (aDiff.BAdj)); // The typecasts avoid compiler warnings. end; -
Applying hue change to font graphic on the fly
Willicious replied to Willicious's topic in Delphi IDE and APIs
Tag added, apologies for the oversight. If I remove everything to do with the colour shifting, the text does display. The colour-shifting code is actually mostly copied over and then adapted from another part of the project (where it does work). The only thing I couldn't copy was a line which started "Result := ", so it's very likely that this line is what actually draws the hue-shifted bitmap. Adding "Result :=" here generates an undeclared identifier error, so I just left it out and hoped for the best. Clearly, though, I need something to explicitly say "draw the hue-shifted bitmap." -
Radio button options not remembered on re-opening app
Willicious posted a topic in Delphi IDE and APIs
My app uses mainly checkboxes for boolean values in the config menu. These are saved and loaded each time the app is closed and opened, no problem. However, one option calls for radio buttons rather than checkboxes, because it's a choice of 3 different things. If one is chosen, then the others can't be chosen. I use the same code to write the user's preference to the settings.ini file. However, when opening the app, the first radio button is always checked, regardless of what the user chose previously. Does anyone know if radio buttons require different handling than checkboxes when saving/loading the user input to/from a settings file? -
Radio button options not remembered on re-opening app
Willicious replied to Willicious's topic in Delphi IDE and APIs
I can only apologise for this... It turns out it was all down to a simple typographical error 🤦♂️ I had LoadBoolean as 'Prefer A' instead of 'PreferA' - turns out that the spaces matter! So sorry, and thank you to all those who replied!! EDIT: A bonus outcome of this topic is that the code is now tidier and clearer; implementing this as a RadioGroup with an ItemIndex list rather than individual Radio Buttons is definitely better 👍 -
Radio button options not remembered on re-opening app
Willicious replied to Willicious's topic in Delphi IDE and APIs
Can you give an example of what you mean here? Also, how does this differ from the way I've set the Booleans already? -
Radio button options not remembered on re-opening app
Willicious replied to Willicious's topic in Delphi IDE and APIs
Yes, this is what I'm doing. The problem is that it isn't loading the setting. -
Radio button options not remembered on re-opening app
Willicious replied to Willicious's topic in Delphi IDE and APIs
OK, so I've tried doing this as a TRadioGroup instead, and I'm getting exactly the same problem: rgChooseSound: TRadioGroup; procedure TFormNXConfig.SaveToParams; begin GameParams.PreferA := rgChooseSound.ItemIndex = 0; GameParams.PreferB := rgChooseSound.ItemIndex = 1; end; procedure TFormNXConfig.SetOptions; begin if GameParams.PreferA then rgChooseSound.ItemIndex = 0; if GameParams.PreferB then rgChooseSound.ItemIndex = 1; end; procedure TFormNXConfig.SetChooseSoundRadioGroup(aValue: Integer); begin if rgChooseSound.ItemIndex = 0 then GameParams.PreferA; if rgChooseSound.ItemIndex = 1 then GameParams.PreferB; end; Then, in the GameControl unit: property PreferA: Boolean Index moPreferA read GetOptionFlag write SetOptionFlag; property PreferB: Boolean Index moPreferB read GetOptionFlag write SetOptionFlag; procedure TGameParams.SaveToIniFile; begin SaveBoolean('Prefer A', PreferA); SaveBoolean('Prefer B', PreferB); end; Procedure TGameParams.LoadFromIniFile; begin PreferA := LoadBoolean('PreferA', PreferA); PreferB := LoadBoolean('PreferB', PreferB); end; Can anyone see where I'm going wrong, and what I need to do to fix it? Using a RadioGroup and setting the options as list Items from an Index does work (i.e. it has the desired effect in-game), but the same problem of the choice not being remembered when the game is next opened occurs. It always resets to the first of the 2 options, every time. I need it to remember if the 2nd choice has been set, and load this. As far as I can see, my code is at least trying to do this, and I can't see where it's failing.