From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.213.13.12 with SMTP id z12cs1155598ebz; Sun, 3 Jan 2010 07:36:51 -0800 (PST) Received: by 10.224.64.134 with SMTP id e6mr2156600qai.30.1262533010297; Sun, 03 Jan 2010 07:36:50 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 42si18914885qyk.40.2010.01.03.07.36.49; Sun, 03 Jan 2010 07:36:50 -0800 (PST) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id BB92D19782D9; Sun, 3 Jan 2010 10:36:49 -0500 (EST) Received: from magnesium.club.cc.cmu.edu (MAGNESIUM.CLUB.CC.cmu.edu [128.237.157.15]) by rubyforge.org (Postfix) with ESMTP id 873C515B8030 for ; Sun, 3 Jan 2010 10:33:44 -0500 (EST) Received: (qmail 30737 invoked from network); 3 Jan 2010 15:33:44 -0000 Received: from pion.club.cc.cmu.edu (HELO localhost.localdomain) (128.237.157.88) by magnesium.club.cc.cmu.edu with SMTP; 3 Jan 2010 15:33:44 -0000 From: Rich Lane To: sup-devel@rubyforge.org Date: Sun, 3 Jan 2010 07:33:28 -0800 Message-Id: <1262532808-19401-1-git-send-email-rlane@club.cc.cmu.edu> X-Mailer: git-send-email 1.6.3.3 Subject: [sup-devel] [PATCH] add a mouse-enabled colorpicker to contrib X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org Intended to make colorscheme creation easier. --- contrib/colorpicker.rb | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 104 insertions(+), 0 deletions(-) create mode 100644 contrib/colorpicker.rb diff --git a/contrib/colorpicker.rb b/contrib/colorpicker.rb new file mode 100644 index 0000000..c981a23 --- /dev/null +++ b/contrib/colorpicker.rb @@ -0,0 +1,104 @@ +require 'rubygems' + +begin + require 'ncursesw' +rescue LoadError + require 'ncurses' +end + +Ncurses.initscr +Ncurses.noecho +Ncurses.cbreak +Ncurses.start_color + +Ncurses.curs_set 0 +Ncurses.move 0, 0 +Ncurses.clear +Ncurses.refresh +cc = Ncurses.COLORS + +Ncurses::keypad(Ncurses::stdscr, 1) +Ncurses::mousemask(Ncurses::ALL_MOUSE_EVENTS | Ncurses::REPORT_MOUSE_POSITION, []) + +fail "color count is #{cc}, expected 256" unless cc == 256 + +1.upto(255) do |c| + Ncurses.init_pair(c, 0, c) +end + +def cell y, x, c + @map[[y,x]] = c + Ncurses.attron(Ncurses.COLOR_PAIR(c)) + Ncurses.mvaddstr(y, x, " ") + Ncurses.attroff(Ncurses.COLOR_PAIR(c)) +end + +def handle_click y, x + c = @map[[y,x]] or return + name = case c + when 0...16 + c.to_s + when 16...232 + 'c' + (c-16).to_s(6).rjust(3,'0') + when 232...256 + 'g' + (c-232).to_s + end + + Ncurses.mvaddstr 11, 0, "#{name} " + + Ncurses.attron(Ncurses.COLOR_PAIR(c)) + 10.times do |i| + 20.times do |j| + y = 13 + i + x = j + Ncurses.mvaddstr(y, x, " ") + end + end + Ncurses.attroff(Ncurses.COLOR_PAIR(c)) +end + +@map = {} +@fg = @bg = 0 + +begin + 16.times do |i| + cell 0, i, i + end + + 6.times do |i| + 6.times do |j| + 6.times do |k| + c = 16 + 6*6*i + 6*j + k + y = 2 + j + x = 7*i + k + cell y, x, c + end + end + end + + 16.times do |i| + c = 16 + 6*6*6 + i + cell 9, i, c + end + + handle_click 0, 0 + Ncurses.refresh + + while (c = Ncurses.getch) + case c + when 113 #q + break + when Ncurses::KEY_MOUSE + mev = Ncurses::MEVENT.new + Ncurses.getmouse(mev) + case(mev.bstate) + when Ncurses::BUTTON1_CLICKED + handle_click mev.y, mev.x + end + end + Ncurses.refresh + end + +ensure + Ncurses.endwin +end -- 1.6.3.3 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel