Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - mike_g

Pages: 1 [2] 3
21
C / C++ /C# / More problems with pointers :(
« on: May 11, 2007 »
I'm still having problems with pointers. This time I want to return a pointer to an object from a member function, but i cant seem to get it to work.

Heres the class definition:
Code: [Select]
class rooms
{
    private:
        int number;
        float cost;
        guests *p; // <------------------ My pointer
    public:
        rooms();
        ~rooms();
        int GetNumber();
        float GetCost();
        guests GetGuest(); // <---------- Get pointer function
        void AddGuest();
        void SetNumber(int);
        void SetCost(float);
}; 
Heres my get pointer function:
Code: [Select]
guests rooms::GetGuest()            {return *p;}And heres where I call it:
Code: [Select]
         if(room[i].GetGuest() != NULL)
            cout << "Booked\n";
        else
            cout << "Vacant\n";
This wont compile, but if I change the if statement to this:
Code: [Select]
if(&room[i].GetGuest() != NULL)It will but the prog crashes. Apart from that I have experimented with loads of different possibilites, but nothing wants to compile :( Can someone tell me what I am doing wrong here ??? Thanks.



22
As theres quite a few people here that code in ASM here I'm hoping someone could answer this for me. In the FDE cycle, if the same instruction (involving data) has to be run several times does the processor have to fetch the instruction over and over before each time it can get the data. Or does it leave the instruction in its register and just fetch the data until a new instruction is needed. This would be better, but is it how it works?  Cheers.

23
Projects / me RPG
« on: April 14, 2007 »
I recently started making an RPG type game. Its going to be very old school with lots of puzzle solving. So far I got most of the HUD working and you can wander around in the first level of the dungeon but its still pretty bare.

Screenie 1
Screenie 2
Screenie 3

Anyway I hope I manage to finish this.

24
C / C++ /C# / Passing Objects into a function
« on: March 28, 2007 »
I'm working on a C++ assignment at the moment and I want to pass an array of objects into a function. I think I got to use a pointer to the array, but what variable type would it be? Heres my code anyway. My problem is with the InitRooms() function.
Code: [Select]
#include <iostream>
#include <string.h>
using namespace std;

#define num_rooms 10

class guests
{
    private:
        char surname[10];
        int bill; 
    public:
        guests();
        void EndGuest();
        char* GetName();
        void AddCharge(int);
        float GetBill();         
};     

class rooms
{
    private:
        int number;
        float cost;
    public:
        rooms();
        int GetNumber();
        float GetCost();
    //Added setter  functions 
        void SetNumber(int);
        void SetCost(float);
};     

void InitRooms(int*);


int main()
{
    int i;
    rooms room[num_rooms];         //Constuct 10 rooms as globals
    InitRooms(*room[]);            //Set the variables for each room
   
    for(i=1; i<=10; i++)
        cout << "Room: " << room[i].GetNumber() << " at $" << room[i].GetCost() << "\n"; 
   
    cin >> i;
}   

//---- GUEST MEMBER FUNCTIONS ----//
guests::guests()
{
     cout << "enter name: ";
     cin >> surname;
     bill=0;
}
char* guests::GetName()             { return surname; }   
void  guests::AddCharge(int charge) { bill=bill+charge; }
float guests::GetBill()             { return bill; }

//---- ROOM MEMBER FUNCTIONS -----//
rooms::rooms()
{
    number=0;
    cost=0;
}           
int   rooms::GetNumber()            { return number; }
float rooms::GetCost()              { return cost;  } 
void  rooms::SetNumber(int n)       { number = n; }
void  rooms::SetCost(float c)       { cost = c; }

//----- INITIALIZE ROOMS ---------//
void InitRooms(int *room[])
{
    for(int i=1; i<=10; i++) room[i].SetNumber(i);
   
    room[1].SetCost(100);  room[2].SetCost(90);                     
    room[3].SetCost(85.5); room[4].SetCost(80); 
    room[5].SetCost(80);   room[6].SetCost(50); 
    room[7].SetCost(50);   room[8].SetCost(45.5); 
    room[9].SetCost(45.5); room[10].SetCost(40); 

I know an easy way to get this to work would be to have the array of room as a global. One of my teachers last year went berserk on me for using a global, so I'd like find out how to do this. Cheers.

25
Java,JS & Flash / Znax Clone In Javascript
« on: March 27, 2007 »
Heres another game I made in javascript so far its a working clone of Znax, one of my favorite games in the arcade. I'm also working on a set of special tiles and a different time system that will hopefully add some depth and make this a bit more original. If anyone has any cool ideas then let us know. Cheers.

26
Useful links / pngout
« on: March 22, 2007 »
Something cool I found: pngout. It further compresses PNG files losslessly. The link at the top of the page goes to a version with a GUI that is for sale. The second link PNGOUT.EXE is a free version thats only 40k, just drag and drop your PNG's on it to compress em.

27
Heres another entry done in Cobra. Its a pretty simple clock type thing w/o music.

Download: http://mike_g.sitesled.com/20_SEC_CLOCK.zip

28
Blitz / About Colour Palettes[BB2D]
« on: March 16, 2007 »
Using a colour palette is fast, but what happens when you use bitmap images with them? It seems to work very well for creating stuff like gradients (the Pixel Fire fire .bb code being one of my favorites), but if you use images then how do you know where in the array each colour is?

I dont know maybe I dont quite understand the concept yet, or is this just a limitation/complexity that comes with using palettes?

29
Java,JS & Flash / Updating text on a page
« on: March 14, 2007 »
Hey benny, heres the code for the javascript game I made, with css and all. Be warned its pretty crude. Bascially you get 3 minutes to answer as many questions as possible. You score 10 points for each correct one, and lose 5 for each one thats wrong. Oh yeah version 1 works, version 2 dosent.

Heres my problem: At the moment the only way I know how to update text on the screen is by either having it inside a form field, or by redrawing the entire page. You will notice that the target score is in a form field, but I would like it drawn in text.

I figured that it should be possible to update it by creating an object for it and then writing a member function for the object to update the text since the timer and input fields are both capable of doing this. In version 2 I got the target set as a variable in an object but when it changes I dont know how to update it on the screen ???  cheers :)





30
Challenges & Competitions / 20 Second Fishies
« on: March 13, 2007 »
Heres my entry

Its my first demo so I added some pixel art to try and make up for what I lack in programming abilities.

Thanks to zawran and shockwave for help with the coding :)

I havent got any music making software, so I ripped some of the music from the first level of Gaiares cos its old school, cheesy, & cool :) Dont know who made it tho so I cant credit em for it :(

Also I'm sorry for the large download size, its mainly to do with the music. Ironic when its originally about 50k but ends up 1.7MB when zipped as a wav. I guess I got to get something to convert file formats. Anyway hope you guys like it :)

[edit]Oh yeah and the seaweed and Crack effect might come out looking weird sometimes because they are randomised.[/edit]

31
Its kind of embarrasing asking such a simple maths question but:

Say I have a start x/y co-ordinate, an angle in degrees, and a distance. How can I get the end x/y co-ordinates from this?

32
Cobra / Amoeba Things
« on: March 09, 2007 »
Heres a Cobra conversion of the amoeba things I made in Blitz. I added a fill parameter to it using the built in floodfill command.
Code: [Select]
program
    uses pure2d, keyset

var
    fuzzer: array[10, 360] of integer
    fuzzdir: array[10, 360] of integer

procedure FUZZ_INIT(number, intensity, fuzz)
var
    i:integer
begin       
    for i = 1 to fuzz
        fuzzer[number, i] = Rand(0, intensity)
    next
end 

procedure FUZZY_CIRCLE(number, cx, cy, rad, fuzz, intensity, vibration, randy, colour, fill)
var
    angle_step: real
    degrees: real
    first_x, first_y: integer
    last_x, last_y: integer
    this_x, this_y: integer
    i: integer

begin   
    angle_step = (toreal(360) / toreal(fuzz))
    first_x = (cx - (rad +fuzzer[number, 1]) * Cos(degrees))
    first_y = (cy - (rad +fuzzer[number, 1]) * Sin(degrees))
    this_x = (cx - (rad +fuzzer[number, 1]) * Cos(degrees))
    this_y = (cy - (rad +fuzzer[number, 1]) * Sin(degrees))
    FUZZ_MOVE(number, 1, intensity, vibration, randy)


    For i = 2 To fuzz
        degrees = degrees + angle_step   
        last_x = this_x
        last_y = this_y
        FUZZ_MOVE(number, i, intensity, vibration, randy)
        this_x = (cx - (rad +fuzzer[number, i]) * Cos(degrees))
    this_y = (cy - (rad +fuzzer[number, i]) * Sin(degrees))
    Line (last_x, last_y, this_x, this_y, colour)
    Next
    Line (this_x, this_y, first_x, first_y, colour)
   
    if fill = 1 then FloodFill(cx, cy, colour, colour, TRUE)
end

procedure FUZZ_MOVE(number, i, intense, vibration, randy)

begin
    If fuzzdir[number, i] = 0
    fuzzer[number, i] = fuzzer[number, i] + vibration +Rand(0, randy)
    Else
    fuzzer[number, i] = fuzzer[number, i] - vibration -Rand(0, randy)
    EndIf

    If fuzzer[number, i] >= intense
    fuzzdir[number, i] = 1
    else
        if fuzzer[number, i] <= -intense
        fuzzdir[number, i] =0
        endif
    EndIf
end




begin
    openscreen(1024, 768)
    FUZZ_INIT(1, 100, 360)
    FUZZ_INIT(2, 100, 360)
    FUZZ_INIT(3, 100, 360)
    FUZZ_INIT(4, 100, 360)
    FUZZ_INIT(5, 100, 360)
   
    while not keydown(vk_escape)
    Cls
    FUZZY_CIRCLE(2, 300, 300, 180, 200, 50, 4, 1, ToRGBA(200, 0, 0),1)
    FUZZY_CIRCLE(3, 300, 300, 100, 120, 40, 3, 1, ToRGBA(200, 100, 0),1)
    FUZZY_CIRCLE(2, 300, 300, 50, 60, 30, 2, 1, ToRGBA(200, 150, 0),1)
    FUZZY_CIRCLE(1, 300, 300, 30, 40, 10, 1, 1, ToRGBA(200, 200, 50),1)
    FUZZY_CIRCLE(1, 300, 300, 20, 30, 2, 1, 0, ToRGBA(200, 200, 200),1)
       
       
    FUZZY_CIRCLE(5, 650, 160, 80, 20, 10, 2, 0, ToRGBA(50, 80, 120),1)       
    FUZZY_CIRCLE(5, 660, 150, 50, 15, 10, 2, 0, ToRGBA(50, 120, 200),1)    
        Flip
    wend
   
end

33
Cobra / My First Cobra Prog
« on: March 07, 2007 »
I finally got around to trying out Cobra. So far I quite like it :)

The prog is a conversion of the Circle sector drawing function that I wrote in Blitz. I tried to make it better by adding a fill parameter, using the cobra FloodFill() command. I'm doing something wrong though cos sometimes its filling outside the sector.
Code: [Select]
program
    uses pure2d,keyset

function DRAW_SECTOR(cx, cy, inner_rad, outer_rad, start_deg, sector_deg, fill, r, g, b): boolean
var
    increment: real
    steps: integer
    degrees: real
    x, y, i: integer
    x1, y1, x2, y2: integer
    colour: integer

begin
    colour = ToRGBA(r, g, b)
    //DRAW OUTER CURVE
    increment = toreal(sector_deg / (outer_rad * Pi *2))
    steps = sector_deg / increment
    degrees = start_deg
    for i = 0 to steps+1
        x = cx - outer_rad * Cos(degrees)
        y = cy - outer_rad * Sin(degrees)
        Pixel(x, y, colour)
        degrees = degrees + increment
    next   

    //DRAW INNER CURVE
    increment = toreal(sector_deg /(inner_rad * Pi * 2))
    steps = sector_deg / increment
    degrees = start_deg
    for i = 0 to steps+1
        x = cx - inner_rad * Cos(degrees)
        y = cy - inner_rad * Sin(degrees)
        Pixel(x, y, colour)
        degrees = degrees + increment   
    next   
 
    //DRAW LINES
    x1 = (cx - inner_rad * Cos(start_deg))
    y1 = (cy - inner_rad * sin(start_deg))
    x2 = (cx - outer_rad * Cos(start_deg))
    y2 = (cy - outer_rad * sin(start_deg))
    Line (x1, y1, x2, y2, colour)
    x1 = (cx - inner_rad * Cos(start_deg + sector_deg))
    y1 = (cy - inner_rad * sin(start_deg + sector_deg))
    x2 = (cx - outer_rad * Cos(start_deg + sector_deg))
    y2 = (cy - outer_rad * sin(start_deg + sector_deg))
    Line (x1, y1, x2, y2, colour) 
   
    if fill = 1
        x = (cx - ((inner_rad + outer_rad) / 2 )* Cos((start_deg + sector_deg) / 2))
        y = (cy - ((inner_rad + outer_rad) / 2 )* sin((start_deg + sector_deg) / 2))
        FloodFill(x, y, colour, colour, TRUE)
    endif
end

//EXAMPLE PROGRAM   
var
    i:integer
    a, b: integer

begin
    openscreen
    a=2
    b=1
   
    while not KeyDown(vk_escape)
        cls
        DRAW_SECTOR(200, 200, 60, 100, i, 270, 1, 150, 0, 0) 
        DRAW_SECTOR(200, 200, 20, 50, -i, 270, 1, 100, 0, 0)
       
        DRAW_SECTOR(500, 200, 1+a, 60+a, i+240, 60, 0, 255, 255, 255)
        DRAW_SECTOR(500, 200, 1+a, 60+a, i+120, 60, 0, 255, 255, 255)
        DRAW_SECTOR(500, 200, 1+a, 60+a, i, 60, 0, 255, 255, 255)         
       
        a=a+b
        if a > 100 then b = -b
        if a < 2 then b =-b
                 
        i=i+1
        if i = 360 then i = 0
        flip
    wend
end

34
Blitz / Scrolling LED Text[BB2D]
« on: March 06, 2007 »
Heres a scrolling text function I just managed to finish before I go sleep. It should be fairly easy to put into in progs. The text is all pre-drawn to a bitmap image. I did this because I figured it would be faster than drawing each loop. The downside to that is that no animation or colour changing can be done to it :( I still plan on adding a couple more features and making the font look a little nicer but other than that I consider this pretty much done. Oh and i still got to work out why the mess is occurring, but at least it looks kinda nice :p

Code: [Select]
Graphics 640, 480, 32, 2

;--------------------------------------;
;********** NEEDED IN PROG ************;
;--------------------------------------;
Dim letter_data(236, 8)
INIT_LETTER_DATA()

Type led
Field x, y, w, h, dir, spd, image, spawn, x_start
End Type
;--------------------------------------;
;************ DEMO LOOP ***************;
;--------------------------------------;
CREATE_LED(0, 0, 1, 0, 150, 0, 6, 0, "Some stuff    ")
CREATE_LED(65, 0, 2, 100, 0, 150, 10, 0, "hello heres an example of a scrolling text function")
CREATE_LED(160, 1, 5, 120, 20, 0, 6, 1, "0010 1000 0110 1111 0101 1100 ")
CREATE_LED(200, 1, 2, 150, 20, 0, 10, 1, "daer ot gnisufnoc eb dluow sihT     Confusing   ")
CREATE_LED(300, 0, 8, 0, 150, 0, 4, 1, "read me      ")
CREATE_LED(380, 0, 3, 150, 150, 250, 6, 1, "Heres a mess   ")
CREATE_LED(360, 0, 3, 100, 0, 100, 10, 0, "hello heres an example of a scrolling text function    ")
While Not KeyHit(1)
Cls
DRAW_LEDS()
Flip
Wend


;--------------------------------------;
;************ FUNCTIONS ***************;
;--------------------------------------;
Function DRAW_LEDS()
For l.led = Each led
DrawImage l\image, l\x, l\y
If l\dir = 0
l\x=l\x-l\spd
;loop the text
If l\x+l\w < GraphicsWidth() And l\spawn = 0
l\spawn = 1

l2.led = New led
l2\x = l\x_start: l2\y = l\y
l2\w = l\w: l2\h = l\h
l2\dir = l\dir: l2\spd = l\spd
l2\image = l\image
l2\x_start = l\x_start
;clean up text thats scrolled off screen
Else If l\x+l\w < 0
Delete l.led
EndIf
Else
l\x=l\x+l\spd
;loop the text
If l\x > 0 And l\spawn = 0
l\spawn = 1

l2.led = New led
l2\x = l\x_start: l2\y = l\y
l2\w = l\w: l2\h = l\h
l2\dir = l\dir: l2\spd = l\spd
l2\image = l\image
l2\x_start = l\x_start
;clean up text thats scrolled off screen
Else If l\x > GraphicsWidth()
Delete l.led
EndIf
EndIf

Next

End Function

;-----------------CREATE LED PARAMETERS----------------------;
;x_pos = x position for image to start at
;y_pos = y position for image to start at
;dir = direction led moves: 0 = left, 1 = right
;spd = speed image moves
;r, g , b = colour elements
;dot_size = the size of the dots
;dot_type = dot shape: 0 = round, 1 = square
;led_string = The text you want to display
;------------------------------------------------------------;

Function CREATE_LED(y_pos, dir, spd, r, g, b, dot_size, dot_type, led_string$)
length = Len(led_string$)
l.led = New led
l\image = CreateImage(8*dot_size*length, 8*dot_size)
l\y = y_pos
l\w = ImageWidth(l\image)
l\h = ImageHeight(l\image)
l\dir = dir: l\spd = spd
If l\dir = 0 
l\x = GraphicsWidth()
l\x_start = l\x
Else
l\x = -l\w
l\x_start = l\x
EndIf 


SetBuffer ImageBuffer(l\image)
For c = 1 To length
char$ = Mid(led_string$, c, 1)

ascii = Asc(char$)
If ascii < 58 And ascii > 47 ;Is Numeric
loc = ((Asc(char$)-48)*6)+1
Else If ascii > 64 And ascii < 91 ;Alpha Upper Case
loc = ((Asc(char$)-55)*6)+1
Else If ascii > 96 And ascii < 123  ;Lower case gets converted to upper
loc = ((Asc(char$)-87)*6)+1
Else If ascii = 32 ;Is space
space = 1
Else ;Is metacharacter

EndIf

If space = 0
For x = 0 To 5
For y = 1 To 8
If letter_data(loc+x, y) = 1
Color r, g, b
If dot_type = 0
Oval ((c-1)* dot_size*8)+((x)*dot_size), ((y-1)*dot_size), dot_size-2,dot_size-2, 1
Else
Rect ((c-1)* dot_size*8)+((x)*dot_size), ((y-1)*dot_size), dot_size-2,dot_size-2, 1
EndIf
If r-40 > 0
r2=r-80
Else
r=0
EndIf
If g-40 > 0
g2=g-80
Else
g2=0
EndIf
If b-40 > 0
b2=b-80
Else
b=0
EndIf

Color r2, g2, b2
If dot_type = 0
Oval ((c-1)* dot_size*8)+((x)*dot_size), ((y-1)*dot_size), dot_size-2,dot_size-2, 0
Else
Rect ((c-1)* dot_size*8)+((x)*dot_size), ((y-1)*dot_size), dot_size-2,dot_size-2, 0
EndIf

EndIf
Next
Next
EndIf
space = 0
Next 

SetBuffer BackBuffer()
End Function

;--------------------------------------;
Function INIT_LETTER_DATA()
;0 to 9
For y = 1 To 8
For x = 1 To 60
Read letter_data(x, y)
Next
Next
;A to J
For y = 1 To 8
For x = 61 To 120
Read letter_data(x, y)
Next
Next
;K to T
For y = 1 To 8
For x = 121 To 180
Read letter_data(x, y)
Next
Next
;U to Z
For y = 1 To 8
For x =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,0,0,1, 0,0,1,1,0,0
Data 1,0,0,0,0,1, 1,1,1,1,1,1, 1,0,0,0,0,1, 1,0,0,0,1,1, 0,1,1,1,1,0, 1,0,0,0,0,0, 0,0,0,0,1,1, 1,0,0,0,0,1, 0,1,1,1,1,0, 0,0,1,1,0,0

;U to Z
Data 1,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,0,0,1, 1,1,1,1,1,1
Data 1,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,0,0,1, 0,0,0,0,0,1
Data 1,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,0,0,1, 0,1,0,0,1,0, 1,0,0,0,0,1, 0,0,0,0,1,0
Data 1,0,0,0,0,1, 0,1,0,0,1,0, 1,0,0,0,0,1, 0,0,1,1,0,0, 0,1,1,1,1,1, 0,0,0,1,0,0
Data 1,0,0,0,0,1, 0,1,0,0,1,0, 1,0,0,0,0,1, 0,0,1,1,0,0, 0,0,0,0,0,1, 0,0,1,0,0,0
Data 1,0,0,0,0,1, 0,1,0,0,1,0, 1,0,1,1,0,1, 0,1,0,0,1,0, 0,0,0,0,0,1, 0,1,0,0,0,0
Data 1,0,0,0,0,1, 0,0,1,1,0,0, 0,1,1,1,1,0, 1,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,0,0,0
Data 0,1,1,1,1,0, 0,0,1,1,0,0, 0,1,0,0,1,0, 1,0,0,0,0,1, 0,1,1,1,1,0, 1,1,1,1,1,1

35
Blitz / How to do alpha blending?[BB2D]
« on: March 04, 2007 »
Hi, Im working on a prog at the moment with a gradient background with bubbles on it that are drawn lighter. I tried to work out how to blend it by copying from the Trans Sprite example in the blitz sample files. Couldent get it to work tho  :( Then I tried all sorts of other things that dident work :( In the end I just added a hex value to the colour to lighten it , but now when the blue element goes > 255 the colour turns to a yucky brown :(

I'll post my code. The colour alterations are done in the CIRCLE() functions. If someone could tell me how I could do this better, or provide me with a link, or something else useful it would be much appreciated by me :) 

Code: [Select]
Graphics 640, 480, 32, 2
Global back = CreateImage(640, 480)
INIT_BACKGROUND()


Type bubble
Field x, y, rad, col, wobble, spd
End Type

For i = 1 To 10
b.bubble = New bubble
b\x=Rand(0, 640): b\y=Rand(0, 480)
b\rad=Rand(10, 30): b\col=$ffffff
b\spd=Rand(2, 5)
b\wobble = Rand(1, 360)
Next

While Not KeyHit(1)
Cls

DrawImage back, 0, 0
BACK_ANIM()

BUBBLE_SPAWN()
BUBBLE_WOBBLE()
BUBBLE_CLEAN()

i=i+1
If i = 360 Then i = 0
Flip
Wend


Function INIT_BACKGROUND()
SetBuffer ImageBuffer(back)
LockBuffer
For y = 0 To 479
Color r#, g#, b#
Line 0, y, 639, y
b#=b#+0.5
If y > 200 Then g#=g#+0.7
If y > 250 Then r#=r#+0.5
Next
UnlockBuffer
SetBuffer BackBuffer()
End Function


Function BACK_ANIM()

LockBuffer
For b.bubble = Each bubble
b\y = b\y-b\spd
F_CIRCLE(b\x, b\y, b\rad)
CIRCLE(b\x, b\y, b\rad)
Next
UnlockBuffer

End Function


Function BUBBLE_SPAWN()
If Rand(1, 10) = 1
b.bubble = New bubble
b\x=Rand(0, 640): b\y=480
b\rad=Rand(10, 30): b\col=$ffffff
b\spd=Rand(2, 5)
b\wobble = Rand(1, 360)
EndIf
End Function

Function BUBBLE_WOBBLE()
For b.bubble = Each bubble
b\x=b\x+Cos(b\wobble)
b\wobble=b\wobble+b\spd
Next
End Function

Function BUBBLE_CLEAN()
For b.bubble = Each bubble
If b\y < -b\rad Then Delete b.bubble
Next
End Function



Function CIRCLE(cx, cy, radius)
   d = 3 - (radius Shl 1)
   x = 0
   y = radius
   
   Repeat
      c = (ReadPixel(cx + x, cy + y))
  WritePixel cx + x, cy + y, c+$111111


  c = (ReadPixel(cx + x, cy - y))   
  WritePixel cx + x, cy - y, c+$111111

      c = (ReadPixel(cx - x, cy + y))
      WritePixel cx - x, cy + y, c+$111111     

      c = (ReadPixel(cx - x, cy - y))
  WritePixel cx - x, cy - y, c+$111111
     
      c = (ReadPixel(cx + y, cy + x))
  WritePixel cx + y, cy + x, c+$111111
     
      c = (ReadPixel(cx + y, cy - x))
  WritePixel cx + y, cy - x, c+$111111
     
      c = (ReadPixel(cx - y, cy + x))
  WritePixel cx - y, cy + x, c+$111111     
 
  c = (ReadPixel(cx - y, cy - x))   
  WritePixel cx - y, cy - x, c+$111111
     
  If d < 0 Then
         d = d + (x Shl 2) + 6
      Else
         d = d + ((x-y) Shl 2) + 10
         y = y - 1
      End If
      x = x + 1
   Until x > y
End Function

Function F_CIRCLE(cx, cy, rad)
inc# = Float(360/(rad*Pi*2))
steps = 90/inc#
For i = 1 To steps
x1 = (cx - rad * Cos(deg#))
y1 = (cy - rad * Sin(deg#))

x2 = cx+cx-x1
y2 = cy+cy-y1

If x1 < 0 Then x1 = 0
If x2 > 1023 Then x2 = 1023
If y1 < 0 Then y1 = 0
If y1 > 767 Then y1 = 767
If y2 < 0 Then y2 = 0
If y2 > 767 Then y2 = 767

If y2 > old_y ;Prevents scanline from being drawn more than once
old_y = y2

For x = x1 To x2
col= ReadPixelFast(x, y1)
WritePixelFast x, y1, col+$111111
Next

If i > 1 ;Prevents scanline from being drawn more than once
For x = x1 To x2
col= ReadPixelFast(x, y2)
WritePixelFast x, y2, col+$111111
Next
EndIf
EndIf

deg# = deg# + inc#
Next
End Function

36
Blitz / Sector Drawing Function[BB2D]
« on: March 04, 2007 »
I havent been coding for quite some time now. I plan on getting back into it. Anyway heres something I came up with last night. Its nothing amazing, it just draws sectors of circles.

Code: [Select]
Graphics 640, 480, 32, 2
SetBuffer BackBuffer()
While Not KeyHit(1)
Cls
DRAW_SECTOR(200, 200, 20, 100, 60, i, $ffffff)
DRAW_SECTOR(200, 200, 20, 100, 60, i+120, $ffffff)
DRAW_SECTOR(200, 200, 20, 100, 60, i+240, $ffffff)

DRAW_SECTOR(500, 200, 70, 100, 300, i, $ffffff)
DRAW_SECTOR(500, 200, 20, 50, 300, 360-i, $ffffff)

i=i+1
If i = 360 Then i = 0
Flip
Wend

Function DRAW_SECTOR(cx, cy, start_rad, end_rad, sector_deg, start_deg, col)
LockBuffer
;DRAW OUTER CURVE
inc# = Float(sector_deg/(end_rad*Pi*2))
steps = sector_deg/inc#
deg# = start_deg
For i = 1 To steps
x = (cx - end_rad * Cos(deg#))
y = (cy - end_rad * Sin(deg#))
If x >= 0 And x < GraphicsWidth() And y >= 0 And y < GraphicsHeight()
WritePixelFast x, y, col
EndIf
deg# = deg# + inc#
Next

;DRAW INNER CURVE
inc# = Float(sector_deg/(start_rad*Pi*2))
steps = sector_deg/inc#
deg# = start_deg
For i = 1 To steps
x = (cx - start_rad * Cos(deg#))
y = (cy - start_rad * Sin(deg#))
If x >= 0 And x < GraphicsWidth() And y >= 0 And y < GraphicsHeight()
WritePixelFast x, y, col
EndIf
deg# = deg# + inc#
Next

;DRAW LINES
x1 = (cx - start_rad * Cos(start_deg))
y1 = (cy - start_rad * Sin(start_deg))
x2 = (cx - end_rad * Cos(start_deg))
y2 = (cy - end_rad * Sin(start_deg))
Line x1, y1, x2, y2
x1 = (cx - start_rad * Cos(start_deg+sector_deg))
y1 = (cy - start_rad * Sin(start_deg+sector_deg))
x2 = (cx - end_rad * Cos(start_deg+sector_deg))
y2 = (cy - end_rad * Sin(start_deg+sector_deg))
Line x1, y1, x2, y2
UnlockBuffer
End Function

37
Blitz / Whats Faster?[BB2D]
« on: January 12, 2007 »
I am having a go at using the Data statement for the first time and I was wondering, what would be faster:

Reading the data each loop, or reading the data once and writing it to an array then reading the array each loop. Or  maybe it dosent make any difference.

38
Jim posted some code for me the other day to draw a rotatable rectangle. I have been trying to change the point of rotation from a corner of the shape to the centre of it. I seem to have got it centred on one axis but cant centered on the other, and my rectangle now seems to be bigger than its meant to be o_0. Anyway I'm not so good at maths so I have sort of been guessing what to do, heres my code:
Code: [Select]
SetBuffer BackBuffer()
While Not KeyHit(1)
Cls
ROTATING_RECT(200, 150, 80, 40, i)
i=i+1
If i = 360 Then i = 0
Flip
Wend

Function ROTATING_RECT(x, y, w, h, angle)
s# = Sin(angle)
c# = Cos(angle)

ox = (w/2)
oy = (h/2)

sw# = ox*s
cw# = ox*c
sh# = oy*s
ch# = oy*c

x1 = x-cw-ch: y1 = y-sw-sh
x2 = x+cw+ch: y2 = y+sw+sh
x3 = x+cw-sh+ch-sw: y3 = y+sw+ch+sh+cw
x4 = x-sh-cw-sw-ch: y4 = y+ch-sw+cw-sh

Plot x, y
Plot x1, y1
Plot x2, y2
Plot x3, y3
Plot x4, y4
End Function
Since my code might be more confusing than helpfull. Heres Jims code converted to draw in Blitz as well:
Code: [Select]
SetBuffer BackBuffer()
While Not KeyHit(1)
Cls
ROTATING_RECT(200, 150, 80, 30, i)
i=i+1
If i = 360 Then i = 0
Flip
Wend

Function ROTATING_RECT(x, y, w, h, angle)
s# = Sin(angle)
c# = Cos(angle)
sw# = w*s
cw# = w*c
sh# = h*s
ch# = h*c

Plot x, y
Plot x+cw, y+sw
Plot x+cw-sh, y+sw+ch
Plot x-sh, y+ch
End Function

39
General coding questions / Rotating Rectangle
« on: January 07, 2007 »
I would like to find out how I could make a filled rotateable rectange function. My idea was that the function could have 5 parameters like: ROT_RECT(x, y, width, height, angle). which rotates around the center point. Help would be much appreciated.

40
Blitz / GUI Functions[BB2D]
« on: January 06, 2007 »
Just incase any of you guys ever need a dropdown menu or scrollbar in Blitz youre welcome to use these functions I made  :)

Dropdown menu:
Code: [Select]
Graphics 1024, 768
SetBuffer BackBuffer()
;-----------------------------------------------------------------------------------------------------
;**********************!!! GLOBALS NEEDED IN PROGRAM !!! *********************************************
Global menuopen, listlength, x_select ;Menu variables
Global sublength, y_substart, parentnum ;Submenu variables
Global inputstring$ ;Selected action
Const  menu_fields = 10 ;Set array dimensions
Const  list_fields = 10
Const  sub_fields  = 10
Dim menus$(menu_fields, list_fields, sub_fields) ;Create the array
Global dropdown_font_1 = LoadFont(verdana ,16 , True, False,False) ;First font is for titles
Global dropdown_font_2 = LoadFont(verdana ,16 , False, False,False) ;Second font for list items
;*****************************************************************************************************
;-----------------------------------------------------------------------------------------------------

;DEMO STUFF
Global demofont = LoadFont(verdana ,30 , True, False,False)
inputstring$ = "Nothing yet"
;Declare Menu Titles
menus$(0,0,0) = "File"
menus$(1,0,0) = "Options"
menus$(2,0,0) = "Preferences"
menus$(3,0,0) = "Graphics"
menus$(4,0,0) = "Sound"
menus$(5,0,0) = "Controls"
menus$(8,0,0) = "Other Things"
;Name items on menu lists
menus$(0,1,0) = "New"
menus$(0,2,0) = "Save"
menus$(0,3,0) = "Save As"
menus$(0,4,0) = "Load"
menus$(0,5,0) = "Quit"

menus$(1,1,0) = "Option 1"
menus$(1,2,0) = "Option 2"
menus$(1,3,0) = "Option 3"
menus$(1,4,0) = "Option 4"
menus$(1,5,0) = "Option 5"
menus$(1,6,0) = "Option 6"
menus$(1,7,0) = "Option 7"
menus$(1,8,0) = "Option 8"
menus$(1,9,0) = "Option 9"

menus$(2,1,0) = "Preference 1"
menus$(2,2,0) = "Preference 2"

menus$(3,1,0) = "Nice"
menus$(3,2,0) = "Not So Nice"
menus$(3,3,0) = "Bad"

menus$(4,1,0) = "On"
menus$(4,2,0) = "Off"

menus$(5,1,0) = "Cofigure"

menus$(8,1,0) = "This Thing"
menus$(8,2,0) = "That Thing"
menus$(8,3,0) = "Something"
menus$(8,4,0) = "Nothing"
menus$(8,5,0) = "Everything"
;Name items in sub lists
menus$(0,1,1) = "Big Thing"
menus$(0,1,2) = "Medium Thing"
menus$(0,1,3) = "Small Thing"
menus$(0,1,4) = "Other Thing"

menus$(0,3,1) = "This"
menus$(0,3,2) = "That"
menus$(0,3,3) = "Whatever"

menus$(1,3,1) = "Woohoo"
menus$(1,3,2) = "Somethings"
menus$(1,3,3) = "Here"

menus$(1,8,1) = "Sub List 1"
menus$(1,8,2) = "Sub List 2"
menus$(1,8,3) = "Sub List 3"
menus$(1,8,4) = "Sub List 4"
menus$(1,8,5) = "Sub List 5"
;-------------------------------------------------------------------------------------------------------
;****************************** MAIN LOOP **************************************************************
;-------------------------------------------------------------------------------------------------------
While Not KeyHit(1)
Cls
DROPDOWNMENU(1024, 20)
Color 255, 255, 255: Rect MouseX(), MouseY(), 3, 3, 1
SetFont demofont: Color 100, 100, 100 :Text 330, 500, "You have selected: "+inputstring$
Flip
Wend

;-------------------------------------------------------------------------------------------------------
;****************************** FUNCTION ***************************************************************
;-------------------------------------------------------------------------------------------------------

;"BAR_WIDTH" SHOULD BE GRAPHICS X RESOLUTION UNLESS YOU WANT THE BAR TO ONLY SPAN PART OF THE SCREEN
;"BAR_HEIGHT" DETERMINES THE HEIGHT OF THE BAR, FONT SIZES SHOULD BE SET APPROPRIATELY
;THE BAR IS DIVIDED INTO AN AMOUNT OF FIELDS DETERMINED BY THE "MENU_FIELDS" CONSTANT
;THE MAXIMUM NUMBER OF ITEMS ON THE MENU LISTS IS THE "LIST_FIELDS" CONSTANT -1 FOR THE TITLE

Function DROPDOWNMENU(bar_width, bar_height)

field_width = bar_width / menu_fields
x_pos = x_select * field_width
list_height = listlength * bar_height

;Draw Menu Bar
Color 50,  50, 60   :Rect 0, 0, bar_width, bar_height, 1
Color 150, 150, 200 :Rect 0, 0, bar_width, bar_height, 0
;Draw menu bar titles
SetFont dropdown_font_1
Color 100, 100, 100
For i = 0 To 100
Text 6+(i*field_width), 2, menus$(i,0,0)
If i = menu_fields Then Exit
Next

;IF THE CURSOR IS OVER THE MENUBAR
If MouseY() < bar_height And MouseX() < bar_width
listlength = 0
x_select = (MouseX() / field_width)
If menus$(x_select, 0,0) <> ""
For i = 1 To 100
If menus$(x_select, i,0) <> "" Then listlength = listlength +1
If i = list_fields Then Exit
Next
x_pos = x_select * field_width
list_height = listlength * bar_height
Color 50, 50, 60 :Rect x_pos, bar_height-1, field_width, list_height+1
Color 150, 150, 200 :Rect x_pos, 0, field_width, bar_height+list_height, 0
Color 100, 100, 100
SetFont dropdown_font_2
For i = 1 To 100
Text x_pos+4, (i*bar_height), menus$(x_select, i, 0)
If menus$(x_select, i, 1) <> ""
SetFont dropdown_font_1
Text (x_pos+field_width-10), (i*bar_height), ">"
SetFont dropdown_font_2
EndIf
If i = list_fields Then Exit
Next
menuopen = 1
EndIf
;ELSE IF THE MENU IS OPENED AND CURSOR MOVED DOWN OVER THE LIST
Else If menuopen > 0 And MouseX() > x_pos And MouseX() < (x_pos+field_width) And MouseY() < (list_height+bar_height)
Color 50, 50, 60 :Rect x_pos, bar_height-1, field_width, list_height+1
Color 150, 150, 200 :Rect x_pos, 0, field_width, bar_height+list_height,0
Color 100, 100, 100
SetFont dropdown_font_2
For i = 1 To 100
Text x_pos+4, (i*bar_height), menus$(x_select, i, 0)
If menus$(x_select, i, 1) <> ""
SetFont dropdown_font_1
Text (x_pos+field_width-10), (i*bar_height), ">"
SetFont dropdown_font_2
EndIf
If i = list_fields Then Exit
Next
;HIGHLIGHT ITEM ON LIST THAT CURSOR IS OVER
y_select = (MouseY()/bar_height) :parentnum = y_select
Color 100, 100, 100 :Rect x_pos+1, (y_select*bar_height), field_width-2, bar_height-1
Color 50, 50, 60 :Text x_pos+4, (y_select*bar_height), menus$(x_select, y_select,0) 
;IF MOUSEHIT INPUT ACTION
If MouseHit(1) Then inputstring$ = menus$(x_select, y_select,0)
;IF THERE IS A SUB MENU UNDER SELECTED ENTRY THEN DISPLAY IT
If menus$(x_select, y_select, 1) <> ""
sublength = 0
For i = 1 To 100
If menus$(x_select, y_select, i) <> ""
sublength = sublength + 1
y_substart = ((y_select*bar_height)+(i*bar_height)-bar_height)
EndIf 
If i = sub_fields Then Exit
Next
y_substart = y_substart - (sublength*bar_height)+bar_height
Color 50, 50, 60 :Rect (x_pos+field_width), y_substart, field_width, (sublength*bar_height)
Color 150, 150, 200 :Rect (x_pos+field_width), y_substart, field_width, (sublength*bar_height),0
Color 50, 50, 60 :Rect (x_pos+field_width)-1, y_substart+1, 2, bar_height-2
Color 100, 100, 100
For i = 1 To 100
If menus$(x_select, y_select, i) <> ""
Text (x_pos+field_width+4), (y_substart+(i*bar_height)-bar_height), menus$(x_select, y_select, i)
EndIf
If i = sub_fields Then Exit
Next 
menuopen = 2
Else
menuopen = 1
EndIf
;ELSE IF MENU OPEN AND CURSOR IS OVER A SUB LIST
Else If menuopen=2 And MouseX()>=(x_pos+field_width-1) And MouseX()<(x_pos+(field_width*2)) And MouseY() > y_substart And MouseY() < (y_substart+(sublength*bar_height))
;DRAW PARENT LIST
Color 50, 50, 60 :Rect x_pos, bar_height-1, field_width, list_height+1
Color 150, 150, 200 :Rect x_pos, 0, field_width, bar_height+list_height,0
Color 100, 100, 100
SetFont dropdown_font_2
For i = 1 To 100
Text x_pos+4, (i*bar_height), menus$(x_select, i, 0)
If menus$(x_select, i, 1) <> ""
SetFont dropdown_font_1
Text (x_pos+field_width-10), (i*bar_height), ">"
SetFont dropdown_font_2
EndIf
If i = list_fields Then Exit
Next
;DRAW SUBLIST
Color 50, 50, 60 :Rect (x_pos+field_width), y_substart, field_width, (sublength*bar_height)
Color 150, 150, 200 :Rect (x_pos+field_width), y_substart-1, field_width, (sublength*bar_height)+1,0
Color 50, 50, 60 :Rect (x_pos+field_width)-1, y_substart+1, 2, bar_height-2
Color 100, 100, 100
For i = 1 To 100
If menus$(x_select, parentnum, i) <> ""
Text (x_pos+field_width+4), (y_substart+(i*bar_height)-bar_height), menus$(x_select, parentnum, i)
EndIf
If i = sub_fields Then Exit
Next 
;HIGHLIGHT SELECTED ITEM ON SUBLIST
y_select = ((MouseY()-y_substart)/bar_height)
Color 100, 100, 100 :Rect x_pos+field_width+1, ((y_select*bar_height)+y_substart), field_width-2, bar_height-1
Color 50, 50, 60 :Text x_pos+field_width+4, ((y_select*bar_height)+y_substart), menus$(x_select, parentnum,y_select+1)
;IF MOUSEHIT INPUT ACTION
If MouseHit(1) Then inputstring$ = menus$(x_select, parentnum,y_select+1)
;ELSE RESET GLOBALS
Else
menuopen = 0 :listlength = 0 :x_select = 0 :sublength = 0
EndIf
End Function
Scrollbars:
Code: [Select]
;-------------------------------------------------------------------------------------------------------
Graphics 1024, 768
SetBuffer BackBuffer()
Global scroll_h#, scroll_v#, grab_bar
ClsColor 30,20, 10
;-----------------------------------------------------------------------------------------------------
While quit = 0
Cls
BACKGROUND()
Color 160, 160, 110
SCROLLBAR_V(200,0, 16, 200, 1200)
SCROLLBAR_H(0, 200, 200, 16, 800)
CURSOR()
Flip
If KeyHit(1) Then quit = 1
Wend
End
;-----------------------------------------------------------------------------------------------------
Function CURSOR()
Color 255, 255, 255
Rect MouseX(), MouseY(), 3, 3
End Function
;-----------------------------------------------------------------------------------------------------
Function BACKGROUND()
Viewport 0, 0, 200, 200
For i = 0 To 800
Color R, G, B
Line 0+i-scroll_h#, 0-scroll_v#, 0+i-scroll_h# , 1200-scroll_v#
If G < 200 And set1 = 0
If R > 0 Then R = R - 1
G = G + 1
Else If B < 200 And set2 = 0
If G > 1 Then G = G - 1
B = B + 1
set1 = 1
Else If R < 200
If B > 1 Then B = B - 1
R = R + 1
set2 = 1
Else
set1 = 0
set2 = 0
EndIf 
Next
Color 0, 0, 0
For i = 0 To 1600 Step 10
Color D, D, D
Text 2-scroll_h, i-scroll_v,"SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING"
D = D + 10
Next
Viewport 0, 0, 1024, 768
End Function
;-----------------------------------------------------------------------------------------------------
Function SCROLLBAR_V(x_pos, y_pos, bar_w, bar_h, list_l#)

slider_l# = bar_h - (2 * bar_w)
bar_percent# = 100 / (list_l# / slider_l#)
slider_div# =  slider_l# / 100
bar_height# = bar_percent# * slider_div#
slide_spd# = (scroll_v# * ((slider_l# - bar_height#)/(list_l# -bar_h)))

If MouseDown(1) And grab_bar = 0
If MouseX() > x_pos  And MouseX() < x_pos + bar_w
If MouseY() > y_pos And MouseY() < y_pos + bar_w
If scroll_v# > 0 Then scroll_v# = scroll_v# - 2
  Else If MouseY() > y_pos +(bar_h - bar_w) And MouseY() < y_pos + bar_h
If scroll_v# < list_l# - bar_h Then scroll_v# = scroll_v# + 2
Else If MouseY() > y_pos + slide_spd# +bar_w And MouseY() < y_pos+slide_spd#+bar_w+bar_height#
grab_bar = 1
EndIf
EndIf
EndIf

If grab_bar = 1
old_y = MouseY()
Delay 20
diff# = MouseY() - old_y 
drag_slider# = diff# * (list_l# / slider_l#)
If scroll_v# >= 0 And scroll_v# < list_l#
If scroll_v# + drag_slider# < 0
scroll_v# = 0
Else If scroll_v# + drag_slider# > list_l# -bar_h
scroll_v# = list_l# - bar_h
Else
scroll_v# = scroll_v# + drag_slider#
EndIf
EndIf
EndIf

If Not MouseDown(1) Then grab_bar = 0

Color 0, 0, 0
Rect x_pos, y_pos, bar_w, bar_h
For i = 0 To 1
Color 20, 20, 20
Rect x_pos, y_pos+(i * (slider_l# +bar_w)), bar_w, bar_w
Color 80, 80, 80
Rect x_pos+1, y_pos+(i * (slider_l# +bar_w)), bar_w-1, bar_w-1
Color 50, 50, 50
Rect x_pos+1, y_pos+1+(i * (slider_l# +bar_w)), bar_w-2, bar_w-2
Next

For z = 0 To (bar_w / 2) - (bar_w / 4)
Color 140, 40, 40
Rect x_pos+(bar_w/2) - 1 -z, y_pos +(bar_w / 4)-1 +(z*2) , 2 +(z*2), 2
Rect x_pos+(bar_w/2) - 1 -z, y_pos +bar_h -(bar_w / 4)-1 -(z*2), 2 +(z*2), 2
Next

Color 50, 50, 50
Rect x_pos+1, y_pos + bar_w +slide_spd#+1, bar_w-2, bar_height#-2
Color 120, 120, 120
Rect x_pos+2, y_pos + bar_w +slide_spd#+1, bar_w-3, bar_height#-3
Color 80, 80, 80
Rect x_pos+2, y_pos+2 + bar_w +slide_spd#, bar_w-4, bar_height#-4
Color 140, 40, 40
Rect x_pos+5, y_pos+5 + bar_w +slide_spd#, bar_w-10, bar_height#-10

End Function
;-----------------------------------------------------------------------------------------------------
Function SCROLLBAR_H(x_pos, y_pos, bar_w, bar_h, list_l#)

slider_l# = bar_w - (2 * bar_h)
bar_percent# = 100 / (list_l# / slider_l#)
slider_div# =  slider_l# / 100
bar_height# = bar_percent# * slider_div#
slide_spd# = (scroll_h# * ((slider_l# - bar_height#)/(list_l# -bar_w)))


If MouseDown(1) And grab_bar = 0
If MouseY() > y_pos  And MouseY() < y_pos + bar_h
If MouseX() > x_pos And MouseX() < x_pos + bar_h
If scroll_h# > 0 Then scroll_h# = scroll_h# - 2
  Else If MouseX() > x_pos +(bar_w - bar_h) And MouseX() < x_pos + bar_w
If scroll_h# < list_l# - bar_w Then scroll_h# = scroll_h# + 2
Else If MouseX() > x_pos + slide_spd# +bar_h And MouseX() < x_pos+slide_spd#+bar_h+bar_height#
grab_bar = 2
EndIf
EndIf
EndIf

If grab_bar = 2
old_x = MouseX()
Delay 20
diff# = MouseX() - old_x 
drag_slider# = diff# * (list_l# / slider_l#)
If scroll_h# >= 0 And scroll_h# < list_l#
If scroll_h# + drag_slider#  < 0
scroll_h# = 0
Else If scroll_h# + drag_slider#  > list_l# -bar_w
scroll_h# = list_l# - bar_w
Else
scroll_h# = scroll_h# + drag_slider#   
EndIf
EndIf
EndIf

If Not MouseDown(1) Then grab_bar = 0

Color 60, 60, 50
Rect x_pos, y_pos, bar_w, bar_h
Color 160, 160, 110
Rect x_pos, y_pos, bar_h, bar_h
Rect x_pos +(slider_l# +bar_h), y_pos , bar_h, bar_h
Color 110, 160, 160
Rect x_pos + bar_h +slide_spd#, y_pos , bar_height#, bar_h
End Function
Slow and unfinished windows:
Code: [Select]
Graphics 1024, 768
SetBuffer BackBuffer()

;-----------------------------------------------------------------------------------------------------
;**************************** VARIABLES NEEDED *******************************************************
;-----------------------------------------------------------------------------------------------------
Global font1 = LoadFont(verdana ,16 , True, False,False)
Global font2 = LoadFont(verdana ,16 , False, False,False)

Const graphics_width = 1024,  graphics_height = 768
Global old_mouse_x, old_mouse_y
Type window
;MAIN WINDOW VARIABLES
Field x, y, w, h, title$, hh, stretch
Field s_bar, d_down,locked
;DROPDOWN MENU VARIABLES
Field menus$[100], inputstring$
Field menuopen, listlength, x_select
;SCROLLBAR VARIABLES
End Type
Dim win_han(20)

;s_bar SETS SCROLLBARS: 0=NONE, 1=VERTICAL , 2=VERTICAL AND HORIZONTAL, 3=HORIZONTAL
;d_down = 1 THEN INCLUDE DROPDOWN MENU IN WINDOW
;locked = 1 THEN WINDOW CANNOT BE STRETCHED, DRAGGED, OR MOVED TO THE FRONT BY CLICKING ON IT

;-----------------------------------------------------------------------------------------------------
;************************** SET WINDOW COLOURS *******************************************************
;-----------------------------------------------------------------------------------------------------

;BORDERS ;BORDER HILITE
Const wr1=30, wg1=40, wb1=33, wr2=100, wg2=130, wb2=110
;BACKGROUND ;CLOSE BUTTON
Const wr3=20, wg3=30, wb3=35, wr4=150, wg4=40, wb4=40
  ;MENU BAR ;TEXT COLOUR
Const wr5=20, wg5=30, wb5=25, wr6=100, wg6=100, wb6=100


;-----------------------------------------------------------------------------------------------------
;********************** CREATE SOME WINDOWS AND DEMO LOOP ********************************************
;-----------------------------------------------------------------------------------------------------

w.window = New window
w\x=100: w\y=100: w\w=128: w\h=200: w\title$="WINDOW": w\hh=20
win_han(1) = Handle(w)
w.window = New window
w\x=120: w\y=200: w\w=300: w\h=300: w\title$="ANOTHER ONE": w\hh=20 :w\d_down=1
win_han(2) = Handle(w)
w\menus$[00] = "File"
w\menus$[10] = "Options"
w\menus$[20] = "Preferences"
w\menus$[30] = "Graphics"
w\menus$[40] = "Sound"
w\menus$[50] = "Controls"
w\menus$[80] = "Other Things"
;Name items on menu lists
w\menus$[01] = "New"
w\menus$[02] = "Save"
w\menus$[03] = "Save As"
w\menus$[04] = "Load"
w\menus$[05] = "Quit"

w\menus$[11] = "Option 1"
w\menus$[12] = "Option 2"
w\menus$[13] = "Option 3"
w\menus$[14] = "Option 4"
w\menus$[15] = "Option 5"
w\menus$[16] = "Option 6"
w\menus$[17] = "Option 7"
w\menus$[18] = "Option 8"
w\menus$[19] = "Option 9"

w\menus$[21] = "Preference 1"
w\menus$[22] = "Preference 2"

w\menus$[31] = "Nice"
w\menus$[32] = "Not So Nice"
w\menus$[33] = "Bad"

w\menus$[41] = "On"
w\menus$[42] = "Off"

w\menus$[51] = "Cofigure"

w\menus$[81] = "This Thing"
w\menus$[82] = "That Thing"
w\menus$[83] = "Something"
w\menus$[84] = "Nothing"
w\menus$[85] = "Everything"
w.window = New window
w\x=300: w\y=460: w\w=230: w\h=100: w\title$="THE THIRD ONE": w\hh=20
win_han(3) = Handle(w)
w.window = New window
w\x=60: w\y=440: w\w=160: w\h=120: w\title$="FOURTH": w\hh=20 :w\d_down=1
win_han(4) = Handle(w)

w\menus$[00] = "File"
w\menus$[10] = "Options"
w\menus$[01] = "New"
w\menus$[02] = "Save"
w\menus$[03] = "Save As"
w\menus$[04] = "Load"
w\menus$[05] = "Quit"

w\menus$[11] = "Option 1"
w\menus$[12] = "Option 2"
w\menus$[13] = "Option 3"
w\menus$[14] = "Option 4"
w\menus$[15] = "Option 5"
w\menus$[16] = "Option 6"

t = MilliSecs() + 1000
While Not KeyHit(1)

; Frame rate
If MilliSecs() >= t Then
lastFPS = FPS
FPS = 0
t = MilliSecs() + 1000
End If
FPS = FPS + 1

Cls
WINDOW()
Color 255, 255, 255: Rect MouseX(), MouseY(), 3, 3
Text 2,2, lastFPS
Flip
Wend
;-----------------------------------------------------------------------------------------------------
;*****************************************************************************************************
;-----------------------------------------------------------------------------------------------------
Function WINDOW()
For w.window = Each window
;DRAW THE WINDOWS
If w\d_down = 1
drop_bit = 16
Else
drop_bit = 0
EndIf

Color wr1, wg1, wb1: Rect w\x, w\y, w\w, w\h+drop_bit,1 ;WINDOW FRAME
Color wr2, wg2, wb2: Rect w\x, w\y, w\w, w\h+drop_bit,0 ;WINDOW FRAME BORDER
Color wr3, wg3, wb3: Rect w\x+6, w\y+w\hh+drop_bit, w\w-12, w\h-w\hh-6, 1;WINDOW CONTENTS
Color wr2, wg2, wb2: Rect w\x+6, w\y+w\hh+drop_bit, w\w-12, w\h-w\hh-6,0 ;INNER BORDER

Viewport w\x, w\y, (w\w-w\hh), w\hh
Color wr6, wg6, wb6: SetFont font1: Text w\x+6, w\y+4, w\title$ ;WINDOW TITLE
Viewport 0, 0, graphics_width, graphics_height

Color wr4, wg4, wb4: Rect w\x+w\w-w\hh+4,w\y+4,w\hh-8,w\hh-8,1 ;CLOSE BUTTON
;-----------------------------------------------------------------------------------------------------
;IF WINDOW HAS SCROLLBARS THEN DRAW THEM
If w\s_bar = 1

Else If w\s_bar = 2

Else If w\s_bar = 3

EndIf
;-----------------------------------------------------------------------------------------------------

;IF WINDOW HAS A DROPDOWN MENU THEN DRAW IT
win_num = win_num + 1
If w\d_down = 1
;SET VARIABLES
field_width = 100
bx=w\x+6: by=w\y+20: bar_width=1000: bar_height=16
;VIEWPORT THE BAR
Color wr2, wg2, wb2   :Line bx+w\w-13, by, bx+w\w-13, by+16
If w\menuopen = 1 And MouseX() > bx+(((w\w-12)/100)*100)
portwidth = (((w\w-12)/100)*100)+100
Viewport(w\x+6, w\y+20, portwidth, 17)
Else
Viewport(w\x+6, w\y+20, w\w-13, 17)
EndIf
;DRAW MENU BAR
Color wr5, wg5, wb5   :Rect bx, by, bar_width, bar_height, 1
Color wr2, wg2, wb2   :Rect bx, by, bar_width, bar_height+1, 0

;DRAW MENU BAR TITLES
SetFont font1
Color wr6, wg6, wb6
For i = 0 To 9
Text bx+2+(i*field_width), by, w\menus$[i*10]
Next
Viewport(0,0,graphics_width,graphics_height)
;IF THE CURSOR IS OVER THE MENUBAR
If MouseX() > bx And MouseX() < (bx+w\w-12) And MouseY() > by And MouseY() < (by+16)
w\x_select = ((MouseX()-bx) / field_width)
If w\menus$[w\x_select*10] <> ""
w\listlength = 0
For i = 1 To 9
If w\menus$[(w\x_select*10)+i] <> "" Then w\listlength = w\listlength +1
Next
x_pos = w\x_select * field_width
list_height = w\listlength * bar_height
Color wr5, wg5, wb5 :Rect bx+x_pos, by+bar_height-1, field_width, list_height+1
Color wr2, wg2, wb2 :Rect bx+x_pos, by, field_width, bar_height+list_height, 0
Color wr6, wg6, wb6
SetFont font2
For i = 1 To 9
Text bx+x_pos+4, by+(i*bar_height), w\menus$[(w\x_select*10)+i]
Next
w\menuopen = 1
EndIf
;ELSE IF THE MENU IS OPENED AND CURSOR MOVED DOWN OVER THE LIST
Else If w\menuopen = 1
x_pos = w\x_select * field_width
list_height = w\listlength * bar_height
If MouseX() > (bx+x_pos) And MouseX() < (bx+x_pos+field_width) And MouseY() > by And MouseY() < (by+list_height+bar_height)
Color wr5, wg5, wb5 :Rect bx+x_pos, by+bar_height-1, field_width, list_height+1
Color wr2, wg2, wb2 :Rect bx+x_pos, by, field_width, bar_height+list_height, 0
Color wr6, wg6, wb6
SetFont font2
For i = 1 To 9
Text bx+x_pos+4, by+(i*bar_height), w\menus$[(w\x_select*10)+i]
Next
;HIGHLIGHT ITEM ON LIST THAT CURSOR IS OVER
y_select = ((MouseY()-by)/bar_height)
Color wr6, wg6, wb6 :Rect bx+x_pos+1, by+(y_select*bar_height), field_width-2, bar_height-1
Color wr5, wg5, wb5 :Text bx+x_pos+4, by+(y_select*bar_height), w\menus$[(w\x_select*10)+y_select] 
Else
w\menuopen = 0 :w\listlength = 0 :w\x_select = 0
EndIf
Else ;ELSE RESET GLOBALS
w\menuopen = 0 :w\listlength = 0 :w\x_select = 0
EndIf

EndIf
;-----------------------------------------------------------------------------------------------------
;IF CLICK ON WINDOW MOVE IT TO THE FRONT
If MouseHit(1) Or clicked = 1
;check that mouse is over window
If MouseX() > w\x And MouseX() < (w\x+w\w) And MouseY() > w\y And MouseY() < (w\y+w\h+drop_bit)
;check that there are no windows on top of it
For w2.window = Each window
win_num2 = win_num2 + 1
;make sure that the window is above it, not below
If win_num2 > win_num
;if a window is overlapping then do nothing and exit the loop
If MouseX() > w2\x And MouseX() < (w2\x+w2\w) And MouseY() > (w2\y) And MouseY() < ((w2\y+w2\h)+(w2\d_down*16))
  no_go = 1
Exit 
EndIf 
EndIf
Next
win_num2 = 0
;if there are no windows overlapping it then move it to the front
If no_go = 0
Insert w.window After Last window
EndIf
Else
clicked = 1
EndIf
EndIf

;-----------------------------------------------------------------------------------------------------
;MANIPULATE THE WINDOWS
If MouseDown(1)
If w.window = Last window
If w\stretch = 0
;STRETCH DIAGONAL
If MouseX() > (w\x+w\w-6) And MouseX() < (w\x+w\w) And MouseY() > (w\y+w\h-6+drop_bit) And MouseY() < (w\y+w\h+drop_bit)
w\stretch = 3
;STRETCH WIDTH
Else If MouseX() > (w\x+w\w-6) And MouseX() < (w\x+w\w) And MouseY() > (w\y+w\hh) And MouseY() < (w\y+w\h)
w\stretch = 1
;STRETCH HEIGHT
Else If MouseY() > (w\y+w\h-6+drop_bit) And MouseY() < (w\y+w\h+drop_bit) And MouseX() > w\x And MouseX() < (w\x+w\w)
w\stretch = 2
;DRAG WINDOW
Else If MouseX() > w\x And MouseX() < (w\x+w\w-w\hh) And MouseY() > w\y And MouseY() < (w\y+w\hh)
w\stretch = 4
old_mouse_x = MouseX()
old_mouse_y = MouseY()
;CLOSE WINDOW
Else If MouseX() > (w\x+w\w-w\hh+4) And MouseX() < (w\x+w\w-4) And MouseY() > (w\y+4) And MouseY() < (w\y+w\hh-4)
w\stretch = 5
EndIf
EndIf
EndIf 

If w\stretch = 1
If w\w > (w\hh*2)
w\w = (MouseX()-w\x)
Else
w\w =((w\hh*2)+10)
w\stretch = 0
EndIf
Else If w\stretch = 2
If w\h > (w\hh*2)
w\h = (MouseY()-w\y)
Else
w\h = ((w\hh*2)+10)
w\stretch = 0
EndIf
Else If w\stretch = 3
If w\w > (w\hh*2)
w\w = (MouseX()-w\x)
Else
w\w =((w\hh*2)+10)
w\stretch = 0
EndIf
If w\h > (w\hh*2)
w\h = (MouseY()-w\y)
Else
w\h = ((w\hh*2)+10)
w\stretch = 0
EndIf
Else If w\stretch = 4
w\x = w\x +(MouseX()-old_mouse_x)
w\y = w\y +(MouseY()-old_mouse_y)
old_mouse_x = MouseX()
old_mouse_y = MouseY()
Else If w\stretch = 5
Delete w.window
Exit
EndIf
Else
w\stretch = 0
EndIf
Next
End Function

Pages: 1 [2] 3