GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Aug-2007, 14:17
Z_guy's Avatar
Z_guy Z_guy is offline
New Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 6
Z_guy is on a distinguished road
Question

Drawing order


Hi!
I'm making a card game using FLTK and I need to be able to dynamically change the drawing order of the cards.

Is this possible with just FLTK calls or do I have to make a class that manages the drawing order of the cards and then calls the cards draw() function in that order?
  #2  
Old 26-Aug-2007, 16:37
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough

Re: Drawing order


Quote:
Originally Posted by Z_guy
Hi!
I'm making a card game using FLTK and I need to be able to dynamically change the drawing order of the cards.

Is this possible with just FLTK calls or do I have to make a class that manages the drawing order of the cards and then calls the cards draw() function in that order?

Do you have cards displayed over each other? If so, you may want to look into the tab order for display purposes. I was toying around with a card game a while back, I'll see if I can find some code that does that.

If it is something else, explain a little more in detail or, better yet, show us a little bit of code that shows what you are after.

Mark

BTW, Welcome to GIDForums™ FLTK Forum. Glad to have you on board!
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #3  
Old 26-Aug-2007, 17:05
Z_guy's Avatar
Z_guy Z_guy is offline
New Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 6
Z_guy is on a distinguished road

Re: Drawing order


Quote:
Originally Posted by cable_guy_67
Do you have cards displayed over each other? If so, you may want to look into the tab order for display purposes. I was toying around with a card game a while back, I'll see if I can find some code that does that.

If it is something else, explain a little more in detail or, better yet, show us a little bit of code that shows what you are after.

Mark

BTW, Welcome to GIDForums™ FLTK Forum. Glad to have you on board!

This is what I'm getting now:

As you can see, the uppmost cards are not drawn in the right position. What I want is some sort of z ordering of the cards.
  #4  
Old 03-Sep-2007, 03:42
bluekid bluekid is offline
Awaiting Email Confirmation
 
Join Date: Apr 2006
Posts: 32
bluekid will become famous soon enough

Re: Drawing order


use group and change order of child redraw group
  #5  
Old 04-Sep-2007, 11:55
Z_guy's Avatar
Z_guy Z_guy is offline
New Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 6
Z_guy is on a distinguished road

Re: Drawing order


Quote:
Originally Posted by bluekid
use group and change order of child redraw group
Could you please post a code example?
  #6  
Old 08-Sep-2007, 01:17
bluekid bluekid is offline
Awaiting Email Confirmation
 
Join Date: Apr 2006
Posts: 32
bluekid will become famous soon enough

Re: Drawing order


main.h
CPP / C++ / C Code:
// generated by Fast Light User Interface Designer (fluid) version 1.0107

#ifndef main_h
#define main_h
#include <FL/Fl.H>
void bt_callback(Fl_Widget*, void* userdata);
#include <FL/Fl_Double_Window.H>
extern Fl_Double_Window *window_main;
#include <FL/Fl_Button.H>
extern void bt_callback(Fl_Button*, void*);
extern Fl_Button *btnTest;
#include <FL/Fl_Return_Button.H>
extern void bt_callback(Fl_Return_Button*, void*);
extern Fl_Return_Button *btnClose;
#include <FL/Fl_Group.H>
extern Fl_Group *Group;
#include <FL/Fl_Box.H>
#endif
main.cpp

CPP / C++ / C Code:
// generated by Fast Light User Interface Designer (fluid) version 1.0107

#include "main.h"
#include <stdlib.h>

void bt_callback(Fl_Widget*, void* userdata) {
  if(userdata == "change"){
  Fl_Widget *tmp;
  // get first element of group
  tmp=Group->child(0);
  // remove from group
  Group->remove(tmp);
  // add end 
  Group->add(tmp);
  // redraw
  Group->redraw();
}

if(userdata == "another"){
  Fl_Widget *tmp;
  Fl_Widget **tary;
  // get child arrey of group
  tary=(Fl_Widget **)Group->array();
  // get first element of group
  tmp=tary[0];
  // third element put into first element of group  
  tary[0]=tary[2];
  // first element put into first element of group  
  tary[2]=tmp;
  // redraw
  Group->redraw();
}

else if (userdata == "close")
	exit(0);
}

Fl_Double_Window *window_main=(Fl_Double_Window *)0;

Fl_Button *btnTest=(Fl_Button *)0;

Fl_Return_Button *btnClose=(Fl_Return_Button *)0;

Fl_Group *Group=(Fl_Group *)0;

int main(int argc, char **argv) {
  Fl_Double_Window* w;
  { Fl_Double_Window* o = window_main = new Fl_Double_Window(493, 170, "FLTK window");
    w = o;
    o->align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE);
    { Fl_Button* o = btnTest = new Fl_Button(291, 15, 190, 35, "Change Drawing Order");
      o->callback((Fl_Callback*)bt_callback, (void*)("change"));
    }
    { Fl_Return_Button* o = btnClose = new Fl_Return_Button(295, 120, 190, 35, "Close");
      o->callback((Fl_Callback*)bt_callback, (void*)("close"));
    }
    { Fl_Group* o = Group = new Fl_Group(10, 8, 240, 190);
      { Fl_Box* o = new Fl_Box(55, 21, 125, 36, "First");
        o->box(FL_PLASTIC_UP_BOX);
        o->color((Fl_Color)4);
      }
      { Fl_Box* o = new Fl_Box(105, 31, 125, 36, "Second");
        o->box(FL_PLASTIC_UP_BOX);
        o->color((Fl_Color)1);
      }
      { Fl_Box* o = new Fl_Box(115, 25, 50, 101, "Third");
        o->box(FL_PLASTIC_UP_BOX);
        o->color((Fl_Color)3);
      }
      o->end();
    }
    { Fl_Button* o = new Fl_Button(291, 65, 190, 40, "Another Method");
      o->callback((Fl_Callback*)bt_callback, (void*)("another"));
    }
    o->end();
  }
  w->show(argc, argv);
  return Fl::run();
}


thats all
  #7  
Old 09-Sep-2007, 13:57
Z_guy's Avatar
Z_guy Z_guy is offline
New Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 6
Z_guy is on a distinguished road

Re: Drawing order


Thank you very much!
I can't test it right now, but hopefully it will work! :-)
 
 

Recent GIDBlogWriting a book by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
triangle (polygon), drawing, sizing, and rotation programme using linked lists... promsan C Programming Language 12 14-May-2007 15:03
Program Newbie: 3 numbers in ascending order You Look Bored C++ Forum 9 03-Aug-2006 13:47
CPanel Hosting, Teamspeak 2 Hosting, SHOUTcast Hosting, As Low As $2.00 per Month Kalypsoweb Web Hosting Advertisements & Offers 0 30-Jul-2006 17:00
How to save a drawing to the file amgturk MS Visual C++ / MFC Forum 2 25-Jul-2005 01:29
Two virtual hosts, cgi script behaves differently on each blimbo Apache Web Server Forum 0 04-Aug-2004 10:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:39.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.