⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sys-graphics.zc

📁 实现树形结构
💻 ZC
字号:
//[of]:description
//[c]Private part of the implementation of the graphics classes
//[cf]
//[of]:license
//[c]Code Browser - a folding text editor for programmers
//[c]Copyright (C) 2003-07 Marc Kerbiquet
//[c]
//[c]This program is free software; you can redistribute it and/or modify
//[c]it under the terms of the GNU General Public License as published by
//[c]the Free Software Foundation; either version 2 of the License, or
//[c](at your option) any later version.
//[c]
//[c]This program is distributed in the hope that it will be useful,
//[c]but WITHOUT ANY WARRANTY; without even the implied warranty of
//[c]MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//[c]GNU General Public License for more details.
//[c]
//[c]You should have received a copy of the GNU General Public License
//[c]along with this program; if not, write to the Free Software
//[c]Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//[cf]
//[of]:imports
import "base/types"
import "base/memory-allocator"
import "text/string"
import "text/string-buffer"
//[c]
import "glib/glib"
import "glib/glib-object"
import "gdk/gdk"
import "gtk/gtk"
import "pango/pango"
//[cf]
//[c]
//[of]:point
public struct point : local GdkPoint
	// same as GdkPoint
end

public equ x (p:point) = x (super (p)) 
public equ y (p:point) = y (super (p))
//[cf]
//[of]:rectangle
public struct rectangle : local GdkRectangle
	// same as GdkRectangle
end

public equ x (r: rectangle) = x (super (r)) 
public equ y (r: rectangle) = y (super (r))
public equ w (r: rectangle) = width (super (r))
public equ h (r: rectangle) = height (super (r))
//[cf]
//[c]
//[of]:sys font
//[c]
public struct sys font
	public id : GdkFont

	// Pango
	public desc : PangoFontDescription
end
//[c]
public equ is pango font (m: sys font) = not nil (desc (m))
//[cf]
//[of]:sys cursor
//[c]
public struct sys cursor
	public id : GdkCursor
end
//[cf]
//[of]:sys brush
//[c]
public struct sys brush
	pixmap : GdkPixmap
end
//[cf]
//[of]:sys canvas
//[c]
public struct sys canvas

	public drawable : GdkDrawable
	public gc : GdkGC
	public context : PangoContext
	public layout : PangoLayout
	public the font : sys font
	public back color : local GdkColor
	public text color : local GdkColor

end
//[c]
public func initialize (m: sys canvas, drawable: GdkDrawable, gc: GdkGC, w: GtkWidget)

	drawable (m) = drawable
	gc (m) = gc
	def context = gtk_widget_create_pango_context (w)
	context (m) = context
	layout (m) = pango_layout_new (context)
	the font (m) = nil

end
//[c]
//[c]
public func initialize (m: sys canvas, w: GtkWidget)
	initialize (m, nil, nil, w)
end
//[c]
public func release (m: sys canvas)
	g_object_unref (layout (m))
	g_object_unref (context (m))
end
//[cf]
//[of]:utility functions
//[of]:to UTF8 (string)
//[c]Convert a locale string to UTF8
//[c]
//[c]If the current locale is UTF8, iso8859-1 is used instead.
//[c]
public func to UTF8 (str: string)
	return to UTF8 (str, -1, nil)
end
//[cf]
//[of]:to UTF8 (string, size, out size)
//[c]Convert a locale string to UTF8
//[c]
//[c]If the current locale is UTF8, iso8859-1 is used instead.
//[c]
public func to UTF8 (str: string, len: dword, bytes : [] gsize)

	def s: string
	def charset: [1] string
	// the current locale is not UTF8 ?
	if g_get_charset (charset) <> TRUE
		s = g_locale_to_utf8 (str, len:int:gssize, nil, bytes, nil)
		if not nil (s)
			return s
		end
		// conversion has failed: try conversion iso8859-1 to UTF-8
	end

	s = g_convert (str, len:int:gssize, "UTF-8", "iso8859-1", nil, bytes, nil)
	if is nil (s)
		// conversion has failed: return source string
		return str
	end
	return s

end
//[cf]
//[of]:from UTF8 (string)
//[c]
public func from UTF8 (str: string)
	return from UTF8 (str, -1, nil)
end
//[cf]
//[of]:from UTF8 (string, size, out size)
//[c]
public func from UTF8 (str: string, len: dword, bytes : [] gsize)

	// UTF-8 is not supported, so if the charset is UTF-8,
	// the application automatically convert it to latin-1.
	def s: string
	def charset: [1] string
	if g_get_charset (charset) <> TRUE
		s = g_locale_from_utf8 (str, len:int:gssize, nil, bytes, nil)
		if not nil (s)
			// conversion has failed: return source string
			return s
		end
	end

	s = g_convert (str, len:int:gssize, "iso8859-1", "UTF-8", nil, bytes, nil)
	if is nil (s)
		// conversion has failed: return source string
		return str
	end
	return s

end
//[cf]
//[cf]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -