<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE navit SYSTEM "navit.dtd">
+<config>
<plugins>
<plugin path="$NAVIT_LIBDIR/*/${NAVIT_LIBPREFIX}lib*.so"/>
<plugin path="$NAVIT_LIBDIR/*/${NAVIT_LIBPREFIX}libgraphics_null.so" active="no" />
<layout name="Tag">
<layer name="sea" details="0">
- <item type="wood" order="0-">
+ <item type="poly_wood" order="0-">
<polygon color="#8ec78d" />
</item>
- <item type="town_poly" order="0-">
+ <item type="poly_town" order="0-">
<polygon color="#ffc895" />
<polyline color="#ebb481" />
</item>
- <item type="water_poly" order="0-">
+ <item type="poly_water" order="0-">
<polygon color="#82c8ea" />
<polyline color="#5096b8" />
<label label_size="5" />
</item>
- <item type="park_poly" order="0-">
+ <item type="poly_park" order="0-">
<polygon color="#7cc334" />
<label label_size="5" />
</item>
- <item type="airport_poly" order="0-">
+ <item type="poly_airport" order="0-">
<polygon color="#a0a0a0" />
</item>
- <item type="sport_poly" order="0-">
+ <item type="poly_sport" order="0-">
<polygon color="#4af04f" />
</item>
- <item type="industry_poly,building_poly,place_poly" order="0-">
+ <item type="poly_industry,poly_building,poly_place" order="0-">
<polygon color="#e6e6e6" />
</item>
<item type="water_line" order="0-">
<polyline color="#5096b8" width="1" />
<label label_size="5" />
</item>
+ <item type="poly_apron" order="0-">
+ <polygon color="#d0d0d0" />
+ </item>
+ <item type="poly_terminal" order="7-">
+ <polygon color="#e3c6a6" />
+ </item>
<item type="rail" order="6-">
<polyline color="#808080" width="3" />
</item>
<item type="street_nopass" order="10-">
<polyline color="#000000" width="1" />
</item>
+ <item type="street_service" order="11">
+ <polyline color="#d2d2d2" width="4" />
+ <polyline color="#fefefe" width="2" />
+ </item>
+ <item type="street_service" order="12">
+ <polyline color="#d2d2d2" width="5" />
+ <polyline color="#fefefe" width="3" />
+ </item>
+ <item type="street_service" order="13">
+ <polyline color="#d2d2d2" width="6" />
+ <polyline color="#fefefe" width="4" />
+ </item>
+ <item type="street_service" order="14">
+ <polyline color="#d2d2d2" width="7" />
+ <polyline color="#fefefe" width="5" />
+ </item>
+ <item type="street_service" order="15">
+ <polyline color="#d2d2d2" width="8" />
+ <polyline color="#fefefe" width="6" />
+ </item>
+ <item type="street_service" order="16">
+ <polyline color="#d2d2d2" width="9" />
+ <polyline color="#fefefe" width="7" />
+ </item>
+ <item type="street_service" order="17">
+ <polyline color="#d2d2d2" width="10" />
+ <polyline color="#fefefe" width="8" />
+ </item>
+ <item type="street_service" order="18">
+ <polyline color="#d2d2d2" width="11" />
+ <polyline color="#fefefe" width="9" />
+ </item>
+
<item type="street_0,street_1_city,street_1_land" order="10">
<polyline color="#d2d2d2" width="4" />
<polyline color="#ffffff" width="2" />
<item type="street_nopass,street_0,street_1_city,street_1_land" order="12-18">
<label label_size="9" />
</item>
+ <item type="aeroway_taxiway" order="10">
+ <polyline color="#989994" width="4" />
+ <polyline color="#d3dbbc" width="2" />
+ </item>
+ <item type="aeroway_taxiway" order="11">
+ <polyline color="#989994" width="6" />
+ <polyline color="#d3dbbc" width="4" />
+ </item>
+ <item type="aeroway_taxiway" order="12">
+ <polyline color="#989994" width="10" />
+ <polyline color="#d3dbbc" width="8" />
+ </item>
+ <item type="aeroway_taxiway" order="13">
+ <polyline color="#989994" width="12" />
+ <polyline color="#d3dbbc" width="9" />
+ </item>
+ <item type="aeroway_taxiway" order="14">
+ <polyline color="#989994" width="15" />
+ <polyline color="#d3dbbc" width="13" />
+ </item>
+ <item type="aeroway_taxiway" order="15">
+ <polyline color="#989994" width="17" />
+ <polyline color="#d3dbbc" width="14" />
+ </item>
+ <item type="aeroway_taxiway" order="16">
+ <polyline color="#989994" width="33" />
+ <polyline color="#d3dbbc" width="26" />
+ </item>
+ <item type="aeroway_taxiway" order="17">
+ <polyline color="#989994" width="69" />
+ <polyline color="#d3dbbc" width="61" />
+ </item>
+ <item type="aeroway_taxiway" order="18">
+ <polyline color="#989994" width="132" />
+ <polyline color="#d3dbbc" width="126" />
+ </item>
+ <item type="aeroway_runway" order="2-6">
+ <polyline color="#404040" width="1" />
+ </item>
+ <item type="aeroway_runway" order="7-8">
+ <polyline color="#404040" width="3" />
+ <polyline color="#d3dbbc" width="1" />
+ </item>
+ <item type="aeroway_runway" order="9">
+ <polyline color="#6b6f5f" width="5" />
+ <polyline color="#d3dbbc" width="3" />
+ </item>
+ <item type="aeroway_runway" order="10">
+ <polyline color="#6b6f5f" width="6" />
+ <polyline color="#d3dbbc" width="4" />
+ </item>
+ <item type="aeroway_runway" order="11">
+ <polyline color="#6b6f5f" width="9" />
+ <polyline color="#d3dbbc" width="7" />
+ </item>
+ <item type="aeroway_runway" order="12">
+ <polyline color="#6b6f5f" width="13" />
+ <polyline color="#d3dbbc" width="9" />
+ </item>
+ <item type="aeroway_runway" order="13">
+ <polyline color="#6b6f5f" width="18" />
+ <polyline color="#d3dbbc" width="14" />
+ </item>
+ <item type="aeroway_runway" order="14">
+ <polyline color="#6b6f5f" width="21" />
+ <polyline color="#d3dbbc" width="17" />
+ </item>
+ <item type="aeroway_runway" order="15">
+ <polyline color="#6b6f5f" width="24" />
+ <polyline color="#d3dbbc" width="20" />
+ </item>
+ <item type="aeroway_runway" order="16">
+ <polyline color="#6b6f5f" width="39" />
+ <polyline color="#d3dbbc" width="33" />
+ </item>
+ <item type="aeroway_runway" order="17">
+ <polyline color="#6b6f5f" width="78" />
+ <polyline color="#d3dbbc" width="72" />
+ </item>
+ <item type="aeroway_runway" order="18">
+ <polyline color="#6b6f5f" width="156" />
+ <polyline color="#d3dbbc" width="150" />
+ </item>
<item type="town_label,district_label,town_label_0e0,town_label_1e0,town_label_2e0,town_label_5e0,town_label_1e1,town_label_2e1,town_label_5e1,town_label_1e2,town_label_2e2,town_label_5e2,district_label_0e0,district_label_1e0,district_label_2e0,district_label_5e0,district_label_1e1,district_label_2e1,district_label_5e1,district_label_1e2,district_label_2e2,district_label_5e2" order="12-">
<circle color="#000000" radius="3" label_size="7" />
</item>
<polyline color="#3f3f3f" width="1" />
</item>
- <item type="poi_airport" order="0-">
+ <item type="poi_airport" order="5-">
<icon src="airport.xpm" />
</item>
<item type="town_ghost" order="0-">
<icon src="ghost_town.xpm" />
</item>
- <item type="poi_hotel" order="0-">
+ <item type="poi_hotel" order="12-">
<icon src="hotel.xpm" />
</item>
- <item type="poi_car_parking" order="0-">
+ <item type="poi_car_parking" order="11-">
<icon src="parking.xpm" />
</item>
<item type="poi_car_dealer_parts" order="0-">
<icon src="car_dealer.xpm" />
</item>
- <item type="poi_fuel" order="0-">
+ <item type="poi_fuel" order="10-">
<icon src="fuel.xpm" />
</item>
<item type="poi_shopping" order="0-">
<icon src="shopping.xpm" />
</item>
- <item type="poi_attraction" order="0-">
+ <item type="poi_attraction" order="5-">
<icon src="attraction.xpm" />
</item>
- <item type="poi_bar" order="0-">
+ <item type="poi_bar" order="12-">
<icon src="bar.xpm" />
</item>
<item type="poi_bridge" order="0-">
<icon src="bridge.xpm" />
</item>
- <item type="highway_exit" order="0-">
+ <item type="highway_exit" order="11-">
<icon src="exit.xpm" />
</item>
- <item type="poi_camp_rv" order="0-">
+ <item type="poi_camp_rv" order="9-">
<icon src="camping.xpm" />
</item>
- <item type="poi_museum_history" order="0-">
+ <item type="poi_museum_history" order="12-">
<icon src="museum.xpm" />
</item>
- <item type="poi_hospital" order="0-">
+ <item type="poi_hospital" order="12-">
<icon src="hospital.xpm" />
</item>
<item type="point_unkn" order="0-">
<circle color="#8080ff" radius="3" />
</item>
- <item type="poi_dining" order="0-">
+ <item type="poi_dining" order="12-">
<icon src="dining.xpm" />
</item>
- <item type="poi_fastfood" order="0-">
+ <item type="poi_fastfood" order="12-">
<icon src="fastfood.xpm" />
</item>
- <item type="poi_police" order="0-">
+ <item type="poi_police" order="12-">
<icon src="police.xpm" />
</item>
<item type="poi_auto_club" order="0-">
<item type="poi_autoservice" order="0-">
<icon src="autoservice.xpm" />
</item>
- <item type="poi_bank" order="0-">
+ <item type="poi_bank" order="12-">
<icon src="bank.xpm" />
</item>
<item type="poi_bay" order="0-">
<item type="poi_cemetery" order="0-">
<icon src="cemetery.xpm" />
</item>
- <item type="poi_church" order="0-">
+ <item type="poi_church" order="11-">
<icon src="church.xpm" />
</item>
- <item type="poi_cinema" order="0-">
+ <item type="poi_cinema" order="12-">
<icon src="cinema.xpm" />
</item>
<item type="poi_civil" order="0-">
<item type="poi_fair" order="0-">
<icon src="fair.xpm" />
</item>
- <item type="poi_firebrigade" order="0-">
+ <item type="poi_firebrigade" order="12-">
<icon src="firebrigade.xpm" />
</item>
<item type="poi_fish" order="0-">
<item type="poi_garmin" order="0-">
<icon src="garmin.xpm" />
</item>
- <item type="poi_golf" order="0-">
+ <item type="poi_golf" order="12-">
<icon src="golf.xpm" />
</item>
<item type="poi_goverment_building" order="0-">
<item type="poi_icesport" order="0-">
<icon src="icesport.xpm" />
</item>
- <item type="poi_information" order="0-">
+ <item type="poi_information" order="12-">
<icon src="information.xpm" />
</item>
<item type="poi_justice" order="0-">
<item type="poi_levee" order="0-">
<icon src="levee.xpm" />
</item>
- <item type="poi_library" order="0-">
+ <item type="poi_library" order="12-">
<icon src="library.xpm" />
</item>
<item type="poi_locale" order="0-">
<item type="poi_personal_service" order="0-">
<icon src="personal_service.xpm" />
</item>
- <item type="poi_pharmacy" order="0-">
+ <item type="poi_pharmacy" order="12-">
<icon src="pharmacy.xpm" />
</item>
- <item type="poi_post" order="0-">
+ <item type="poi_post" order="13-">
<icon src="post.xpm" />
</item>
<item type="poi_public_office" order="0-">
<item type="poi_resort" order="0-">
<icon src="resort.xpm" />
</item>
- <item type="poi_rest_room" order="0-">
+ <item type="poi_rest_room" order="13-">
<icon src="rest_room.xpm" />
</item>
- <item type="poi_restaurant" order="0-">
+ <item type="poi_restaurant" order="12-">
<icon src="restaurant.xpm" />
</item>
<item type="poi_restricted_area" order="0-">
<icon src="restricted_area.xpm" />
</item>
- <item type="poi_restroom" order="0-">
+ <item type="poi_restroom" order="13-">
<icon src="restroom.xpm" />
</item>
<item type="poi_sailing" order="0-">
<item type="poi_scenic_area" order="0-">
<icon src="scenic_area.xpm" />
</item>
- <item type="poi_school" order="0-">
+ <item type="poi_school" order="12-">
<icon src="school.xpm" />
</item>
<item type="poi_service" order="0-">
<item type="poi_shower" order="0-">
<icon src="shower.xpm" />
</item>
- <item type="poi_skiing" order="0-">
+ <item type="poi_skiing" order="12-">
<icon src="skiing.xpm" />
</item>
<item type="poi_social_service" order="0-">
<item type="poi_subdivision" order="0-">
<icon src="subdivision.xpm" />
</item>
- <item type="poi_swimming" order="0-">
+ <item type="poi_swimming" order="12-">
<icon src="swimming.xpm" />
</item>
- <item type="poi_telephone" order="0-">
+ <item type="poi_telephone" order="13-">
<icon src="telephone.xpm" />
</item>
- <item type="poi_theater" order="0-">
+ <item type="poi_theater" order="12-">
<icon src="theater.xpm" />
</item>
<item type="poi_tide" order="0-">
<icon src="tide.xpm" />
</item>
- <item type="poi_tower" order="0-">
+ <item type="poi_tower" order="13-">
<icon src="tower.xpm" />
</item>
<item type="poi_trail" order="0-">
<item type="poi_zoo" order="0-">
<icon src="zoo.xpm" />
</item>
- <item type="poi_picnic" order="0-">
+ <item type="poi_picnic" order="11-">
<icon src="picnic.xpm" />
</item>
<item type="poi_gc_multi" order="0-">
<item type="poi_gc_webcam" order="0-">
<icon src="gc_webcam.xpm" />
</item>
- <item type="flats,scrub,military_zone,marine_poly,plantation,tundra" order="0-">
+ <item type="traffic_signals" order="13-">
+ <icon src="traffic_signals.xpm" />
+ </item>
+ <item type="poly_flats,poly_scrub,poly_military_zone,poly_marine,plantation,tundra" order="0-">
<polygon color="#a0a0a0" />
<label label_size="5" />
</item>
<layout name="Nacht">
</layout>
</navit>
+</config>
#include "color.h"
#include "plugin.h"
+#define ID_CHILD_GFX 2000
+#include "xpm2bmp.h";
+#ifndef GET_WHEEL_DELTA_WPARAM
+ #define GET_WHEEL_DELTA_WPARAM(wParam) ((short)HIWORD(wParam))
+#endif
+
+struct graphics_image_priv {
+ PXPM2BMP pxpm;
+};
void ErrorExit(LPTSTR lpszFunction)
(LPTSTR) &lpMsgBuf,
0, NULL );
- // Display the error message and exit the process
-
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR));
sprintf((LPTSTR)lpDisplayBuf, TEXT("%s failed with error %d: %s"), lpszFunction, dw, lpMsgBuf);
enum draw_mode_num mode;
};
+struct graphics_gc_priv {
+ HWND hwnd;
+ int line_width;
+ COLORREF fg_color;
+ COLORREF bg_color;
+ struct graphics_priv *gr;
+};
+
struct graphics_priv *g_gra;
+static HDC hMemDC;
+static HBITMAP hBitmap;
+static HBITMAP hOldBitmap;
+
+// Fills the region 'rgn' in graded colours
+static void MakeMemoryDC(HANDLE hWnd, HDC hdc )
+{
+ if ( hMemDC )
+ {
+ if ( hOldBitmap )
+ {
+ SelectObject( hMemDC, hOldBitmap );
+ DeleteObject( hBitmap );
+ hBitmap = NULL;
+ hOldBitmap = NULL;
+ }
+ }
+
+ // Creates memory DC
+ hMemDC = CreateCompatibleDC(hdc);
+ if ( hMemDC )
+ {
+ RECT rectRgn;
+ GetClientRect( hWnd, &rectRgn );
+ int Width = rectRgn.right - rectRgn.left;
+ int Height = rectRgn.bottom - rectRgn.top;
+ printf( "resize memDC to: %d %d \n", Width, Height );
+
+ hBitmap = CreateCompatibleBitmap(hdc, Width, Height );
+
+ if ( hBitmap )
+ {
+ hOldBitmap = (HBITMAP) SelectObject( hMemDC, hBitmap);
+ }
+ }
+}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
+
+if ( Message != 15 )
+ printf( "CHILD %d %d %d \n", Message, wParam, lParam );
switch(Message)
{
case WM_CREATE:
{
- g_gra->wnd_handle = hwnd;
- //if (g_gra->resize_callback)
- // (*g_gra->resize_callback)(g_gra->resize_callback_data, g_gra->width, g_gra->height);
- //MoveWindow( hwnd, 0,0, 780, 680, TRUE );
+ g_gra->wnd_handle = hwnd;
+ //if (g_gra->resize_callback)
+ // (*g_gra->resize_callback)(g_gra->resize_callback_data, g_gra->width, g_gra->height);
+ //MoveWindow( hwnd, 0,0, 780, 680, TRUE );
+
+ {
+ HDC hdc;
+ hdc = GetDC( hwnd );
+ MakeMemoryDC(hwnd, hdc );
+ ReleaseDC( hwnd, hdc );
+ }
+ PostMessage( g_gra->wnd_parent_handle, WM_USER + 1, 0, 0 );
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
+ case WM_USER + 1:
+ break;
}
break;
case WM_CLOSE:
g_gra->width = LOWORD( lParam );
g_gra->height = HIWORD( lParam );
+ {
+ HDC hdc;
+ hdc = GetDC( hwnd );
+ MakeMemoryDC(hwnd, hdc );
+ ReleaseDC( hwnd, hdc );
+ }
+ printf( "resize gfx to: %d %d \n", g_gra->width, g_gra->height );
+
}
break;
case WM_DESTROY:
PostQuitMessage(0);
+ exit( 0 );
+ break;
+ case WM_PAINT:
+ {
+
+ HDC hdc = GetDC(hwnd );
+ if ( hMemDC )
+ {
+ BitBlt( hdc, 0, 0, g_gra->width , g_gra->height, hMemDC, 0, 0, SRCCOPY );
+ }
+ ReleaseDC( hwnd, hdc );
+ }
+ break;
+ case WM_MOUSEMOVE:
+ {
+ int xPos = LOWORD(lParam);
+ int yPos = HIWORD(lParam);
+ struct point pt = {xPos, yPos};
+
+ printf( "WM_MOUSEMOVE: %d %d \n", xPos, yPos );
+ (*g_gra->motion_callback)(g_gra->motion_callback_data, &pt);
+ }
+
+ break;
+ case WM_LBUTTONUP:
+ {
+ int xPos = LOWORD(lParam);
+ int yPos = HIWORD(lParam);
+
+ struct point pt = { xPos, yPos };
+
+ printf( "WM_LBUTTONUP: %d %d \n", xPos, yPos );
+ if (g_gra->button_callback )
+ {
+ struct point pt = {xPos, yPos};
+ (*g_gra->button_callback)(g_gra->button_callback_data, 0, 1, &pt);
+ }
+
+ }
+ break;
+
+ case WM_LBUTTONDOWN:
+ {
+ int xPos = LOWORD(lParam);
+ int yPos = HIWORD(lParam);
+ printf( "WM_LBUTTONDOWN: %d %d \n", xPos, yPos );
+ if (g_gra->button_callback )
+ {
+ struct point pt = {xPos, yPos};
+ (*g_gra->button_callback)(g_gra->button_callback_data, 1, 1, &pt);
+ }
+ }
+ break;
+
+ case WM_HSCROLL:
+ case WM_VSCROLL:
+ printf( "mousewheel delta %d\n", wParam );
+ break;
+ case WM_MOUSEWHEEL:
+ printf( "mousewheel delta %d\n", wParam );
+
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
wc.hIconSm = NULL;
-HANDLE hdl = gr->wnd_parent_handle;
- GetWindowRect( gr->wnd_parent_handle,&rcParent);
+ HANDLE hdl = gr->wnd_parent_handle;
+ GetClientRect( gr->wnd_parent_handle,&rcParent);
if(!RegisterClassEx(&wc))
{
ErrorExit( "Window Registration Failed!" );
- return 0;
+ return NULL;
}
- g_gra->width = rcParent.right - rcParent.left;
- g_gra->height = rcParent.bottom - rcParent.top;
+ g_gra->width = rcParent.right - rcParent.left;
+ g_gra->height = rcParent.bottom - rcParent.top;
hwnd = CreateWindow( g_szClassName,
g_gra->width,
g_gra->height,
gr->wnd_parent_handle,
- NULL,
+ (HMENU)ID_CHILD_GFX,
NULL,
NULL);
-static void
-graphics_destroy(struct graphics_priv *gr)
+static void graphics_destroy(struct graphics_priv *gr)
{
+ g_free( gr );
}
-static void
-gc_destroy(struct graphics_gc_priv *gc)
+static void gc_destroy(struct graphics_gc_priv *gc)
{
-
+ g_free( gc );
}
-static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
+static HPEN line_pen;
+
+static void gc_set_linewidth(struct graphics_gc_priv *gc, int w)
{
-// gdk_gc_set_line_attributes(gc->gc, w, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
+ gc->line_width = w;
}
-static void
-gc_set_dashes(struct graphics_gc_priv *gc, unsigned char *dash_list, int n)
+static void gc_set_dashes(struct graphics_gc_priv *gc, unsigned char *dash_list, int n)
{
// gdk_gc_set_dashes(gc->gc, 0, (gint8 *)dash_list, n);
// gdk_gc_set_line_attributes(gc->gc, 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_ROUND, GDK_JOIN_ROUND);
}
-static void
-gc_set_color(struct graphics_gc_priv *gc, struct color *c, int fg)
+
+
+static void gc_set_color(struct graphics_gc_priv *gc, struct color *c, int fg)
{
-// GdkColor gdkc;
-// gdkc.pixel=0;
-// gdkc.red=c->r;
-// gdkc.green=c->g;
-// gdkc.blue=c->b;
-// gdk_colormap_alloc_color(gc->gr->colormap, &gdkc, FALSE, TRUE);
-// if (fg)
-// gdk_gc_set_foreground(gc->gc, &gdkc);
-// else
-// gdk_gc_set_background(gc->gc, &gdkc);
+
+ gc->fg_color = RGB( c->r, c->g, c->b );
}
-static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
+static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
{
-// gc_set_color(gc, c, 1);
+ gc->fg_color = RGB( c->r, c->g, c->b );
}
static void gc_set_background(struct graphics_gc_priv *gc, struct color *c)
{
-// gc_set_color(gc, c, 0);
+ gc->bg_color = RGB( c->r, c->g, c->b );
+ if ( hMemDC )
+ SetBkColor( hMemDC, gc->bg_color );
+
}
static struct graphics_gc_methods gc_methods = {
static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
{
-// struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1);
-
+ struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1);
*meth=gc_methods;
-// gc->gc=gdk_gc_new(gr->widget->window);
-// gc->gr=gr;
- return NULL;
+ gc->hwnd = g_gra->wnd_handle;
+ gc->line_width = 1;
+ gc->fg_color = RGB( 0,0,0 );
+ gc->bg_color = RGB( 255,255,255 );
+ return gc;
}
static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
{
-
int i;
HANDLE hndl = gr->wnd_handle;
- HDC dc = GetDC( gr->wnd_handle );
+ HDC dc = hMemDC;
+
+ HPEN holdpen;
+ HPEN hpen;
+
+ hpen = CreatePen( PS_SOLID, gc->line_width, gc->fg_color );
+ holdpen = SelectObject( dc, hpen );
+
+ SetBkColor( dc, gc->bg_color );
int first = 1;
for ( i = 0; i< count; i++ )
LineTo( dc, p[i].x, p[i].y );
}
}
- ReleaseDC( gr->wnd_handle, dc );
+
+ SelectObject( dc, holdpen );
+ DeleteObject( hpen );
}
static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
{
-// if (gr->mode == draw_mode_begin || gr->mode == draw_mode_end)
-// gdk_draw_polygon(gr->drawable, gc->gc, TRUE, (GdkPoint *)p, count);
-// if (gr->mode == draw_mode_end || gr->mode == draw_mode_cursor)
-// gdk_draw_polygon(gr->widget->window, gc->gc, TRUE, (GdkPoint *)p, count);
+ //if (gr->mode == draw_mode_begin || gr->mode == draw_mode_end)
+ {
+ int i;
+ POINT points[ count ];
+ for ( i=0;i< count; i++ )
+ {
+ points[i].x = p[i].x;
+ points[i].y = p[i].y;
+ }
+ HBRUSH holdbrush;
+ HBRUSH hbrush;
+
+ SetBkColor( hMemDC, gc->bg_color );
+
+ hbrush = CreateSolidBrush( gc->fg_color );
+ holdbrush = SelectObject( hMemDC, hbrush );
+ Polygon( hMemDC, points,count );
+ SelectObject( hMemDC, holdbrush );
+ DeleteObject( hbrush );
+ }
}
+
static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
{
// gdk_draw_rectangle(gr->drawable, gc->gc, TRUE, p->x, p->y, w, h);
static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
{
+ HDC dc = hMemDC;
+
+ HPEN holdpen;
+ HPEN hpen;
+
+ hpen = CreatePen( PS_SOLID, gc->line_width, gc->fg_color );
+ holdpen = SelectObject( dc, hpen );
+
+ SetBkColor( hMemDC, gc->bg_color );
+
+ Ellipse( dc, p->x - r, p->y -r, p->x + r, p->y + r );
+
+ SelectObject( dc, holdpen );
+ DeleteObject( hpen );
+
// if (gr->mode == draw_mode_begin || gr->mode == draw_mode_end)
// gdk_draw_arc(gr->drawable, gc->gc, FALSE, p->x-r/2, p->y-r/2, r, r, 0, 64*360);
// if (gr->mode == draw_mode_end || gr->mode == draw_mode_cursor)
static void draw_restore(struct graphics_priv *gr, struct point *p, int w, int h)
{
- printf( "restore\n");
+ // AF TODO
+ printf( "draw restore \n" );
+
+ InvalidateRect( gr->wnd_handle, NULL, FALSE );
}
static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
{
+ printf( "set draw_mode to %d\n", (int)mode );
+
if ( mode == draw_mode_begin )
{
if ( gr->wnd_handle == NULL )
+ {
CreateGraphicsWindows( gr );
-
- HDC hdcScreen = GetDC( gr->wnd_handle );
-/*
- hbmScreen = CreateCompatibleBitmap(hdcScreen,
- GetDeviceCaps(hdcScreen, HORZRES),
- GetDeviceCaps(hdcScreen, VERTRES));
- */
-
+ }
}
// force paint
if (mode == draw_mode_end && gr->mode == draw_mode_begin)
{
+ InvalidateRect( gr->wnd_handle, NULL, FALSE );
}
gr->mode=mode;
static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot)
{
- return NULL;
+ struct graphics_image_priv* ret;
+
+ ret = g_new( struct graphics_image_priv, 1 );
+ printf( "loading image '%s'\n", name );
+ ret->pxpm = Xpm2bmp_new();
+ Xpm2bmp_load( ret->pxpm, name );
+ return ret;
}
+static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
+{
+ Xpm2bmp_paint( img->pxpm , hMemDC, p->x, p->y );
+}
static struct graphics_methods graphics_methods = {
graphics_destroy,
draw_rectangle,
draw_circle,
draw_text,
- NULL, // draw_image,
+ draw_image,
#ifdef HAVE_IMLIB2
NULL, // draw_image_warp,
#else
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <windows.h>
+#include <wingdi.h>
+#include "Xpm2bmp.h"
+
+// #define _DBG
+
+// function prototypes
+static int CreateBitmapFromXpm( const char* filename, PXPM2BMP pXpm2bmp );
+
+// typedefs
+static XPMCOLORENTRY theRGBRecords[] =
+{
+ {"ALICEBLUE", 240, 248, 255},
+ {"ANTIQUEWHITE", 250, 235, 215},
+ {"AQUAMARINE", 50, 191, 193},
+ {"AZURE", 240, 255, 255},
+ {"BEIGE", 245, 245, 220},
+ {"BISQUE", 255, 228, 196},
+ {"BLACK", 0, 0, 0},
+ {"BLANCHEDALMOND", 255, 235, 205},
+ {"BLUE", 0, 0, 255},
+ {"BLUEVIOLET", 138, 43, 226},
+ {"BROWN", 165, 42, 42},
+ {"BURLYWOOD", 222, 184, 135},
+ {"CADETBLUE", 95, 146, 158},
+ {"CHARTREUSE", 127, 255, 0},
+ {"CHOCOLATE", 210, 105, 30},
+ {"CORAL", 255, 114, 86},
+ {"CORNFLOWERBLUE", 34, 34, 152},
+ {"CORNSILK", 255, 248, 220},
+ {"CYAN", 0, 255, 255},
+ {"DARKGOLDENROD", 184, 134, 11},
+ {"DARKGREEN", 0, 86, 45},
+ {"DARKKHAKI", 189, 183, 107},
+ {"DARKOLIVEGREEN", 85, 86, 47},
+ {"DARKORANGE", 255, 140, 0},
+ {"DARKORCHID", 139, 32, 139},
+ {"DARKSALMON", 233, 150, 122},
+ {"DARKSEAGREEN", 143, 188, 143},
+ {"DARKSLATEBLUE", 56, 75, 102},
+ {"DARKSLATEGRAY", 47, 79, 79},
+ {"DARKTURQUOISE", 0, 166, 166},
+ {"DARKVIOLET", 148, 0, 211},
+ {"DEEPPINK", 255, 20, 147},
+ {"DEEPSKYBLUE", 0, 191, 255},
+ {"DIMGRAY", 84, 84, 84},
+ {"DODGERBLUE", 30, 144, 255},
+ {"FIREBRICK", 142, 35, 35},
+ {"FLORALWHITE", 255, 250, 240},
+ {"FORESTGREEN", 80, 159, 105},
+ {"GAINSBORO", 220, 220, 220},
+ {"GHOSTWHITE", 248, 248, 255},
+ {"GOLD", 218, 170, 0},
+ {"GOLDENROD", 239, 223, 132},
+ {"GRAY", 126, 126, 126},
+ {"GRAY0", 0, 0, 0},
+ {"GRAY1", 3, 3, 3},
+ {"GRAY10", 26, 26, 26},
+ {"GRAY100", 255, 255, 255},
+ {"GRAY11", 28, 28, 28},
+ {"GRAY12", 31, 31, 31},
+ {"GRAY13", 33, 33, 33},
+ {"GRAY14", 36, 36, 36},
+ {"GRAY15", 38, 38, 38},
+ {"GRAY16", 41, 41, 41},
+ {"GRAY17", 43, 43, 43},
+ {"GRAY18", 46, 46, 46},
+ {"GRAY19", 48, 48, 48},
+ {"GRAY2", 5, 5, 5},
+ {"GRAY20", 51, 51, 51},
+ {"GRAY21", 54, 54, 54},
+ {"GRAY22", 56, 56, 56},
+ {"GRAY23", 59, 59, 59},
+ {"GRAY24", 61, 61, 61},
+ {"GRAY25", 64, 64, 64},
+ {"GRAY26", 66, 66, 66},
+ {"GRAY27", 69, 69, 69},
+ {"GRAY28", 71, 71, 71},
+ {"GRAY29", 74, 74, 74},
+ {"GRAY3", 8, 8, 8},
+ {"GRAY30", 77, 77, 77},
+ {"GRAY31", 79, 79, 79},
+ {"GRAY32", 82, 82, 82},
+ {"GRAY33", 84, 84, 84},
+ {"GRAY34", 87, 87, 87},
+ {"GRAY35", 89, 89, 89},
+ {"GRAY36", 92, 92, 92},
+ {"GRAY37", 94, 94, 94},
+ {"GRAY38", 97, 97, 97},
+ {"GRAY39", 99, 99, 99},
+ {"GRAY4", 10, 10, 10},
+ {"GRAY40", 102, 102, 102},
+ {"GRAY41", 105, 105, 105},
+ {"GRAY42", 107, 107, 107},
+ {"GRAY43", 110, 110, 110},
+ {"GRAY44", 112, 112, 112},
+ {"GRAY45", 115, 115, 115},
+ {"GRAY46", 117, 117, 117},
+ {"GRAY47", 120, 120, 120},
+ {"GRAY48", 122, 122, 122},
+ {"GRAY49", 125, 125, 125},
+ {"GRAY5", 13, 13, 13},
+ {"GRAY50", 127, 127, 127},
+ {"GRAY51", 130, 130, 130},
+ {"GRAY52", 133, 133, 133},
+ {"GRAY53", 135, 135, 135},
+ {"GRAY54", 138, 138, 138},
+ {"GRAY55", 140, 140, 140},
+ {"GRAY56", 143, 143, 143},
+ {"GRAY57", 145, 145, 145},
+ {"GRAY58", 148, 148, 148},
+ {"GRAY59", 150, 150, 150},
+ {"GRAY6", 15, 15, 15},
+ {"GRAY60", 153, 153, 153},
+ {"GRAY61", 156, 156, 156},
+ {"GRAY62", 158, 158, 158},
+ {"GRAY63", 161, 161, 161},
+ {"GRAY64", 163, 163, 163},
+ {"GRAY65", 166, 166, 166},
+ {"GRAY66", 168, 168, 168},
+ {"GRAY67", 171, 171, 171},
+ {"GRAY68", 173, 173, 173},
+ {"GRAY69", 176, 176, 176},
+ {"GRAY7", 18, 18, 18},
+ {"GRAY70", 179, 179, 179},
+ {"GRAY71", 181, 181, 181},
+ {"GRAY72", 184, 184, 184},
+ {"GRAY73", 186, 186, 186},
+ {"GRAY74", 189, 189, 189},
+ {"GRAY75", 191, 191, 191},
+ {"GRAY76", 194, 194, 194},
+ {"GRAY77", 196, 196, 196},
+ {"GRAY78", 199, 199, 199},
+ {"GRAY79", 201, 201, 201},
+ {"GRAY8", 20, 20, 20},
+ {"GRAY80", 204, 204, 204},
+ {"GRAY81", 207, 207, 207},
+ {"GRAY82", 209, 209, 209},
+ {"GRAY83", 212, 212, 212},
+ {"GRAY84", 214, 214, 214},
+ {"GRAY85", 217, 217, 217},
+ {"GRAY86", 219, 219, 219},
+ {"GRAY87", 222, 222, 222},
+ {"GRAY88", 224, 224, 224},
+ {"GRAY89", 227, 227, 227},
+ {"GRAY9", 23, 23, 23},
+ {"GRAY90", 229, 229, 229},
+ {"GRAY91", 232, 232, 232},
+ {"GRAY92", 235, 235, 235},
+ {"GRAY93", 237, 237, 237},
+ {"GRAY94", 240, 240, 240},
+ {"GRAY95", 242, 242, 242},
+ {"GRAY96", 245, 245, 245},
+ {"GRAY97", 247, 247, 247},
+ {"GRAY98", 250, 250, 250},
+ {"GRAY99", 252, 252, 252},
+ {"GREEN", 0, 255, 0},
+ {"GREENYELLOW", 173, 255, 47},
+ {"HONEYDEW", 240, 255, 240},
+ {"HOTPINK", 255, 105, 180},
+ {"INDIANRED", 107, 57, 57},
+ {"IVORY", 255, 255, 240},
+ {"KHAKI", 179, 179, 126},
+ {"LAVENDER", 230, 230, 250},
+ {"LAVENDERBLUSH", 255, 240, 245},
+ {"LAWNGREEN", 124, 252, 0},
+ {"LEMONCHIFFON", 255, 250, 205},
+ {"LIGHTBLUE", 176, 226, 255},
+ {"LIGHTCORAL", 240, 128, 128},
+ {"LIGHTCYAN", 224, 255, 255},
+ {"LIGHTGOLDENROD", 238, 221, 130},
+ {"LIGHTGOLDENRODYELLOW", 250, 250, 210},
+ {"LIGHTGRAY", 168, 168, 168},
+ {"LIGHTPINK", 255, 182, 193},
+ {"LIGHTSALMON", 255, 160, 122},
+ {"LIGHTSEAGREEN", 32, 178, 170},
+ {"LIGHTSKYBLUE", 135, 206, 250},
+ {"LIGHTSLATEBLUE", 132, 112, 255},
+ {"LIGHTSLATEGRAY", 119, 136, 153},
+ {"LIGHTSTEELBLUE", 124, 152, 211},
+ {"LIGHTYELLOW", 255, 255, 224},
+ {"LIMEGREEN", 0, 175, 20},
+ {"LINEN", 250, 240, 230},
+ {"MAGENTA", 255, 0, 255},
+ {"MAROON", 143, 0, 82},
+ {"MEDIUMAQUAMARINE", 0, 147, 143},
+ {"MEDIUMBLUE", 50, 50, 204},
+ {"MEDIUMFORESTGREEN", 50, 129, 75},
+ {"MEDIUMGOLDENROD", 209, 193, 102},
+ {"MEDIUMORCHID", 189, 82, 189},
+ {"MEDIUMPURPLE", 147, 112, 219},
+ {"MEDIUMSEAGREEN", 52, 119, 102},
+ {"MEDIUMSLATEBLUE", 106, 106, 141},
+ {"MEDIUMSPRINGGREEN", 35, 142, 35},
+ {"MEDIUMTURQUOISE", 0, 210, 210},
+ {"MEDIUMVIOLETRED", 213, 32, 121},
+ {"MIDNIGHTBLUE", 47, 47, 100},
+ {"MINTCREAM", 245, 255, 250},
+ {"MISTYROSE", 255, 228, 225},
+ {"MOCCASIN", 255, 228, 181},
+ {"NAVAJOWHITE", 255, 222, 173},
+ {"NAVY", 35, 35, 117},
+ {"NAVYBLUE", 35, 35, 117},
+ {"OLDLACE", 253, 245, 230},
+ {"OLIVEDRAB", 107, 142, 35},
+ {"ORANGE", 255, 135, 0},
+ {"ORANGERED", 255, 69, 0},
+ {"ORCHID", 239, 132, 239},
+ {"PALEGOLDENROD", 238, 232, 170},
+ {"PALEGREEN", 115, 222, 120},
+ {"PALETURQUOISE", 175, 238, 238},
+ {"PALEVIOLETRED", 219, 112, 147},
+ {"PAPAYAWHIP", 255, 239, 213},
+ {"PEACHPUFF", 255, 218, 185},
+ {"PERU", 205, 133, 63},
+ {"PINK", 255, 181, 197},
+ {"PLUM", 197, 72, 155},
+ {"POWDERBLUE", 176, 224, 230},
+ {"PURPLE", 160, 32, 240},
+ {"RED", 255, 0, 0},
+ {"ROSYBROWN", 188, 143, 143},
+ {"ROYALBLUE", 65, 105, 225},
+ {"SADDLEBROWN", 139, 69, 19},
+ {"SALMON", 233, 150, 122},
+ {"SANDYBROWN", 244, 164, 96},
+ {"SEAGREEN", 82, 149, 132},
+ {"SEASHELL", 255, 245, 238},
+ {"SIENNA", 150, 82, 45},
+ {"SKYBLUE", 114, 159, 255},
+ {"SLATEBLUE", 126, 136, 171},
+ {"SLATEGRAY", 112, 128, 144},
+ {"SNOW", 255, 250, 250},
+ {"SPRINGGREEN", 65, 172, 65},
+ {"STEELBLUE", 84, 112, 170},
+ {"TAN", 222, 184, 135},
+ {"THISTLE", 216, 191, 216},
+ {"TOMATO", 255, 99, 71},
+ {"TRANSPARENT", 0, 0, 1},
+ {"TURQUOISE", 25, 204, 223},
+ {"VIOLET", 156, 62, 206},
+ {"VIOLETRED", 243, 62, 150},
+ {"WHEAT", 245, 222, 179},
+ {"WHITE", 255, 255, 255},
+ {"WHITESMOKE", 245, 245, 245},
+ {"YELLOW", 255, 255, 0},
+ {"YELLOWGREEN", 50, 216, 56}
+};
+
+
+PXPM2BMP Xpm2bmp_new()
+{
+ PXPM2BMP preturn = (PXPM2BMP)calloc( sizeof( XPM2BMP ) , 1 );
+ return preturn;
+}
+
+
+int Xpm2bmp_load( PXPM2BMP pXpm2bmp, const char* filename )
+{
+ return CreateBitmapFromXpm( filename, pXpm2bmp );
+}
+
+int Xpm2bmp_paint( PXPM2BMP pXpm2bmp, HDC hdc, int x1,int y1 )
+{
+ StretchDIBits(hdc,
+ x1, y1, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ 0, 0, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ pXpm2bmp->wimage_data_trans,
+ (BITMAPINFO *)pXpm2bmp->bmih_trans,
+ DIB_RGB_COLORS,
+ SRCAND );
+
+ StretchDIBits(hdc,
+ x1, y1, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ 0, 0, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ pXpm2bmp->wimage_data,
+ (BITMAPINFO *)pXpm2bmp->bmih,
+ DIB_RGB_COLORS,
+ SRCPAINT );
+
+ return 0;
+}
+
+static int parse_line_values( const char* line, PXPM2BMP pXpm2bmp )
+{
+ int return_value = 0;
+ char* parse_line = (char*)line;
+ char* tok;
+ int value_pos = 0;
+
+ parse_line = strchr( parse_line, '"' );
+ parse_line++;
+
+ tok = strtok( parse_line, " \t\n" );
+
+ while ( tok != 0 )
+ {
+ int val = atoi( tok );
+ switch ( value_pos )
+ {
+ case 0: pXpm2bmp->size_x = val; break;
+ case 1: pXpm2bmp->size_y = val; break;
+ case 2: pXpm2bmp->colors = val; break;
+ case 3: pXpm2bmp->chars_per_pixel = val; break;
+ case 4: pXpm2bmp->hotspot_x = val; break;
+ case 5: pXpm2bmp->hotspot_y = val; break;
+ }
+ tok = strtok( NULL, " \t" );
+ value_pos ++;
+
+ }
+
+ return return_value;
+}
+
+static int hex2int( char c )
+{
+ if ((c >= '0') && (c <='9' )) return c - '0';
+ if ((c >= 'A') && (c <= 'F')) return c - 'A' + 10;
+ if ((c >= 'a') && (c <= 'f')) return c - 'a' + 10;
+ return -1;
+}
+
+static DWORD string2hex16( const char* str )
+{
+ int i1 = hex2int( str[0] );
+ int i2 = hex2int( str[1] );
+ if ( ( i1 >= 0 ) && ( i2 >= 0 ) )
+ return i1*16+i2;
+ return -1;
+}
+
+static int parse_color_values( const char* line, PXPM2BMP pXpm2bmp )
+{
+ int return_value = 0;
+
+ char* cq = strchr( line, '"' );
+ char* cchar = strchr( cq+pXpm2bmp->chars_per_pixel, 'c' );
+ char* chash = strchr( cq+pXpm2bmp->chars_per_pixel, '#' );
+ char* qe = strchr( cq+pXpm2bmp->chars_per_pixel, '"' );
+
+ cq++;
+
+ if ( cq )
+ {
+ memcpy( pXpm2bmp->color_entires[ pXpm2bmp-> color_entires_size].color_str, cq, pXpm2bmp->chars_per_pixel + 1 );
+ pXpm2bmp->color_entires[ pXpm2bmp-> color_entires_size].color_str[ pXpm2bmp->chars_per_pixel ] = '\0';
+
+
+ if ( cchar && chash && qe)
+ {
+ chash++;
+ *qe = 0;
+ int len = strlen( chash );
+
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = string2hex16( &chash[0] );
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = string2hex16( &chash[len / 3] );
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = string2hex16( &chash[len * 2 / 3] );
+#ifdef _DBG
+printf( "adding color %s => %d RGB %x %x %x \n",
+ line,
+ pXpm2bmp->color_entires_size,
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r,
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g,
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b );
+#endif
+ }
+ else
+ {
+ int q;
+ char *start = cchar + 1;
+ char *end = start;
+
+ while ( *start != 0 )
+ {
+ if ( ( *start != '\t' ) && ( *start != ' ' ) )
+ {
+ break;
+ }
+ start++;
+ }
+
+ end = start;
+ while ( *end != 0 )
+ {
+ if ( ( *end == '\t' ) || ( *end == ' ' ) || ( *end == '"' ))
+ {
+ *end = 0;
+ }
+ end++;
+ }
+
+ start = _strupr( start );
+
+ for ( q=0; q < sizeof( theRGBRecords ) / sizeof( theRGBRecords[0] ); q++ )
+ {
+
+ if ( 0 == strcmp( start, theRGBRecords[q].color_str ) )
+ {
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = theRGBRecords[q].r;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = theRGBRecords[q].g;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = theRGBRecords[q].b;
+ }
+ }
+ if ( 0 == strcmp( start, "NONE" ) )
+ {
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = 255;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = 0;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = 255;
+ }
+ }
+ }
+ pXpm2bmp->color_entires_size++;
+
+ return return_value;
+}
+
+static int vv = 0;
+
+static int parse_pixel_line_values( const char* line, PXPM2BMP pXpm2bmp, unsigned char* pixel_data, unsigned char* pixel_data_trans )
+{
+ int return_value = 0;
+ int i,j;
+
+
+ char* cq = strchr( line, '"' );
+ int pix_idx = 0;
+ int size_x = pXpm2bmp->size_x;
+ int len = strlen( cq );
+
+ cq++;
+
+ if ( len > pXpm2bmp->chars_per_pixel * size_x )
+ {
+ for ( i=0; i< size_x; i++ )
+ {
+ int found = 0;
+ char* cmp = &cq[ i * pXpm2bmp->chars_per_pixel];
+
+ for ( j=0; j< pXpm2bmp-> color_entires_size; j++ )
+ {
+ if ( strncmp( cmp, pXpm2bmp->color_entires[ j ].color_str, pXpm2bmp->chars_per_pixel ) == 0 )
+ {
+ int r = pXpm2bmp->color_entires[ j ].r;
+ int g = pXpm2bmp->color_entires[ j ].g;
+ int b = pXpm2bmp->color_entires[ j ].b;
+
+ if ( ( r == 255 ) && ( g == 0 ) && ( r == 255 ) )
+ {
+ r=g=b=0;
+ pixel_data_trans[ pix_idx ] = 255;
+ pixel_data_trans[ pix_idx+1 ] = 255;
+ pixel_data_trans[ pix_idx+2 ] = 255;
+ }
+ else
+ {
+ pixel_data_trans[ pix_idx ] = 0;
+ pixel_data_trans[ pix_idx+1 ] = 0;
+ pixel_data_trans[ pix_idx+2 ] = 0;
+ }
+
+ // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].r;
+ // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].g;
+ // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].b;
+ pixel_data[ pix_idx++ ] = b;
+ pixel_data[ pix_idx++ ] = g;
+ pixel_data[ pix_idx++ ] = r;
+ found = 1;
+ vv++;
+ break;
+ }
+ }
+ if ( !found )
+ {
+ fprintf( stderr, "XPMLIB: error color not found\n" );
+ }
+
+ }
+ }
+ else
+ {
+ return_value = -1;
+ fprintf( stderr, "XPMLIB: invalid line length\n" );
+ }
+ return return_value;
+}
+
+
+static int CreateBitmapFromXpm( const char* filename, PXPM2BMP pXpm2bmp )
+{
+ int return_val = 0;
+ unsigned char i, row;
+ char line[ 1024 ];
+ int nbytes ;
+ FILE* file_xpm = fopen( filename, "r" );
+
+ int phase = 0;
+ row = 0;
+
+ if ( file_xpm )
+ {
+ while ( fgets(line, sizeof( line ), file_xpm ) )
+ {
+#ifdef _DBG
+ printf( "PARSING: %s\n", line );
+#endif
+ if ( line[ 0 ] != '"' )
+ continue;
+
+ switch ( phase )
+ {
+ case 0:
+ parse_line_values( line, pXpm2bmp );
+#ifdef _DBG
+ printf( "size_x %d\n", pXpm2bmp->size_x );
+ printf( "size_y %d\n", pXpm2bmp->size_y );
+#endif
+ phase = 1;
+
+ pXpm2bmp->color_entires_size = 0;
+ nbytes = ( pXpm2bmp->chars_per_pixel + 1 ) * pXpm2bmp->colors;
+
+ pXpm2bmp->color_entires = calloc( sizeof( XPMCOLORENTRY ), pXpm2bmp->colors + 100 );
+ pXpm2bmp->color_entires[0].color_str = calloc( nbytes, pXpm2bmp->colors );
+ for ( i = 1; i< pXpm2bmp->colors; i++ )
+ {
+ pXpm2bmp->color_entires[i].color_str = pXpm2bmp->color_entires[0].color_str + ( pXpm2bmp->chars_per_pixel + 1 ) * i;
+ }
+
+ if (!(pXpm2bmp->dib = (unsigned char *)malloc(sizeof(BITMAPINFOHEADER) + pXpm2bmp->size_x * pXpm2bmp->size_y * 3)))
+ {
+ return 4;
+ }
+ if (!(pXpm2bmp->dib_trans = (unsigned char *)calloc(sizeof(BITMAPINFOHEADER) + pXpm2bmp->size_x * pXpm2bmp->size_y * 3,1)))
+ {
+ return 4;
+ }
+
+ memset(pXpm2bmp->dib, 0, sizeof(BITMAPINFOHEADER));
+ pXpm2bmp->bmih = (BITMAPINFOHEADER *)pXpm2bmp->dib;
+ pXpm2bmp->bmih->biSize = sizeof(BITMAPINFOHEADER);
+ pXpm2bmp->bmih->biWidth = pXpm2bmp->size_x;
+ pXpm2bmp->bmih->biHeight = -((long)pXpm2bmp->size_y);
+ pXpm2bmp->bmih->biPlanes = 1;
+ pXpm2bmp->bmih->biBitCount = 24;
+ pXpm2bmp->bmih->biCompression = 0;
+ pXpm2bmp->wimage_data = pXpm2bmp->dib + sizeof(BITMAPINFOHEADER);
+
+
+ pXpm2bmp->bmih_trans = (BITMAPINFOHEADER *)pXpm2bmp->dib_trans;
+ pXpm2bmp->bmih_trans->biSize = sizeof(BITMAPINFOHEADER);
+ pXpm2bmp->bmih_trans->biWidth = pXpm2bmp->size_x;
+ pXpm2bmp->bmih_trans->biHeight = -((long)pXpm2bmp->size_y);
+ pXpm2bmp->bmih_trans->biPlanes = 1;
+ pXpm2bmp->bmih_trans->biBitCount = 24;
+ pXpm2bmp->bmih_trans->biCompression = 0;
+ pXpm2bmp->wimage_data_trans = pXpm2bmp->dib_trans + sizeof(BITMAPINFOHEADER);
+// memset( pXpm2bmp->wimage_data_trans, 255, 5* 22 * 3 );
+
+ break;
+ case 1:
+ parse_color_values( line, pXpm2bmp );
+ if ( pXpm2bmp->color_entires_size >= pXpm2bmp->colors )
+ {
+ phase = 2;
+ }
+
+ break;
+ case 2:
+ parse_pixel_line_values( line, pXpm2bmp,
+ pXpm2bmp->wimage_data + row * pXpm2bmp->size_x * 3,
+ pXpm2bmp->wimage_data_trans + row * pXpm2bmp->size_x * 3 );
+
+ row++;
+ if ( row >= pXpm2bmp->size_y )
+ {
+ phase = 3;
+ }
+ break;
+ }
+
+ }
+
+ fclose( file_xpm );
+ }
+ return return_val;
+}