Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 07-02-2003, 04:25 AM   #1 (permalink)
Stween
Registered User
 
Join Date: Jul 2003
Posts: 4
Stween is on a distinguished road
C & Gtk: drawing areas

Ello,

I've been fiddling about a little with GTK a little bit (nothing serious, I'm just looking to see how it all works), and something has puzzled me.

Drawing areas... the information in the official gtk tutorial is sparse on this topic (other than the scribble example, and brief searches aren't turning up much for me.

What I'd *really* like to know is, how do I set colours for individual pixels, be they drawn by the user clicking on the drawing area or from loading image data from disk? This has me kinda stumped.

But perhaps I'm just too tired... Anyone here know much about gtk coding?
Stween is offline   Reply With Quote
Old 07-02-2003, 12:16 PM   #2 (permalink)
EscapeCharacter
GNU/Punk
 
EscapeCharacter's Avatar
 
Join Date: Jul 2002
Location: stuffs
Posts: 66
EscapeCharacter is on a distinguished road
Send a message via AIM to EscapeCharacter
so you are trying to have a drawing area to get random colors drawn where you click? if so you could do this by getting the x and y coordinates of the mouse and depending where that is on the drawing area set the color you want and XDrawPoint(or whatever the gtk equiv is).

note: XDrawPoint is a xlib routine. i dont know gtk but since it is based on xlib that should be a good starting point for you.
__________________
cd /usr/ports/misc/life && make install
EscapeCharacter is offline   Reply With Quote
Old 07-03-2003, 12:48 PM   #3 (permalink)
Stween
Registered User
 
Join Date: Jul 2003
Posts: 4
Stween is on a distinguished road
What I'm trying to do is load image data from disk - the image data is stored in C header files in an abnormal format. I can read in the data fine, what stumps me is how do I go from the data which I can read into handy arrays, to something that I can display.

I've been reading through the gdk stuff, and have started fiddling with gdk pixbuf's, which look like they might be the way to go, but I still can't set the individual pixels, and there seems to be no easy way to take my array of values and create a simple pixbuf out of them.

Ultimately, I'm trying to create a simple app that draws a few of these (they're small, 8x8 tiles), but setting pixel values seems to be the biggest hurdle here

The (small) application I'm writing here is as much a programming exercise to try and learn a little GTK and get used to more C, but I'd really like to get over this little issue - I can pretty much see how I'm doing everything other than this Why isn't it as simple as 'pb[x][y].red= 0xFF'?!
Stween is offline   Reply With Quote
Old 07-03-2003, 04:35 PM   #4 (permalink)
EscapeCharacter
GNU/Punk
 
EscapeCharacter's Avatar
 
Join Date: Jul 2002
Location: stuffs
Posts: 66
EscapeCharacter is on a distinguished road
Send a message via AIM to EscapeCharacter
what format is the image? since you said it is included in a header file that makes me believe it may be a xpm which has its own xlib routines to handle it. libxpm and whatnot.
__________________
cd /usr/ports/misc/life && make install
EscapeCharacter is offline   Reply With Quote
Old 07-04-2003, 04:27 AM   #5 (permalink)
Stween
Registered User
 
Join Date: Jul 2003
Posts: 4
Stween is on a distinguished road
Quote:
Originally posted by EscapeCharacter
what format is the image? since you said it is included in a header file that makes me believe it may be a xpm which has its own xlib routines to handle it. libxpm and whatnot.
Ok, the map tiles themselves use a 256 colour palette which is selected from a 15-bit colour palette - this colour palette arranges colours as BGR (the reverse of what is normally used), with 5 bits per channel.

This is represented in the header file by an array of 256 16-bit unsigned numbers (presumably the most significant bit is ignored when looking at the 15-bits required for the colour).

What I'd be wanting to do would be read in both the tile data and the palette, and use the values in the tile data to lookup the appropriate palette colour and set the pixel to that.

In my mind, it's a really simple thing to achieve... The only hazy bit is the difference between the 15-bit palette the tiles are using and the 24-bit palette I'd probably have to represent it with, but even then, a couple of bit shifting operations to get the RGB fields in the correct place would allow me to see what tiles are where; I can probably overlook wonky colours there
Stween is offline   Reply With Quote
Old 07-06-2003, 06:52 AM   #6 (permalink)
Stween
Registered User
 
Join Date: Jul 2003
Posts: 4
Stween is on a distinguished road
Although, thinking about it, I suppose I could read in the relevant data, output it to a file in xpm format, then load it that way...

Just seems like a horrible workaround ... but it might just work
Stween is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB or C#, or something else Apodysophilia MS Technologies ( ASP, VB, C#, .NET ) 6 10-15-2004 09:48 AM
operate overloading member function in C# sureshkumar_kc MS Technologies ( ASP, VB, C#, .NET ) 2 10-15-2004 02:36 AM
For those who have Learned C from "The C Programming Lanuage" DemosthenesB Standard C, C++ 5 07-13-2003 12:22 AM
edit? anon Lounge 10 11-21-2002 03:02 PM


All times are GMT -8. The time now is 08:20 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting