|
Help with level editor user interface |
Felix-The-Ghost
Member #9,729
April 2008
|
----------------------------------------------------------------------------------- Okay I need help again. I thought I had the math part right but it's drawing slightly off. It looks fine at first, but when scrolled all the way down the scollbar overlaps the button I have the function at the very bottom; draw_scrollbar. I think it's calculating the X wrong, but I think the stretched width is correct. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
I haven't looked at the code, but don't forget to scale the offset for the position of the top of the scrollbar as well. That could be why it overextends. Another consideration is that you need to track the offset of the mouse click on the scrollbar and record it when you start to drag the scrollbar so it doesn't move too far in either direction. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Felix-The-Ghost
Member #9,729
April 2008
|
Heh. I can tell you didn't look at the code But why would I need to scale the offset? I'm using stretched blitting so it just has the first x,y and the width and height, which are relative to the first x and y. So if I got the x wrong...the whole thing's wrong. |
LennyLen
Member #5,313
December 2004
|
I took a look at the code, but your program is getting so big now (especially for a single file project) that trying to figure out exactly what you're doing is difficult. It doesn't help that some of the variable names you're using aren't very descriptive. If you can isolate the scrollbar code into a new smaller project, then it would be easier to help you, and when the problem is sorted, you can fix it in the main project. This might also be a good time to break your code down into smaller modules, before it gets too big to work with easily.
|
Felix-The-Ghost
Member #9,729
April 2008
|
Do you mean I should permanently separate it or just for the sake of easy aid? What sort of things to people usually separate? I was thinking about getting the bitmap loading into a new file but I didn't really know how I'd do that. I can try to make a new program with the scrollbar code if that's what you want. Thanks. Oh and which variable names aren't descriptive? Some of the vague ones should have comments next to their declarations if that helps. I don't remember having any ridiculous ones though...the worst is that some of them are similar, such as Scrollbar->w and Scrollbar_Width. The first is the length of the bitmap file, the second is the width of the stretched scrollbar. |
LennyLen
Member #5,313
December 2004
|
Quote: I can try to make a new program with the scrollbar code if that's what you want. That's what I meant, yes. Quote: What sort of things to people usually separate? It varies from project to project, but for yours, I'd initially seperate it into the 'main' module, which contains your main() function plus your variable definitions and your initialization routines; a 'drawing' module; and a 'logic' module. You can then break these down further if necessary. edit: Quote: Oh and which variable names aren't descriptive? TestClipT and TestBuffer were the two I was thinking of.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Quote: What sort of things to people usually separate? I separate things that are easily recognized as discrete objects or ideas. In effect, things like widgets, sets of data, data manipulation, generic i/o handlers, etc... When you asked me about why the scrollbar offset should be scaled, I was talking about the offset of the drawing position of the scrollbar handle in relation to the scrollbar area. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Felix-The-Ghost
Member #9,729
April 2008
|
I don't know how I'd do that... Also would there ever be a need to group related variables? I sort of did that with this code but they are still all in the same file. Should I make the functions separate like put them in another .CPP? If I include the file in the DevProject it'll arrange it the necessary way automatically? Oh and LennyLen, TestBuffer is the name of the loaded bitmap that is clipped. Look in the part where it loads bitmaps, probably one of the last ones. The TestClipT stands for TestClipTop; it represents the top of the clipping area of the TestBuffer(which is drawn at the top of the view area). I increase this by one (with limits) when the scrollbutton is clicked, and blit with this variable and a fixed height to produce a clipping effect. Once I get the scrollbar working I'll actually remove TestBuffer and related and just hard-code the drawing of tiles onto a new one, so when there are updates the scrollbar remains relative with the ratio. I guess I'll get started with a new one since I already had gotten decent dragging support for the bar and a splash screen. I'll strip all the other functions off though. edit: attached the stripped down version. I removed everything except the splash screen, because it's sexy drag the scrollbar as far as it goes, then click the scrolldown button and you'll see it goes a little further. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Quote: Would I use the same ratio?
Yes. All you need to do is find the ratios for : b) The length of the visible portion of the object being viewed to the total length of the viewable object. The ratio of (a) is your stretch factor in that dimension. The ratio of (b) times the length of the scrollbar area gives you the length of the scrollbar handle. The scrollbar handle's offset divided by the ratio of (b) gives you the actual size of the viewing object's drawing offset. It's best to just draw out the design on paper first, and then when you know what you're doing, put it into code. That method helps me finish things anyway. Quote: Also would there ever be a need to group related variables? I sort of did that with this code but they are still all in the same file. Should I make the functions separate like put them in another .CPP? Well, it would probably help you to make a separate module for your map data and methods, a map class that knows which tiles can be in it and holds an index to a tile list for each position in the map. Another module could be used for your editor. A third module could be for a tileset class, that's used by your map class and your editor class, etc... My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Felix-The-Ghost
Member #9,729
April 2008
|
Okay I get it, very distinct things get grouped together. drawing everything ? Also I'll try using the ratio...I thought I tried it before but it didn't work...maybe I used the wrong one. I sketch math based things on paper too. Or MS Paint. edit: okay this is not working out so well...
void draw_scrollbar() //draws a scrollbar of [in]correct scale { ScrollRatio = (TestBuffer->h / ScrollArea); //ratio of the entire bitmap's height to the scrollbar area's length ViewRatio = (TestBuffer->h / TestClipHeight); //ratio of the entire bitmap's height to the visible portion Scrollbar_X_Pos = (TestClipT/ViewRatio)+(Scrollbar_X_Offset/ScrollRatio); Scrollbar_Width = (TestClipHeight/ViewRatio); stretch_sprite(Buffer, Scrollbar, Scrollbar_X_Pos, Scrollbar_Y_Offset, Scrollbar_Width, Scrollbar->h); //having difficulties here }
I used to use just one ratio; big to small. I thought (TestBuffer->h / ScrollArea) was the same as (TestClipHeight / Scrollbar_Width) |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Don't use integer division. Convert to doubles and get a double type ratio. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Felix-The-Ghost
Member #9,729
April 2008
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Quote: Would that fix it? It will get rid of the inaccuracy caused by clipping of the fractional part. Is that the only thing wrong? I don't know, but I can try looking over things more tomorrow. Store the ratios as a double, use temporary doubles or casts to prevent the integer division. // int a = 12 , b = 5; double atob = double(a)/double(b);// using double constructors double atob2 = (double)a/(double)b;// using casts to double type int also_a = int(atob*double(b));// may not actually get exactly 'a' back // due to floating point inaccuracy // Please try to be consistent in your formatting schemes, it makes it a lot easier to read code if you do. (Don't mix tab indentation with space indentation, always indent when there is a new block {}) My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Felix-The-Ghost
Member #9,729
April 2008
|
? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Quote: I use DevCpp. When I indent with the tab button it adds a lot of spaces, or at least it seems so because I often highlight them individually and delete some to make the indents even. DevCpp may have a setting to control the number of spaces that a tab press will indent. CodeBlocks certainly does, but if there are tabs in the source code then you have to look at arrows every place there's a tab so I just replace them all with 2 or 3 spaces depending on what I'm coding for. Quote: Where did I not indent at a new block? Things like this (from your last code posting) : if (Scrollbar_X_Pos < Scrollbar_X_Offset) { Scrollbar_X_Pos = Scrollbar_X_Offset; //don't expand past the left button }
Quote: I guess I'll start cleaning up my code before I post it here. If you get in the habit of always doing your formatting consistently, you'll never have to 'clean it up'. Quote: What are atob and atob2? The ratio of a to b and a second method to find the same ratio. Just an example. Quote: And when I tried casting doubles it made the scrollbar over-expand in both directions. Okay, so let's see what your code is now. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Felix-The-Ghost
Member #9,729
April 2008
|
Yeah, I format my main code consistently, but I mean for stuff like this I usually just throw the required/important things together with minimum editing because I don't plan on reusing it. That's where I forgot to reindent after deleting some other blocks that weren't needed(yeah I copy+pasted if I was typing it it would have looked better . So does atob stand for something? I'll get the new code on here. I'll fix it up first too. |
someone972
Member #7,719
August 2006
|
It goes too far left because you scale the offset, this should remain the same. Scrollbar_X_Pos = (double(TestClipT)/ViewRatio)+(double(Scrollbar_X_Offset)/ScrollRatio); //should be Scrollbar_X_Pos = (double(TestClipT)/ViewRatio)+double(Scrollbar_X_Offset); The ViewRatio should be calulated using ScrollArea. ViewRatio = (double(TestBuffer->h) / double(TestClipHeight)); //should be ViewRatio = (double(TestBuffer->h) / double(ScrollArea)); This works correctly for me. It should stay where it is supposed to now. ______________________________________ |
Felix-The-Ghost
Member #9,729
April 2008
|
Gosh you edited your post... |
someone972
Member #7,719
August 2006
|
Ya, sorry about that. I was rapidly changing my post as I figured things out, at the end removing all the unnecessary pieces hoping you hadn't seen yet.:-X It appears as though you only need to change ViewRatio to Scroll Ratio in the width area and change the X position as stated above. ScrollRatio = (double(TestBuffer->h) / double(ScrollArea)); //original ViewRatio = (double(TestBuffer->h) / double(TestClipHeight)); //original Scrollbar_X_Pos = (double(TestClipT)/ViewRatio)+double(Scrollbar_X_Offset); //changed this Scrollbar_Width = (double(TestClipHeight)/ScrollRatio); //and this EDIT2: sorry again, I'm changing this too. ______________________________________ |
Felix-The-Ghost
Member #9,729
April 2008
|
Can you scroll all the way to the right and tell me if the is a little gap there? I edited mine and there is a little pixel gap. It scrolls and clicks the buttons the same now though. I wonder if I misunderstood Edgar. So you're saying that ScrollRatio and ViewRatio are actually the same now? That's what I was saying earlier... Quote: I used to use just one ratio; big to small. I thought (TestBuffer->h / ScrollArea) was the same as (TestClipHeight / Scrollbar_Width) also is this page stretched to you? Can you post again instead of editing please for clarity? |
someone972
Member #7,719
August 2006
|
Okay this one should work this time: Scrollbar_X_Pos = (double(TestClipT)/ScrollRatio)+double(Scrollbar_X_Offset); Scrollbar_Width = (double(TestClipHeight)/ScrollRatio); The Ratio's are the same as in the original file you posted. The pixel gap is there because ScrollArea is 184 and should be 185 I think. EDIT: This way seems to continue to work properly when the scroll area is increased. ______________________________________ |
Felix-The-Ghost
Member #9,729
April 2008
|
gosh so many edits... |
someone972
Member #7,719
August 2006
|
I guess I don't understand the problem now. Perhaps all my edits got something changed that wasn't supposed to be. Check my binary that's attached and see if it works as desired. If it does I can give you the right source. ______________________________________ |
Felix-The-Ghost
Member #9,729
April 2008
|
someone972
Member #7,719
August 2006
|
Ok, sorry it took so long to reply, I've been watching COPS. The only function I changed is the draw_scrollbar, here is the one I am using: void draw_scrollbar() { ScrollRatio = (double(TestBuffer->h) / double(ScrollArea)); ViewRatio = (double(TestBuffer->h) / double(TestClipHeight)); Scrollbar_X_Pos = (double(TestClipT)/ScrollRatio)+double(Scrollbar_X_Offset); Scrollbar_Width = (double(TestClipHeight)/ScrollRatio); stretch_sprite(Buffer, Scrollbar, Scrollbar_X_Pos, Scrollbar_Y_Offset, Scrollbar_Width, Scrollbar->h); }; I have also attached the entire source file if changing that doesn't work. ______________________________________ |
|
|